Search in sources :

Example 1 with XAResource

use of javax.transaction.xa.XAResource in project graphdb by neo4j-attic.

the class XaConnectionHelpImpl method getTransaction.

/**
     * Returns the {@link XaTransaction} associated with this connection. If
     * transaction is already completed it will still be returned.
     * 
     * @return The {@link XaTransaction} associated with this connection
     * @throws XAException
     *             If the transaction hasn't completed and the resource isn't
     *             enlisted
     */
protected XaTransaction getTransaction() throws XAException {
    XAResource xar = getXaResource();
    XaTransaction xat = null;
    if (xar instanceof XaResourceHelpImpl) {
        xat = ((XaResourceHelpImpl) xar).getCompletedTx();
    }
    if (xat != null) {
        return xat;
    }
    return xaRm.getXaTransaction(xar);
}
Also used : XAResource(javax.transaction.xa.XAResource)

Example 2 with XAResource

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

the class XaDataSourceManager method getBranchId.

synchronized byte[] getBranchId(XAResource xaResource) {
    if (xaResource instanceof XaResource) {
        byte[] branchId = ((XaResource) xaResource).getBranchId();
        if (branchId != null) {
            return branchId;
        }
    }
    Iterator<Map.Entry<String, XaDataSource>> itr = dataSources.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry<String, XaDataSource> entry = itr.next();
        XaDataSource dataSource = entry.getValue();
        XAResource resource = dataSource.getXaConnection().getXaResource();
        try {
            if (resource.isSameRM(xaResource)) {
                String name = entry.getKey();
                return sourceIdMapping.get(name);
            }
        } catch (XAException e) {
            throw new TransactionFailureException("Unable to check is same resource", e);
        }
    }
    throw new TransactionFailureException("Unable to find mapping for XAResource[" + xaResource + "]");
}
Also used : XAResource(javax.transaction.xa.XAResource) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) XAException(javax.transaction.xa.XAException) XaResource(org.neo4j.kernel.impl.transaction.xaframework.XaResource) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with XAResource

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

the class XaConnectionHelpImpl method getTransaction.

/**
     * Returns the {@link XaTransaction} associated with this connection. If
     * transaction is already completed it will still be returned.
     * 
     * @return The {@link XaTransaction} associated with this connection
     * @throws XAException
     *             If the transaction hasn't completed and the resource isn't
     *             enlisted
     */
protected XaTransaction getTransaction() throws XAException {
    XAResource xar = getXaResource();
    XaTransaction xat = null;
    if (xar instanceof XaResourceHelpImpl) {
        xat = ((XaResourceHelpImpl) xar).getCompletedTx();
    }
    if (xat != null) {
        return xat;
    }
    return xaRm.getXaTransaction(xar);
}
Also used : XAResource(javax.transaction.xa.XAResource)

Example 4 with XAResource

use of javax.transaction.xa.XAResource in project graphdb by neo4j-attic.

the class TestXa method testLogicalLogPrePrepared.

@Test
public void testLogicalLogPrePrepared() throws Exception {
    Xid xid = new XidImpl(new byte[3], new byte[3]);
    XAResource xaRes = xaCon.getXaResource();
    xaRes.start(xid, XAResource.TMNOFLAGS);
    long node1 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node1);
    long node2 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node2);
    long n1prop1 = ds.nextId(PropertyStore.class);
    xaCon.getNodeConsumer().addProperty(node1, n1prop1, index("prop1"), "string1");
    int relType1 = (int) ds.nextId(RelationshipType.class);
    xaCon.getRelationshipTypeConsumer().addRelationshipType(relType1, "relationshiptype1");
    long rel1 = ds.nextId(Relationship.class);
    xaCon.getRelationshipConsumer().createRelationship(rel1, node1, node2, relType1);
    long r1prop1 = ds.nextId(PropertyStore.class);
    xaCon.getRelationshipConsumer().addProperty(rel1, r1prop1, index("prop1"), "string1");
    xaCon.getNodeConsumer().changeProperty(node1, n1prop1, "string2");
    xaCon.getRelationshipConsumer().changeProperty(rel1, r1prop1, "string2");
    xaRes.end(xid, XAResource.TMSUCCESS);
    xaCon.clearAllTransactions();
    copyLogicalLog(path());
    ds.close();
    deleteLogicalLogIfExist();
    renameCopiedLogicalLog(path());
    ds = newNeoStore();
    //        ds = new NeoStoreXaDataSource( file( "neo" ), file( "nioneo_logical.log" ),
    //            lockManager, lockReleaser );
    xaCon = (NeoStoreXaConnection) ds.getXaConnection();
    xaRes = xaCon.getXaResource();
    assertEquals(0, xaRes.recover(XAResource.TMNOFLAGS).length);
}
Also used : Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XidImpl(org.neo4j.kernel.impl.transaction.XidImpl) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 5 with XAResource

