本文整理匯總了Java中javax.transaction.TransactionManager類的典型用法代碼示例。如果您正苦於以下問題:Java TransactionManager類的具體用法?Java TransactionManager怎麽用?Java TransactionManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TransactionManager類屬於javax.transaction包,在下文中一共展示了TransactionManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: SpringSessionSynchronization
import javax.transaction.TransactionManager; //導入依賴的package包/類
public SpringSessionSynchronization(
SessionHolder sessionHolder, SessionFactory sessionFactory,
SQLExceptionTranslator jdbcExceptionTranslator, boolean newSession) {
this.sessionHolder = sessionHolder;
this.sessionFactory = sessionFactory;
this.jdbcExceptionTranslator = jdbcExceptionTranslator;
this.newSession = newSession;
// Check whether the SessionFactory has a JTA TransactionManager.
TransactionManager jtaTm =
SessionFactoryUtils.getJtaTransactionManager(sessionFactory, sessionHolder.getAnySession());
if (jtaTm != null) {
this.hibernateTransactionCompletion = true;
// Fetch current JTA Transaction object
// (just necessary for JTA transaction suspension, with an individual
// Hibernate Session per currently active/suspended transaction).
try {
this.jtaTransaction = jtaTm.getTransaction();
}
catch (SystemException ex) {
throw new DataAccessResourceFailureException("Could not access JTA transaction", ex);
}
}
}
示例2: test_RollbackExceptionHandling_rollbackafterthrown
import javax.transaction.TransactionManager; //導入依賴的package包/類
@Test
public void test_RollbackExceptionHandling_rollbackafterthrown()
throws Exception {
TransactionManager tm = mockTm();
when(tm.getStatus()).thenReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE, Status.STATUS_MARKED_ROLLBACK);
doThrow(new RollbackException().initCause(new OptimisticLockException())).when(tm).commit();
XAJpaTemplate tx = new XAJpaTemplate(emSupplier, tm, coordinator);
try {
tx.tx(TransactionType.Required, new EmConsumer() {
public void accept(EntityManager em) {
em.persist(new Object());
}
});
} catch (RuntimeException e) {
// this is ok
}
verify(tm, times(5)).getStatus();
verify(tm, times(1)).commit();
verify(tm, times(1)).rollback();
}
示例3: setup
import javax.transaction.TransactionManager; //導入依賴的package包/類
@Before
public void setup() {
sessionContext = new TestSessionContext(null, null);
callable = new Callable<Object>() {
@Override
public Void call() throws Exception {
return null;
}
};
ctx = new IInvocationCtx() {
@Override
public TransactionManager getTransactionManager() {
return null;
}
@Override
public boolean isApplicationException(Exception e) {
return false;
}
};
}
示例4: getDataSource
import javax.transaction.TransactionManager; //導入依賴的package包/類
@Bean(name = "dataSource")
public DataSource getDataSource(@Autowired XADataSource xaDataSource, @Autowired TransactionManager transactionManager) {
BasicManagedDataSource bds = new BasicManagedDataSource();
bds.setXaDataSourceInstance(xaDataSource);
bds.setTransactionManager(transactionManager);
bds.setMaxTotal(50);
bds.setInitialSize(20);
bds.setMaxWaitMillis(60000);
bds.setMinIdle(6);
bds.setLogAbandoned(true);
bds.setRemoveAbandonedOnBorrow(true);
bds.setRemoveAbandonedOnMaintenance(true);
bds.setRemoveAbandonedTimeout(1800);
bds.setTestWhileIdle(true);
bds.setTestOnBorrow(false);
bds.setTestOnReturn(false);
bds.setValidationQuery("select 'x' ");
bds.setValidationQueryTimeout(1);
bds.setTimeBetweenEvictionRunsMillis(30000);
bds.setNumTestsPerEvictionRun(20);
return bds;
}
示例5: setup
import javax.transaction.TransactionManager; //導入依賴的package包/類
@Before
public void setup() {
sessionContext = new TestSessionContext(null, null);
callable = new Callable<Object>() {
@Override
public Void call() {
return null;
}
};
ctx = new IInvocationCtx() {
@Override
public TransactionManager getTransactionManager() {
return null;
}
@Override
public boolean isApplicationException(Exception e) {
return false;
}
};
}
示例6: multipleCloseTest
import javax.transaction.TransactionManager; //導入依賴的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() );
}
}
}
}
示例7: connect
import javax.transaction.TransactionManager; //導入依賴的package包/類
private void connect() throws HibernateException {
if (!isCurrentTransaction) {
//if there is no current transaction callback registered
//when we obtain the connection, try to register one now
//note that this is not going to handle the case of
//multiple-transactions-per-connection when the user is
//manipulating transactions (need to use Hibernate txn)
TransactionManager tm = factory.getTransactionManager();
if (tm!=null) {
try {
javax.transaction.Transaction tx = tm.getTransaction();
if ( isJTATransactionActive(tx) ) {
tx.registerSynchronization( new CacheSynchronization(this) );
isCurrentTransaction = true;
}
}
catch (Exception e) {
throw new TransactionException("could not register synchronization with JTA TransactionManager", e);
}
}
}
connection = batcher.openConnection();
connect = false;
}
示例8: getDataSource
import javax.transaction.TransactionManager; //導入依賴的package包/類
@Bean(name = "mybatisDataSource")
public DataSource getDataSource(@Autowired XADataSource xaDataSource, @Autowired TransactionManager transactionManager) {
BasicManagedDataSource bds = new BasicManagedDataSource();
bds.setXaDataSourceInstance(xaDataSource);
bds.setTransactionManager(transactionManager);
bds.setMaxTotal(50);
bds.setInitialSize(20);
bds.setMaxWaitMillis(60000);
bds.setMinIdle(6);
bds.setLogAbandoned(true);
bds.setRemoveAbandonedOnBorrow(true);
bds.setRemoveAbandonedOnMaintenance(true);
bds.setRemoveAbandonedTimeout(1800);
bds.setTestWhileIdle(true);
bds.setTestOnBorrow(false);
bds.setTestOnReturn(false);
bds.setValidationQuery("select 'x' ");
bds.setValidationQueryTimeout(1);
bds.setTimeBetweenEvictionRunsMillis(30000);
bds.setNumTestsPerEvictionRun(20);
return bds;
}
示例9: testBug46169
import javax.transaction.TransactionManager; //導入依賴的package包/類
@Test
public void testBug46169() throws Exception {
String tableName = CacheUtils.init("CacheTest");
assertFalse(tableName == null || tableName.equals(""));
logger.debug("Table name: " + tableName);
logger.debug("init for bug46169 Successful!");
Cache cache = CacheUtils.getCache();
TransactionManager xmanager =
(TransactionManager) cache.getJNDIContext().lookup("java:/TransactionManager");
assertNotNull(xmanager);
Transaction trans = xmanager.suspend();
assertNull(trans);
try {
logger.debug("Destroying table: " + tableName);
CacheUtils.destroyTable(tableName);
logger.debug("Closing cache...");
logger.debug("destroyTable for bug46169 Successful!");
} finally {
CacheUtils.closeCache();
}
}
示例10: basicRollbackTest
import javax.transaction.TransactionManager; //導入依賴的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() );
}
}
示例11: connectionOutsideTransactionTest
import javax.transaction.TransactionManager; //導入依賴的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() );
}
}
示例12: TestEEfiJtaPlatform
import javax.transaction.TransactionManager; //導入依賴的package包/類
public TestEEfiJtaPlatform(
final TransactionManager transactionManager,
final TransactionServices transactionServices
) {
this.transactionManager = transactionManager;
this.transactionServices = transactionServices;
}
示例13: removedService
import javax.transaction.TransactionManager; //導入依賴的package包/類
@Override
public void removedService(ServiceReference<TransactionManager> reference, ServiceRegistration reg) {
try {
reg.unregister();
context.ungetService(reference);
} catch (Exception e) {
LOG.debug("Exception during unregister", e);
}
}
示例14: test_RollbackExceptionHandling_rollbackiscalledonmarkedrollback
import javax.transaction.TransactionManager; //導入依賴的package包/類
@Test
public void test_RollbackExceptionHandling_rollbackiscalledonmarkedrollback() throws Exception {
TransactionManager tm = mockTm();
when(tm.getStatus()).thenReturn(Status.STATUS_NO_TRANSACTION,
Status.STATUS_MARKED_ROLLBACK);
XAJpaTemplate tx = new XAJpaTemplate(emSupplier, tm, coordinator);
tx.tx(TransactionType.Required, new EmConsumer() {
public void accept(EntityManager em) {
em.persist(new Object());
}
});
verify(tm, times(3)).getStatus();
verify(tm, never()).commit();
verify(tm, times(1)).rollback();
}
示例15: create
import javax.transaction.TransactionManager; //導入依賴的package包/類
@Override
public TransactionManager create() {
TransactionManager transactionManager = null;
ApplicationServer as = ApplicationServer.currentApplicationServer();
if ( as == ApplicationServer.WEBSPHERE ) {
transactionManager = DelegatingTransactionManager.transactionManager();
}
else {
transactionManager = platform.retrieveTransactionManager();
}
return transactionManager;
}