use of javax.transaction.SystemException in project geode by apache.
the class JNDIInvoker method mapTransactions.
/**
* Bind the transaction resources. Bind UserTransaction and TransactionManager.
* <p>
* If there is pre-existing JNDI tree in the system and TransactionManager / UserTransaction is
* already bound, GemFire will make use of these resources, but if TransactionManager /
* UserTransaction is not available, the GemFire TransactionManager / UserTransaction will be
* bound to the JNDI tree.
* </p>
*
*/
public static void mapTransactions(DistributedSystem distSystem) {
try {
TransactionUtils.setLogWriter(distSystem.getLogWriter().convertToLogWriterI18n());
cleanup();
if (IGNORE_JTA) {
return;
}
ctx = new InitialContext();
doTransactionLookup();
} catch (NamingException ne) {
LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
if (ne instanceof NoInitialContextException) {
String exception = "JNDIInvoker::mapTransactions:: No application server context found, Starting GemFire JNDI Context Context ";
if (writer.finerEnabled())
writer.finer(exception);
try {
initializeGemFireContext();
transactionManager = TransactionManagerImpl.getTransactionManager();
ctx.rebind("java:/TransactionManager", transactionManager);
if (writer.fineEnabled())
writer.fine("JNDIInvoker::mapTransactions::Bound TransactionManager to Context GemFire JNDI Tree");
UserTransactionImpl utx = new UserTransactionImpl();
ctx.rebind("java:/UserTransaction", utx);
if (writer.fineEnabled())
writer.fine("JNDIInvoker::mapTransactions::Bound Transaction to Context GemFire JNDI Tree");
} catch (NamingException ne1) {
if (writer.infoEnabled())
writer.info(LocalizedStrings.JNDIInvoker_JNDIINVOKERMAPTRANSACTIONSNAMINGEXCEPTION_WHILE_BINDING_TRANSACTIONMANAGERUSERTRANSACTION_TO_GEMFIRE_JNDI_TREE);
} catch (SystemException se1) {
if (writer.infoEnabled())
writer.info(LocalizedStrings.JNDIInvoker_JNDIINVOKERMAPTRANSACTIONSSYSTEMEXCEPTION_WHILE_BINDING_USERTRANSACTION_TO_GEMFIRE_JNDI_TREE);
}
} else if (ne instanceof NameNotFoundException) {
String exception = "JNDIInvoker::mapTransactions:: No TransactionManager associated to Application server context, trying to bind GemFire TransactionManager";
if (writer.finerEnabled())
writer.finer(exception);
try {
transactionManager = TransactionManagerImpl.getTransactionManager();
ctx.rebind("java:/TransactionManager", transactionManager);
if (writer.fineEnabled())
writer.fine("JNDIInvoker::mapTransactions::Bound TransactionManager to Application Server Context");
UserTransactionImpl utx = new UserTransactionImpl();
ctx.rebind("java:/UserTransaction", utx);
if (writer.fineEnabled())
writer.fine("JNDIInvoker::mapTransactions::Bound UserTransaction to Application Server Context");
} catch (NamingException ne1) {
if (writer.infoEnabled())
writer.info(LocalizedStrings.JNDIInvoker_JNDIINVOKERMAPTRANSACTIONSNAMINGEXCEPTION_WHILE_BINDING_TRANSACTIONMANAGERUSERTRANSACTION_TO_APPLICATION_SERVER_JNDI_TREE);
} catch (SystemException se1) {
if (writer.infoEnabled())
writer.info(LocalizedStrings.JNDIInvoker_JNDIINVOKERMAPTRANSACTIONSSYSTEMEXCEPTION_WHILE_BINDING_TRANSACTIONMANAGERUSERTRANSACTION_TO_APPLICATION_SERVER_JNDI_TREE);
}
}
}
}
use of javax.transaction.SystemException in project geode by apache.
the class ExceptionJUnitTest method testAddNullTransaction.
@Test
public void testAddNullTransaction() throws Exception {
try {
utx.begin();
GlobalTransaction gtx = tm.getGlobalTransaction();
Transaction txn = null;
gtx.addTransaction(txn);
utx.commit();
fail("SystemException not thrown on adding null transaction");
} catch (SystemException e) {
utx.commit();
}
}
use of javax.transaction.SystemException in project geode by apache.
the class TxnTimeOutDUnitTest method runTest3.
public static void runTest3(Object o) throws SystemException, NotSupportedException, NamingException, InterruptedException {
boolean exceptionOccurred = false;
int sleeptime = ((Integer) o).intValue();
Context ctx = cache.getJNDIContext();
UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
utx.begin();
utx.setTransactionTimeout(sleeptime);
Thread.sleep(sleeptime * 2000);
try {
utx.commit();
} catch (Exception e) {
exceptionOccurred = true;
}
if (!exceptionOccurred) {
fail("exception did not occur although was supposed to occur");
}
}
use of javax.transaction.SystemException in project jackrabbit by apache.
the class UserTransactionImpl method rollback.
/**
* @see javax.transaction.UserTransaction#rollback
*/
public void rollback() throws IllegalStateException, SecurityException, SystemException {
if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK) {
throw new IllegalStateException("Transaction not active");
}
try {
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.end(xid, XAResource.TMFAIL);
}
status = Status.STATUS_ROLLING_BACK;
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.rollback(xid);
}
status = Status.STATUS_ROLLEDBACK;
} catch (XAException e) {
SystemException se = new SystemException("Unable to rollback transaction: XA_ERR=" + e.errorCode);
se.initCause(e.getCause());
throw se;
}
}
use of javax.transaction.SystemException in project jackrabbit by apache.
the class UserTransactionImpl method commit.
/**
* @see javax.transaction.UserTransaction#commit
*/
public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException {
if (status != Status.STATUS_ACTIVE) {
throw new IllegalStateException("Transaction not active");
}
try {
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.end(xid, XAResource.TMSUCCESS);
}
status = Status.STATUS_PREPARING;
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.prepare(xid);
}
status = Status.STATUS_PREPARED;
status = Status.STATUS_COMMITTING;
if (distributedThreadAccess) {
Thread distributedThread = new Thread() {
public void run() {
try {
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.commit(xid, false);
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
};
distributedThread.start();
distributedThread.join(1000);
if (distributedThread.isAlive()) {
throw new SystemException("Commit from different thread but same XID must not block");
}
} else {
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.commit(xid, false);
}
}
status = Status.STATUS_COMMITTED;
} catch (XAException e) {
if (e.errorCode >= XAException.XA_RBBASE && e.errorCode <= XAException.XA_RBEND) {
RollbackException re = new RollbackException("Transaction rolled back: XA_ERR=" + e.errorCode);
re.initCause(e.getCause());
throw re;
} else {
SystemException se = new SystemException("Unable to commit transaction: XA_ERR=" + e.errorCode);
se.initCause(e.getCause());
throw se;
}
} catch (InterruptedException e) {
throw new SystemException("Thread.join() interrupted");
}
}
Aggregations