Search in sources :

Example 16 with XAException

use of javax.transaction.xa.XAException in project neo4j-mobile-android by neo4j-contrib.

the class WriteTransaction method doPrepare.

@Override
protected void doPrepare() throws XAException {
    if (committed) {
        throw new XAException("Cannot prepare committed transaction[" + getIdentifier() + "]");
    }
    if (prepared) {
        throw new XAException("Cannot prepare prepared transaction[" + getIdentifier() + "]");
    }
    // generate records then write to logical log via addCommand method
    prepared = true;
    for (RelationshipTypeRecord record : relTypeRecords.values()) {
        Command.RelationshipTypeCommand command = new Command.RelationshipTypeCommand(neoStore.getRelationshipTypeStore(), record);
        relTypeCommands.add(command);
        addCommand(command);
    }
    for (NodeRecord record : nodeRecords.values()) {
        if (!record.inUse() && record.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
            throw new InvalidRecordException("Node record " + record + " still has relationships");
        }
        Command.NodeCommand command = new Command.NodeCommand(neoStore.getNodeStore(), record);
        nodeCommands.add(command);
        if (!record.inUse()) {
            removeNodeFromCache(record.getId());
        }
        addCommand(command);
    }
    for (RelationshipRecord record : relRecords.values()) {
        Command.RelationshipCommand command = new Command.RelationshipCommand(neoStore.getRelationshipStore(), record);
        relCommands.add(command);
        if (!record.inUse()) {
            removeRelationshipFromCache(record.getId());
        }
        addCommand(command);
    }
    for (PropertyIndexRecord record : propIndexRecords.values()) {
        Command.PropertyIndexCommand command = new Command.PropertyIndexCommand(neoStore.getPropertyStore().getIndexStore(), record);
        propIndexCommands.add(command);
        addCommand(command);
    }
    for (PropertyRecord record : propertyRecords.values()) {
        Command.PropertyCommand command = new Command.PropertyCommand(neoStore.getPropertyStore(), record);
        propCommands.add(command);
        addCommand(command);
    }
}
Also used : XAException(javax.transaction.xa.XAException) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) RelationshipTypeRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) XaCommand(org.neo4j.kernel.impl.transaction.xaframework.XaCommand) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 17 with XAException

use of javax.transaction.xa.XAException in project hazelcast by hazelcast.

the class XAResourceProxy method start.

@Override
public void start(Xid xid, int flags) throws XAException {
    long threadId = currentThreadId();
    TransactionContext threadContext = threadContextMap.get(currentThreadId());
    switch(flags) {
        case TMNOFLAGS:
            List<TransactionContext> contexts = new CopyOnWriteArrayList<TransactionContext>();
            List<TransactionContext> currentContexts = xidContextMap.putIfAbsent(xid, contexts);
            if (currentContexts != null) {
                throw new XAException("There is already TransactionContexts for the given xid: " + xid);
            }
            TransactionContext context = createTransactionContext(xid);
            contexts.add(context);
            threadContextMap.put(threadId, context);
            break;
        case TMRESUME:
        case TMJOIN:
            List<TransactionContext> contextList = xidContextMap.get(xid);
            if (contextList == null) {
                throw new XAException("There is no TransactionContexts for the given xid: " + xid);
            }
            if (threadContext == null) {
                threadContext = createTransactionContext(xid);
                threadContextMap.put(threadId, threadContext);
                contextList.add(threadContext);
            }
            break;
        default:
            throw new XAException("Unknown flag!" + flags);
    }
}
Also used : XAException(javax.transaction.xa.XAException) TransactionContext(com.hazelcast.transaction.TransactionContext) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 18 with XAException

use of javax.transaction.xa.XAException in project hazelcast by hazelcast.

the class ClientXACompatibilityTest method testEnd_FromDifferentThread.

