use of javax.transaction.HeuristicMixedException in project graphdb by neo4j-attic.
the class TxManager method rollbackCommit.
private void rollbackCommit(Thread thread, TransactionImpl tx) throws HeuristicMixedException, RollbackException, SystemException {
try {
tx.doRollback();
} catch (XAException e) {
e.printStackTrace();
log.severe("Unable to rollback marked transaction. " + "Some resources may be commited others not. " + "Neo4j kernel should be SHUTDOWN for " + "resource maintance and transaction recovery ---->");
setTmNotOk();
throw new HeuristicMixedException("Unable to rollback " + " ---> 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);
throw new RollbackException("Failed to commit, transaction rolledback");
}
use of javax.transaction.HeuristicMixedException in project spring-framework by spring-projects.
the class JtaTransactionManagerTests method jtaTransactionManagerWithHeuristicMixedExceptionOnCommit.
@Test
public void jtaTransactionManagerWithHeuristicMixedExceptionOnCommit() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
willThrow(new HeuristicMixedException("heuristic exception")).given(ut).commit();
try {
JtaTransactionManager ptm = newJtaTransactionManager(ut);
TransactionTemplate tt = new TransactionTemplate(ptm);
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
// something transactional
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCompletion(int status) {
assertTrue("Correct completion status", status == TransactionSynchronization.STATUS_UNKNOWN);
}
});
}
});
fail("Should have thrown HeuristicCompletionException");
} catch (HeuristicCompletionException ex) {
// expected
assertTrue(ex.getOutcomeState() == HeuristicCompletionException.STATE_MIXED);
}
verify(ut).begin();
}
use of javax.transaction.HeuristicMixedException in project galley by Commonjava.
the class FastLocalCacheProvider method copy.
@Override
public void copy(ConcreteResource from, ConcreteResource to) throws IOException {
final String fromNFSPath = getKeyForResource(from);
final String toNFSPath = getKeyForResource(to);
//FIXME: there is no good solution here for thread locking as there are two resource needs to be locked. If handled not correctly, will cause dead lock
InputStream nfsFrom = null;
OutputStream nfsTo = null;
try {
//FIXME: need to think about this lock of the re-entrant way and ISPN lock wait
nfsOwnerCache.beginTransaction();
nfsOwnerCache.lock(fromNFSPath, toNFSPath);
plCacheProvider.copy(from, to);
nfsFrom = new FileInputStream(getNFSDetachedFile(from));
File nfsToFile = getNFSDetachedFile(to);
if (!nfsToFile.exists() && !nfsToFile.isDirectory()) {
if (!nfsToFile.getParentFile().exists()) {
nfsToFile.getParentFile().mkdirs();
}
try {
nfsToFile.createNewFile();
} catch (IOException e) {
logger.error("[galley] New nfs file created not properly.", e);
}
}
nfsTo = new FileOutputStream(nfsToFile);
IOUtils.copy(nfsFrom, nfsTo);
//FIXME: need to use put?
nfsOwnerCache.putIfAbsent(toNFSPath, getCurrentNodeIp());
nfsOwnerCache.commit();
} catch (NotSupportedException | SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e) {
logger.error("[galley] Transaction error for nfs cache during file copying.", e);
try {
nfsOwnerCache.rollback();
} catch (SystemException se) {
final String errorMsg = "[galley] Transaction rollback error for nfs cache during file copying.";
logger.error(errorMsg, se);
throw new IllegalStateException(errorMsg, se);
}
} finally {
IOUtils.closeQuietly(nfsFrom);
IOUtils.closeQuietly(nfsTo);
}
}
use of javax.transaction.HeuristicMixedException in project aries by apache.
the class TxDBServlet method insertIntoTransaction.
/**
* This method demonstrates how to enlist JDBC connection into Transaction according OSGi enterprise specification.
*
* @param xads XADataSource
* @param tm TransactionManager
* @param value which will be inserted into table
* @param toCommit Specify if the transaction will be committed or rolledback
* @throws SQLException
* @throws GenericJTAException
*/
private void insertIntoTransaction(XADataSource xads, TransactionManager tm, String value, boolean toCommit) throws SQLException, GenericJTAException {
XAConnection xaConnection = xads.getXAConnection();
Connection connection = xaConnection.getConnection();
XAResource xaResource = xaConnection.getXAResource();
try {
tm.begin();
Transaction transaction = tm.getTransaction();
transaction.enlistResource(xaResource);
PreparedStatement insertStatement = connection.prepareStatement(INSERT_INTO_TABLE);
insertStatement.setString(1, value);
insertStatement.executeUpdate();
if (toCommit) {
transaction.commit();
} else {
transaction.rollback();
}
} catch (RollbackException e) {
throw new GenericJTAException(e);
} catch (SecurityException e) {
throw new GenericJTAException(e);
} catch (IllegalStateException e) {
throw new GenericJTAException(e);
} catch (HeuristicMixedException e) {
throw new GenericJTAException(e);
} catch (HeuristicRollbackException e) {
throw new GenericJTAException(e);
} catch (SystemException e) {
throw new GenericJTAException(e);
} catch (NotSupportedException e) {
throw new GenericJTAException(e);
}
}
Aggregations