diff options
author | jameswil <jameswil@users.sourceforge.net> | 2007-01-30 02:12:16 +0000 |
---|---|---|
committer | jameswil <jameswil@users.sourceforge.net> | 2007-01-30 02:12:16 +0000 |
commit | b4a14ecaa9fa8f1970d0b20727742018ca18aaeb (patch) | |
tree | 6e69db6a747fa014cdc7519df251001056727fa0 /src | |
parent | 1ba18b1fd6e9ae3c1f9581be4a64e3a58f499b01 (diff) |
Update to address connection leak when cursor creation fails.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java index 6f797b7..489c288 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java @@ -457,12 +457,23 @@ class JDBCStorage<S extends Storable> extends StandardQueryFactory<S> public Cursor<S> fetch(FilterValues<S> values) throws FetchException {
boolean forUpdate = mRepository.openTransactionManager().isForUpdate();
- Connection con = mRepository.getConnection();
+ Connection con;
+ try {
+ con = mRepository.getConnection();
+ } catch (FetchException e) {
+ throw e.toPersistException();
+ }
try {
PreparedStatement ps = con.prepareStatement(prepareSelect(values, forUpdate));
setParameters(ps, values);
return new JDBCCursor<S>(JDBCStorage.this, con, ps);
} catch (Exception e) {
+ //in case of exception, yield connection
+ try {
+ mRepository.yieldConnection(con);
+ } catch (FetchException e) {
+ //ignore and allow triggering exception to propagate
+ }
throw mRepository.toFetchException(e);
}
}
|