From b4a14ecaa9fa8f1970d0b20727742018ca18aaeb Mon Sep 17 00:00:00 2001 From: jameswil Date: Tue, 30 Jan 2007 02:12:16 +0000 Subject: Update to address connection leak when cursor creation fails. --- .../java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') 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 extends StandardQueryFactory public Cursor fetch(FilterValues 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(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); } } -- cgit v1.2.3