use of javax.transaction.RollbackException in project geode by apache.
the class LocalRegion method getJTAEnlistedTX.
private TXStateInterface getJTAEnlistedTX() {
if (this.ignoreJTA) {
// fixes bug 45541
return null;
}
TXStateInterface txState = getTXState();
if (txState != null) {
return txState;
} else {
try {
if (!this.ignoreJTA && this.cache.getJTATransactionManager() != null) {
Transaction jtaTransaction = this.cache.getJTATransactionManager().getTransaction();
if (jtaTransaction == null || jtaTransaction.getStatus() == Status.STATUS_NO_TRANSACTION) {
return null;
}
txState = this.cache.getTXMgr().beginJTA();
jtaTransaction.registerSynchronization(txState);
return txState;
} else {
return null;
}
} catch (SystemException se) {
// this can be thrown when the system is shutting down (see bug #39728)
this.stopper.checkCancelInProgress(se);
jtaEnlistmentFailureCleanup(txState, se);
return null;
} catch (RollbackException | IllegalStateException re) {
jtaEnlistmentFailureCleanup(txState, re);
return null;
}
}
}
use of javax.transaction.RollbackException in project geode by apache.
the class FacetsJCAConnectionManagerImpl method allocateConnection.
/*
* allocates a ManagedConnection from the ConnectionPool or creates a new
* ManagedConnection. @param javax.resource.spi.ManagedConnectionFactory
*
* @param javax.resource.spi.ConnectionRequestInfo
*
* @throws ResourceException
*/
public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo reqInfo) throws ResourceException {
if (!isActive) {
throw new ResourceException(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPLALLOCATECONNECTIONNO_VALID_CONNECTION_AVAILABLE.toLocalizedString());
}
ManagedConnection conn = null;
try {
conn = (ManagedConnection) mannPoolCache.getPooledConnectionFromPool();
} catch (PoolException ex) {
ex.printStackTrace();
throw new ResourceException(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_IN_GETTING_CONNECTION_FROM_POOL_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
}
// Transaction Manager.
try {
synchronized (this) {
if (transManager == null) {
transManager = JNDIInvoker.getTransactionManager();
}
}
Transaction txn = transManager.getTransaction();
if (txn != null) {
// Check if Data Source provides XATransaction
// if(configs.getTransactionType = "XATransaction")
XAResource xar = conn.getXAResource();
txn.enlistResource(xar);
java.util.List resList = (List) xalistThreadLocal.get();
if (resList.size() == 0) {
// facets specific implementation
// register syschronisation only once
txn.registerSynchronization(this);
}
resList.add(conn);
// xalistThreadLocal.set(resList);
// Asif :Add in the Map after successful registration of XAResource
// xaResourcesMap.put(conn, xar);
// else throw a resource exception
}
} catch (RollbackException ex) {
String exception = LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_AN_EXCEPTION_WAS_CAUGHT_WHILE_ALLOCATING_A_CONNECTION_DUE_TO_0.toLocalizedString(ex.getMessage());
throw new ResourceException(exception, ex);
} catch (SystemException ex) {
throw new ResourceException(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_SYSTEM_EXCEPTION_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
}
return conn.getConnection(subject, reqInfo);
}
use of javax.transaction.RollbackException in project geode by apache.
the class QueryAndJtaJUnitTest method testScenario1.
@Test
public void testScenario1() throws Exception {
Context ctx = cache.getJNDIContext();
UserTransaction ta = null;
// Connection conn = null;
try {
qs.createIndex("iIndex", IndexType.FUNCTIONAL, "ID", "/portfolios");
// PUT 4 objects in region, QUERY, CREATEINDEX
for (int i = 0; i < 4; i++) {
currRegion.put("key" + i, new Portfolio(i));
}
QueryObserverImpl observer2 = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer2);
q = qs.newQuery("select distinct * from /portfolios where ID != 53");
Object r = q.execute();
if (!observer2.isIndexesUsed) {
fail("NO INDEX WAS USED, IT WAS EXPECTED TO BE USED");
}
if (((Collection) r).size() != 4) {
fail("Query result not of expected size");
}
// print("Size of query result :"+ ((Collection)r).size());
// print("Result of query =" + Utils.printResult(r));
// print("Index IS: " + ((RangeIndex)i2).dump());
// BEGIN TX PUT new 4 objects in region, QUERY,CREATEINDEX, ROLLBACK
ta = (UserTransaction) ctx.lookup("java:/UserTransaction");
ta.begin();
for (int i = 9; i < 13; i++) {
currRegion.put("key" + i, new Portfolio(i));
}
observer2 = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer2);
q = qs.newQuery("select distinct * from /portfolios where ID != 53");
r = q.execute();
if (!observer2.isIndexesUsed) {
fail("NO INDEX WAS USED, IT WAS EXPECTED TO BE USED");
}
if (((Collection) r).size() != 4) {
fail("Query result not of expected size");
}
// print("Size of query result :"+ ((Collection)r).size());
// print("Result of query =" + Utils.printResult(r));
Index i1 = qs.createIndex("tIndex", IndexType.FUNCTIONAL, "status", "/portfolios");
// print("Index IS: " + ((RangeIndex)i1).dump());
observer2 = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer2);
q = qs.newQuery("select distinct * from /portfolios where status = 'active'");
r = q.execute();
if (!observer2.isIndexesUsed) {
fail("NO INDEX WAS USED, IT WAS EXPECTED TO BE USED");
}
if (((Collection) r).size() != 2) {
fail("Query result not of expected size");
}
observer2 = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer2);
q = qs.newQuery("select distinct * from /portfolios where status = 'inactive'");
r = q.execute();
if (!observer2.isIndexesUsed) {
fail("NO INDEX WAS USED, IT WAS EXPECTED TO BE USED");
}
if (((Collection) r).size() != 2) {
fail("Query result not of expected size");
}
ta.rollback();
// PRINT INDEX AFTER ROLLBACK, REMOVEINDEX.
observer2 = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer2);
q = qs.newQuery("select distinct * from /portfolios where status = 'active'");
r = q.execute();
if (!observer2.isIndexesUsed) {
fail("NO INDEX WAS USED, IT WAS EXPECTED TO BE USED");
}
if (((Collection) r).size() != 2) {
fail("Query result not of expected size");
}
// print("AfterRollback \n"+currRegion.values());
// print("Index IS: " + ((RangeIndex)i1).dump());
qs.removeIndex(i1);
// BEGIN TX PUT new 4 objects in region,CREATEINDEX, QUERY ,COMMIT
ta.begin();
for (int i = 9; i < 13; i++) {
currRegion.put("key" + i, new Portfolio(i));
}
i1 = qs.createIndex("tIndex", IndexType.FUNCTIONAL, "status", "/portfolios");
// print("Index IS: " + ((RangeIndex)i1).dump());
observer2 = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer2);
q = qs.newQuery("select distinct * from /portfolios where status = 'active'");
r = q.execute();
if (!observer2.isIndexesUsed) {
fail("NO INDEX WAS USED, IT WAS EXPECTED TO BE USED");
}
if (((Collection) r).size() != 2) {
fail("Query result not of expected size");
}
for (int i = 9; i < 13; i++) {
currRegion.put("key" + i, new Portfolio(i));
}
observer2 = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer2);
q = qs.newQuery("select distinct * from /portfolios where status = 'active'");
r = q.execute();
if (!observer2.isIndexesUsed) {
fail("NO INDEX WAS USED, IT WAS EXPECTED TO BE USED");
}
if (((Collection) r).size() != 2) {
fail("Query result not of expected size");
}
// print("Size of query result :"+ ((Collection)r).size());
// print("Result of query =" + Utils.printResult(r));
// print("Index on status IS: " + ((RangeIndex)i1).dump());
// print("Index On ID IS: " + ((RangeIndex)i2).dump());
ta.commit();
// WAIT FOR 2 secs DISPLAYINDEX, QUERY
Thread.sleep(2000);
// print("Aftercommit \n"+currRegion.values());
// print("Index IS: " + ((RangeIndex)i1).dump());
observer2 = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer2);
q = qs.newQuery("select distinct * from /portfolios where status = 'active'");
r = q.execute();
if (!observer2.isIndexesUsed) {
fail("NO INDEX WAS USED, IT WAS EXPECTED TO BE USED");
}
if (((Collection) r).size() != 4) {
fail("Query result not of expected size");
}
observer2 = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer2);
q = qs.newQuery("select distinct * from /portfolios where status = 'inactive'");
r = q.execute();
if (!observer2.isIndexesUsed) {
fail("NO INDEX WAS USED, IT WAS EXPECTED TO BE USED");
}
if (((Collection) r).size() != 4) {
fail("Query result not of expected size");
}
observer2 = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer2);
q = qs.newQuery("select distinct * from /portfolios where ID != 53");
r = q.execute();
if (!observer2.isIndexesUsed) {
fail("NO INDEX WAS USED, IT WAS EXPECTED TO BE USED");
}
if (((Collection) r).size() != 8) {
fail("Query result not of expected size");
}
// print("Size of query result :"+ ((Collection)r).size());
// print("Result of query =" + Utils.printResult(r));
// print("Index On ID IS: " + ((RangeIndex)i2).dump());
} catch (RollbackException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
ta.rollback();
}
}
use of javax.transaction.RollbackException in project geode by apache.
the class GlobalTransactionJUnitTest method testRegisterSynchronization.
@Test
public void testRegisterSynchronization() throws Exception {
try {
boolean exceptionoccurred = false;
utx.begin();
try {
Transaction txn = tm.getTransaction();
Synchronization sync = new SyncImpl();
txn.registerSynchronization(sync);
} catch (RollbackException e) {
exceptionoccurred = true;
}
if (exceptionoccurred)
fail("exception occurred while trying to register synchronization ");
utx.rollback();
} catch (Exception e) {
try {
utx.rollback();
} catch (Exception e1) {
e1.printStackTrace();
}
fail("exception in testRegisterSynchronization due to " + e);
e.printStackTrace();
}
}
use of javax.transaction.RollbackException in project geode by apache.
the class GlobalTransactionJUnitTest method testRegisterSynchronizationAfterRollBack.
@Test
public void testRegisterSynchronizationAfterRollBack() throws Exception {
try {
boolean exceptionoccurred = false;
utx.begin();
utx.setRollbackOnly();
Context ctx = cache.getJNDIContext();
try {
Transaction txn = tm.getTransaction();
Synchronization sync = new SyncImpl();
txn.registerSynchronization(sync);
} catch (RollbackException e) {
exceptionoccurred = true;
}
if (!exceptionoccurred)
fail("RollbackException not occurred although the transaction was marked for rollback");
utx.rollback();
} catch (Exception e) {
try {
utx.rollback();
} catch (Exception e1) {
e1.printStackTrace();
}
fail("exception in testSetRollbackonly due to " + e);
e.printStackTrace();
}
}
Aggregations