Java 类javax.transaction.TransactionSynchronizationRegistry 实例源码

项目:agroal    文件:EnlistmentTests.java   
@Test
@DisplayName( "Connection outside the scope of a transaction test" )
public void connectionOutsideTransactionTest() throws SQLException {
    TransactionManager txManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
    TransactionSynchronizationRegistry txSyncRegistry = new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple();

    AgroalDataSourceConfigurationSupplier configurationSupplier = new AgroalDataSourceConfigurationSupplier()
            .connectionPoolConfiguration( cp -> cp
                    .transactionIntegration( new NarayanaTransactionIntegration( txManager, txSyncRegistry ) )
            );

    try ( AgroalDataSource dataSource = AgroalDataSource.from( configurationSupplier ) ) {
        Connection connection = dataSource.getConnection();
        logger.info( format( "Got connection {0}", connection ) );
        connection.close();
        assertTrue( connection.isClosed() );
    }
}
项目:agroal    文件:BasicNarayanaTests.java   
@Test
@DisplayName( "Basic rollback test" )
public void basicRollbackTest() throws SQLException {
    TransactionManager txManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
    TransactionSynchronizationRegistry txSyncRegistry = new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple();

    AgroalDataSourceConfigurationSupplier configurationSupplier = new AgroalDataSourceConfigurationSupplier()
            .connectionPoolConfiguration( cp -> cp
                    .transactionIntegration( new NarayanaTransactionIntegration( txManager, txSyncRegistry ) )
            );

    try ( AgroalDataSource dataSource = AgroalDataSource.from( configurationSupplier ) ) {
        txManager.begin();

        Connection connection = dataSource.getConnection();
        logger.info( format( "Got connection {0}", connection ) );

        txManager.rollback();

        assertTrue( connection.isClosed() );
    } catch ( NotSupportedException | SystemException e ) {
        fail( "Exception: " + e.getMessage() );
    }
}
项目:agroal    文件:BasicNarayanaTests.java   
@Test
@DisplayName( "Multiple close test" )
public void multipleCloseTest() throws SQLException {
    TransactionManager txManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
    TransactionSynchronizationRegistry txSyncRegistry = new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple();

    AgroalDataSourceConfigurationSupplier configurationSupplier = new AgroalDataSourceConfigurationSupplier()
            .connectionPoolConfiguration( cp -> cp
                    .transactionIntegration( new NarayanaTransactionIntegration( txManager, txSyncRegistry ) )
            );

    try ( AgroalDataSource dataSource = AgroalDataSource.from( configurationSupplier ) ) {

        // there is a call to connection#close in the try-with-resources block and another on the callback from the transaction#commit()
        try ( Connection connection = dataSource.getConnection() ) {
            logger.info( format( "Got connection {0}", connection ) );
            try {
                txManager.begin();
                txManager.commit();
            } catch ( NotSupportedException | SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e ) {
                fail( "Exception: " + e.getMessage() );
            }
        }  
    }
}
项目:spring4-understanding    文件:HibernateTransactionManagerTests.java   
@Test
public void testSetJtaTransactionManager() throws Exception {
    DataSource ds = mock(DataSource.class);
    TransactionManager tm = mock(TransactionManager.class);
    UserTransaction ut = mock(UserTransaction.class);
    TransactionSynchronizationRegistry tsr = mock(TransactionSynchronizationRegistry.class);
    JtaTransactionManager jtm = new JtaTransactionManager();
    jtm.setTransactionManager(tm);
    jtm.setUserTransaction(ut);
    jtm.setTransactionSynchronizationRegistry(tsr);
    LocalSessionFactoryBuilder lsfb = new LocalSessionFactoryBuilder(ds);
    lsfb.setJtaTransactionManager(jtm);
    Object jtaPlatform = lsfb.getProperties().get(AvailableSettings.JTA_PLATFORM);
    assertNotNull(jtaPlatform);
    assertSame(tm, jtaPlatform.getClass().getMethod("retrieveTransactionManager").invoke(jtaPlatform));
    assertSame(ut, jtaPlatform.getClass().getMethod("retrieveUserTransaction").invoke(jtaPlatform));
    assertTrue(lsfb.getProperties().get(AvailableSettings.TRANSACTION_STRATEGY) instanceof CMTTransactionFactory);
}
项目:ironjacamar    文件:TransactionIntegrationImpl.java   
/**
 * Constructor
 * @param tm The transaction manager
 * @param tsr The transaction synchronization registry
 * @param utr The user transaction registry
 * @param terminator The XA terminator
 * @param rr The recovery registry
 */
