/** * @return The current transaction's event identifier or -1 if no transaction is currently * running. */ public int getEventIdentifier() { TransactionImpl tx = (TransactionImpl) getTransaction(); if (tx != null) { return tx.getEventIdentifier(); } return -1; }
@Override public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException { assertTmOk("tx commit"); Thread thread = Thread.currentThread(); TransactionImpl tx = txThreadMap.get(thread); if (tx == null) { throw logAndReturn("TM error tx commit", new IllegalStateException("Not in transaction")); } boolean hasAnyLocks = false; boolean successful = false; try { hasAnyLocks = finishHook.hasAnyLocks(tx); if (tx.getStatus() != Status.STATUS_ACTIVE && tx.getStatus() != Status.STATUS_MARKED_ROLLBACK) { throw logAndReturn( "TM error tx commit", new IllegalStateException("Tx status is: " + getTxStatusAsString(tx.getStatus()))); } tx.doBeforeCompletion(); // delist resources? if (tx.getStatus() == Status.STATUS_ACTIVE) { comittedTxCount.incrementAndGet(); commit(thread, tx); } else if (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK) { rolledBackTxCount.incrementAndGet(); rollbackCommit(thread, tx); } else { throw logAndReturn( "TM error tx commit", new IllegalStateException("Tx status is: " + getTxStatusAsString(tx.getStatus()))); } successful = true; } finally { if (hasAnyLocks) { finishHook.finishTransaction(tx.getEventIdentifier(), successful); } } }
public void rollback() throws IllegalStateException, SystemException { assertTmOk("tx rollback"); Thread thread = Thread.currentThread(); TransactionImpl tx = txThreadMap.get(thread); if (tx == null) { throw new IllegalStateException("Not in transaction"); } boolean hasAnyLocks = false; try { hasAnyLocks = finishHook.hasAnyLocks(tx); if (tx.getStatus() == Status.STATUS_ACTIVE || tx.getStatus() == Status.STATUS_MARKED_ROLLBACK || tx.getStatus() == Status.STATUS_PREPARING) { tx.setStatus(Status.STATUS_MARKED_ROLLBACK); tx.doBeforeCompletion(); // delist resources? try { rolledBackTxCount.incrementAndGet(); tx.doRollback(); } catch (XAException e) { log.log( Level.SEVERE, "Unable to rollback marked or active transaction. " + "Some resources may be commited others not. " + "Neo4j kernel should be SHUTDOWN for " + "resource maintance and transaction recovery ---->", e); setTmNotOk(e); throw logAndReturn( "TM error tx rollback", Exceptions.withCause( new SystemException( "Unable to rollback " + " ---> error code for rollback: " + e.errorCode), e)); } tx.doAfterCompletion(); txThreadMap.remove(thread); try { if (tx.isGlobalStartRecordWritten()) { getTxLog().txDone(tx.getGlobalId()); } } catch (IOException e) { log.log(Level.SEVERE, "Error writing transaction log", e); setTmNotOk(e); throw logAndReturn( "TM error tx rollback", Exceptions.withCause( new SystemException( "TM encountered a problem, " + " error writing transaction log"), e)); } tx.setStatus(Status.STATUS_NO_TRANSACTION); } else { throw new IllegalStateException("Tx status is: " + getTxStatusAsString(tx.getStatus())); } } finally { if (hasAnyLocks) { finishHook.finishTransaction(tx.getEventIdentifier(), false); } } }