本文整理汇总了Java中bitronix.tm.BitronixTransactionManager.begin方法的典型用法代码示例。如果您正苦于以下问题:Java BitronixTransactionManager.begin方法的具体用法?Java BitronixTransactionManager.begin怎么用?Java BitronixTransactionManager.begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitronix.tm.BitronixTransactionManager
的用法示例。
在下文中一共展示了BitronixTransactionManager.begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFind
import bitronix.tm.BitronixTransactionManager; //导入方法依赖的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.BitronixTransactionManager; //导入方法依赖的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: putIfAbsentAssertions
import bitronix.tm.BitronixTransactionManager; //导入方法依赖的package包/类
private void putIfAbsentAssertions(BitronixTransactionManager transactionManager, Cache<Long, String> txCache1) throws Exception {
transactionManager.begin();
{
assertThat(txCache1.putIfAbsent(1L, "one"), is(nullValue()));
assertThat(txCache1.putIfAbsent(1L, "un"), equalTo("one"));
}
transactionManager.commit();
assertMapping(transactionManager, txCache1, 1L, "one");
transactionManager.begin();
{
assertThat(txCache1.putIfAbsent(1L, "eins"), equalTo("one"));
txCache1.remove(1L);
assertThat(txCache1.putIfAbsent(1L, "een"), is(nullValue()));
}
transactionManager.commit();
assertMapping(transactionManager, txCache1, 1L, "een");
}
示例4: replace2ArgsAssertions
import bitronix.tm.BitronixTransactionManager; //导入方法依赖的package包/类
private void replace2ArgsAssertions(BitronixTransactionManager transactionManager, Cache<Long, String> txCache1) throws Exception {
transactionManager.begin();
{
assertThat(txCache1.replace(1L, "one"), is(nullValue()));
txCache1.put(1L, "un");
assertThat(txCache1.replace(1L, "eins"), equalTo("un"));
}
transactionManager.commit();
assertMapping(transactionManager, txCache1, 1L, "eins");
transactionManager.begin();
{
assertThat(txCache1.replace(1L, "een"), equalTo("eins"));
txCache1.put(1L, "un");
assertThat(txCache1.replace(1L, "een"), equalTo("un"));
txCache1.remove(1L);
assertThat(txCache1.replace(1L, "one"), is(nullValue()));
assertThat(txCache1.get(1L), is(nullValue()));
}
transactionManager.commit();
assertMapping(transactionManager, txCache1, 1L, null);
}
示例5: replace3ArgsAssertions
import bitronix.tm.BitronixTransactionManager; //导入方法依赖的package包/类
private void replace3ArgsAssertions(BitronixTransactionManager transactionManager, Cache<Long, String> txCache1) throws Exception {
transactionManager.begin();
{
assertThat(txCache1.replace(1L, "one", "un"), is(false));
txCache1.put(1L, "un");
assertThat(txCache1.replace(1L, "uno", "eins"), is(false));
assertThat(txCache1.replace(1L, "un", "eins"), is(true));
assertThat(txCache1.get(1L), equalTo("eins"));
}
transactionManager.commit();
assertMapping(transactionManager, txCache1, 1L, "eins");
transactionManager.begin();
{
assertThat(txCache1.replace(1L, "one", "un"), is(false));
assertThat(txCache1.replace(1L, "eins", "un"), is(true));
assertThat(txCache1.replace(1L, "uno", "een"), is(false));
assertThat(txCache1.get(1L), equalTo("un"));
}
transactionManager.commit();
assertMapping(transactionManager, txCache1, 1L, "un");
}
示例6: testXAWithStatefulSerializer
import bitronix.tm.BitronixTransactionManager; //导入方法依赖的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();
}
}
示例7: testUnSharedConnection
import bitronix.tm.BitronixTransactionManager; //导入方法依赖的package包/类
public void testUnSharedConnection() throws Exception {
if (log.isDebugEnabled()) { log.debug("*** Starting testUnSharedConnection: getting TM"); }
BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
tm.setTransactionTimeout(120);
if (log.isDebugEnabled()) { log.debug("*** before begin"); }
tm.begin();
if (log.isDebugEnabled()) { log.debug("*** after begin"); }
if (log.isDebugEnabled()) { log.debug("*** getting connection from DS2"); }
Connection connection1 = poolingDataSource2.getConnection();
// createStatement causes enlistment
connection1.createStatement();
if (log.isDebugEnabled()) { log.debug("*** getting second connection from DS2"); }
Connection connection2 = poolingDataSource2.getConnection();
PooledConnectionProxy handle1 = (PooledConnectionProxy) connection1;
PooledConnectionProxy handle2 = (PooledConnectionProxy) connection2;
assertNotSame(handle1.getProxiedDelegate(), handle2.getProxiedDelegate());
connection1.close();
connection2.close();
tm.commit();
}
示例8: testGetTransactionAssistant
import bitronix.tm.BitronixTransactionManager; //导入方法依赖的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();
}
}
示例9: remove2ArgsAssertions
import bitronix.tm.BitronixTransactionManager; //导入方法依赖的package包/类
private void remove2ArgsAssertions(BitronixTransactionManager transactionManager, Cache<Long, String> txCache1) throws Exception {
transactionManager.begin();
{
assertThat(txCache1.remove(1L, "one"), is(false));
assertThat(txCache1.putIfAbsent(1L, "un"), is(nullValue()));
assertThat(txCache1.remove(1L, "one"), is(false));
assertThat(txCache1.remove(1L, "un"), is(true));
assertThat(txCache1.remove(1L, "un"), is(false));
}
transactionManager.commit();
assertMapping(transactionManager, txCache1, 1L, null);
transactionManager.begin();
{
txCache1.put(1L, "one");
}
transactionManager.commit();
assertMapping(transactionManager, txCache1, 1L, "one");
transactionManager.begin();
{
assertThat(txCache1.remove(1L, "un"), is(false));
assertThat(txCache1.remove(1L, "one"), is(true));
assertThat(txCache1.remove(1L, "one"), is(false));
assertThat(txCache1.putIfAbsent(1L, "un"), is(nullValue()));
assertThat(txCache1.remove(1L, "one"), is(false));
assertThat(txCache1.remove(1L, "un"), is(true));
}
transactionManager.commit();
assertMapping(transactionManager, txCache1, 1L, null);
}
示例10: assertMapping
import bitronix.tm.BitronixTransactionManager; //导入方法依赖的package包/类
private void assertMapping(BitronixTransactionManager transactionManager, Cache<Long, String> cache, long key, String expected) throws Exception {
transactionManager.begin();
String value = cache.get(key);
if (expected == null) {
assertThat(value, is(nullValue()));
} else {
assertThat(value, equalTo(expected));
}
transactionManager.commit();
}
示例11: testSimpleXACache
import bitronix.tm.BitronixTransactionManager; //导入方法依赖的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[]
}
示例12: testXACacheWithWriteThrough
import bitronix.tm.BitronixTransactionManager; //导入方法依赖的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[]
}
示例13: testXACacheWithThreeTiers
import bitronix.tm.BitronixTransactionManager; //导入方法依赖的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[]
}
示例14: testAutoCommitFalseWhenEnlisted
import bitronix.tm.BitronixTransactionManager; //导入方法依赖的package包/类
public void testAutoCommitFalseWhenEnlisted() throws Exception {
Thread.currentThread().setName("testAutoCommitFalseWhenEnlisted");
BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
tm.begin();
Connection c = poolingDataSource1.getConnection();
c.prepareStatement("");
assertFalse(c.getAutoCommit());
c.close();
tm.commit();
tm.shutdown();
}
示例15: testDeferredReleaseAfterMarkedRollback
import bitronix.tm.BitronixTransactionManager; //导入方法依赖的package包/类
public void testDeferredReleaseAfterMarkedRollback() throws Exception {
Thread.currentThread().setName("testDeferredReleaseAfterMarkedRollback");
if (log.isDebugEnabled()) { log.debug("*** getting TM"); }
BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
if (log.isDebugEnabled()) { log.debug("*** before begin"); }
tm.begin();
if (log.isDebugEnabled()) { log.debug("*** after begin"); }
if (log.isDebugEnabled()) { log.debug("*** getting connection from DS1"); }
Connection connection1 = poolingDataSource1.getConnection();
connection1.createStatement();
if (log.isDebugEnabled()) { log.debug("*** marking TX for rollback only"); }
tm.setRollbackOnly();
if (log.isDebugEnabled()) { log.debug("*** closing connection 1"); }
connection1.close();
if (log.isDebugEnabled()) { log.debug("*** rolling back"); }
tm.rollback();
if (log.isDebugEnabled()) { log.debug("*** TX is done"); }
// check flow
List orderedEvents = EventRecorder.getOrderedEvents();
log.info(EventRecorder.dumpToString());
assertEquals(9, orderedEvents.size());
int i=0;
assertEquals(Status.STATUS_ACTIVE, ((JournalLogEvent) orderedEvents.get(i++)).getStatus());
assertEquals(DATASOURCE1_NAME, ((ConnectionDequeuedEvent) orderedEvents.get(i++)).getPooledConnectionImpl().getPoolingDataSource().getUniqueName());
assertEquals(XAResource.TMNOFLAGS, ((XAResourceStartEvent) orderedEvents.get(i++)).getFlag());
assertEquals(Status.STATUS_MARKED_ROLLBACK, ((JournalLogEvent) orderedEvents.get(i++)).getStatus());
assertEquals(XAResource.TMSUCCESS, ((XAResourceEndEvent) orderedEvents.get(i++)).getFlag());
assertEquals(Status.STATUS_ROLLING_BACK, ((JournalLogEvent) orderedEvents.get(i++)).getStatus());
assertEquals(XAResourceRollbackEvent.class, orderedEvents.get(i++).getClass());
assertEquals(Status.STATUS_ROLLEDBACK, ((JournalLogEvent) orderedEvents.get(i++)).getStatus());
assertEquals(DATASOURCE1_NAME, ((ConnectionQueuedEvent) orderedEvents.get(i++)).getPooledConnectionImpl().getPoolingDataSource().getUniqueName());
}