Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ private void heartBeat() {
}

private void testConnection() {
Connection conn = null;
PooledConnection conn = null;
try {
// Get a connection from the pool and test it
conn = getConnection();
conn = getPooledConnection();
heartbeatPoolExhaustedCount = 0;
if (testConnection(conn)) {
notifyDataSourceIsUp();
Expand All @@ -394,7 +394,7 @@ private void testConnection() {
if (!conn.getAutoCommit()) {
conn.rollback();
}
conn.close();
conn.closePooledConnection(false);
}
} catch (SQLException ex) {
Log.warn("Can't close connection in checkDataSource!");
Expand Down Expand Up @@ -541,8 +541,12 @@ void returnConnection(PooledConnection pooledConnection) {
/**
* This is a bad connection and must be removed from the pool's busy list and fully closed.
*/
void returnConnectionForceClose(PooledConnection pooledConnection) {
void returnConnectionForceClose(PooledConnection pooledConnection, boolean testPool) {
returnTheConnection(pooledConnection, true);
if (testPool) {
// Got a bad connection so check the pool
testConnection();
}
}

void removeClosedConnection(PooledConnection pooledConnection) {
Expand All @@ -558,10 +562,6 @@ private void returnTheConnection(PooledConnection pooledConnection, boolean forc
poolListener.onBeforeReturnConnection(pooledConnection);
}
queue.returnPooledConnection(pooledConnection, forceClose);
if (forceClose) {
// Got a bad connection so check the pool
testConnection();
}
}

void returnConnectionReset(PooledConnection pooledConnection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,16 @@ private boolean isReadOnlyMessage(SQLException ex) {
*/
@Override
public void close() throws SQLException {
closePooledConnection(true);
}

void closePooledConnection(boolean testPool) throws SQLException {
if (status == STATUS_IDLE) {
throw new SQLException(IDLE_CONNECTION_ACCESSED_ERROR + "close()");
}
boolean mayHaveUncommittedChanges = !autoCommit && !readOnly && status == STATUS_ACTIVE;
if (mayHaveUncommittedChanges && pool.enforceCleanClose()) {
pool.returnConnectionForceClose(this);
pool.returnConnectionForceClose(this, testPool);
throw new AssertionError("Tried to close a dirty connection. See https://github.com/ebean-orm/ebean-datasource/issues/116 for details.");
}
if (hadErrors) {
Expand All @@ -459,7 +463,7 @@ public void close() throws SQLException {
return;
} else if (pool.invalidConnection(this)) {
// the connection is BAD, remove it, close it and test the pool
pool.returnConnectionForceClose(this);
pool.returnConnectionForceClose(this, testPool);
return;
}
}
Expand Down Expand Up @@ -513,7 +517,7 @@ public void close() throws SQLException {
} catch (Exception ex) {
// the connection is BAD, remove it, close it and test the pool
Log.warn("Error when trying to return connection to pool, closing fully.", ex);
pool.returnConnectionForceClose(this);
pool.returnConnectionForceClose(this, testPool);
}
}

Expand Down
Loading