1 16 17 package org.springframework.orm.ibatis.support; 18 19 import javax.sql.DataSource ; 20 21 import com.ibatis.db.sqlmap.SqlMap; 22 23 import org.springframework.dao.support.DaoSupport; 24 import org.springframework.orm.ibatis.SqlMapTemplate; 25 26 43 public abstract class SqlMapDaoSupport extends DaoSupport { 44 45 private SqlMapTemplate sqlMapTemplate = new SqlMapTemplate(); 46 47 private boolean externalTemplate = false; 48 49 54 public final void setDataSource(DataSource dataSource) { 55 this.sqlMapTemplate.setDataSource(dataSource); 56 } 57 58 61 public final DataSource getDataSource() { 62 return (this.sqlMapTemplate != null ? this.sqlMapTemplate.getDataSource() : null); 63 } 64 65 70 public final void setSqlMap(SqlMap sqlMap) { 71 this.sqlMapTemplate.setSqlMap(sqlMap); 72 } 73 74 77 public final SqlMap getSqlMap() { 78 return this.sqlMapTemplate.getSqlMap(); 79 } 80 81 86 public final void setSqlMapTemplate(SqlMapTemplate sqlMapTemplate) { 87 if (sqlMapTemplate == null) { 88 throw new IllegalArgumentException ("Cannot set sqlMapTemplate to null"); 89 } 90 this.sqlMapTemplate = sqlMapTemplate; 91 this.externalTemplate = true; 92 } 93 94 98 public final SqlMapTemplate getSqlMapTemplate() { 99 return sqlMapTemplate; 100 } 101 102 protected final void checkDaoConfig() { 103 if (!this.externalTemplate) { 104 this.sqlMapTemplate.afterPropertiesSet(); 105 } 106 } 107 108 } 109 | Popular Tags |