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);
}
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 + "]");
}
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);
}
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);
}
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();
}
Aggregations