Skip to content

Commit

Permalink
Catch Throwable and close connection (versus just SQLException). If a…
Browse files Browse the repository at this point in the history
…n Error is thrown, then we could end up with open connections.
  • Loading branch information
chenson42 committed Nov 6, 2012
1 parent 887ef00 commit 7a1a4a4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
Expand Up @@ -247,11 +247,11 @@ protected Object[] expandArgs(String sql, Object[] args) {
return args;
}

public SqlException translate(Exception ex) {
public SqlException translate(Throwable ex) {
return translate(ex.getMessage(), ex);
}

public SqlException translate(String message, Exception ex) {
public SqlException translate(String message, Throwable ex) {
if (isUniqueKeyViolation(ex) && !(ex instanceof UniqueKeyException)) {
return new UniqueKeyException(ex);
} else if (ex instanceof SqlException) {
Expand Down
Expand Up @@ -74,11 +74,11 @@ public <T, W> Map<T, W> query(String sql, String keyCol, String valueCol, Object

public void testConnection();

public SqlException translate(Exception ex);
public SqlException translate(Throwable ex);

public boolean isUniqueKeyViolation(Exception ex);
public boolean isUniqueKeyViolation(Throwable ex);

public boolean isForeignKeyViolation(Exception ex);
public boolean isForeignKeyViolation(Throwable ex);

public ISqlTransaction startSqlTransaction();

Expand Down
Expand Up @@ -68,6 +68,9 @@ public JdbcSqlReadCursor(JdbcSqlTemplate sqlTemplate, ISqlRowMapper<T> mapper, S
} catch (SQLException ex) {
close();
throw sqlTemplate.translate(sql, ex);
} catch (Throwable ex) {
close();
throw sqlTemplate.translate(sql, ex);
}
}

Expand Down
Expand Up @@ -730,7 +730,7 @@ protected long insertWithGeneratedKey(Connection conn, String sql, String column
return key;
}

public boolean isUniqueKeyViolation(Exception ex) {
public boolean isUniqueKeyViolation(Throwable ex) {
boolean primaryKeyViolation = false;
if (primaryKeyViolationCodes != null || primaryKeyViolationSqlStates != null) {
SQLException sqlEx = findSQLException(ex);
Expand Down Expand Up @@ -763,7 +763,7 @@ public boolean isUniqueKeyViolation(Exception ex) {
return primaryKeyViolation;
}

public boolean isForeignKeyViolation(Exception ex) {
public boolean isForeignKeyViolation(Throwable ex) {
boolean foreignKeyViolation = false;
if (foreignKeyViolationCodes != null || foreignKeyViolationSqlStates != null) {
SQLException sqlEx = findSQLException(ex);
Expand Down

0 comments on commit 7a1a4a4

Please sign in to comment.