1 16 package com.ibatis.db.dao.jdbc; 17 18 import com.ibatis.common.exception.NestedRuntimeException; 19 import com.ibatis.common.resources.Resources; 20 import com.ibatis.db.dao.DaoException; 21 import com.ibatis.db.dao.DaoTransaction; 22 import com.ibatis.db.dao.DaoTransactionPool; 23 import com.ibatis.sqlmap.client.SqlMapClient; 24 import com.ibatis.sqlmap.client.SqlMapClientBuilder; 25 26 import java.io.Reader ; 27 import java.sql.SQLException ; 28 import java.util.Map ; 29 30 public class SqlMap2DaoTransactionPool implements DaoTransactionPool { 31 32 private SqlMapClient sqlMap; 33 34 public void configure(Map properties) 35 throws DaoException { 36 37 try { 38 String xmlConfig = (String ) properties.get("sql-map-config-file"); 39 40 Reader reader = Resources.getResourceAsReader(xmlConfig); 41 sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader); 42 } catch (Exception e) { 43 throw new NestedRuntimeException("Error configuring SqlMapClientDaoTransactionPool. Cause: " + e, e); 44 } 45 46 } 47 48 public DaoTransaction getTransaction() 49 throws DaoException { 50 try { 51 sqlMap.startTransaction(); 52 return new SqlMap2DaoTransaction(sqlMap); 53 } catch (SQLException e) { 54 throw new DaoException("Error getting transaction. Cause: " + e, e); 55 } 56 } 57 58 public void releaseTransaction(DaoTransaction trans) 59 throws DaoException { 60 } 62 63 public SqlMapClient getSqlMapClient() { 64 return sqlMap; 65 } 66 67 68 } 69 | Popular Tags |