use of org.neo4j.graphdb.NotInTransactionException in project neo4j by neo4j.
the class ProcedureGDBFacadeSPI method currentTransaction.
@Override
public KernelTransaction currentTransaction() {
availability.assertDatabaseAvailable();
KernelTransaction tx = sourceModule.threadToTransactionBridge.getKernelTransactionBoundToThisThread(false);
if (tx == null) {
throw new NotInTransactionException();
}
return tx;
}
use of org.neo4j.graphdb.NotInTransactionException in project neo4j by neo4j.
the class TransactionConstraintsIT method writeOperationOnSlaveHasToBePerformedWithinTransaction.
@Test
public void writeOperationOnSlaveHasToBePerformedWithinTransaction() throws Exception {
// GIVEN
HighlyAvailableGraphDatabase aSlave = cluster.getAnySlave();
// WHEN
try {
aSlave.createNode();
fail("Shouldn't be able to do a write operation outside a transaction");
} catch (NotInTransactionException e) {
// THEN
}
}
use of org.neo4j.graphdb.NotInTransactionException in project neo4j by neo4j.
the class TransactionConstraintsIT method writeOperationOnMasterHasToBePerformedWithinTransaction.
@Test
public void writeOperationOnMasterHasToBePerformedWithinTransaction() throws Exception {
// GIVEN
HighlyAvailableGraphDatabase master = cluster.getMaster();
// WHEN
try {
master.createNode();
fail("Shouldn't be able to do a write operation outside a transaction");
} catch (NotInTransactionException e) {
// THEN
}
}
use of org.neo4j.graphdb.NotInTransactionException 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 org.neo4j.graphdb.NotInTransactionException 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;
}
Aggregations