use of javax.transaction.TransactionManager in project geode by apache.
the class JCALocalTransaction method begin.
@Override
public void begin() throws ResourceException {
try {
if (!this.initDone || this.cache.isClosed()) {
this.init();
}
LogWriter logger = this.cache.getLogger();
if (logger.fineEnabled()) {
logger.fine("JCALocalTransaction::begin:");
}
TransactionManager tm = this.cache.getJTATransactionManager();
if (this.tid != null) {
throw new LocalTransactionException(" A transaction is already in progress");
}
if (tm != null && tm.getTransaction() != null) {
if (logger.fineEnabled()) {
logger.fine("JCAManagedConnection: JTA transaction is on");
}
// This is having a JTA transaction. Assuming ignore jta flag is true,
// explicitly being a gemfire transaction.
TXStateProxy tsp = this.gfTxMgr.getTXState();
if (tsp == null) {
this.gfTxMgr.begin();
tsp = this.gfTxMgr.getTXState();
tsp.setJCATransaction();
this.tid = tsp.getTransactionId();
if (logger.fineEnabled()) {
logger.fine("JCALocalTransaction:begun GFE transaction");
}
} else {
throw new LocalTransactionException("GemFire is already associated with a transaction");
}
} else {
if (logger.fineEnabled()) {
logger.fine("JCAManagedConnection: JTA Transaction does not exist.");
}
}
} catch (SystemException e) {
throw new ResourceException(e);
}
}
use of javax.transaction.TransactionManager in project geode by apache.
the class JtaIntegrationJUnitTest method testBug46192.
@Test
public void testBug46192() throws Exception {
String tableName = CacheUtils.init("CacheTest");
assertFalse(tableName == null || tableName.equals(""));
logger.debug("Table name: " + tableName);
logger.debug("init for bug46192 Successful!");
Cache cache = CacheUtils.getCache();
TransactionManager xmanager = (TransactionManager) cache.getJNDIContext().lookup("java:/TransactionManager");
assertNotNull(xmanager);
try {
xmanager.rollback();
fail("Expected IllegalStateException");
} catch (IllegalStateException expected) {
// passed
}
try {
xmanager.commit();
fail("Expected IllegalStateException");
} catch (IllegalStateException expected) {
// passed
}
try {
logger.debug("Destroying table: " + tableName);
CacheUtils.destroyTable(tableName);
logger.debug("Closing cache...");
logger.debug("destroyTable for bug46192 Successful!");
} finally {
CacheUtils.closeCache();
}
}
use of javax.transaction.TransactionManager in project geode by apache.
the class JtaIntegrationJUnitTest method testBug46169.
@Test
public void testBug46169() throws Exception {
String tableName = CacheUtils.init("CacheTest");
assertFalse(tableName == null || tableName.equals(""));
logger.debug("Table name: " + tableName);
logger.debug("init for bug46169 Successful!");
Cache cache = CacheUtils.getCache();
TransactionManager xmanager = (TransactionManager) cache.getJNDIContext().lookup("java:/TransactionManager");
assertNotNull(xmanager);
Transaction trans = xmanager.suspend();
assertNull(trans);
try {
logger.debug("Destroying table: " + tableName);
CacheUtils.destroyTable(tableName);
logger.debug("Closing cache...");
logger.debug("destroyTable for bug46169 Successful!");
} finally {
CacheUtils.closeCache();
}
}
use of javax.transaction.TransactionManager in project ignite by apache.
the class WebSphereTmFactory method create.
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public TransactionManager create() {
try {
Class clazz = Class.forName("com.ibm.tx.jta.impl.TranManagerSet");
Method m = clazz.getMethod("instance", (Class[]) null);
TransactionManager tranMgr = (TransactionManager) m.invoke(null, (Object[]) null);
return new WebSphereTransactionManager(tranMgr);
} catch (SecurityException | ClassNotFoundException | IllegalArgumentException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new IgniteException(e);
}
}
use of javax.transaction.TransactionManager in project tomee by apache.
the class BaseEjbProxyHandler method getLiveHandleRegistry.
public ConcurrentMap getLiveHandleRegistry() {
final BeanContext beanContext = getBeanContext();
final ThreadContext tc = ThreadContext.getThreadContext();
if (tc != null && tc.getBeanContext() != beanContext && /* parent bean */
tc.getCurrentOperation() == Operation.BUSINESS) {
ProxyRegistry registry = tc.get(ProxyRegistry.class);
if (registry == null) {
registry = new ProxyRegistry();
tc.set(ProxyRegistry.class, registry);
}
return registry.liveHandleRegistry;
} else {
// use the tx if there
final SystemInstance systemInstance = SystemInstance.get();
final TransactionManager txMgr = systemInstance.getComponent(TransactionManager.class);
try {
final Transaction tx = txMgr.getTransaction();
if (tx != null && tx.getStatus() == Status.STATUS_ACTIVE) {
final TransactionSynchronizationRegistry registry = systemInstance.getComponent(TransactionSynchronizationRegistry.class);
final String resourceKey = ProxyRegistry.class.getName();
ConcurrentMap map = ConcurrentMap.class.cast(registry.getResource(resourceKey));
if (map == null) {
map = new ConcurrentHashMap();
registry.putResource(resourceKey, map);
try {
final ConcurrentMap tmp = map;
tx.registerSynchronization(new Synchronization() {
@Override
public void beforeCompletion() {
// no-op
}
@Override
public void afterCompletion(final int status) {
tmp.clear();
}
});
} catch (final RollbackException e) {
// not really possible since we check the status
// let it go to default
}
}
return map;
}
} catch (final SystemException e) {
// let it go to default
}
// back to default but it doesnt release the memory
ProxyRegistry proxyRegistry = beanContext.get(ProxyRegistry.class);
if (proxyRegistry == null) {
proxyRegistry = new ProxyRegistry();
beanContext.set(ProxyRegistry.class, proxyRegistry);
}
return proxyRegistry.liveHandleRegistry;
}
}
Aggregations