1 16 package com.ibatis.dao.engine.transaction.sqlmap; 17 18 import com.ibatis.common.resources.Resources; 19 import com.ibatis.dao.client.DaoException; 20 import com.ibatis.dao.client.DaoTransaction; 21 import com.ibatis.dao.engine.transaction.DaoTransactionManager; 22 import com.ibatis.sqlmap.client.SqlMapClient; 23 import com.ibatis.sqlmap.client.SqlMapClientBuilder; 24 25 import java.io.IOException ; 26 import java.io.Reader ; 27 import java.util.Properties ; 28 29 32 public class SqlMapDaoTransactionManager implements DaoTransactionManager { 33 34 private SqlMapClient client; 35 36 42 public void configure(Properties properties) { 43 try { 44 Reader reader = null; 45 if (properties.containsKey("SqlMapConfigURL")) { 46 reader = Resources.getUrlAsReader((String ) properties.get("SqlMapConfigURL")); 47 } else if (properties.containsKey("SqlMapConfigResource")) { 48 reader = Resources.getResourceAsReader((String ) properties.get("SqlMapConfigResource")); 49 } else { 50 throw new DaoException("SQLMAP transaction manager requires either 'SqlMapConfigURL' or 'SqlMapConfigResource' to be specified as a property."); 51 } 52 client = SqlMapClientBuilder.buildSqlMapClient(reader, properties); 53 } catch (IOException e) { 54 throw new DaoException("Error configuring SQL Map. Cause: " + e); 55 } 56 } 57 58 64 public DaoTransaction startTransaction() { 65 return new SqlMapDaoTransaction(client); 66 } 67 68 74 public void commitTransaction(DaoTransaction trans) { 75 ((SqlMapDaoTransaction) trans).commit(); 76 } 77 78 84 public void rollbackTransaction(DaoTransaction trans) { 85 ((SqlMapDaoTransaction) trans).rollback(); 86 } 87 88 } 89 | Popular Tags |