public TransactionIntegrationImpl(TransactionManager tm,
                                  TransactionSynchronizationRegistry tsr,
                                  org.jboss.tm.usertx.UserTransactionRegistry utr,
                                  org.jboss.tm.JBossXATerminator terminator,
                                  org.jboss.tm.XAResourceRecoveryRegistry rr)
{
   if (tm instanceof org.jboss.tm.TransactionTimeoutConfiguration)
   {
      this.tm = new TransactionManagerDelegator(tm);
   }
   else
   {
      this.tm = tm;
   }
   this.tsr = tsr;
   this.utr = new UserTransactionRegistryImpl(utr);
   this.terminator = terminator;
   this.rr = rr;
}
项目:ironjacamar    文件:BootstrapContextImpl.java   
/**
 * Constructor
 * @param wm The WorkManager
 * @param tsr The TransactionSynchronizationRegistry
 * @param terminator The XATerminator
 * @param validatorFactory the ValidatorFactory
 */
public BootstrapContextImpl(WorkManager wm,
                            TransactionSynchronizationRegistry tsr,
                            XATerminator terminator,
                            ValidatorFactory validatorFactory)
{
   this.workManager = wm;
   this.transactionSynchronizationRegistry = tsr;
   this.xaTerminator = terminator;
   this.supportedContexts = new HashSet<Class>(3);
   this.validatorFactory = validatorFactory;
   this.supportedContexts.add(HintsContext.class);
   this.supportedContexts.add(SecurityContext.class);
   this.supportedContexts.add(TransactionContext.class);

   this.timers = null;
}
项目:tomee    文件:Assembler.java   
private void checkBuiltInResourceTypes(final ResourceReference reference, final String jndi) {
    final Class<?> resourceType = reference.getResourceType();
    if ("java:comp/BeanManager".equals(jndi) && resourceType != BeanManager.class) {
        throw new DefinitionException(
                "Resource " + reference.getJndiName() + " in " + reference.getOwnerClass() + " can't be cast to a BeanManager");
    } else if ("java:comp/TransactionSynchronizationRegistry".equals(jndi) && resourceType != TransactionSynchronizationRegistry.class) {
        throw new DefinitionException(
                "Resource " + reference.getJndiName() + " in " + reference.getOwnerClass() + " can't be cast to a TransactionSynchronizationRegistry");
    } else if ("java:comp/TransactionManager".equals(jndi) && resourceType != TransactionManager.class) {
        throw new DefinitionException(
                "Resource " + reference.getJndiName() + " in " + reference.getOwnerClass() + " can't be cast to a TransactionManager");
    } else if ("java:comp/ValidatorFactory".equals(jndi) && resourceType != ValidatorFactory.class) {
        throw new DefinitionException(
                "Resource " + reference.getJndiName() + " in " + reference.getOwnerClass() + " can't be cast to a ValidatorFactory");
    } else if ("java:comp/Validator".equals(jndi) && resourceType != Validator.class) {
        throw new DefinitionException(
                "Resource " + reference.getJndiName() + " in " + reference.getOwnerClass() + " can't be cast to a Validator");
    }
}
项目:tomee    文件:SetValuedCmr.java   
public SetValuedCmr(final EntityBean source, final String sourceProperty, final Class<Bean> relatedType, final String relatedProperty) {
    if (source == null) {
        throw new NullPointerException("source is null");
    }
    if (relatedType == null) {
        throw new NullPointerException("relatedType is null");
    }

    this.source = source;
    this.sourceProperty = sourceProperty;
    this.relatedProperty = relatedProperty;

    this.relatedInfo = Cmp2Util.getBeanContext(relatedType);

    transactionRegistry = SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class);
}
项目:tomee    文件:CmrSet.java   
public CmrSet(final EntityBean source, final String sourceProperty, final BeanContext relatedInfo, final String relatedProperty, final Collection<Bean> relatedBeans) {
    this.source = source;
    this.sourceProperty = sourceProperty;
    this.relatedInfo = relatedInfo;
    this.relatedProperty = relatedProperty;
    this.relatedBeans = relatedBeans;

    relatedLocal = relatedInfo.getLocalInterface();
    final TransactionSynchronizationRegistry transactionRegistry = SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class);
    try {
        transactionRegistry.registerInterposedSynchronization(new Synchronization() {
            public void beforeCompletion() {
            }

            public void afterCompletion(final int i) {
                mutable = false;
            }
        });
    } catch (final IllegalStateException ignored) {
        // no tx so not mutable
        mutable = false;
    }
}
项目:tomee    文件:JpaTest.java   
public void setUp() throws Exception {
    super.setUp();


    // setup tx mgr
    transactionManager = new GeronimoTransactionManager();
    SystemInstance.get().setComponent(TransactionSynchronizationRegistry.class, transactionManager);

    // setup naming
    MockInitialContextFactory.install(Collections.singletonMap("java:comp/TransactionSynchronizationRegistry", transactionManager));
    assertSame(transactionManager, new InitialContext().lookup("java:comp/TransactionSynchronizationRegistry"));

    // Put tx mgr into SystemInstance so OpenJPA can find it
    SystemInstance.get().setComponent(TransactionManager.class, transactionManager);

    // init databases
    jtaDs = createJtaDataSource(transactionManager);
    nonJtaDs = createNonJtaDataSource();
    initializeDatabase(jtaDs);
}
项目:btm    文件:BitronixTransactionSynchronizationRegistryTest.java   
public void testMultiThreaded() throws Exception {
    final TransactionSynchronizationRegistry reg = TransactionManagerServices.getTransactionSynchronizationRegistry();

    btm.begin();
    reg.putResource("1", "one");
    assertEquals("one", reg.getResource("1"));
    btm.commit();

    Thread t = new Thread() {
        public void run() {
            try {
                btm.begin();
                reg.putResource("1", "one");
                assertEquals("one", reg.getResource("1"));
                btm.commit();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };

    t.start();
    t.join();
}
项目:btm    文件:BitronixTransactionSynchronizationRegistryTest.java   
public void testRegistrySynchronizations() throws Exception {
    TransactionSynchronizationRegistry reg = TransactionManagerServices.getTransactionSynchronizationRegistry();

    CoutingSynchronization normalSync = new CoutingSynchronization();
    CoutingSynchronization interposedSync = new CoutingSynchronization();

    btm.begin();

    reg.registerInterposedSynchronization(interposedSync);
    btm.getCurrentTransaction().registerSynchronization(normalSync);

    btm.commit();

    assertTrue(normalSync.getBeforeTimestamp() < interposedSync.getBeforeTimestamp());
    assertTrue(interposedSync.getBeforeTimestamp() < normalSync.getAfterTimestamp());
    assertTrue(interposedSync.getAfterTimestamp() < normalSync.getAfterTimestamp());
}
项目:org.ops4j.pax.transx    文件:TransactionManagerService.java   
public void init() throws Exception {
    List<String> clazzes = new ArrayList<>();
    clazzes.add(TransactionManager.class.getName());
    clazzes.add(TransactionSynchronizationRegistry.class.getName());
    clazzes.add(UserTransaction.class.getName());
    clazzes.add(RecoverableTransactionManager.class.getName());
    if (useSpring) {
        clazzes.add(PLATFORM_TRANSACTION_MANAGER_CLASS);
    }
    String[] ifar = clazzes.toArray(new String[clazzes.size()]);
    serviceRegistration = bundleContext.registerService(ifar, transactionManager, null);
    wrapperRegistration = bundleContext.registerService(org.ops4j.pax.transx.tm.TransactionManager.class,
            new TransactionManagerWrapper(transactionManager), null);
}
项目:lams    文件:JtaTransactionManager.java   
/**
 * Look up the JTA 1.1 TransactionSynchronizationRegistry in JNDI via the configured name.
 * <p>Can be overridden in subclasses to provide a different TransactionManager object.
 * @param registryName the JNDI name of the
 * TransactionSynchronizationRegistry
 * @return the TransactionSynchronizationRegistry object
 * @throws TransactionSystemException if the JNDI lookup failed
 * @see #setJndiTemplate
 * @see #setTransactionSynchronizationRegistryName
 */
protected TransactionSynchronizationRegistry lookupTransactionSynchronizationRegistry(String registryName) throws TransactionSystemException {
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Retrieving JTA TransactionSynchronizationRegistry from JNDI location [" + registryName + "]");
        }
        return getJndiTemplate().lookup(registryName, TransactionSynchronizationRegistry.class);
    }
    catch (NamingException ex) {
        throw new TransactionSystemException(
                "JTA TransactionSynchronizationRegistry is not available at JNDI location [" + registryName + "]", ex);
    }
}
项目:lams    文件:JtaTransactionManager.java   
/**
 * Find the JTA 1.1 TransactionSynchronizationRegistry through autodetection:
 * checking whether the UserTransaction object or TransactionManager object
 * implements it, and checking Java EE 5's standard JNDI location.
 * <p>The default implementation simply returns {@code null}.
 * @param ut the JTA UserTransaction object
 * @param tm the JTA TransactionManager object
 * @return the JTA TransactionSynchronizationRegistry handle to use,
 * or {@code null} if none found
 * @throws TransactionSystemException in case of errors
 */
