summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/repo/jdbc
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2008-01-20 21:42:57 +0000
committerBrian S. O'Neill <bronee@gmail.com>2008-01-20 21:42:57 +0000
commit3e44cc0515fc222fb4f43a3b624795863ba4429b (patch)
treec928caada559b6ca42f097e968fcfb5935831e3c /src/main/java/com/amazon/carbonado/repo/jdbc
parentac27602a9b1141ee170c9cdf4bf386078013f1d0 (diff)
Split TransactionManager and created TransactionScope class.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo/jdbc')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCBlob.java4
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCClob.java4
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java23
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java10
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransactionManager.java13
5 files changed, 25 insertions, 29 deletions
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<JDBCTransaction>
*/
// 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<JDBCTransaction>
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<JDBCTransaction>
return mLog;
}
- protected TransactionManager<JDBCTransaction> createTransactionManager() {
- return new JDBCTransactionManager(this);
- }
-
protected <S extends Storable> Storage<S> createStorage(Class<S> type)
throws RepositoryException
{
@@ -701,11 +697,12 @@ public class JDBCRepository extends AbstractRepository<JDBCTransaction>
return mSupportStrategy.createSequenceValueProducer(name);
}
- /**
- * Returns the thread-local JDBCTransactionManager, creating it if needed.
- */
- // Provides access to transaction manager from other classes.
- TransactionManager<JDBCTransaction> localTxnManager() {
- return localTransactionManager();
+ protected JDBCTransactionManager createTransactionManager() {
+ return new JDBCTransactionManager(this);
+ }
+
+ // Provides access to transaction scope from other classes.
+ final TransactionScope<JDBCTransaction> 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<S extends Storable> extends StandardQueryFactory<S>
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<S extends Storable> extends StandardQueryFactory<S>
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<S extends Storable> extends StandardQueryFactory<S>
}
public Cursor<S> fetch(FilterValues<S> 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<S extends Storable> extends StandardQueryFactory<S>
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<S extends Storable> extends StandardQueryFactory<S>
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<JDBCTransaction> {
mRepositoryRef = new WeakReference<JDBCRepository>(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<JDBCTransaction> {
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
{