当前位置: 首页>>代码示例>>Java>>正文


Java TransactionSynchronizationRegistry类代码示例

本文整理汇总了Java中javax.transaction.TransactionSynchronizationRegistry的典型用法代码示例。如果您正苦于以下问题:Java TransactionSynchronizationRegistry类的具体用法?Java TransactionSynchronizationRegistry怎么用?Java TransactionSynchronizationRegistry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TransactionSynchronizationRegistry类属于javax.transaction包,在下文中一共展示了TransactionSynchronizationRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: connectionOutsideTransactionTest

import javax.transaction.TransactionSynchronizationRegistry; //导入依赖的package包/类
@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() );
    }
}
 
开发者ID:agroal,项目名称:agroal,代码行数:19,代码来源:EnlistmentTests.java

示例2: basicRollbackTest

import javax.transaction.TransactionSynchronizationRegistry; //导入依赖的package包/类
@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() );
    }
}
 
开发者ID:agroal,项目名称:agroal,代码行数:25,代码来源:BasicNarayanaTests.java

示例3: multipleCloseTest

import javax.transaction.TransactionSynchronizationRegistry; //导入依赖的package包/类
@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() );
            }
        }  
    }
}
 
开发者ID:agroal,项目名称:agroal,代码行数:26,代码来源:BasicNarayanaTests.java

示例4: testSetJtaTransactionManager

import javax.transaction.TransactionSynchronizationRegistry; //导入依赖的package包/类
@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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:HibernateTransactionManagerTests.java

示例5: TransactionIntegrationImpl

import javax.transaction.TransactionSynchronizationRegistry; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:ironjacamar,项目名称:ironjacamar,代码行数:28,代码来源:TransactionIntegrationImpl.java

示例6: BootstrapContextImpl

import javax.transaction.TransactionSynchronizationRegistry; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:ironjacamar,项目名称:ironjacamar,代码行数:24,代码来源:BootstrapContextImpl.java

示例7: checkBuiltInResourceTypes

import javax.transaction.TransactionSynchronizationRegistry; //导入依赖的package包/类
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");
    }
}
 
开发者ID:apache,项目名称:tomee,代码行数:20,代码来源:Assembler.java

示例8: SetValuedCmr

import javax.transaction.TransactionSynchronizationRegistry; //导入依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:tomee,代码行数:17,代码来源:SetValuedCmr.java

示例9: CmrSet

import javax.transaction.TransactionSynchronizationRegistry; //导入依赖的package包/类
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;
    }
}
 
开发者ID:apache,项目名称:tomee,代码行数:24,代码来源:CmrSet.java

示例10: setUp

import javax.transaction.TransactionSynchronizationRegistry; //导入依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:tomee,代码行数:21,代码来源:JpaTest.java

示例11: testMultiThreaded

import javax.transaction.TransactionSynchronizationRegistry; //导入依赖的package包/类
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();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:25,代码来源:BitronixTransactionSynchronizationRegistryTest.java

示例12: testRegistrySynchronizations

import javax.transaction.TransactionSynchronizationRegistry; //导入依赖的package包/类
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());
}
 
开发者ID:bitronix,项目名称:btm,代码行数:18,代码来源:BitronixTransactionSynchronizationRegistryTest.java

示例13: init

import javax.transaction.TransactionSynchronizationRegistry; //导入依赖的package包/类
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);
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:15,代码来源:TransactionManagerService.java

示例14: lookupTransactionSynchronizationRegistry

import javax.transaction.TransactionSynchronizationRegistry; //导入依赖的package包/类
/**
 * 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);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:JtaTransactionManager.java

示例15: findTransactionSynchronizationRegistry

import javax.transaction.TransactionSynchronizationRegistry; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:43,代码来源:JtaTransactionManager.java


注:本文中的javax.transaction.TransactionSynchronizationRegistry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。