Skip to content

Commit

Permalink
JDBC-470 Fix thread safety issue that can also cause exception of JDB…
Browse files Browse the repository at this point in the history
…C-464
  • Loading branch information
mrotteveel committed Dec 31, 2016
1 parent cef3c5c commit 6ae0926
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/main/org/firebirdsql/gds/impl/GDSHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ public FbStatement allocateStatement() throws SQLException {
* transaction, <code>false</code> otherwise.
*/
public boolean inTransaction() {
return transaction != null && transaction.getState() == TransactionState.ACTIVE;
synchronized (getSynchronizationObject()) {
return transaction != null && transaction.getState() == TransactionState.ACTIVE;
}
}

/**
Expand Down
18 changes: 10 additions & 8 deletions src/main/org/firebirdsql/jdbc/AbstractPreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,16 @@ protected AbstractPreparedStatement(GDSHelper c, String sql, int rsType,
this.metaDataQuery = metaDataQuery;
this.standaloneStatement = standaloneStatement;
this.generatedKeys = generatedKeys;

try {
// TODO See http://tracker.firebirdsql.org/browse/JDBC-352
notifyStatementStarted();
prepareFixedStatement(sql);
} catch (SQLException | RuntimeException e) {
notifyStatementCompleted(false);
throw e;

synchronized (c.getSynchronizationObject()) {
try {
// TODO See http://tracker.firebirdsql.org/browse/JDBC-352
notifyStatementStarted();
prepareFixedStatement(sql);
} catch (SQLException | RuntimeException e) {
notifyStatementCompleted(false);
throw e;
}
}
}

Expand Down

0 comments on commit 6ae0926

Please sign in to comment.