Skip to content

Commit

Permalink
fixed connections leak, added synchronization to avoid deadlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgenySafronov committed Apr 9, 2024
1 parent 2fec02e commit 8da3160
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/main/java/main/model/db/dao/DAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ public boolean updateMultiply(List<T> entities) throws AqualityException {

protected JSONArray CallStoredProcedure(String sql, List<Pair<String, String>> parameters) throws AqualityException {
JSONArray json = null;
CallableStatement callableStatement = executeCallableStatement(sql, parameters, null);
CallableStatement callableStatement = null;
try {
callableStatement = executeCallableStatement(sql, parameters, null);
ResultSet rs = callableStatement.getResultSet();
if (rs != null) {
json = RS_Converter.convertToJSON(rs);
Expand Down Expand Up @@ -284,18 +285,14 @@ private CallableStatement executeCallableStatement(String sql, List<Pair<String,
}

private CallableStatement tryExecute(CallableStatement callableStatement) throws AqualitySQLException {
int counter = 0;
SQLException lastException = null;
while (counter < 5) {
try {
try {
synchronized (DAO.class) {
callableStatement.execute();
return callableStatement;
} catch (SQLException e) {
counter++;
lastException = e;
}
return callableStatement;
} catch (SQLException e) {
throw new AqualitySQLException(e);
}
throw new AqualitySQLException(lastException);
}

private CallableStatement getCallableStatement(String sql) throws AqualityException {
Expand Down

0 comments on commit 8da3160

Please sign in to comment.