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


Java BitronixTransactionManager.begin方法代码示例

本文整理汇总了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();
       }
}
 
开发者ID:maxant,项目名称:genericconnector,代码行数:22,代码来源:MicroserviceResourceProducerTest.java

示例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();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:17,代码来源:XA107Test.java

示例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");
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:XACacheTest.java

示例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);
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:25,代码来源:XACacheTest.java

示例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");
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:25,代码来源:XACacheTest.java

示例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();
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:27,代码来源:StatefulSerializerTest.java

示例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();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:27,代码来源:JdbcSharedConnectionTest.java

示例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();
       }
}
 
开发者ID:maxant,项目名称:genericconnector,代码行数:32,代码来源:MicroserviceResourceProducerTest.java

示例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);
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:35,代码来源:XACacheTest.java

示例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();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:13,代码来源:XACacheTest.java

示例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[]
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:28,代码来源:XAGettingStarted.java

示例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[]
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:33,代码来源:XAGettingStarted.java

示例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[]
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:33,代码来源:XAGettingStarted.java

示例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();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:16,代码来源:NewJdbcProperUsageMockTest.java

示例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());
}
 
开发者ID:bitronix,项目名称:btm,代码行数:39,代码来源:NewJdbcProperUsageMockTest.java


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