Skip to content

Commit

Permalink
18: add logger message for connection established time (#19)
Browse files Browse the repository at this point in the history
* 18: add logger message for connection established time to RemoteConnectionFactory
  • Loading branch information
AnastasiiaSergienko authored Jan 23, 2020
1 parent b653176 commit 3508582
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<description>Common module for JDBC-based data access from Virtual Schemas.</description>
<url>https://github.com/exasol/virtual-schema-common-jdbc</url>
<properties>
<product.version>2.0.1</product.version>
<product.version>2.1.0</product.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
Expand Down Expand Up @@ -229,10 +229,10 @@
<goal>test-jar</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*Test.class</exclude>
<exclude>**/*IT.class</exclude>
</excludes>
<excludes>
<exclude>**/*Test.class</exclude>
<exclude>**/*IT.class</exclude>
</excludes>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public Connection createConnection(final ExaMetadata exaMetadata, final AdapterP
private Connection createConnectionWithUserCredentials(final String username, final String password,
final String connectionString) throws SQLException {
logConnectionAttempt(username, password);
final long start = System.currentTimeMillis();
final Connection connection = DriverManager.getConnection(connectionString, username, password);
logRemoteDatabaseDetails(connection);
logRemoteDatabaseDetails(connection, System.currentTimeMillis() - start);
return connection;
}

Expand All @@ -46,10 +47,10 @@ protected void logConnectionAttempt(final String address, final String username)
() -> "Connecting to \"" + address + "\" as user \"" + username + "\" using password authentication.");
}

protected void logRemoteDatabaseDetails(final Connection connection) throws SQLException {
protected void logRemoteDatabaseDetails(final Connection connection, final long connectionTime) throws SQLException {
final String databaseProductName = connection.getMetaData().getDatabaseProductName();
final String databaseProductVersion = connection.getMetaData().getDatabaseProductVersion();
LOGGER.info(() -> "Connected to " + databaseProductName + " " + databaseProductVersion);
LOGGER.info(() -> "Connected to " + databaseProductName + " " + databaseProductVersion + " in " + connectionTime + " milliseconds.");
}

private Connection createConnection(final String connectionName, final ExaMetadata exaMetadata)
Expand Down Expand Up @@ -78,8 +79,9 @@ private Connection establishConnectionWithKerberos(final String password, final
jdbcProperties.put("password", password);
final KerberosConfigurationCreator kerberosConfigurationCreator = new KerberosConfigurationCreator();
kerberosConfigurationCreator.writeKerberosConfigurationFiles(username, password);
final long start = System.currentTimeMillis();
final Connection connection = DriverManager.getConnection(address, jdbcProperties);
logRemoteDatabaseDetails(connection);
logRemoteDatabaseDetails(connection, System.currentTimeMillis() - start);
return connection;
}

Expand All @@ -91,8 +93,9 @@ private void logConnectionAttemptWithKerberos(final String address, final String
private Connection establishConnectionWithRegularCredentials(final String password, final String username,
final String address) throws SQLException {
logConnectionAttempt(address, username);
final long start = System.currentTimeMillis();
final Connection connection = DriverManager.getConnection(address, username, password);
logRemoteDatabaseDetails(connection);
logRemoteDatabaseDetails(connection, System.currentTimeMillis() - start);
return connection;
}
}
}

0 comments on commit 3508582

Please sign in to comment.