Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Oct 16, 2024
2 parents a81f0e3 + 1ce5982 commit 91c06e6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
49 changes: 32 additions & 17 deletions src/main/java/org/mariadb/jdbc/MariaDbDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@ public Logger getParentLogger() {
public PooledConnection getPooledConnection() throws SQLException {
if (conf == null) config();
org.mariadb.jdbc.Connection conn = Driver.connect(conf);
return conf.pinGlobalTxToPhysicalConnection()
? new MariaDbPoolPinnedConnection(conn)
: new MariaDbPoolConnection(conn);
MariaDbPoolConnection poolConnection =
conf.pinGlobalTxToPhysicalConnection()
? new MariaDbPoolPinnedConnection(conn)
: new MariaDbPoolConnection(conn);
setConnectionCloseListener(poolConnection);
return poolConnection;
}

@Override
Expand All @@ -219,28 +222,40 @@ public PooledConnection getPooledConnection(String username, String password)
if (conf == null) config();
Configuration conf = this.conf.clone(username, password);
org.mariadb.jdbc.Connection conn = Driver.connect(conf);
return conf.pinGlobalTxToPhysicalConnection()
? new MariaDbPoolPinnedConnection(conn)
: new MariaDbPoolConnection(conn);
MariaDbPoolConnection poolConnection =
conf.pinGlobalTxToPhysicalConnection()
? new MariaDbPoolPinnedConnection(conn)
: new MariaDbPoolConnection(conn);
setConnectionCloseListener(poolConnection);
return poolConnection;
}

private void setConnectionCloseListener(MariaDbPoolConnection mariaDbPoolConnection) {
mariaDbPoolConnection.addConnectionEventListener(
new ConnectionEventListener() {

@Override
public void connectionClosed(ConnectionEvent event) {
try {
mariaDbPoolConnection.realClose();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

@Override
public void connectionErrorOccurred(ConnectionEvent event) {}
});
}

@Override
public XAConnection getXAConnection() throws SQLException {
if (conf == null) config();
org.mariadb.jdbc.Connection conn = Driver.connect(conf);
return conf.pinGlobalTxToPhysicalConnection()
? new MariaDbPoolPinnedConnection(conn)
: new MariaDbPoolConnection(conn);
return (MariaDbPoolConnection) getPooledConnection();
}

@Override
public XAConnection getXAConnection(String username, String password) throws SQLException {
if (conf == null) config();
Configuration conf = this.conf.clone(username, password);
org.mariadb.jdbc.Connection conn = Driver.connect(conf);
return conf.pinGlobalTxToPhysicalConnection()
? new MariaDbPoolPinnedConnection(conn)
: new MariaDbPoolConnection(conn);
return (MariaDbPoolConnection) getPooledConnection(username, password);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/mariadb/jdbc/MariaDbPoolConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ public void fireConnectionErrorOccurred(SQLException returnEx) {
@Override
public void close() throws SQLException {
fireConnectionClosed(new ConnectionEvent(this));
}

protected void realClose() throws SQLException {
connection.setPoolConnection(null);
connection.close();
}
Expand Down

0 comments on commit 91c06e6

Please sign in to comment.