Skip to content

Commit

Permalink
Fix connection leak in JdbcDataSourceDatabase constructor and pass …
Browse files Browse the repository at this point in the history
…in username/pass while getting connection
  • Loading branch information
rtadepalli committed Jan 1, 2024
1 parent 3c0ca4b commit 2d287fc
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public final class JdbcDataSourceDatabase implements AdbcDatabase {
private final String username;
private final String password;
private final JdbcQuirks quirks;
private final Connection connection;
private final AtomicInteger counter;
private Connection connection;

JdbcDataSourceDatabase(
BufferAllocator allocator,
Expand All @@ -49,22 +49,19 @@ public final class JdbcDataSourceDatabase implements AdbcDatabase {
this.username = username;
this.password = password;
this.quirks = Objects.requireNonNull(quirks);
try {
this.connection = dataSource.getConnection();
} catch (SQLException e) {
throw JdbcDriverUtil.fromSqlException(e);
}
this.connection = null;
this.counter = new AtomicInteger();
}

@Override
public AdbcConnection connect() throws AdbcException {
final Connection connection;
try {
if (username != null && password != null) {
connection = dataSource.getConnection(username, password);
} else {
connection = dataSource.getConnection();
if (connection == null) {
if (username != null && password != null) {
connection = dataSource.getConnection(username, password);
} else {
connection = dataSource.getConnection();
}
}
} catch (SQLException e) {
throw JdbcDriverUtil.fromSqlException(e);
Expand All @@ -79,7 +76,10 @@ public AdbcConnection connect() throws AdbcException {

@Override
public void close() throws Exception {
connection.close();
if (connection != null) {
connection.close();
}
connection = null;
}

@Override
Expand Down

0 comments on commit 2d287fc

Please sign in to comment.