From a786db8ab53c879858268da6a0cbe4ba9956d160 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Mon, 4 Feb 2008 05:42:54 +0000 Subject: Make TransactionManager creation more flexible. --- src/main/java/com/amazon/carbonado/repo/jdbc/JDBCBlob.java | 4 ++-- src/main/java/com/amazon/carbonado/repo/jdbc/JDBCClob.java | 4 ++-- .../com/amazon/carbonado/repo/jdbc/JDBCRepository.java | 14 +++++++++----- .../java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java | 10 +++++----- 4 files changed, 18 insertions(+), 14 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/repo/jdbc') diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCBlob.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCBlob.java index 69a8f3d..c031a9e 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCBlob.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCBlob.java @@ -126,7 +126,7 @@ class JDBCBlob extends AbstractBlob implements JDBCLob { throw new FetchException("Blob value is null"); } try { - JDBCTransaction txn = mRepo.localTxnScope().getTxn(); + JDBCTransaction txn = mRepo.localTransactionScope().getTxn(); if (txn != null) { txn.register(this); } @@ -143,7 +143,7 @@ class JDBCBlob extends AbstractBlob implements JDBCLob { if ((mBlob = mLoader.load(mRepo)) == null) { throw new PersistException("Blob value is null"); } - JDBCTransaction txn = mRepo.localTxnScope().getTxn(); + JDBCTransaction txn = mRepo.localTransactionScope().getTxn(); if (txn != null) { txn.register(this); } diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCClob.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCClob.java index eedaf80..dc2ec0a 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCClob.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCClob.java @@ -126,7 +126,7 @@ class JDBCClob extends AbstractClob implements JDBCLob { throw new FetchException("Clob value is null"); } try { - JDBCTransaction txn = mRepo.localTxnScope().getTxn(); + JDBCTransaction txn = mRepo.localTransactionScope().getTxn(); if (txn != null) { txn.register(this); } @@ -143,7 +143,7 @@ class JDBCClob extends AbstractClob implements JDBCLob { if ((mClob = mLoader.load(mRepo)) == null) { throw new PersistException("Clob value is null"); } - JDBCTransaction txn = mRepo.localTxnScope().getTxn(); + JDBCTransaction txn = mRepo.localTransactionScope().getTxn(); if (txn != null) { txn.register(this); } diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java index dd4e1ad..75fde77 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java @@ -55,6 +55,7 @@ import com.amazon.carbonado.info.StorableProperty; import com.amazon.carbonado.sequence.SequenceCapability; import com.amazon.carbonado.sequence.SequenceValueProducer; import com.amazon.carbonado.spi.AbstractRepository; +import com.amazon.carbonado.spi.TransactionManager; import com.amazon.carbonado.spi.TransactionScope; import com.amazon.carbonado.util.ThrowUnchecked; @@ -194,6 +195,8 @@ public class JDBCRepository extends AbstractRepository private final JDBCSupportStrategy mSupportStrategy; private JDBCExceptionTransformer mExceptionTransformer; + private final JDBCTransactionManager mTxnMgr; + // Mappings from IsolationLevel to best matching supported level. final IsolationLevel mReadUncommittedLevel; final IsolationLevel mReadCommittedLevel; @@ -246,6 +249,8 @@ public class JDBCRepository extends AbstractRepository // Temporarily set to generic one, in case there's a problem during initialization. mExceptionTransformer = new JDBCExceptionTransformer(); + mTxnMgr = new JDBCTransactionManager(this); + getLog().info("Opening repository \"" + getName() + '"'); // Test connectivity and get some info on transaction isolation levels. @@ -697,12 +702,11 @@ public class JDBCRepository extends AbstractRepository return mSupportStrategy.createSequenceValueProducer(name); } - protected JDBCTransactionManager createTransactionManager() { - return new JDBCTransactionManager(this); + protected final TransactionManager transactionManager() { + return mTxnMgr; } - // Provides access to transaction scope from other classes. - final TransactionScope localTxnScope() { - return localTransactionScope(); + protected final TransactionScope localTransactionScope() { + return mTxnMgr.localScope(); } } 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 e6fe277..942ebee 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java @@ -213,7 +213,7 @@ class JDBCStorage extends StandardQueryFactory if (jblob != null) { try { - JDBCTransaction txn = mRepository.localTxnScope().getTxn(); + JDBCTransaction txn = mRepository.localTransactionScope().getTxn(); if (txn != null) { txn.register(jblob); } @@ -235,7 +235,7 @@ class JDBCStorage extends StandardQueryFactory if (jclob != null) { try { - JDBCTransaction txn = mRepository.localTxnScope().getTxn(); + JDBCTransaction txn = mRepository.localTransactionScope().getTxn(); if (txn != null) { txn.register(jclob); } @@ -606,7 +606,7 @@ class JDBCStorage extends StandardQueryFactory } public Cursor fetch(FilterValues values) throws FetchException { - boolean forUpdate = mRepository.localTxnScope().isForUpdate(); + boolean forUpdate = mRepository.localTransactionScope().isForUpdate(); Connection con = mRepository.getConnection(); try { PreparedStatement ps = con.prepareStatement(prepareSelect(values, forUpdate)); @@ -674,7 +674,7 @@ class JDBCStorage extends StandardQueryFactory throws IOException { indent(app, indentLevel); - boolean forUpdate = mRepository.localTxnScope().isForUpdate(); + boolean forUpdate = mRepository.localTransactionScope().isForUpdate(); app.append(prepareSelect(values, forUpdate)); app.append('\n'); return true; @@ -684,7 +684,7 @@ class JDBCStorage extends StandardQueryFactory throws IOException { try { - boolean forUpdate = mRepository.localTxnScope().isForUpdate(); + boolean forUpdate = mRepository.localTransactionScope().isForUpdate(); String statement = prepareSelect(values, forUpdate); return mRepository.getSupportStrategy().printPlan(app, indentLevel, statement); } catch (FetchException e) { -- cgit v1.2.3