import bitronix.tm.TransactionManagerServices; import bitronix.tm.resource.jdbc.PoolingDataSource; public class TransactionExample { public static void main(String[] args) throws Exception { TransactionManager tm = TransactionManagerServices.getTransactionManager(); PoolingDataSource dataSource = new PoolingDataSource(); dataSource.setClassName("org.h2.jdbcx.JdbcDataSource"); dataSource.setUniqueName("myDataSource"); dataSource.setAllowLocalTransactions(true); dataSource.getDriverProperties().put("URL", "jdbc:h2:mem:test"); dataSource.init(); tm.begin(); try { Connection conn = dataSource.getConnection(); // ... tm.commit(); } catch (Exception e) { tm.rollback(); throw e; } } } bitronix.tm.timer.defaultTransactionTimeout=60 bitronix.tm.timer.serverId=1 bitronix.tm.journal.disk.logPart1Filename=/path/to/btm1.tlog bitronix.tm.journal.disk.logPart2Filename=/path/to/btm2.tlog bitronix.tm.ldr.journal.logPart1Filename=/path/to/btm1.tlog bitronix.tm.ldr.journal.logPart2Filename=/path/to/btm2.tlog bitronix.tm.resource.configuration=/path/to/resources.properties


上一篇:
下一篇:
切换中文