本文整理汇总了Java中bitronix.tm.TransactionManagerServices类的典型用法代码示例。如果您正苦于以下问题:Java TransactionManagerServices类的具体用法?Java TransactionManagerServices怎么用?Java TransactionManagerServices使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TransactionManagerServices类属于bitronix.tm包,在下文中一共展示了TransactionManagerServices类的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: lookup
import bitronix.tm.TransactionManagerServices; //导入依赖的package包/类
@Override
public Object lookup(String s) throws NamingException {
checkClosed();
if (log.isDebugEnabled()) { log.debug("looking up '" + s + "'"); }
Object o;
if (userTransactionName.equals(s))
o = TransactionManagerServices.getTransactionManager();
else if (synchronizationRegistryName.equals(s))
o = TransactionManagerServices.getTransactionSynchronizationRegistry();
else
o = ResourceRegistrar.get(s);
if (o == null)
throw new NameNotFoundException("unable to find a bound object at name '" + s + "'");
return o;
}
示例6: register
import bitronix.tm.TransactionManagerServices; //导入依赖的package包/类
/**
* Register a {@link XAResourceProducer}. If registration happens after the transaction manager started, incremental
* recovery is run on that resource.
* @param producer the {@link XAResourceProducer}.
* @throws RecoveryException When an error happens during recovery.
*/
public static void register(XAResourceProducer producer) throws RecoveryException {
try {
final boolean alreadyRunning = TransactionManagerServices.isTransactionManagerRunning();
final ProducerHolder holder = alreadyRunning ? new InitializableProducerHolder(producer) : new ProducerHolder(producer);
if (resources.add(holder)) {
if (holder instanceof InitializableProducerHolder) {
boolean recovered = false;
try {
if (log.isDebugEnabled()) { log.debug("Transaction manager is running, recovering resource '" + holder.getUniqueName() + "'."); }
IncrementalRecoverer.recover(producer);
((InitializableProducerHolder) holder).initialize();
recovered = true;
} finally {
if (!recovered) { resources.remove(holder); }
}
}
} else {
throw new IllegalStateException("A resource with uniqueName '" + holder.getUniqueName() + "' has already been registered. " +
"Cannot register XAResourceProducer '" + producer + "'.");
}
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Cannot register the XAResourceProducer '" + producer + "' caused by invalid input.", e);
}
}
示例7: stop
import bitronix.tm.TransactionManagerServices; //导入依赖的package包/类
@Override
public void stop(BundleContext context) throws Exception {
BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
tm.shutdown();
tmRegistration.unregister();
utRegistration.unregister();
for (ServiceRegistration reg : dsRegistrations.values()) {
reg.unregister();
}
dsRegistrations.clear();
Configuration conf = TransactionManagerServices.getConfiguration();
log.info(String.format("Stopped JTA for server ID '%s'.", conf.getServerId()));
}
示例8: handleXAException
import bitronix.tm.TransactionManagerServices; //导入依赖的package包/类
private void handleXAException(XAResourceHolderState failedResourceHolder, XAException xaException) throws XAException {
switch (xaException.errorCode) {
case XAException.XA_HEURRB:
forgetHeuristicRollback(failedResourceHolder);
return;
case XAException.XA_HEURCOM:
case XAException.XA_HEURHAZ:
case XAException.XA_HEURMIX:
log.error("heuristic rollback is incompatible with the global state of this transaction - guilty: " + failedResourceHolder);
throw xaException;
default:
String extraErrorDetails = TransactionManagerServices.getExceptionAnalyzer().extractExtraXAExceptionDetails(xaException);
log.warn("resource '" + failedResourceHolder.getUniqueName() + "' reported " + Decoder.decodeXAExceptionErrorCode(xaException) +
" when asked to rollback transaction branch. Transaction is prepared and will rollback via recovery service when resource availability allows."
+ (extraErrorDetails == null ? "" : " Extra error=" + extraErrorDetails), xaException);
}
}
示例9: 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();
}
示例10: 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();
}
示例11: testCachedStatementsCanBeReused
import bitronix.tm.TransactionManagerServices; //导入依赖的package包/类
@Test
public void testCachedStatementsCanBeReused() throws Exception {
BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
tm.setTransactionTimeout(60);
tm.begin();
try {
Connection connection = poolingDataSource1.getConnection();
try {
PreparedStatement prepareStatement1 = connection.prepareStatement("SELECT 1 FROM nothing WHERE a=? AND b=? AND c=? AND d=?");
assertFalse(prepareStatement1.isClosed());
prepareStatement1.close();
assertTrue(prepareStatement1.isClosed());
PreparedStatement prepareStatement2 = connection.prepareStatement("SELECT 1 FROM nothing WHERE a=? AND b=? AND c=? AND d=?");
assertFalse(prepareStatement2.isClosed());
} finally {
connection.close();
}
} finally {
tm.shutdown();
}
}
示例12: testSharedConnectionInGlobal
import bitronix.tm.TransactionManagerServices; //导入依赖的package包/类
public void testSharedConnectionInGlobal() throws Exception {
if (log.isDebugEnabled()) { log.debug("*** testSharedConnectionInGlobal: Starting 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 DS1"); }
Connection connection1 = poolingDataSource1.getConnection();
if (log.isDebugEnabled()) { log.debug("*** getting second connection from DS1"); }
Connection connection2 = poolingDataSource1.getConnection();
PooledConnectionProxy handle1 = (PooledConnectionProxy) connection1;
PooledConnectionProxy handle2 = (PooledConnectionProxy) connection2;
assertSame(handle1.getProxiedDelegate(), handle2.getProxiedDelegate());
connection1.close();
connection2.close();
tm.commit();
}
示例13: setUp
import bitronix.tm.TransactionManagerServices; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
TransactionManagerServices.getConfiguration().setJournal("null").setGracefulShutdownInterval(2);
TransactionManagerServices.getTransactionManager();
MockXAConnectionFactory.setStaticCloseXAConnectionException(null);
MockXAConnectionFactory.setStaticCreateXAConnectionException(null);
pcf = new PoolingConnectionFactory();
pcf.setMinPoolSize(1);
pcf.setMaxPoolSize(2);
pcf.setMaxIdleTime(1);
pcf.setClassName(MockXAConnectionFactory.class.getName());
pcf.setUniqueName("pcf");
pcf.setAllowLocalTransactions(true);
pcf.setAcquisitionTimeout(1);
pcf.init();
}
示例14: testPoolShrink
import bitronix.tm.TransactionManagerServices; //导入依赖的package包/类
public void testPoolShrink() throws Exception {
Field poolField = pcf.getClass().getDeclaredField("pool");
poolField.setAccessible(true);
XAPool pool = (XAPool) poolField.get(pcf);
assertEquals(1, pool.inPoolSize());
assertEquals(1, pool.totalPoolSize());
Connection c1 = pcf.createConnection();
assertEquals(0, pool.inPoolSize());
assertEquals(1, pool.totalPoolSize());
Connection c2 = pcf.createConnection();
assertEquals(0, pool.inPoolSize());
assertEquals(2, pool.totalPoolSize());
c1.close();
c2.close();
Thread.sleep(1200); // leave enough time for the ide connections to expire
TransactionManagerServices.getTaskScheduler().interrupt(); // wake up the task scheduler
Thread.sleep(1200); // leave enough time for the scheduled shrinking task to do its work
assertEquals(1, pool.inPoolSize());
assertEquals(1, pool.totalPoolSize());
}
示例15: setDataSource
import bitronix.tm.TransactionManagerServices; //导入依赖的package包/类
@Test
public void setDataSource() throws Exception {
XADataSource dataSource = mock(XADataSource.class);
XAConnection xaConnection = mock(XAConnection.class);
Connection connection = mock(Connection.class);
given(dataSource.getXAConnection()).willReturn(xaConnection);
given(xaConnection.getConnection()).willReturn(connection);
this.bean.setDataSource(dataSource);
this.bean.setBeanName("beanName");
this.bean.afterPropertiesSet();
this.bean.init();
this.bean.createPooledConnection(dataSource, this.bean);
verify(dataSource).getXAConnection();
TransactionManagerServices.getTaskScheduler().shutdown();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:16,代码来源:PoolingDataSourceBeanTests.java