protected TransactionSynchronizationRegistry findTransactionSynchronizationRegistry(UserTransaction ut, TransactionManager tm)
        throws TransactionSystemException {

    if (this.userTransactionObtainedFromJndi) {
        // UserTransaction has already been obtained from JNDI, so the
        // TransactionSynchronizationRegistry probably sits there as well.
        String jndiName = DEFAULT_TRANSACTION_SYNCHRONIZATION_REGISTRY_NAME;
        try {
            TransactionSynchronizationRegistry tsr = getJndiTemplate().lookup(jndiName, TransactionSynchronizationRegistry.class);
            if (logger.isDebugEnabled()) {
                logger.debug("JTA TransactionSynchronizationRegistry found at default JNDI location [" + jndiName + "]");
            }
            return tsr;
        }
        catch (NamingException ex) {
            if (logger.isDebugEnabled()) {
                logger.debug(
                        "No JTA TransactionSynchronizationRegistry found at default JNDI location [" + jndiName + "]", ex);
            }
        }
    }
    // Check whether the UserTransaction or TransactionManager implements it...
    if (ut instanceof TransactionSynchronizationRegistry) {
        return (TransactionSynchronizationRegistry) ut;
    }
    if (tm instanceof TransactionSynchronizationRegistry) {
        return (TransactionSynchronizationRegistry) tm;
    }
    // OK, so no JTA 1.1 TransactionSynchronizationRegistry is available...
    return null;
}
项目:agroal    文件:EnlistmentTests.java   
@Test
@DisplayName( "Enroll connection after previous connection close test" )
public void enrollConnectionCloseTest() throws SQLException {
    TransactionManager txManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
    TransactionSynchronizationRegistry txSyncRegistry = new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple();

    AgroalDataSourceConfigurationSupplier configurationSupplier = new AgroalDataSourceConfigurationSupplier()
            .connectionPoolConfiguration( cp -> cp
                    .transactionIntegration( new NarayanaTransactionIntegration( txManager, txSyncRegistry ) )
                    .connectionFactoryConfiguration( cf -> cf
                            .autoCommit( true ) )
            );

    try ( AgroalDataSource dataSource = AgroalDataSource.from( configurationSupplier ) ) {
        txManager.begin();

        Connection connection = dataSource.getConnection();
        logger.info( format( "Got connection {0}", connection ) );
        String connectionToString = connection.toString();
        connection.close();

        Connection secondConnection = dataSource.getConnection();
        logger.info( format( "Got connection {0}", secondConnection ) );

        // TODO: comparing toString is brittle. Find a better way to make sure the underlying physical connection is the same.
        assertEquals( connectionToString, secondConnection.toString(), "Expect the same connection under the same transaction" );
        assertFalse( secondConnection.getAutoCommit(), "AutoCommit temporarily disabled in enlisted connection" );
        secondConnection.close();

        txManager.commit();

        assertTrue( connection.isClosed() );
        assertTrue( secondConnection.isClosed() );
    } catch ( NotSupportedException | SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e ) {
        fail( "Exception: " + e.getMessage() );
    }
}
项目:agroal    文件:EnlistmentTests.java   
@Test
@DisplayName( "Lazy enlistment test" )
public void lazyEnlistmentTest() throws SQLException {
    TransactionManager txManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
    TransactionSynchronizationRegistry txSyncRegistry = new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple();

    AgroalDataSourceConfigurationSupplier configurationSupplier = new AgroalDataSourceConfigurationSupplier()
            .connectionPoolConfiguration( cp -> cp
                    .transactionIntegration( new NarayanaTransactionIntegration( txManager, txSyncRegistry ) )
            );

    try ( AgroalDataSource dataSource = AgroalDataSource.from( configurationSupplier ) ) {
        Connection connection = dataSource.getConnection();
        logger.info( format( "Got connection {0}", connection ) );

        try {
            txManager.begin();
            assertThrows( SQLException.class, connection::createStatement );
            logger.info( format( "Call to a method on the connection thrown a SQLException" ) );
            txManager.commit();

            assertFalse( connection.isClosed(), "Not expecting the connection to be close since it was not enrolled into the transaction" );
        } catch ( NotSupportedException | SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e ) {
            fail( "Exception: " + e.getMessage() );
        }
    }
}
项目:agroal    文件:BasicNarayanaTests.java   
@Test
@DisplayName( "Connection acquire test" )
public void basicConnectionAcquireTest() throws SQLException {
    TransactionManager txManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
    TransactionSynchronizationRegistry txSyncRegistry = new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple();

    AgroalDataSourceConfigurationSupplier configurationSupplier = new AgroalDataSourceConfigurationSupplier()
            .connectionPoolConfiguration( cp -> cp
                    .transactionIntegration( new NarayanaTransactionIntegration( txManager, txSyncRegistry ) )
                    .connectionFactoryConfiguration( cf -> cf.autoCommit( true ) )
            );

    try ( AgroalDataSource dataSource = AgroalDataSource.from( configurationSupplier ) ) {
        txManager.begin();

        Connection connection = dataSource.getConnection();
        logger.info( format( "Got connection {0}", connection ) );

        assertAll( () -> {
            assertThrows( SQLException.class, () -> connection.setAutoCommit( true ) );
            assertFalse( connection.getAutoCommit(), "Expect connection to have autocommit not set" );
            // TODO: comparing toString is brittle. Find a better way to make sure the underlying physical connection is the same.
            assertEquals( connection.toString(), dataSource.getConnection().toString(), "Expect the same connection under the same transaction" );
        } );

        txManager.commit();

        assertTrue( connection.isClosed() );
    } catch ( NotSupportedException | SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e ) {
        fail( "Exception: " + e.getMessage() );
    }
}
项目:wildfly-nosql    文件:Neo4jDriverSubsystemAdd.java   
private void startNeo4jDriverSubsysteService(final OperationContext context) {
    Neo4jSubsystemService neo4jSubsystemService = new Neo4jSubsystemService();
    context.getServiceTarget().addService(Neo4jSubsystemService.serviceName(), neo4jSubsystemService).setInitialMode(ServiceController.Mode.ACTIVE)
    .addDependency(TransactionManagerService.SERVICE_NAME, TransactionManager.class, neo4jSubsystemService.getTransactionManagerInjector())
    .addDependency(TransactionSynchronizationRegistryService.SERVICE_NAME, TransactionSynchronizationRegistry.class, neo4jSubsystemService.getTxSyncRegistryInjector())
            .install();
}
项目:wildfly-nosql    文件:DriverProxy.java   
public DriverProxy(Object driver, TransactionManager transactionManager, TransactionSynchronizationRegistry transactionSynchronizationRegistry, String profileName, String jndiName) {
    this.underlyingDriver = driver;
    this.transactionManager = transactionManager;
    this.transactionSynchronizationRegistry = transactionSynchronizationRegistry;
    this.profileName = profileName;
    this.jndiName = jndiName;
}
项目:spring4-understanding    文件:JtaTransactionManager.java   
/**
 * Look up the JTA 1.1 TransactionSynchronizationRegistry in JNDI via the configured name.
 * <p>Can be overridden in subclasses to provide a different TransactionManager object.
 * @param registryName the JNDI name of the
 * TransactionSynchronizationRegistry
 * @return the TransactionSynchronizationRegistry object
 * @throws TransactionSystemException if the JNDI lookup failed
 * @see #setJndiTemplate
 * @see #setTransactionSynchronizationRegistryName
 */
