diff options
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo')
6 files changed, 39 insertions, 33 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 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<JDBCTransaction> 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<JDBCTransaction> // 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<JDBCTransaction> return mSupportStrategy.createSequenceValueProducer(name);
}
- protected JDBCTransactionManager createTransactionManager() {
- return new JDBCTransactionManager(this);
+ protected final TransactionManager<JDBCTransaction> transactionManager() {
+ return mTxnMgr;
}
- // Provides access to transaction scope from other classes.
- final TransactionScope<JDBCTransaction> localTxnScope() {
- return localTransactionScope();
+ protected final TransactionScope<JDBCTransaction> 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<S extends Storable> extends StandardQueryFactory<S> 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<S extends Storable> extends StandardQueryFactory<S> 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<S extends Storable> extends StandardQueryFactory<S> }
public Cursor<S> fetch(FilterValues<S> 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<S extends Storable> extends StandardQueryFactory<S> 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<S extends Storable> extends StandardQueryFactory<S> 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) {
diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java index a0c549b..4bf4e2b 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java @@ -63,6 +63,7 @@ import com.amazon.carbonado.sequence.SequenceValueProducer; import com.amazon.carbonado.spi.AbstractRepository;
import com.amazon.carbonado.spi.ExceptionTransformer;
import com.amazon.carbonado.spi.LobEngine;
+import com.amazon.carbonado.spi.TransactionManager;
import com.amazon.carbonado.spi.TransactionScope;
/**
@@ -93,6 +94,7 @@ abstract class BDBRepository<Txn> extends AbstractRepository<Txn> private final AtomicReference<Repository> mRootRef;
private final StorableCodecFactory mStorableCodecFactory;
private final ExceptionTransformer mExTransformer;
+ private final BDBTransactionManager<Txn> mTxnMgr;
Checkpointer mCheckpointer;
DeadlockDetector mDeadlockDetector;
@@ -141,6 +143,7 @@ abstract class BDBRepository<Txn> extends AbstractRepository<Txn> mTriggerFactories = builder.getTriggerFactories();
mRootRef = rootRef;
mExTransformer = exTransformer;
+ mTxnMgr = new BDBTransactionManager<Txn>(mExTransformer, this);
mRunCheckpointer = !builder.getReadOnly() && builder.getRunCheckpointer();
mRunDeadlockDetector = builder.getRunDeadlockDetector();
@@ -342,10 +345,6 @@ abstract class BDBRepository<Txn> extends AbstractRepository<Txn> return new SequenceValueGenerator(BDBRepository.this, name);
}
- protected BDBTransactionManager<Txn> createTransactionManager() {
- return new BDBTransactionManager<Txn>(mExTransformer, this);
- }
-
/**
* @see com.amazon.carbonado.spi.RepositoryBuilder#isMaster
*/
@@ -489,9 +488,12 @@ abstract class BDBRepository<Txn> extends AbstractRepository<Txn> return mExTransformer.toRepositoryException(e);
}
- // Provides access to transaction scope from other classes.
- final TransactionScope<Txn> localTxnScope() {
- return localTransactionScope();
+ protected final TransactionManager<Txn> transactionManager() {
+ return mTxnMgr;
+ }
+
+ protected final TransactionScope<Txn> localTransactionScope() {
+ return mTxnMgr.localScope();
}
/**
diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java index e7368ac..126e40f 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java @@ -203,7 +203,7 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag }
}
- TransactionScope<Txn> scope = localTxnScope();
+ TransactionScope<Txn> scope = localTransactionScope();
// Lock out shutdown task.
scope.getLock().lock();
@@ -317,7 +317,7 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag boolean reverseOrder)
throws FetchException
{
- TransactionScope<Txn> scope = localTxnScope();
+ TransactionScope<Txn> scope = localTransactionScope();
if (reverseRange) {
{
@@ -447,7 +447,7 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag boolean isPrimaryEmpty;
try {
- TransactionScope<Txn> scope = mRepository.localTxnScope();
+ TransactionScope<Txn> scope = mRepository.localTransactionScope();
// Lock out shutdown task.
scope.getLock().lock();
try {
@@ -572,7 +572,7 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag }
try {
- Txn txn = mRepository.localTxnScope().getTxn();
+ Txn txn = mRepository.localTransactionScope().getTxn();
return db_compact(txn, mPrimaryDatabase, start, end);
} catch (Exception e) {
throw mRepository.toRepositoryException(e);
@@ -667,8 +667,8 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag return mRepository.toRepositoryException(e);
}
- TransactionScope<Txn> localTxnScope() {
- return mRepository.localTxnScope();
+ TransactionScope<Txn> localTransactionScope() {
+ return mRepository.localTransactionScope();
}
/**
@@ -726,7 +726,7 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag * prevent threads from starting work that will likely fail along the way.
*/
void checkClosed() throws FetchException {
- TransactionScope<Txn> scope = localTxnScope();
+ TransactionScope<Txn> scope = localTransactionScope();
// Lock out shutdown task.
scope.getLock().lock();
@@ -747,7 +747,7 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag }
void close() throws Exception {
- TransactionScope<Txn> scope = mRepository.localTxnScope();
+ TransactionScope<Txn> scope = mRepository.localTransactionScope();
scope.getLock().lock();
try {
if (mPrimaryDatabase != null) {
@@ -998,7 +998,7 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag }
public byte[] tryLoad(byte[] key) throws FetchException {
- TransactionScope<Txn> scope = mStorage.localTxnScope();
+ TransactionScope<Txn> scope = mStorage.localTransactionScope();
byte[] result;
// Lock out shutdown task.
scope.getLock().lock();
@@ -1021,7 +1021,7 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag }
public boolean tryInsert(S storable, byte[] key, byte[] value) throws PersistException {
- TransactionScope<Txn> scope = mStorage.localTxnScope();
+ TransactionScope<Txn> scope = mStorage.localTransactionScope();
Object result;
// Lock out shutdown task.
scope.getLock().lock();
@@ -1044,7 +1044,7 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag }
public void store(S storable, byte[] key, byte[] value) throws PersistException {
- TransactionScope<Txn> scope = mStorage.localTxnScope();
+ TransactionScope<Txn> scope = mStorage.localTransactionScope();
// Lock out shutdown task.
scope.getLock().lock();
try {
@@ -1061,7 +1061,7 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag }
public boolean tryDelete(byte[] key) throws PersistException {
- TransactionScope<Txn> scope = mStorage.localTxnScope();
+ TransactionScope<Txn> scope = mStorage.localTransactionScope();
// Lock out shutdown task.
scope.getLock().lock();
try {
|