diff options
author | Jesse Morgan <morganjm@amazon.com> | 2015-03-06 09:36:52 -0800 |
---|---|---|
committer | Jesse Morgan <morganjm@amazon.com> | 2015-03-06 09:36:52 -0800 |
commit | f14d8fc7de0f49dc66d5a2871d5141f5c679a2b2 (patch) | |
tree | 22585844329e2a537c616257a7a68dc3629459c4 /src | |
parent | 13f58b778c5559b24f1b371cfb54ad80a5ba4b3f (diff) | |
parent | bb5b9878e8a9e96161dea08b077258568bb66425 (diff) |
Merge branch 'master' into v1.3v1.3.1
Conflicts:
pom.xml
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransaction.java | 15 | ||||
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransactionManager.java | 30 |
2 files changed, 31 insertions, 14 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransaction.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransaction.java index ffa2e5c..00e6947 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransaction.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransaction.java @@ -106,10 +106,17 @@ class JDBCTransaction { }
/**
- * @return connection to close, or null if not ready to because this was a
- * nested transaction
+ * @return true if the connection should be closed after the transaction is aborted.
*/
- Connection abort() throws SQLException {
+ boolean shouldCloseConnection() {
+ return !mIsNested;
+ }
+
+ /**
+ * Note: The caller should close the connection after aborting if
+ * shouldCloseConnection() returns true.
+ */
+ void abort() throws SQLException {
if (mRegisteredLobs != null) {
for (JDBCLob lob : mRegisteredLobs) {
lob.close();
@@ -134,13 +141,11 @@ class JDBCTransaction { }
}
- return null;
} else {
if (mReady) {
mConnection.rollback();
mReady = false;
}
- return mConnection;
}
}
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransactionManager.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransactionManager.java index c649058..9fe2ff4 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransactionManager.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransactionManager.java @@ -97,18 +97,30 @@ class JDBCTransactionManager extends TransactionManager<JDBCTransaction> { @Override
protected void abortTxn(JDBCTransaction txn) throws PersistException {
+ PersistException ex = null;
+
try {
- Connection con;
- if ((con = txn.abort()) != null) {
- JDBCRepository repo = mRepositoryRef.get();
- if (repo == null) {
- con.close();
- } else {
- repo.closeConnection(con);
+ txn.abort();
+ } catch (Throwable e) {
+ ex = mExTransformer.toPersistException(e);
+ throw ex;
+ } finally {
+ try {
+ if (txn.shouldCloseConnection()) {
+ Connection con = txn.getConnection();
+ JDBCRepository repo = mRepositoryRef.get();
+ if (repo == null) {
+ con.close();
+ } else {
+ repo.closeConnection(con);
+ }
+ }
+ } catch (Throwable e) {
+ // Don't lose the original exception.
+ if (ex == null) {
+ throw mExTransformer.toPersistException(e);
}
}
- } catch (Throwable e) {
- throw mExTransformer.toPersistException(e);
}
}
}
|