protected TransactionSynchronizationRegistry lookupTransactionSynchronizationRegistry(String registryName) throws TransactionSystemException {
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Retrieving JTA TransactionSynchronizationRegistry from JNDI location [" + registryName + "]");
        }
        return getJndiTemplate().lookup(registryName, TransactionSynchronizationRegistry.class);
    }
    catch (NamingException ex) {
        throw new TransactionSystemException(
                "JTA TransactionSynchronizationRegistry is not available at JNDI location [" + registryName + "]", ex);
    }
}
项目:spring4-understanding    文件:JtaTransactionManager.java   
/**
 * Find the JTA 1.1 TransactionSynchronizationRegistry through autodetection:
 * checking whether the UserTransaction object or TransactionManager object
 * implements it, and checking Java EE 5's standard JNDI location.
 * <p>The default implementation simply returns {@code null}.
 * @param ut the JTA UserTransaction object
 * @param tm the JTA TransactionManager object
 * @return the JTA TransactionSynchronizationRegistry handle to use,
 * or {@code null} if none found
 * @throws TransactionSystemException in case of errors
 */
protected TransactionSynchronizationRegistry findTransactionSynchronizationRegistry(UserTransaction ut, TransactionManager tm)
        throws TransactionSystemException {

    if (this.userTransactionObtainedFromJndi) {
        // UserTransaction has already been obtained from JNDI, so the
        // TransactionSynchronizationRegistry probably sits there as well.
        String jndiName = DEFAULT_TRANSACTION_SYNCHRONIZATION_REGISTRY_NAME;
        try {
            TransactionSynchronizationRegistry tsr = getJndiTemplate().lookup(jndiName, TransactionSynchronizationRegistry.class);
            if (logger.isDebugEnabled()) {
                logger.debug("JTA TransactionSynchronizationRegistry found at default JNDI location [" + jndiName + "]");
            }
            return tsr;
        }
        catch (NamingException ex) {
            if (logger.isDebugEnabled()) {
                logger.debug(
                        "No JTA TransactionSynchronizationRegistry found at default JNDI location [" + jndiName + "]", ex);
            }
        }
    }
    // Check whether the UserTransaction or TransactionManager implements it...
    if (ut instanceof TransactionSynchronizationRegistry) {
        return (TransactionSynchronizationRegistry) ut;
    }
    if (tm instanceof TransactionSynchronizationRegistry) {
        return (TransactionSynchronizationRegistry) tm;
    }
    // OK, so no JTA 1.1 TransactionSynchronizationRegistry is available...
    return null;
}
项目:jpasecurity    文件:DefaultSecureEntityManager.java   
private TransactionSynchronizationRegistry getTransactionSynchronizationRegistry() {
    try {
        return InitialContext.doLookup("java:comp/TransactionSynchronizationRegistry");
    } catch (NamingException e) {
        return null;
    }
}
项目:requery    文件:ManagedTransaction.java   
private TransactionSynchronizationRegistry getSynchronizationRegistry() {
    if (registry == null) {
        try {
            registry = InitialContext.doLookup("java:comp/TransactionSynchronizationRegistry");
        } catch (NamingException e) {
            throw new TransactionException(e);
        }
    }
    return registry;
}
项目:kumuluzee    文件:TxScopedEntityManager.java   
public TxScopedEntityManager(String unitName, EntityManagerFactory emf, SynchronizationType sync, TransactionManager transactionManager, TransactionSynchronizationRegistry transactionSynchronizationRegistry, NonTxEntityManagerHolder nonTxEmHolder) {
    this.unitName = unitName;
    this.emf = emf;
    this.sync = sync;
    this.transactionManager = transactionManager;
    this.transactionSynchronizationRegistry = transactionSynchronizationRegistry;
    this.nonTxEmHolder = nonTxEmHolder;
}
项目:switchyard    文件:TransactionManagerFactoryTest.java   
@Test
public void createSpringTransactionManager() throws Exception {
    mixIn.getInitialContext().bind(TransactionManagerFactory.JBOSS_USER_TRANSACTION, mock(UserTransaction.class));
    mixIn.getInitialContext().bind(TransactionManagerFactory.JBOSS_TRANSACTION_MANANGER, mock(TransactionManager.class));
    mixIn.getInitialContext().bind(TransactionManagerFactory.JBOSS_TRANSACTION_SYNC_REG, mock(TransactionSynchronizationRegistry.class));
    final TransactionManagerFactory factory = TransactionManagerFactory.getInstance();
    final PlatformTransactionManager tm = factory.create();
    assertThat(tm, is(notNullValue()));
}
项目:switchyard    文件:TransactionManagerFactoryTest.java   
@Test
public void createJBossTransactionManager() throws Exception {
    mixIn.getInitialContext().bind(TransactionManagerFactory.JBOSS_USER_TRANSACTION, mock(UserTransaction.class));
    mixIn.getInitialContext().bind(TransactionManagerFactory.JBOSS_TRANSACTION_MANANGER, mock(TransactionManager.class));
    mixIn.getInitialContext().bind(TransactionManagerFactory.JBOSS_TRANSACTION_SYNC_REG, mock(TransactionSynchronizationRegistry.class));
    final TransactionManagerFactory factory = TransactionManagerFactory.getInstance();
    final PlatformTransactionManager tm = factory.create();
    assertThat(tm, is(instanceOf(JtaTransactionManager.class)));
}
项目:switchyard    文件:InboundHandlerTestBase.java   
@BeforeClass
public static void beforeClass() throws Exception {
    mixIn.initialize();
    mixIn.getInitialContext().bind(TransactionManagerFactory.JBOSS_USER_TRANSACTION, mock(UserTransaction.class));
    mixIn.getInitialContext().bind(TransactionManagerFactory.JBOSS_TRANSACTION_MANANGER, mock(TransactionManager.class));
    mixIn.getInitialContext().bind(TransactionManagerFactory.JBOSS_TRANSACTION_SYNC_REG, mock(TransactionSynchronizationRegistry.class));
}
项目:switchyard    文件:OutboundHandlerTest.java   
@Test
public void checkTransactionManagerRegistration() throws Exception {
    _mixIn.initialize();
    _mixIn.getInitialContext().bind(TransactionManagerFactory.JBOSS_USER_TRANSACTION, mock(UserTransaction.class));
    _mixIn.getInitialContext().bind(TransactionManagerFactory.JBOSS_TRANSACTION_MANANGER, mock(TransactionManager.class));
    _mixIn.getInitialContext().bind(TransactionManagerFactory.JBOSS_TRANSACTION_SYNC_REG, mock(TransactionSynchronizationRegistry.class));

    bindingModel = mock(CamelBindingModel.class);
    when(bindingModel.getComponentURI()).thenReturn(URI.create("transaction:foo?transactionManager=%23jtaTransactionManager"));
    when(bindingModel.getReference()).thenReturn(referenceModel);
    _messageComposer = CamelComposition.getMessageComposer();
    _serviceDomain.registerService(_targetService.getServiceName(),
        new InOnlyService(), 
        new OutboundHandler(bindingModel,
            (SwitchYardCamelContext) context, _messageComposer, null
        ) {
        {
            setState(State.STARTED);
        }
    }
    );
    _service = _serviceDomain.registerServiceReference(
        _targetService.getServiceName(), new InOnlyService());
    Exchange exchange = _service.createExchange();

    MockEndpoint endpoint = getMockEndpoint("mock:result");
    endpoint.expectedBodiesReceived("foo");
    exchange.send(exchange.createMessage().setContent("foo"));

    assertThat(context.getRegistry().lookup(TransactionManagerFactory.TM), is(notNullValue()));
    _mixIn.uninitialize();
}
项目:switchyard    文件:TransactionMixInTest.java   
@Test
public void testTransactionSynchronizationRegistry() throws Exception {
    UserTransaction transaction = getUserTransaction();
    transaction.begin();
    TransactionSynchronizationRegistry tsr = getTransactionSynchronizationRegistry();
    TestSynchronization sync = new TestSynchronization();
    tsr.registerInterposedSynchronization(sync);
    transaction.commit();
    Assert.assertTrue(sync.beforeCompletionInvoked);
    Assert.assertTrue(sync.afterCompletionInvoked);
    Assert.assertEquals(Status.STATUS_COMMITTED, sync.transactionStatus);
}
项目:teiid-embedded    文件:IronJacamarHelperImpl.java   
@Override
public DataSource newDataSource(Consumer<Configuration> consumer) throws ResourceException {

    Objects.requireNonNull(consumer);
    Configuration config = new Configuration();
    consumer.accept(config);

    Objects.requireNonNull(config.localManagedConnectionFactory());
    LocalManagedConnectionFactory mcf = config.localManagedConnectionFactory();
    mcf.setResourceAdapter(new JDBCResourceAdapter());

    TransactionManager tm = NarayanaHelper.Factory.transactionManager(c -> c.coreEnvironmentBean(core -> {
        core.setSocketProcessIdPort(0);
        core.setSocketProcessIdMaxPorts(2);
    }).coordinatorEnvironmentBean(coordinator -> {
        coordinator.setEnableStatistics(false);
        coordinator.setDefaultTimeout(300);
        coordinator.setTransactionStatusManagerEnable(false);
        coordinator.setTxReaperCancelFailWaitPeriod(120000);
    }).objectStoreEnvironmentBean(objectStore -> {
        objectStore.setObjectStoreDir(System.getProperty("java.io.tmpdir")  + File.separator + "narayana");
    }));
    TransactionSynchronizationRegistry tsr = NarayanaHelper.Factory.transactionSynchronizationRegistry();
    UserTransactionRegistry utr = new UserTransactionRegistryImpl();
    XATerminator terminator = new XATerminatorImpl();
    TransactionIntegration txIntegration = new TransactionIntegrationImpl(tm, tsr, utr, terminator, null);

    TxConnectionManagerImpl cm = new TxConnectionManagerImpl(txIntegration, true);
    String mcp = LeakDumperManagedConnectionPool.class.getName();
    PoolConfiguration poolConfig = config.poolConfiguration();
    if(poolConfig == null) {
        poolConfig = new PoolConfiguration();
    }
    OnePool pool = new OnePool(mcf, poolConfig, false, true, mcp);
    pool.setConnectionManager(cm);
    cm.setPool(pool);

    return (DataSource) mcf.createConnectionFactory(cm);
}
项目:wisdom-jdbc    文件:TransactionManagerService.java   
@Validate
public void register() {
    registration = bundleContext.registerService(new String[]{
            UserTransaction.class.getName(),
            TransactionManager.class.getName(),
            TransactionSynchronizationRegistry.class.getName(),
            XidImporter.class.getName(),
            MonitorableTransactionManager.class.getName(),
            RecoverableTransactionManager.class.getName()
    }, transactionManager, null);
}
项目:ironjacamar    文件:TransactionIntegrationImpl.java   
/**
 * Constructor
 * @param tm The transaction manager
 * @param tsr The transaction synchronization registry
 * @param utr The user transaction registry
 * @param terminator The XA terminator
 * @param rr The recovery registry
 */
