use of javax.transaction.Transaction in project neo4j-mobile-android by neo4j-contrib.
the class TxManager method attemptWaitForTxCompletionAndBlockFutureTransactions.
@Override
public void attemptWaitForTxCompletionAndBlockFutureTransactions(long maxWaitTimeMillis) {
msgLog.logMessage("TxManager is blocking new transactions and waiting for active to fail...");
blocked = true;
List<Transaction> failedTransactions = new ArrayList<Transaction>();
synchronized (txThreadMap) {
for (Transaction tx : txThreadMap.values()) {
try {
int status = tx.getStatus();
if (status != Status.STATUS_COMMITTING && status != Status.STATUS_ROLLING_BACK) {
// Set it to rollback only if it's not committing or rolling back
tx.setRollbackOnly();
}
} catch (IllegalStateException e) {
// OK
failedTransactions.add(tx);
} catch (SystemException e) {
// OK
failedTransactions.add(tx);
}
}
}
msgLog.logMessage("TxManager blocked transactions" + ((failedTransactions.isEmpty() ? "" : ", but failed for: " + failedTransactions.toString())));
long endTime = System.currentTimeMillis() + maxWaitTimeMillis;
while (txThreadMap.size() > 0 && System.currentTimeMillis() < endTime) Thread.yield();
}
use of javax.transaction.Transaction in project neo4j-mobile-android by neo4j-contrib.
the class PersistenceManager method getResource.
private NeoStoreTransaction getResource(boolean registerEventHooks) {
NeoStoreTransaction con = null;
Transaction tx = this.getCurrentTransaction();
if (tx == null) {
throw new NotInTransactionException();
}
con = txConnectionMap.get(tx);
if (con == null) {
try {
XaConnection xaConnection = persistenceSource.getXaDataSource().getXaConnection();
XAResource xaResource = xaConnection.getXaResource();
if (!tx.enlistResource(xaResource)) {
throw new ResourceAcquisitionFailedException("Unable to enlist '" + xaResource + "' in " + "transaction");
}
con = persistenceSource.createTransaction(xaConnection);
tx.registerSynchronization(new TxCommitHook(tx));
if (registerEventHooks)
registerTransactionEventHookIfNeeded();
txConnectionMap.put(tx, con);
} catch (javax.transaction.RollbackException re) {
String msg = "The transaction is marked for rollback only.";
throw new ResourceAcquisitionFailedException(msg, re);
} catch (javax.transaction.SystemException se) {
String msg = "TM encountered an unexpected error condition.";
throw new ResourceAcquisitionFailedException(msg, se);
}
}
return con;
}
use of javax.transaction.Transaction in project neo4j-mobile-android by neo4j-contrib.
the class PersistenceManager method delistResourcesForTransaction.
void delistResourcesForTransaction() throws NotInTransactionException {
Transaction tx = this.getCurrentTransaction();
if (tx == null) {
throw new NotInTransactionException();
}
NeoStoreTransaction con = txConnectionMap.get(tx);
if (con != null) {
try {
tx.delistResource(con.getXAResource(), XAResource.TMSUCCESS);
} catch (SystemException e) {
throw new TransactionFailureException("Failed to delist resource '" + con + "' from current transaction.", e);
}
}
}
use of javax.transaction.Transaction in project neo4j-mobile-android by neo4j-contrib.
the class PropertyIndexManager method createPropertyIndex.
// concurent transactions may create duplicate keys, oh well
PropertyIndex createPropertyIndex(String key) {
Transaction tx = getTransaction();
if (tx == null) {
throw new NotInTransactionException("Unable to create property index for " + key);
}
TxCommitHook hook = txCommitHooks.get(tx);
if (hook == null) {
hook = new TxCommitHook();
txCommitHooks.put(tx, hook);
}
PropertyIndex index = hook.getIndex(key);
if (index != null) {
return index;
}
int id = (int) idGenerator.nextId(PropertyIndex.class);
index = new PropertyIndex(key, id);
hook.addIndex(index);
persistenceManager.createPropertyIndex(key, id);
return index;
}
use of javax.transaction.Transaction in project spring-framework by spring-projects.
the class JtaTransactionManagerTests method jtaTransactionManagerWithPropagationRequiresNewAndExisting.
@Test
public void jtaTransactionManagerWithPropagationRequiresNewAndExisting() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
TransactionManager tm = mock(TransactionManager.class);
Transaction tx = mock(Transaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
given(tm.suspend()).willReturn(tx);
JtaTransactionManager ptm = newJtaTransactionManager(ut, tm);
TransactionTemplate tt = new TransactionTemplate(ptm);
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
}
});
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
verify(ut).begin();
verify(ut).commit();
verify(tm).resume(tx);
}
Aggregations