本文整理汇总了Java中bitronix.tm.TransactionManagerServices.getTransactionManager方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionManagerServices.getTransactionManager方法的具体用法?Java TransactionManagerServices.getTransactionManager怎么用?Java TransactionManagerServices.getTransactionManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitronix.tm.TransactionManagerServices
的用法示例。
在下文中一共展示了TransactionManagerServices.getTransactionManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFind
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Test
public void testFind() throws ResourceException, NotSupportedException, SystemException {
MicroserviceResourceFactory msrFactory = mock(MicroserviceResourceFactory.class);
MicroserviceXAResource xa = new MicroserviceXAResource("a", mock(CommitRollbackCallback.class));
when(msrFactory.build()).thenReturn(xa);
MicroserviceResourceProducer.registerMicroserviceResourceFactory("a", msrFactory);
MicroserviceResourceProducer producer = MicroserviceResourceProducer.getProducers().values().iterator().next();
BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
try{
tm.begin();
//TEST
producer.getTransactionAssistant(); //enlists resource into TX and means we can then go find it
XAResource found = producer.findXAResourceHolder(xa).getXAResource();
assertEquals(xa, found);
}finally{
tm.rollback();
}
}
示例2: testXAWorksWithJsr107
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Test
public void testXAWorksWithJsr107() throws Exception {
BitronixTransactionManager transactionManager = TransactionManagerServices.getTransactionManager();
URI uri = getClass().getResource("/configs/simple-xa.xml").toURI();
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(uri, getClass().getClassLoader());
Cache<String, String> xaCache = cacheManager.getCache("xaCache", String.class, String.class);
transactionManager.begin();
{
xaCache.put("key", "one");
}
transactionManager.commit();
cacheManager.close();
}
示例3: testXAWithStatefulSerializer
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Test
public void testXAWithStatefulSerializer() throws Exception {
BitronixTransactionManager manager = TransactionManagerServices.getTransactionManager();
try (CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.using(new LookupTransactionManagerProviderConfiguration(
BitronixTransactionManagerLookup.class))
.withCache("xaCache",
CacheConfigurationBuilder
.newCacheConfigurationBuilder(Long.class, Person.class,
ResourcePoolsBuilder.heap(5))
.withExpiry(ExpiryPolicyBuilder.noExpiration()).add(new XAStoreConfiguration("xaCache"))
.build())
.build(true)) {
Cache<Long, Person> cache = cacheManager.getCache("xaCache", Long.class, Person.class);
manager.begin();
cache.put(1L, new Person("James", 42));
manager.commit();
manager.begin();
assertNotNull(cache.get(1L));
manager.commit();
} finally {
manager.shutdown();
}
}
示例4: testClusteredCacheWithXA
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Test
public void testClusteredCacheWithXA() throws Exception {
TransactionManagerServices.getConfiguration().setJournal("null");
BitronixTransactionManager transactionManager =
TransactionManagerServices.getTransactionManager();
PersistentCacheManager persistentCacheManager = null;
try {
CacheManagerBuilder.newCacheManagerBuilder()
.using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class))
.with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application")).autoCreate())
.withCache("xaCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 8, MemoryUnit.MB))
)
.add(new XAStoreConfiguration("xaCache"))
.build()
)
.build(true);
} catch (StateTransitionException e) {
assertThat(e.getCause().getCause().getMessage(), is("Unsupported resource type : interface org.ehcache.clustered.client.config.DedicatedClusteredResourcePool"));
}
transactionManager.shutdown();
}
示例5: setUp
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
TransactionManagerServices.getConfiguration().setJournal("null").setGracefulShutdownInterval(2);
TransactionManagerServices.getTransactionManager();
MockitoXADataSource.setStaticCloseXAConnectionException(null);
MockitoXADataSource.setStaticGetXAConnectionException(null);
pds = new PoolingDataSource();
pds.setMinPoolSize(1);
pds.setMaxPoolSize(2);
pds.setMaxIdleTime(1);
pds.setClassName(MockitoXADataSource.class.getName());
pds.setUniqueName("pds");
pds.setAllowLocalTransactions(true);
pds.setAcquisitionTimeout(1);
pds.init();
}
示例6: testPrepares
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Test
public void testPrepares() throws Exception {
BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
tm.setTransactionTimeout(60);
tm.begin();
Connection connection = poolingDataSource2.getConnection();
for (int i = 0; i < 1000; i++) {
PreparedStatement prepareStatement = connection.prepareStatement("SELECT 1 FROM nothing WHERE a=? AND b=? AND c=? AND d=?");
assertFalse(prepareStatement.isClosed());
prepareStatement.close();
assertTrue(prepareStatement.isClosed());
}
connection.close();
tm.commit();
tm.shutdown();
}
示例7: testCachedPrepared
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Test
public void testCachedPrepared() throws Exception {
BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
tm.setTransactionTimeout(60);
tm.begin();
Connection connection = poolingDataSource1.getConnection();
PreparedStatement prepareStatement1 = connection.prepareStatement("SELECT 1 FROM nothing WHERE a=? AND b=? AND c=? AND d=?");
PreparedStatement prepareStatement2 = connection.prepareStatement("SELECT 1 FROM nothing WHERE a=? AND b=? AND c=? AND d=?");
Assert.assertSame(prepareStatement1.unwrap(PreparedStatement.class), prepareStatement2.unwrap(PreparedStatement.class));
prepareStatement2.close();
prepareStatement2 = connection.prepareStatement("SELECT 1 FROM nothing WHERE a=? AND b=? AND c=? AND d=?");
Assert.assertSame(prepareStatement1.unwrap(PreparedStatement.class), prepareStatement2.unwrap(PreparedStatement.class));
prepareStatement1.close();
prepareStatement2.close();
connection.close();
tm.shutdown();
}
示例8: bitronixTransactionManager
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Bean
@ConditionalOnMissingBean(TransactionManager.class)
public BitronixTransactionManager bitronixTransactionManager(
bitronix.tm.Configuration configuration) {
// Inject configuration to force ordering
return TransactionManagerServices.getTransactionManager();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:BitronixJtaConfiguration.java
示例9: testGetTransactionAssistant
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Test
public void testGetTransactionAssistant() throws ResourceException, NotSupportedException, SystemException {
MicroserviceResourceFactory msrFactory = mock(MicroserviceResourceFactory.class);
MicroserviceXAResource xa = new MicroserviceXAResource("a", null);
when(msrFactory.build()).thenReturn(xa);
MicroserviceResourceProducer.registerMicroserviceResourceFactory("a", msrFactory);
MicroserviceResourceProducer producer = MicroserviceResourceProducer.getProducers().values().iterator().next();
BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
try{
tm.begin();
//TEST
TransactionAssistant ta = producer.getTransactionAssistant();
assertNotNull(ta);
//check its enlisted in TX
assertEquals(1, TransactionContextHelper.currentTransaction().getEnlistedResourcesUniqueNames().size());
assertEquals("a", TransactionContextHelper.currentTransaction().getEnlistedResourcesUniqueNames().iterator().next());
//TEST
ta.close();
//cannot check its delisted from TX, because that happens during deconstruction of the transaction, becuase the TX is a global one
//close also removed it from the holders - so check its gone
assertNull(producer.findXAResourceHolder(xa));
}finally{
tm.rollback();
}
}
示例10: setUpBtmConfig
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Before
public void setUpBtmConfig() throws Exception {
storagePath = folder.newFolder();
initTransactionManagerServices();
transactionManager = TransactionManagerServices.getTransactionManager();
}
示例11: lookupTransactionManagerWrapper
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Override
public TransactionManagerWrapper lookupTransactionManagerWrapper() { // <2>
if (!TransactionManagerServices.isTransactionManagerRunning()) { // <3>
throw new IllegalStateException("BTM must be started beforehand");
}
TransactionManagerWrapper tmWrapper = new TransactionManagerWrapper(TransactionManagerServices.getTransactionManager(),
new BitronixXAResourceRegistry()); // <4>
LOGGER.info("Using looked up transaction manager : {}", tmWrapper);
return tmWrapper;
}
示例12: testSimpleXACache
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Test
public void testSimpleXACache() throws Exception {
// tag::testSimpleXACache[]
BitronixTransactionManager transactionManager =
TransactionManagerServices.getTransactionManager(); // <1>
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class)) // <2>
.withCache("xaCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, // <3>
ResourcePoolsBuilder.heap(10)) // <4>
.add(new XAStoreConfiguration("xaCache")) // <5>
.build()
)
.build(true);
final Cache<Long, String> xaCache = cacheManager.getCache("xaCache", Long.class, String.class);
transactionManager.begin(); // <6>
{
xaCache.put(1L, "one"); // <7>
}
transactionManager.commit(); // <8>
cacheManager.close();
transactionManager.shutdown();
// end::testSimpleXACache[]
}
示例13: testNonTransactionalAccess
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Test
public void testNonTransactionalAccess() throws Exception {
// tag::testNonTransactionalAccess[]
BitronixTransactionManager transactionManager =
TransactionManagerServices.getTransactionManager(); // <1>
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class)) // <2>
.withCache("xaCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, // <3>
ResourcePoolsBuilder.heap(10)) // <4>
.add(new XAStoreConfiguration("xaCache")) // <5>
.build()
)
.build(true);
final Cache<Long, String> xaCache = cacheManager.getCache("xaCache", Long.class, String.class);
try {
xaCache.get(1L); // <6>
fail("expected XACacheException");
} catch (XACacheException e) {
// expected
}
cacheManager.close();
transactionManager.shutdown();
// end::testNonTransactionalAccess[]
}
示例14: testXACacheWithWriteThrough
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testXACacheWithWriteThrough() throws Exception {
// tag::testXACacheWithWriteThrough[]
BitronixTransactionManager transactionManager =
TransactionManagerServices.getTransactionManager(); // <1>
Class<CacheLoaderWriter<?, ?>> klazz = (Class<CacheLoaderWriter<?, ?>>) (Class) (SampleLoaderWriter.class);
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class)) // <2>
.withCache("xaCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, // <3>
ResourcePoolsBuilder.heap(10)) // <4>
.add(new XAStoreConfiguration("xaCache")) // <5>
.add(new DefaultCacheLoaderWriterConfiguration(klazz, singletonMap(1L, "eins"))) // <6>
.build()
)
.build(true);
final Cache<Long, String> xaCache = cacheManager.getCache("xaCache", Long.class, String.class);
transactionManager.begin(); // <7>
{
assertThat(xaCache.get(1L), equalTo("eins")); // <8>
xaCache.put(1L, "one"); // <9>
}
transactionManager.commit(); // <10>
cacheManager.close();
transactionManager.shutdown();
// end::testXACacheWithWriteThrough[]
}
示例15: testXACacheWithThreeTiers
import bitronix.tm.TransactionManagerServices; //导入方法依赖的package包/类
@Test
public void testXACacheWithThreeTiers() throws Exception {
// tag::testXACacheWithThreeTiers[]
BitronixTransactionManager transactionManager =
TransactionManagerServices.getTransactionManager(); // <1>
PersistentCacheManager persistentCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class)) // <2>
.with(CacheManagerBuilder.persistence(new File(getStoragePath(), "testXACacheWithThreeTiers"))) // <3>
.withCache("xaCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, // <4>
ResourcePoolsBuilder.newResourcePoolsBuilder() // <5>
.heap(10, EntryUnit.ENTRIES)
.offheap(10, MemoryUnit.MB)
.disk(20, MemoryUnit.MB, true)
)
.add(new XAStoreConfiguration("xaCache")) // <6>
.build()
)
.build(true);
final Cache<Long, String> xaCache = persistentCacheManager.getCache("xaCache", Long.class, String.class);
transactionManager.begin(); // <7>
{
xaCache.put(1L, "one"); // <8>
}
transactionManager.commit(); // <9>
persistentCacheManager.close();
transactionManager.shutdown();
// end::testXACacheWithThreeTiers[]
}