Skip to content

Commit

Permalink
Adding mongo driver information
Browse files Browse the repository at this point in the history
  • Loading branch information
affonsov committed Nov 4, 2022
1 parent f1b1a60 commit 6d14e9e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import software.amazon.documentdb.jdbc.common.utilities.SqlError;
import software.amazon.documentdb.jdbc.common.utilities.SqlState;
import software.amazon.documentdb.jdbc.metadata.DocumentDbDatabaseSchemaMetadata;
import software.amazon.documentdb.jdbc.query.DocumentDBDriverInformation;

import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -304,7 +305,8 @@ private void initializeClients(final DocumentDbConnectionProperties connectionPr
// Create the mongo client.
final MongoClientSettings settings = connectionProperties
.buildMongoClientSettings(getSshLocalPort());
mongoClient = MongoClients.create(settings);
mongoClient = MongoClients.create(settings,
DocumentDBDriverInformation.getMongoDriverInformation(connectionProperties));
mongoDatabase = mongoClient.getDatabase(connectionProperties.getDatabase());
pingDatabase();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import software.amazon.documentdb.jdbc.metadata.DocumentDbSchemaColumn;
import software.amazon.documentdb.jdbc.metadata.DocumentDbSchemaTable;
import software.amazon.documentdb.jdbc.persist.DocumentDbSchemaSecurityException;
import software.amazon.documentdb.jdbc.query.DocumentDBDriverInformation;

import java.io.Console;
import java.io.File;
Expand Down Expand Up @@ -393,7 +394,8 @@ private static void performCommand(

private static MongoClient getMongoClient(final DocumentDbConnectionProperties properties) {
if (client == null) {
client = MongoClients.create(properties.buildMongoClientSettings());
client = MongoClients.create(properties.buildMongoClientSettings(),
DocumentDBDriverInformation.getMongoDriverInformation(properties));
}
return client;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import software.amazon.documentdb.jdbc.common.utilities.JdbcColumnMetaData;
import software.amazon.documentdb.jdbc.common.utilities.SqlError;
import software.amazon.documentdb.jdbc.common.utilities.SqlState;
import software.amazon.documentdb.jdbc.query.DocumentDBDriverInformation;
import software.amazon.documentdb.jdbc.query.DocumentDbMqlQueryContext;
import software.amazon.documentdb.jdbc.query.DocumentDbQueryMappingService;

Expand Down Expand Up @@ -222,7 +223,8 @@ private void resetQueryState() {

private void performCancel() throws SQLException {
final MongoClientSettings settings = connectionProperties.buildMongoClientSettings();
try (MongoClient client = MongoClients.create(settings)) {
try (MongoClient client = MongoClients.create(settings,
DocumentDBDriverInformation.getMongoDriverInformation(connectionProperties))) {
final MongoDatabase database = client.getDatabase("admin");

// Find the opId to kill using the queryId.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import software.amazon.documentdb.jdbc.persist.DocumentDbSchemaReader;
import software.amazon.documentdb.jdbc.persist.DocumentDbSchemaSecurityException;
import software.amazon.documentdb.jdbc.persist.DocumentDbSchemaWriter;
import software.amazon.documentdb.jdbc.query.DocumentDBDriverInformation;

import javax.annotation.Nullable;
import java.sql.SQLException;
Expand Down Expand Up @@ -390,7 +391,7 @@ private static DocumentDbSchema getCollectionMetadataDirect(
final MongoClientSettings settings = properties.buildMongoClientSettings();
final MongoClient mongoClient = client != null
? client
: MongoClients.create(settings);
: MongoClients.create(settings, DocumentDBDriverInformation.getMongoDriverInformation(properties));
try {
final MongoDatabase database = mongoClient.getDatabase(databaseName);
for (String collectionName : getFilteredCollectionNames(database)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import software.amazon.documentdb.jdbc.metadata.DocumentDbSchema;
import software.amazon.documentdb.jdbc.metadata.DocumentDbSchemaColumn;
import software.amazon.documentdb.jdbc.metadata.DocumentDbSchemaTable;
import software.amazon.documentdb.jdbc.query.DocumentDBDriverInformation;

import javax.annotation.Nullable;
import java.sql.SQLException;
Expand Down Expand Up @@ -87,7 +88,8 @@ public DocumentDbSchemaReader(final @NonNull DocumentDbConnectionProperties prop
this.properties = properties;
this.client = client != null
? client
: MongoClients.create(properties.buildMongoClientSettings());
: MongoClients.create(properties.buildMongoClientSettings(),
DocumentDBDriverInformation.getMongoDriverInformation(properties));
this.closeClient = client == null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import software.amazon.documentdb.jdbc.metadata.DocumentDbSchema;
import software.amazon.documentdb.jdbc.metadata.DocumentDbSchemaColumn;
import software.amazon.documentdb.jdbc.metadata.DocumentDbSchemaTable;
import software.amazon.documentdb.jdbc.query.DocumentDBDriverInformation;

import java.sql.SQLException;
import java.time.Instant;
Expand Down Expand Up @@ -87,7 +88,8 @@ public DocumentDbSchemaWriter(final @NonNull DocumentDbConnectionProperties prop
this.properties = properties;
this.client = client != null
? client
: MongoClients.create(properties.buildMongoClientSettings());
: MongoClients.create(properties.buildMongoClientSettings(),
DocumentDBDriverInformation.getMongoDriverInformation(properties));
this.closeClient = client == null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import software.amazon.documentdb.jdbc.common.test.DocumentDbFlapDoodleTest;
import software.amazon.documentdb.jdbc.common.utilities.JdbcColumnMetaData;
import software.amazon.documentdb.jdbc.persist.DocumentDbSchemaWriter;
import software.amazon.documentdb.jdbc.query.DocumentDBDriverInformation;
import software.amazon.documentdb.jdbc.query.DocumentDbQueryMappingService;

import java.sql.ResultSet;
Expand Down Expand Up @@ -322,7 +323,8 @@ private static class MockQueryExecutor extends DocumentDbQueryExecutor {
@Override
protected java.sql.ResultSet runQuery(final String sql) throws SQLException {
final MongoClientSettings settings = VALID_CONNECTION_PROPERTIES.buildMongoClientSettings();
try (MongoClient client = MongoClients.create(settings)) {
try (MongoClient client = MongoClients.create(settings,
DocumentDBDriverInformation.getMongoDriverInformation(VALID_CONNECTION_PROPERTIES))) {
final MongoDatabase database =
client.getDatabase(VALID_CONNECTION_PROPERTIES.getDatabase());
final MongoCollection<Document> collection = database.getCollection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import software.amazon.documentdb.jdbc.DocumentDbConnectionProperties;
import software.amazon.documentdb.jdbc.DocumentDbConnectionProperty;
import software.amazon.documentdb.jdbc.DocumentDbMetadataScanMethod;
import software.amazon.documentdb.jdbc.query.DocumentDBDriverInformation;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
Expand Down Expand Up @@ -212,9 +213,10 @@ public String newCollectionName(final boolean isTemporary) {

@Override
public MongoClient createMongoClient() throws SQLException {
return MongoClients.create(DocumentDbConnectionProperties
.getPropertiesFromConnectionString(getJdbcConnectionString())
.buildMongoClientSettings());
DocumentDbConnectionProperties properties = DocumentDbConnectionProperties
.getPropertiesFromConnectionString(getJdbcConnectionString());
return MongoClients.create(properties
.buildMongoClientSettings(), DocumentDBDriverInformation.getMongoDriverInformation(properties));
}

@Override
Expand Down

0 comments on commit 6d14e9e

Please sign in to comment.