Skip to content

Commit

Permalink
adapt logs
Browse files Browse the repository at this point in the history
  • Loading branch information
YotillaAntoni committed Jan 14, 2025
1 parent b1ec1b3 commit 143df5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,26 @@ public DriverConnectionFactory(
public Connection openConnection(ConnectorSession session)
throws SQLException
{
log.info("Open connection " + COUNTER.incrementAndGet());
log.info("Driver open connection " + COUNTER.incrementAndGet());
Properties properties = getCredentialProperties(session.getIdentity());
Connection connection = dataSource.getConnection(properties);
checkState(connection != null, "Driver returned null connection, make sure the connection URL '%s' is valid for the driver %s", connectionUrl, driver);
return connection;

return new ForwardingConnection() {
@Override
protected Connection delegate() throws SQLException {
return connection;
}

@Override
public void close() throws SQLException {
try {
connection.close();
} finally {
log.info("Driver close connection " + COUNTER.decrementAndGet());
}
}
};
}

private Properties getCredentialProperties(ConnectorIdentity identity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void executeAsSys(@Language("SQL") String sql)

public void execute(@Language("SQL") String sql, String user, String password)
{
log.info("Get connection " + COUNTER.incrementAndGet());
log.info("Server get connection " + COUNTER.incrementAndGet());
try (Connection connection = DriverManager.getConnection(getJdbcUrl(), getProperties(user, password));
Statement statement = connection.createStatement()) {
statement.execute(sql);
Expand All @@ -105,7 +105,7 @@ public void execute(@Language("SQL") String sql, String user, String password)
throw new RuntimeException("Failed to execute statement '" + sql + "'", e);
}
finally {
log.info("Close connection " + COUNTER.decrementAndGet());
log.info("Server close connection " + COUNTER.decrementAndGet());
}
}

Expand Down

0 comments on commit 143df5b

Please sign in to comment.