1 16 package com.ibatis.dao.engine.transaction.jta; 17 18 import com.ibatis.dao.client.DaoException; 19 import com.ibatis.dao.client.DaoTransaction; 20 import com.ibatis.dao.engine.transaction.DaoTransactionManager; 21 22 import javax.naming.InitialContext ; 23 import javax.sql.DataSource ; 24 import javax.transaction.UserTransaction ; 25 import java.util.Properties ; 26 27 public class JtaDaoTransactionManager implements DaoTransactionManager { 28 29 private DataSource dataSource; 30 private UserTransaction userTransaction; 31 32 public void configure(Properties properties) { 33 String utxName = null; 34 String dsName = null; 35 try { 36 utxName = (String ) properties.get("UserTransaction"); 37 InitialContext initCtx = new InitialContext (); 38 userTransaction = (UserTransaction ) initCtx.lookup(utxName); 39 dsName = (String ) properties.get("DBJndiContext"); 40 dataSource = (DataSource ) initCtx.lookup(dsName); 41 } catch (Exception e) { 42 throw new DaoException("Error initializing JTA transaction while looking up UserTransaction (" + utxName + ") or DataSource (" + dsName + "). Cause: " + e); 43 } 44 } 45 46 public DaoTransaction startTransaction() { 47 return new JtaDaoTransaction(userTransaction, dataSource); 48 } 49 50 public void commitTransaction(DaoTransaction trans) { 51 ((JtaDaoTransaction) trans).commit(); 52 } 53 54 public void rollbackTransaction(DaoTransaction trans) { 55 ((JtaDaoTransaction) trans).rollback(); 56 } 57 } 58 | Popular Tags |