public TransactionIntegrationImpl(TransactionManager tm,
                                  TransactionSynchronizationRegistry tsr,
                                  UserTransactionRegistry utr,
                                  XATerminator terminator,
                                  XAResourceRecoveryRegistry rr)
{
   this.tm = tm;
   this.tsr = tsr;
   this.utr = utr;
   this.terminator = terminator;
   this.rr = rr;
}
项目:transaction-cdi    文件:DefaultTransactionSupport.java   
/**
 * {@inheritDoc}
 */
@Override
protected TransactionSynchronizationRegistry lookupSynchronizationRegistry()
{
    try
    {
        return (TransactionSynchronizationRegistry) new InitialContext()
            .lookup(TRANSACTION_SYNCHRONIZATION_REGISTRY_JNDI_NAME);
    }
    catch (NamingException e)
    {
        throw new RuntimeException(e);
    }
}
项目:tomee    文件:CdiJndiTest.java   
@Test
public void check() {
    assertNotNull(extension.getMgr());
    assertNotNull(extension.getRegistry());
    assertEquals(OpenEJB.getTransactionManager(), extension.getMgr());
    assertEquals(SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class), extension.getRegistry());
}
项目:tomee    文件:DbcpDataSourceCreator.java   
@Override
public DataSource managed(final String name, final CommonDataSource ds) {
    final TransactionManager transactionManager = OpenEJB.getTransactionManager();
    if (ds instanceof XADataSource) {
        return new ManagedXADataSource(ds, transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
    }
    return new ManagedDataSource(DataSource.class.cast(ds), transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
}
项目:tomee    文件:PoolDataSourceCreator.java   
@Override
public DataSource managed(final String name, final CommonDataSource ds) {
    final TransactionManager transactionManager = OpenEJB.getTransactionManager();
    if (ds instanceof XADataSource) {
        return new ManagedXADataSource(ds, transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
    }
    return new ManagedDataSource(DataSource.class.cast(ds), transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
}
项目:tomee    文件:PoolDataSourceCreator.java   
@Override
public DataSource poolManagedWithRecovery(final String name, final XAResourceWrapper xaResourceWrapper, final String driver, final Properties properties) {
    final TransactionManager transactionManager = new TransactionManagerWrapper(OpenEJB.getTransactionManager(), name, xaResourceWrapper);
    final CommonDataSource ds = pool(name, driver, properties);
    if (ds instanceof XADataSource) {
        return new ManagedXADataSource(ds, transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
    }
    return new ManagedDataSource(DataSource.class.cast(ds), transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
}
项目:tomee    文件:SimpleDataSourceCreator.java   
@Override
public DataSource managed(final String name, final CommonDataSource ds) {
    final TransactionManager transactionManager = OpenEJB.getTransactionManager();
    if (XADataSource.class.isInstance(ds)) {
        return new ManagedXADataSource(XADataSource.class.cast(ds), transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
    }
    return new ManagedDataSource(DataSource.class.cast(ds), transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
}
项目:tomee    文件:ManagedConnection.java   
public ManagedConnection(final CommonDataSource ds,
                         final TransactionManager txMgr,
                         final TransactionSynchronizationRegistry txRegistry,
                         final String user, final String password) {
    transactionManager = txMgr;
    registry = txRegistry;
    closed = false;
    key = new Key(ds, user, password);
}