use of javax.transaction.xa.XAResource in project graphdb by neo4j-attic.

the class TestXa method testLogicalLogPrepared.

@Test
public void testLogicalLogPrepared() throws Exception {
    Xid xid = new XidImpl(new byte[2], new byte[2]);
    XAResource xaRes = xaCon.getXaResource();
    xaRes.start(xid, XAResource.TMNOFLAGS);
    long node1 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node1);
    long node2 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node2);
    long n1prop1 = ds.nextId(PropertyStore.class);
    xaCon.getNodeConsumer().addProperty(node1, n1prop1, index("prop1"), "string1");
    int relType1 = (int) ds.nextId(RelationshipType.class);
    xaCon.getRelationshipTypeConsumer().addRelationshipType(relType1, "relationshiptype1");
    long rel1 = ds.nextId(Relationship.class);
    xaCon.getRelationshipConsumer().createRelationship(rel1, node1, node2, relType1);
    long r1prop1 = ds.nextId(PropertyStore.class);
    xaCon.getRelationshipConsumer().addProperty(rel1, r1prop1, index("prop1"), "string1");
    xaCon.getNodeConsumer().changeProperty(node1, n1prop1, "string2");
    xaCon.getRelationshipConsumer().changeProperty(rel1, r1prop1, "string2");
    xaRes.end(xid, XAResource.TMSUCCESS);
    xaRes.prepare(xid);
    ds.rotateLogicalLog();
    copyLogicalLog(path());
    xaCon.clearAllTransactions();
    ds.close();
    deleteLogicalLogIfExist();
    renameCopiedLogicalLog(path());
    ds = newNeoStore();
    //        ds = new NeoStoreXaDataSource( file( "neo" ), file( "nioneo_logical.log" ),
    //            lockManager, lockReleaser );
    xaCon = (NeoStoreXaConnection) ds.getXaConnection();
    xaRes = xaCon.getXaResource();
    assertEquals(1, xaRes.recover(XAResource.TMNOFLAGS).length);
    xaRes.commit(xid, true);
    xaCon.clearAllTransactions();
}
Also used : Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XidImpl(org.neo4j.kernel.impl.transaction.XidImpl) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Aggregations

XAResource (javax.transaction.xa.XAResource)37 Xid (javax.transaction.xa.Xid)13 Test (org.junit.Test)13 SystemException (javax.transaction.SystemException)10 Transaction (javax.transaction.Transaction)10 XidImpl (org.neo4j.kernel.impl.transaction.XidImpl)9 XAException (javax.transaction.xa.XAException)8 RollbackException (javax.transaction.RollbackException)7 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)6 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)6 HashMap (java.util.HashMap)5 RelationshipType (org.neo4j.graphdb.RelationshipType)5 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 ResourceException (javax.resource.ResourceException)4 ManagedConnection (javax.resource.spi.ManagedConnection)4 XAConnection (javax.sql.XAConnection)4 HazelcastXAResource (com.hazelcast.transaction.HazelcastXAResource)3 Iterator (java.util.Iterator)3