From 3e44cc0515fc222fb4f43a3b624795863ba4429b Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sun, 20 Jan 2008 21:42:57 +0000 Subject: Split TransactionManager and created TransactionScope class. --- .../com/amazon/carbonado/repo/jdbc/JDBCBlob.java | 4 ++-- .../com/amazon/carbonado/repo/jdbc/JDBCClob.java | 4 ++-- .../amazon/carbonado/repo/jdbc/JDBCRepository.java | 23 ++++++++++------------ .../amazon/carbonado/repo/jdbc/JDBCStorage.java | 10 +++++----- .../repo/jdbc/JDBCTransactionManager.java | 13 ++++++------ 5 files changed, 25 insertions(+), 29 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 ba5cdcf..69a8f3d 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.localTxnManager().getTxn(); + JDBCTransaction txn = mRepo.localTxnScope().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.localTxnManager().getTxn(); + JDBCTransaction txn = mRepo.localTxnScope().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 c4e74f1..eedaf80 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.localTxnManager().getTxn(); + JDBCTransaction txn = mRepo.localTxnScope().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.localTxnManager().getTxn(); + JDBCTransaction txn = mRepo.localTxnScope().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 0d93570..dd4e1ad 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java @@ -55,7 +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; /** @@ -324,7 +324,7 @@ public class JDBCRepository extends AbstractRepository */ // Is called by auto-generated code and must be public. public boolean isTransactionForUpdate() { - return localTransactionManager().isForUpdate(); + return localTransactionScope().isForUpdate(); } /** @@ -419,7 +419,7 @@ public class JDBCRepository extends AbstractRepository throw new FetchException("Repository is closed"); } - JDBCTransaction txn = localTransactionManager().getTxn(); + JDBCTransaction txn = localTransactionScope().getTxn(); if (txn != null) { // Return the connection used by the current transaction. return txn.getConnection(); @@ -656,10 +656,6 @@ public class JDBCRepository extends AbstractRepository return mLog; } - protected TransactionManager createTransactionManager() { - return new JDBCTransactionManager(this); - } - protected Storage createStorage(Class type) throws RepositoryException { @@ -701,11 +697,12 @@ public class JDBCRepository extends AbstractRepository return mSupportStrategy.createSequenceValueProducer(name); } - /** - * Returns the thread-local JDBCTransactionManager, creating it if needed. - */ - // Provides access to transaction manager from other classes. - TransactionManager localTxnManager() { - return localTransactionManager(); + protected JDBCTransactionManager createTransactionManager() { + return new JDBCTransactionManager(this); + } + + // Provides access to transaction scope from other classes. + final TransactionScope localTxnScope() { + return localTransactionScope(); } } 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 3fbd302..e6fe277 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.localTxnManager().getTxn(); + JDBCTransaction txn = mRepository.localTxnScope().getTxn(); if (txn != null) { txn.register(jblob); } @@ -235,7 +235,7 @@ class JDBCStorage extends StandardQueryFactory if (jclob != null) { try { - JDBCTransaction txn = mRepository.localTxnManager().getTxn(); + JDBCTransaction txn = mRepository.localTxnScope().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.localTxnManager().isForUpdate(); + boolean forUpdate = mRepository.localTxnScope().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.localTxnManager().isForUpdate(); + boolean forUpdate = mRepository.localTxnScope().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.localTxnManager().isForUpdate(); + boolean forUpdate = mRepository.localTxnScope().isForUpdate(); String statement = prepareSelect(values, forUpdate); return mRepository.getSupportStrategy().printPlan(app, indentLevel, statement); } catch (FetchException e) { 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 a70e4c3..ca63331 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransactionManager.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransactionManager.java @@ -29,8 +29,7 @@ import com.amazon.carbonado.Transaction; import com.amazon.carbonado.spi.TransactionManager; /** - * Manages transactions for JDBCRepository. Only one instance is allocated per - * thread. + * Manages transactions for JDBCRepository. * * @author Brian S O'Neill */ @@ -46,11 +45,6 @@ class JDBCTransactionManager extends TransactionManager { mRepositoryRef = new WeakReference(repository); } - @Override - public boolean isForUpdate() { - return super.isForUpdate() && mRepositoryRef.get().supportsSelectForUpdate(); - } - protected IsolationLevel selectIsolationLevel(Transaction parent, IsolationLevel level) { JDBCRepository repo = mRepositoryRef.get(); if (repo == null) { @@ -59,6 +53,11 @@ class JDBCTransactionManager extends TransactionManager { return repo.selectIsolationLevel(parent, level); } + protected boolean supportsForUpdate() { + JDBCRepository repo = mRepositoryRef.get(); + return repo != null && repo.supportsSelectForUpdate(); + } + protected JDBCTransaction createTxn(JDBCTransaction parent, IsolationLevel level) throws SQLException, FetchException { -- cgit v1.2.3