com.atomikos.icatch.jta.UserTransactionImp Java Examples
The following examples show how to use
com.atomikos.icatch.jta.UserTransactionImp.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NodeListener.java From JPPF with Apache License 2.0 | 6 votes |
/** * Terminate the transaction and return an exception if any occurred. * @return Exception if any error occurred. */ @Override public Exception call() { try { // create the datasource; it will be automatically enlisted in the transaction getDataSource(); // start the atomikos transaction manager final UserTransactionImp utx = new UserTransactionImp(); utx.setTransactionTimeout(60); if (rollbackOnly) utx.setRollbackOnly(); utx.begin(); final Connection c = getConnection(); c.close(); return null; } catch (final Exception e) { return e; } }
Example #2
Source File: NodeListener.java From JPPF with Apache License 2.0 | 6 votes |
/** * Terminate the transaction and return an exception if any occurred. * @return Exception if any error occurred. */ @Override public Exception call() { try { final UserTransactionImp utx = new UserTransactionImp(); if (utx.getStatus() == Status.STATUS_NO_TRANSACTION) output("WARNING: endTransaction() called outside a tx"); else { output("INFO: transaction " + (rollback ? "rollback" : "commit")); if (rollback) utx.rollback(); else utx.commit(); } return null; } catch (final Exception e) { return e; } }
Example #3
Source File: DataSourceConfig.java From mybatis.flying with Apache License 2.0 | 6 votes |
@Bean(name = "springTransactionManager") // 用户数据源的事务管理器 public JtaTransactionManager accountTxManager() { UserTransactionManager atomikosTransactionManager = new UserTransactionManager(); atomikosTransactionManager.setForceShutdown(true); UserTransaction atomikosUserTransaction = new UserTransactionImp(); try { atomikosUserTransaction.setTransactionTimeout(300); } catch (SystemException e) { } JtaTransactionManager springTransactionManager = new org.springframework.transaction.jta.JtaTransactionManager(); springTransactionManager.setTransactionManager(atomikosTransactionManager); springTransactionManager.setUserTransaction(atomikosUserTransaction); springTransactionManager.setAllowCustomIsolationLevels(true); return springTransactionManager; }
Example #4
Source File: ApplicationUnitTest.java From tutorials with MIT License | 6 votes |
private static long getBalance(DataSource inventoryDataSource, String productId) throws Exception { UserTransactionImp utx = new UserTransactionImp(); utx.begin(); Connection inventoryConnection = inventoryDataSource.getConnection(); Statement s1 = inventoryConnection.createStatement(); String q1 = "select balance from Inventory where productId='" + productId + "'"; ResultSet rs1 = s1.executeQuery(q1); if (rs1 == null || !rs1.next()) throw new Exception("Product not found: " + productId); long balance = rs1.getLong(1); inventoryConnection.close(); utx.commit(); return balance; }
Example #5
Source File: FastDepAtomikosTransactionConfigure.java From fastdep with Apache License 2.0 | 5 votes |
/** * userTransaction * * @return userTransactionImp * @throws Throwable throwable */ @Bean(name = "userTransaction") public UserTransaction userTransaction() throws Throwable { UserTransactionImp userTransactionImp = new UserTransactionImp(); userTransactionImp.setTransactionTimeout(10000); return userTransactionImp; }
Example #6
Source File: SupportConfig.java From jeesupport with MIT License | 5 votes |
/** * atomikos事务实现,一般情况无需修改 * @return */ @Bean public UserTransactionImp atomikosUT() throws SystemException { UserTransactionImp uti = new UserTransactionImp(); if( CommonConfig.getBoolean( "jees.jdbs.enable" ) != true ) return uti; uti.setTransactionTimeout( CommonConfig.getInteger("jees.jdbs.trans.timeout", 300 ) ); log.debug( "--Spring Bean[atomikosUT]初始化." ); return uti; }
Example #7
Source File: SupportConfig.java From jeesupport with MIT License | 5 votes |
/** * spring jta 事务管理器,一般情况无需修改 * @param _utm * @param _uti * @return */ @Bean public JtaTransactionManager transactionManager(@Qualifier( "atomikosTM" ) UserTransactionManager _utm, @Qualifier( "atomikosUT" ) UserTransactionImp _uti ){ JtaTransactionManager jtm = new JtaTransactionManager(); jtm.setTransactionManager( _utm ); jtm.setUserTransaction( _uti ); jtm.setAllowCustomIsolationLevels( CommonConfig.getBoolean("jees.jdbs.trans.allowCustomIsolationLevels", false ) ); log.debug( "--Spring Bean[defaultTM]初始化." ); return jtm; }
Example #8
Source File: JpaCoreConfig.java From bearchoke with Apache License 2.0 | 5 votes |
@Bean public UserTransactionImp userTransactionImp() throws SystemException { UserTransactionImp uti = new UserTransactionImp(); uti.setTransactionTimeout(300); return uti; }
Example #9
Source File: Application.java From tutorials with MIT License | 5 votes |
public void placeOrder(String productId, int amount) throws Exception { UserTransactionImp utx = new UserTransactionImp(); String orderId = UUID.randomUUID() .toString(); boolean rollback = false; try { utx.begin(); Connection inventoryConnection = inventoryDataSource.getConnection(); Connection orderConnection = orderDataSource.getConnection(); Statement s1 = inventoryConnection.createStatement(); String q1 = "update Inventory set balance = balance - " + amount + " where productId ='" + productId + "'"; s1.executeUpdate(q1); s1.close(); Statement s2 = orderConnection.createStatement(); String q2 = "insert into Orders values ( '" + orderId + "', '" + productId + "', " + amount + " )"; s2.executeUpdate(q2); s2.close(); inventoryConnection.close(); orderConnection.close(); } catch (Exception e) { System.out.println(e.getMessage()); rollback = true; } finally { if (!rollback) utx.commit(); else utx.rollback(); } }
Example #10
Source File: AtomikosDatasourceProvider.java From Mycat2 with GNU General Public License v3.0 | 4 votes |
@Override public UserTransaction createUserTransaction() { return new UserTransactionImp(); }
Example #11
Source File: MainConfig.java From spring-boot-jta-atomikos-sample with Apache License 2.0 | 4 votes |
@Bean(name = "userTransaction") public UserTransaction userTransaction() throws Throwable { UserTransactionImp userTransactionImp = new UserTransactionImp(); userTransactionImp.setTransactionTimeout(10000); return userTransactionImp; }