Permalink
Browse files

add auth support

  • Loading branch information...
1 parent 2ff31ad commit 1566e19e23425284968739c4d5af7c5eb320ba86 @poiati committed Jan 26, 2014
Showing with 45 additions and 18 deletions.
  1. +3 −3 build.gradle
  2. +42 −10 src/main/groovy/com/gmongo/GMongoClient.groovy
  3. +0 −5 src/test/groovy/com/gmongo/GMongoClientTest.groovy
View
@@ -3,14 +3,14 @@ apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'signing'
-version = '1.2'
+version = '1.3'
project.ext {
group = 'com.gmongo'
artifact = 'gmongo'
bundleDir = "$buildDir/bundle"
- groovyVersion = "2.1.3"
+ groovyVersion = "2.2.1"
}
repositories {
@@ -20,7 +20,7 @@ repositories {
dependencies {
groovy group: 'org.codehaus.groovy', name: 'groovy', version: project.ext.groovyVersion
groovy group: 'org.codehaus.groovy', name: 'groovy-ant', version: project.ext.groovyVersion
- compile group: 'org.mongodb', name: 'mongo-java-driver', version: '2.11.1'
+ compile group: 'org.mongodb', name: 'mongo-java-driver', version: '2.11.3'
testCompile group: 'org.codehaus.groovy', name: 'groovy-test', version: project.ext.groovyVersion
testCompile group: 'junit', name: 'junit', version: '4.10'
@@ -20,43 +20,75 @@ import com.mongodb.MongoOptions
import com.mongodb.MongoURI
import com.mongodb.MongoClientURI
import com.mongodb.MongoClientOptions
+import com.mongodb.MongoCredential
+import com.mongodb.MongoClient
+import com.mongodb.DB
-class GMongoClient extends GMongo {
+import com.gmongo.internal.DBPatcher
+
+class GMongoClient {
+
+ @Delegate
+ MongoClient mongoClient;
GMongoClient() {
- this(new ServerAddress())
+ this.mongoClient = new MongoClient(new ServerAddress())
}
GMongoClient(String host) {
- this(new ServerAddress(host))
+ this.mongoClient = new MongoClient(new ServerAddress(host))
}
GMongoClient(String host, MongoClientOptions options) {
- this(new ServerAddress(host), options);
+ this.mongoClient = new MongoClient(new ServerAddress(host), options)
}
GMongoClient(String host, int port) {
- this(new ServerAddress(host, port));
+ this.mongoClient = new MongoClient(new ServerAddress(host, port));
}
GMongoClient(ServerAddress addr) {
- this(addr, new MongoClientOptions.Builder().build());
+ this.mongoClient = new MongoClient(addr, new MongoClientOptions.Builder().build());
}
GMongoClient(ServerAddress addr, MongoClientOptions options) {
- super(addr, new MongoOptions(options));
+ this.mongoClient = new MongoClient(addr, new MongoOptions(options));
}
GMongoClient(List<ServerAddress> seeds) {
- this(seeds, new MongoClientOptions.Builder().build());
+ this.mongoClient = new MongoClient(seeds, new MongoClientOptions.Builder().build());
+ }
+
+ GMongoClient(List<ServerAddress> seeds, List<MongoCredential> credentialsList) {
+ this.mongoClient = new MongoClient(seeds, credentialsList);
+ }
+
+ GMongoClient(List<ServerAddress> seeds, List<MongoCredential> credentialsList, MongoClientOptions options) {
+ this.mongoClient = new MongoClient(seeds, credentialsList, options);
}
GMongoClient(List<ServerAddress> seeds, MongoClientOptions options) {
- super(seeds, new MongoOptions(options));
+ this.mongoClient = new MongoClient(seeds, new MongoOptions(options));
}
GMongoClient(MongoClientURI uri) {
- super(new MongoURI(uri));
+ this.mongoClient = new MongoClient(uri);
+ }
+
+ GMongoClient(ServerAddress addr, List<MongoCredential> credentialsList) {
+ this.mongoClient = new MongoClient(addr, credentialsList);
+ }
+
+ GMongoClient(ServerAddress addr, List<MongoCredential> credentialsList, MongoClientOptions options) {
+ this.mongoClient = new MongoClient(addr, credentialsList, options);
+ }
+
+ DB getDB(String name) {
+ patchAndReturn mongoClient.getDB(name)
+ }
+
+ static private patchAndReturn(db) {
+ DBPatcher.patch(db); return db
}
}
@@ -24,11 +24,6 @@ class GMongoClientTest extends IntegrationTestCase {
assert db.hasProperty(Patcher.PATCH_MARK)
}
- void testStaticConnect() {
- def db2 = GMongoClient.connect(new DBAddress('localhost', 27017, DB_NAME))
- assert db2.hasProperty(Patcher.PATCH_MARK)
- }
-
void testMongoURIConstructor() {
def mongo = new GMongoClient(new MongoClientURI('mongodb://127.0.0.1'))
assert mongo.getDB(DB_NAME).hasProperty(Patcher.PATCH_MARK)

0 comments on commit 1566e19

Please sign in to comment.