You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by se...@apache.org on 2019/07/11 00:43:56 UTC
[calcite] branch master updated: Fix complitation warnings after
mongo java driver upgrade
This is an automated email from the ASF dual-hosted git repository.
sereda pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push:
new fe2b59b Fix complitation warnings after mongo java driver upgrade
fe2b59b is described below
commit fe2b59b82facad4d4e86eb4fa4080513b5dfe541
Author: Andrei Sereda <25...@users.noreply.github.com>
AuthorDate: Wed Jul 10 20:25:15 2019 -0400
Fix complitation warnings after mongo java driver upgrade
Some methods were deprecated after client upgrade to 3.10.2 (see [CALCITE-3157])
---
.../apache/calcite/adapter/mongodb/MongoSchema.java | 10 +++++-----
.../calcite/adapter/mongodb/MongoSchemaFactory.java | 19 +++++++++----------
.../calcite/adapter/mongodb/MongoAdapterTest.java | 4 ++--
3 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchema.java b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchema.java
index db00445..3faef9f 100644
--- a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchema.java
+++ b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchema.java
@@ -27,7 +27,6 @@ import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoDatabase;
-import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -42,16 +41,17 @@ public class MongoSchema extends AbstractSchema {
* Creates a MongoDB schema.
*
* @param host Mongo host, e.g. "localhost"
- * @param credentialsList Optional credentials (empty list for none)
+ * @param credential Optional credentials (null for none)
* @param options Mongo connection options
* @param database Mongo database name, e.g. "foodmart"
*/
MongoSchema(String host, String database,
- List<MongoCredential> credentialsList, MongoClientOptions options) {
+ MongoCredential credential, MongoClientOptions options) {
super();
try {
- final MongoClient mongo =
- new MongoClient(new ServerAddress(host), credentialsList, options);
+ final MongoClient mongo = credential == null
+ ? new MongoClient(new ServerAddress(host), options)
+ : new MongoClient(new ServerAddress(host), credential, options);
this.mongoDb = mongo.getDatabase(database);
} catch (Exception e) {
throw new RuntimeException(e);
diff --git a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchemaFactory.java b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchemaFactory.java
index 1d8ce74..21ba0b6 100644
--- a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchemaFactory.java
+++ b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchemaFactory.java
@@ -24,8 +24,6 @@ import com.mongodb.AuthenticationMechanism;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredential;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Map;
/**
@@ -46,16 +44,17 @@ public class MongoSchemaFactory implements SchemaFactory {
final MongoClientOptions.Builder options = MongoClientOptions.builder();
- final List<MongoCredential> credentials = new ArrayList<>();
+ final MongoCredential credential;
if (authMechanismName != null) {
- final MongoCredential credential = createCredentials(operand);
- credentials.add(credential);
+ credential = createCredential(operand);
+ } else {
+ credential = null;
}
- return new MongoSchema(host, database, credentials, options.build());
+ return new MongoSchema(host, database, credential, options.build());
}
- private MongoCredential createCredentials(Map<String, Object> map) {
+ private MongoCredential createCredential(Map<String, Object> map) {
final String authMechanismName = (String) map.get("authMechanism");
final AuthenticationMechanism authenticationMechanism =
AuthenticationMechanism.fromMechanismName(authMechanismName);
@@ -70,11 +69,11 @@ public class MongoSchemaFactory implements SchemaFactory {
case SCRAM_SHA_1:
return MongoCredential.createScramSha1Credential(username, authDatabase,
password.toCharArray());
+ case SCRAM_SHA_256:
+ return MongoCredential.createScramSha256Credential(username, authDatabase,
+ password.toCharArray());
case GSSAPI:
return MongoCredential.createGSSAPICredential(username);
- case MONGODB_CR:
- return MongoCredential.createMongoCRCredential(username, authDatabase,
- password.toCharArray());
case MONGODB_X509:
return MongoCredential.createMongoX509Credential(username);
}
diff --git a/mongodb/src/test/java/org/apache/calcite/adapter/mongodb/MongoAdapterTest.java b/mongodb/src/test/java/org/apache/calcite/adapter/mongodb/MongoAdapterTest.java
index 6f843df..31fb74a 100644
--- a/mongodb/src/test/java/org/apache/calcite/adapter/mongodb/MongoAdapterTest.java
+++ b/mongodb/src/test/java/org/apache/calcite/adapter/mongodb/MongoAdapterTest.java
@@ -94,7 +94,7 @@ public class MongoAdapterTest implements SchemaFactory {
// Manually insert data for data-time test.
MongoCollection<BsonDocument> datatypes = database.getCollection("datatypes")
.withDocumentClass(BsonDocument.class);
- if (datatypes.count() > 0) {
+ if (datatypes.countDocuments() > 0) {
datatypes.deleteMany(new BsonDocument());
}
@@ -112,7 +112,7 @@ public class MongoAdapterTest implements SchemaFactory {
throws IOException {
Objects.requireNonNull(collection, "collection");
- if (collection.count() > 0) {
+ if (collection.countDocuments() > 0) {
// delete any existing documents (run from a clean set)
collection.deleteMany(new BsonDocument());
}