@Test
public void testEnd_FromDifferentThread() throws Exception {
    xaResource.start(xid, TMNOFLAGS);
    TransactionContext context = xaResource.getTransactionContext();
    TransactionalMap<Object, Object> map = context.getMap("map");
    map.put("key", "value");
    final CountDownLatch latch = new CountDownLatch(1);
    new Thread() {

        @Override
        public void run() {
            try {
                xaResource.end(xid, XAResource.TMFAIL);
                latch.countDown();
            } catch (XAException e) {
                e.printStackTrace();
            }
        }
    }.start();
    assertOpenEventually(latch, 10);
}
Also used : XAException(javax.transaction.xa.XAException) TransactionContext(com.hazelcast.transaction.TransactionContext) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with XAException

use of javax.transaction.xa.XAException in project hazelcast by hazelcast.

the class ClientXACompatibilityTest method testJoin_DifferentThread.

@Test
public void testJoin_DifferentThread() throws Exception {
    final String name = randomString();
    final String key1 = randomString();
    final String key2 = randomString();
    final String val1 = randomString();
    final String val2 = randomString();
    xaResource.start(xid, TMNOFLAGS);
    TransactionContext context = xaResource.getTransactionContext();
    TransactionalMap<Object, Object> map = context.getMap(name);
    map.put(key1, val1);
    xaResource.end(xid, TMSUCCESS);
    Thread thread = new Thread() {

        @Override
        public void run() {
            try {
                xaResource.start(xid, TMJOIN);
                TransactionContext transactionContext = xaResource.getTransactionContext();
                TransactionalMap<Object, Object> m = transactionContext.getMap(name);
                m.put(key2, val2);
                xaResource.end(xid, TMSUCCESS);
            } catch (XAException e) {
                e.printStackTrace();
            }
        }
    };
    thread.start();
    thread.join();
    xaResource.commit(xid, true);
    IMap<Object, Object> m = client.getMap(name);
    assertEquals(val1, m.get(key1));
    assertEquals(val2, m.get(key2));
}
Also used : XAException(javax.transaction.xa.XAException) TransactionContext(com.hazelcast.transaction.TransactionContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 20 with XAException

use of javax.transaction.xa.XAException in project hazelcast by hazelcast.

the class XAResourceImpl method start.

@Override
public void start(Xid xid, int flags) throws XAException {
    long threadId = currentThreadId();
    TransactionContext threadContext = threadContextMap.get(currentThreadId());
    switch(flags) {
        case TMNOFLAGS:
            List<TransactionContext> contexts = new CopyOnWriteArrayList<TransactionContext>();
            List<TransactionContext> currentContexts = xidContextMap.putIfAbsent(xid, contexts);
            if (currentContexts != null) {
                throw new XAException("There is already TransactionContexts for the given xid: " + xid);
            }
            TransactionContext context = createTransactionContext(xid);
            contexts.add(context);
            threadContextMap.put(threadId, context);
            break;
        case TMRESUME:
        case TMJOIN:
            List<TransactionContext> contextList = xidContextMap.get(xid);
            if (contextList == null) {
                throw new XAException("There is no TransactionContexts for the given xid: " + xid);
            }
            if (threadContext == null) {
                threadContext = createTransactionContext(xid);
                threadContextMap.put(threadId, threadContext);
                contextList.add(threadContext);
            }
            break;
        default:
            throw new XAException("Unknown flag! " + flags);
    }
}
Also used : XAException(javax.transaction.xa.XAException) TransactionContext(com.hazelcast.transaction.TransactionContext) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

XAException (javax.transaction.xa.XAException)68 IOException (java.io.IOException)20 Xid (javax.transaction.xa.Xid)19 SystemException (javax.transaction.SystemException)14 TransactionContext (com.hazelcast.transaction.TransactionContext)12 RollbackException (javax.transaction.RollbackException)8 XAResource (javax.transaction.xa.XAResource)8 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)7 HeuristicMixedException (javax.transaction.HeuristicMixedException)6 Test (org.junit.Test)6 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)6 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 HashMap (java.util.HashMap)5 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)4 ArrayList (java.util.ArrayList)3 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)3 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)3 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)3 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)3