Search in sources :

Example 1 with XaConnection

use of org.neo4j.kernel.impl.transaction.xaframework.XaConnection 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;
}
Also used : XAResource(javax.transaction.xa.XAResource) Transaction(javax.transaction.Transaction) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException) XaConnection(org.neo4j.kernel.impl.transaction.xaframework.XaConnection)

Aggregations

RollbackException (javax.transaction.RollbackException)1 SystemException (javax.transaction.SystemException)1 Transaction (javax.transaction.Transaction)1 XAResource (javax.transaction.xa.XAResource)1 NotInTransactionException (org.neo4j.graphdb.NotInTransactionException)1 XaConnection (org.neo4j.kernel.impl.transaction.xaframework.XaConnection)1