summaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com')
-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.java14
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java10
-rw-r--r--src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java16
-rw-r--r--src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java24
-rw-r--r--src/main/java/com/amazon/carbonado/spi/AbstractRepository.java28
7 files changed, 47 insertions, 53 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 {
diff --git a/src/main/java/com/amazon/carbonado/spi/AbstractRepository.java b/src/main/java/com/amazon/carbonado/spi/AbstractRepository.java
index c9bc0b5..191f94e 100644
--- a/src/main/java/com/amazon/carbonado/spi/AbstractRepository.java
+++ b/src/main/java/com/amazon/carbonado/spi/AbstractRepository.java
@@ -54,7 +54,6 @@ public abstract class AbstractRepository<Txn>
implements Repository, ShutdownCapability, SequenceCapability
{
private final String mName;
- private final TransactionManager<Txn> mTxnMgr;
private final ReadWriteLock mShutdownLock;
private final StoragePool mStoragePool;
@@ -97,8 +96,6 @@ public abstract class AbstractRepository<Txn>
}
}
};
-
- mTxnMgr = createTransactionManager();
}
public String getName() {
@@ -112,19 +109,19 @@ public abstract class AbstractRepository<Txn>
}
public Transaction enterTransaction() {
- return mTxnMgr.localScope().enter(null);
+ return localTransactionScope().enter(null);
}
public Transaction enterTransaction(IsolationLevel level) {
- return mTxnMgr.localScope().enter(level);
+ return localTransactionScope().enter(level);
}
public Transaction enterTopTransaction(IsolationLevel level) {
- return mTxnMgr.localScope().enterTop(level);
+ return localTransactionScope().enterTop(level);
}
public IsolationLevel getTransactionIsolationLevel() {
- return mTxnMgr.localScope().getIsolationLevel();
+ return localTransactionScope().getIsolationLevel();
}
/**
@@ -207,18 +204,14 @@ public abstract class AbstractRepository<Txn>
}
/**
- * Returns the TransactionManager which was passed into the constructor.
+ * Returns the repository's TransactionManager.
*/
- protected TransactionManager<Txn> transactionManager() {
- return mTxnMgr;
- }
+ protected abstract TransactionManager<Txn> transactionManager();
/**
* Returns the thread-local TransactionScope, creating it if needed.
*/
- protected TransactionScope<Txn> localTransactionScope() {
- return mTxnMgr.localScope();
- }
+ protected abstract TransactionScope<Txn> localTransactionScope();
/**
* Call to prevent shutdown hook from running. Be sure to call
@@ -281,11 +274,6 @@ public abstract class AbstractRepository<Txn>
protected abstract SequenceValueProducer createSequenceValueProducer(String name)
throws RepositoryException;
- /**
- * Called upon to create a new TransactionManager instance.
- */
- protected abstract TransactionManager<Txn> createTransactionManager();
-
void info(String message) {
Log log = getLog();
if (log != null) {
@@ -337,7 +325,7 @@ public abstract class AbstractRepository<Txn>
repository.mSequencePool.returnReservedValues(null);
try {
- repository.mTxnMgr.close(suspendThreads);
+ repository.transactionManager().close(suspendThreads);
} catch (Throwable e) {
repository.error("Failed to close TransactionManager", e);
}