use of javax.transaction.HeuristicRollbackException in project neo4j-mobile-android by neo4j-contrib.
the class TxManager method commit.
private void commit(Thread thread, TransactionImpl tx) throws SystemException, HeuristicMixedException, HeuristicRollbackException {
// mark as commit in log done TxImpl.doCommit()
Throwable commitFailureCause = null;
int xaErrorCode = -1;
if (tx.getResourceCount() == 0) {
tx.setStatus(Status.STATUS_COMMITTED);
} else {
try {
tx.doCommit();
} catch (XAException e) {
xaErrorCode = e.errorCode;
log.log(Level.SEVERE, "Commit failed, status=" + getTxStatusAsString(tx.getStatus()) + ", errorCode=" + xaErrorCode, e);
if (tx.getStatus() == Status.STATUS_COMMITTED) {
// this should never be
setTmNotOk(e);
throw logAndReturn("TM error tx commit", new TransactionFailureException("commit threw exception but status is committed?", e));
}
} catch (Throwable t) {
log.log(Level.SEVERE, "Commit failed", t);
commitFailureCause = t;
}
}
if (tx.getStatus() != Status.STATUS_COMMITTED) {
try {
tx.doRollback();
} catch (Throwable e) {
log.log(Level.SEVERE, "Unable to rollback transaction. " + "Some resources may be commited others not. " + "Neo4j kernel should be SHUTDOWN for " + "resource maintance and transaction recovery ---->", e);
setTmNotOk(e);
String commitError;
if (commitFailureCause != null) {
commitError = "error in commit: " + commitFailureCause;
} else {
commitError = "error code in commit: " + xaErrorCode;
}
String rollbackErrorCode = "Uknown error code";
if (e instanceof XAException) {
rollbackErrorCode = Integer.toString(((XAException) e).errorCode);
}
throw logAndReturn("TM error tx commit", Exceptions.withCause(new HeuristicMixedException("Unable to rollback ---> " + commitError + " ---> error code for rollback: " + rollbackErrorCode), 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 commit", Exceptions.withCause(new SystemException("TM encountered a problem, " + " error writing transaction log"), e));
}
tx.setStatus(Status.STATUS_NO_TRANSACTION);
if (commitFailureCause == null) {
throw logAndReturn("TM error tx commit", new HeuristicRollbackException("Failed to commit, transaction rolledback ---> " + "error code was: " + xaErrorCode));
} else {
throw logAndReturn("TM error tx commit", Exceptions.withCause(new HeuristicRollbackException("Failed to commit, transaction rolledback ---> " + commitFailureCause), commitFailureCause));
}
}
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 commit", Exceptions.withCause(new SystemException("TM encountered a problem, " + " error writing transaction log"), e));
}
tx.setStatus(Status.STATUS_NO_TRANSACTION);
}
use of javax.transaction.HeuristicRollbackException in project wildfly by wildfly.
the class MessageEndpointInvocationHandler method afterDelivery.
@Override
public void afterDelivery() throws ResourceException {
final TransactionManager tm = getTransactionManager();
try {
if (currentTx != null) {
if (currentTx.getStatus() == Status.STATUS_MARKED_ROLLBACK)
tm.rollback();
else
tm.commit();
currentTx = null;
}
if (previousTx != null) {
tm.resume(previousTx);
previousTx = null;
}
} catch (InvalidTransactionException e) {
throw new LocalTransactionException(e);
} catch (HeuristicMixedException e) {
throw new LocalTransactionException(e);
} catch (SystemException e) {
throw new LocalTransactionException(e);
} catch (HeuristicRollbackException e) {
throw new LocalTransactionException(e);
} catch (RollbackException e) {
throw new LocalTransactionException(e);
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(previousClassLoader);
previousClassLoader = null;
}
}
use of javax.transaction.HeuristicRollbackException in project graphdb by neo4j-attic.
the class TxManager method commit.
private void commit(Thread thread, TransactionImpl tx) throws SystemException, HeuristicMixedException, HeuristicRollbackException {
// mark as commit in log done TxImpl.doCommit()
Throwable commitFailureCause = null;
int xaErrorCode = -1;
if (tx.getResourceCount() == 0) {
tx.setStatus(Status.STATUS_COMMITTED);
} else {
try {
tx.doCommit();
} catch (XAException e) {
xaErrorCode = e.errorCode;
e.printStackTrace();
log.severe("Commit failed, status=" + getTxStatusAsString(tx.getStatus()) + ", errorCode=" + xaErrorCode);
if (tx.getStatus() == Status.STATUS_COMMITTED) {
// this should never be
setTmNotOk();
throw new TransactionFailureException("commit threw exception but status is committed?", e);
}
} catch (Throwable t) {
t.printStackTrace();
commitFailureCause = t;
}
}
if (tx.getStatus() != Status.STATUS_COMMITTED) {
try {
tx.doRollback();
} catch (XAException e) {
e.printStackTrace();
log.severe("Unable to rollback transaction. " + "Some resources may be commited others not. " + "Neo4j kernel should be SHUTDOWN for " + "resource maintance and transaction recovery ---->");
setTmNotOk();
if (commitFailureCause != null) {
commitFailureCause.printStackTrace();
}
throw new HeuristicMixedException("Unable to rollback ---> error code in commit: " + xaErrorCode + " ---> error code for rollback: " + e.errorCode);
}
tx.doAfterCompletion();
txThreadMap.remove(thread);
try {
if (tx.isGlobalStartRecordWritten()) {
getTxLog().txDone(tx.getGlobalId());
}
} catch (IOException e) {
e.printStackTrace();
log.severe("Error writing transaction log");
setTmNotOk();
throw new SystemException("TM encountered a problem, " + " error writing transaction log," + e);
}
tx.setStatus(Status.STATUS_NO_TRANSACTION);
if (commitFailureCause == null) {
throw new HeuristicRollbackException("Failed to commit, transaction rolledback ---> " + "error code was: " + xaErrorCode);
} else {
throw new HeuristicRollbackException("Failed to commit, transaction rolledback ---> " + commitFailureCause);
}
}
tx.doAfterCompletion();
txThreadMap.remove(thread);
try {
if (tx.isGlobalStartRecordWritten()) {
getTxLog().txDone(tx.getGlobalId());
}
} catch (IOException e) {
e.printStackTrace();
log.severe("Error writing transaction log");
setTmNotOk();
throw new SystemException("TM encountered a problem, " + " error writing transaction log," + e);
}
tx.setStatus(Status.STATUS_NO_TRANSACTION);
}
use of javax.transaction.HeuristicRollbackException in project ofbiz-framework by apache.
the class TransactionUtil method commit.
/**
* Commits the transaction in the current thread IF transactions are available
*/
public static void commit() throws GenericTransactionException {
UserTransaction ut = TransactionFactoryLoader.getInstance().getUserTransaction();
if (ut != null) {
try {
int status = ut.getStatus();
if (Debug.verboseOn())
Debug.logVerbose("Current status : " + getTransactionStateString(status), module);
if (status != STATUS_NO_TRANSACTION && status != STATUS_COMMITTING && status != STATUS_COMMITTED && status != STATUS_ROLLING_BACK && status != STATUS_ROLLEDBACK) {
ut.commit();
// clear out the stamps to keep it clean
clearTransactionStamps();
// clear out the stack too
clearTransactionBeginStack();
clearSetRollbackOnlyCause();
if (Debug.verboseOn())
Debug.logVerbose("Transaction committed", module);
} else {
Debug.logWarning("Not committing transaction, status is " + getStatusString(), module);
}
} catch (RollbackException e) {
RollbackOnlyCause rollbackOnlyCause = getSetRollbackOnlyCause();
if (rollbackOnlyCause != null) {
// the transaction is now definitely over, so clear stuff as normal now that we have the info from it that we want
clearTransactionStamps();
clearTransactionBeginStack();
clearSetRollbackOnlyCause();
Debug.logError(e, "Rollback Only was set when trying to commit transaction here; throwing rollbackOnly cause exception", module);
throw new GenericTransactionException("Roll back error, could not commit transaction, was rolled back instead because of: " + rollbackOnlyCause.getCauseMessage(), rollbackOnlyCause.getCauseThrowable());
}
Throwable t = e.getCause() == null ? e : e.getCause();
throw new GenericTransactionException("Roll back error (with no rollbackOnly cause found), could not commit transaction, was rolled back instead: " + t.toString(), t);
} catch (IllegalStateException e) {
Throwable t = e.getCause() == null ? e : e.getCause();
throw new GenericTransactionException("Could not commit transaction, IllegalStateException exception: " + t.toString(), t);
} catch (HeuristicMixedException e) {
Throwable t = e.getCause() == null ? e : e.getCause();
throw new GenericTransactionException("Could not commit transaction, HeuristicMixed exception: " + t.toString(), t);
} catch (HeuristicRollbackException e) {
Throwable t = e.getCause() == null ? e : e.getCause();
throw new GenericTransactionException("Could not commit transaction, HeuristicRollback exception: " + t.toString(), t);
} catch (SystemException e) {
Throwable t = e.getCause() == null ? e : e.getCause();
throw new GenericTransactionException("System error, could not commit transaction: " + t.toString(), t);
}
} else {
Debug.logInfo("UserTransaction is null, not committing", module);
}
}
use of javax.transaction.HeuristicRollbackException in project narayana by jbosstm.
the class JDBC2Test method testBC.
@Test
public void testBC() throws SystemException, NotSupportedException, SQLException, HeuristicRollbackException, HeuristicMixedException, RollbackException {
try (Statement stmt = conn.createStatement()) {
try {
stmt.executeUpdate("DROP TABLE test_table");
} catch (Exception e) {
// Ignore
} finally {
stmt.executeUpdate("CREATE TABLE test_table (a INTEGER,b INTEGER)");
}
}
javax.transaction.TransactionManager tx = com.arjuna.ats.jta.TransactionManager.transactionManager();
tx.begin();
TransactionSynchronizationRegistryImple transactionSynchronizationRegistryImple = new TransactionSynchronizationRegistryImple();
transactionSynchronizationRegistryImple.registerInterposedSynchronization(new Synchronization() {
@Override
public void beforeCompletion() {
try {
ResultSet res = conn.prepareStatement("SELECT * FROM test_table").executeQuery();
int rowCount1 = 0;
while (res.next()) {
rowCount1++;
}
conn.createStatement().execute("INSERT INTO test_table (a, b) VALUES (1,2)");
res = conn.prepareStatement("SELECT * FROM test_table").executeQuery();
int rowCount2 = 0;
while (res.next()) {
rowCount2++;
}
conn.close();
if (rowCount2 != rowCount1 + 1) {
fail("Number of rows = " + rowCount2 + ", test was expecting " + rowCount1 + 1);
}
} catch (Exception e) {
fail(e.getMessage());
}
}
@Override
public void afterCompletion(int status) {
}
});
tx.commit();
}
Aggregations