1 16 package com.ibatis.sqlmap.engine.transaction.jta; 17 18 import com.ibatis.sqlmap.client.SqlMapException; 19 import com.ibatis.sqlmap.engine.transaction.BaseTransactionConfig; 20 import com.ibatis.sqlmap.engine.transaction.Transaction; 21 import com.ibatis.sqlmap.engine.transaction.TransactionException; 22 23 import javax.naming.InitialContext ; 24 import javax.naming.NamingException ; 25 import javax.sql.DataSource ; 26 import javax.transaction.UserTransaction ; 27 import java.sql.SQLException ; 28 import java.util.Properties ; 29 30 public class JtaTransactionConfig extends BaseTransactionConfig { 31 32 private DataSource dataSource; 33 private UserTransaction userTransaction; 34 35 public DataSource getDataSource() { 36 return dataSource; 37 } 38 39 public void setDataSource(DataSource ds) { 40 this.dataSource = ds; 41 } 42 43 public void initialize(Properties props) throws SQLException , TransactionException { 44 String utxName = null; 45 try { 46 utxName = (String ) props.get("UserTransaction"); 47 InitialContext initCtx = new InitialContext (); 48 userTransaction = (UserTransaction ) initCtx.lookup(utxName); 49 } catch (NamingException e) { 50 throw new SqlMapException("Error initializing JtaTransactionConfig while looking up UserTransaction (" + utxName + "). Cause: " + e); 51 } 52 } 53 54 public Transaction newTransaction(int transactionIsolation) throws SQLException , TransactionException { 55 return new JtaTransaction(userTransaction, dataSource, transactionIsolation); 56 } 57 58 } 59 60 | Popular Tags |