Skip to content
Open
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
29 changes: 19 additions & 10 deletions core/src/main/java/org/sql2o/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ public Connection rollback(boolean closeConnection){
logger.warn("Could not roll back transaction. message: {}", e);
}
finally {
if(closeConnection) this.closeJdbcConnection();
if(closeConnection) {
this.closeAndClearStatements();
this.closeJdbcConnection();
}
}
return this;
}
Expand All @@ -152,8 +155,10 @@ public Connection commit(boolean closeConnection){
throw new Sql2oException(e);
}
finally {
if(closeConnection)
if(closeConnection) {
this.closeAndClearStatements();
this.closeJdbcConnection();
}
}
return this;
}
Expand Down Expand Up @@ -263,6 +268,17 @@ void removeStatement(Statement statement){
statements.remove(statement);
}

private void closeAndClearStatements() {
for (Statement statement : statements) {
try {
getSql2o().getQuirks().closeStatement(statement);
} catch (Throwable e) {
logger.warn("Could not close statement.", e);
}
}
statements.clear();
}

public void close() {
boolean connectionIsClosed;
try {
Expand All @@ -273,14 +289,7 @@ public void close() {

if (!connectionIsClosed) {

for (Statement statement : statements) {
try {
getSql2o().getQuirks().closeStatement(statement);
} catch (Throwable e) {
logger.warn("Could not close statement.", e);
}
}
statements.clear();
closeAndClearStatements();

boolean rollback = rollbackOnClose;
if (rollback) {
Expand Down