use of org.neo4j.graphdb.NotInTransactionException in project neo4j-mobile-android by neo4j-contrib.
the class LockReleaser method getAndSetupPrimitiveElement.
private PrimitiveElement getAndSetupPrimitiveElement() {
Transaction tx = getTransaction();
if (tx == null) {
throw new NotInTransactionException();
}
PrimitiveElement primitiveElement = cowMap.get(tx);
if (primitiveElement == null) {
primitiveElement = new PrimitiveElement();
cowMap.put(tx, primitiveElement);
}
return primitiveElement;
}
use of org.neo4j.graphdb.NotInTransactionException in project neo4j-mobile-android by neo4j-contrib.
the class IndexConnectionBroker method delistResourcesForTransaction.
void delistResourcesForTransaction() throws NotInTransactionException {
Transaction tx = this.getCurrentTransaction();
if (tx == null) {
throw new NotInTransactionException();
}
T con = txConnectionMap.get(tx);
if (con != null) {
try {
tx.delistResource(con.getXaResource(), XAResource.TMSUCCESS);
} catch (IllegalStateException e) {
throw new RuntimeException("Unable to delist lucene resource from tx", e);
} catch (SystemException e) {
throw new RuntimeException("Unable to delist lucene resource from tx", e);
}
}
}
use of org.neo4j.graphdb.NotInTransactionException in project neo4j-mobile-android by neo4j-contrib.
the class IndexConnectionBroker method acquireResourceConnection.
public T acquireResourceConnection() {
T con = null;
Transaction tx = this.getCurrentTransaction();
if (tx == null) {
throw new NotInTransactionException();
}
con = txConnectionMap.get(tx);
if (con == null) {
try {
con = (T) newConnection();
if (!tx.enlistResource(con.getXaResource())) {
throw new RuntimeException("Unable to enlist '" + con.getXaResource() + "' in " + tx);
}
tx.registerSynchronization(new TxCommitHook(tx));
txConnectionMap.put(tx, con);
} catch (javax.transaction.RollbackException re) {
String msg = "The transaction is marked for rollback only.";
throw new RuntimeException(msg, re);
} catch (javax.transaction.SystemException se) {
String msg = "TM encountered an unexpected error condition.";
throw new RuntimeException(msg, se);
}
}
return con;
}
use of org.neo4j.graphdb.NotInTransactionException in project graphdb by neo4j-attic.
the class LockReleaser method addLockToTransaction.
/**
* Invoking this method with no transaction running will cause the lock to
* be released right away.
*
* @param resource
* the resource on which the lock is taken
* @param type
* type of lock (READ or WRITE)
* @throws NotInTransactionException
*/
public void addLockToTransaction(Object resource, LockType type) throws NotInTransactionException {
Transaction tx = getTransaction();
List<LockElement> lockElements = lockMap.get(tx);
if (lockElements != null) {
lockElements.add(new LockElement(resource, type));
} else {
if (tx == null) {
// no transaction we release lock right away
if (type == LockType.WRITE) {
lockManager.releaseWriteLock(resource, null);
} else if (type == LockType.READ) {
lockManager.releaseReadLock(resource, null);
}
return;
}
lockElements = new ArrayList<LockElement>();
lockMap.put(tx, lockElements);
lockElements.add(new LockElement(resource, type));
// tx was read only
try {
tx.registerSynchronization(new ReadOnlyTxReleaser(tx));
} catch (Exception e) {
throw new TransactionFailureException("Failed to register lock release synchronization hook", e);
}
}
}
use of org.neo4j.graphdb.NotInTransactionException in project graphdb by neo4j-attic.
the class PersistenceManager method getResource.
private ResourceConnection getResource() {
ResourceConnection con = null;
Transaction tx = this.getCurrentTransaction();
if (tx == null) {
throw new NotInTransactionException();
}
con = txConnectionMap.get(tx);
if (con == null) {
try {
con = persistenceSource.createResourceConnection();
if (!tx.enlistResource(con.getXAResource())) {
throw new ResourceAcquisitionFailedException("Unable to enlist '" + con.getXAResource() + "' in " + "transaction");
}
tx.registerSynchronization(new TxCommitHook(tx));
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