Search in sources :

Example 96 with TransactionManager

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);
    }
}
Also used : LocalTransactionException(javax.resource.spi.LocalTransactionException) SystemException(javax.transaction.SystemException) LogWriter(org.apache.geode.LogWriter) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) TransactionManager(javax.transaction.TransactionManager) ResourceException(javax.resource.ResourceException)

Example 97 with TransactionManager

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();
    }
}
Also used : TransactionManager(javax.transaction.TransactionManager) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 98 with TransactionManager

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();
    }
}
Also used : Transaction(javax.transaction.Transaction) TransactionManager(javax.transaction.TransactionManager) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 99 with TransactionManager

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);
    }
}
Also used : TransactionManager(javax.transaction.TransactionManager) IgniteException(org.apache.ignite.IgniteException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 100 with TransactionManager

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;
    }
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext) ConcurrentMap(java.util.concurrent.ConcurrentMap) Synchronization(javax.transaction.Synchronization) RollbackException(javax.transaction.RollbackException) BeanContext(org.apache.openejb.BeanContext) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) SystemInstance(org.apache.openejb.loader.SystemInstance) TransactionManager(javax.transaction.TransactionManager) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

TransactionManager (javax.transaction.TransactionManager)110 Test (org.junit.Test)40 Transaction (javax.transaction.Transaction)24 SystemException (javax.transaction.SystemException)22 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)15 UserTransaction (javax.transaction.UserTransaction)14 JtaTransactionCoordinatorImpl (org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl)12 JtaTransactionManager (org.springframework.transaction.jta.JtaTransactionManager)11 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)9 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)9 Method (java.lang.reflect.Method)7 EntityManager (javax.persistence.EntityManager)7 NotSupportedException (javax.transaction.NotSupportedException)7 RollbackException (javax.transaction.RollbackException)7 SynchronizationCollectorImpl (org.hibernate.test.resource.common.SynchronizationCollectorImpl)6 TestForIssue (org.hibernate.testing.TestForIssue)6 IOException (java.io.IOException)5 InitialContext (javax.naming.InitialContext)5 DataSource (javax.sql.DataSource)5 JtaPlatform (org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform)5