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);
}
}
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);
}
}
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);
}
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));
}
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);
}
}
Aggregations