1 16 package com.ibatis.dao.client.template; 17 18 import com.ibatis.common.util.PaginatedList; 19 import com.ibatis.dao.client.DaoException; 20 import com.ibatis.dao.client.DaoManager; 21 import com.ibatis.dao.engine.transaction.sqlmap.SqlMapDaoTransaction; 22 import com.ibatis.sqlmap.client.SqlMapExecutor; 23 import com.ibatis.sqlmap.client.SqlMapTransactionManager; 24 import com.ibatis.sqlmap.client.event.RowHandler; 25 26 import java.sql.SQLException ; 27 import java.util.List ; 28 import java.util.Map ; 29 30 38 public abstract class SqlMapDaoTemplate extends DaoTemplate implements SqlMapExecutor { 39 40 47 public SqlMapDaoTemplate(DaoManager daoManager) { 48 super(daoManager); 49 } 50 51 59 protected SqlMapExecutor getSqlMapExecutor() { 60 SqlMapDaoTransaction trans = (SqlMapDaoTransaction) daoManager.getTransaction(this); 61 return trans.getSqlMap(); 62 } 63 64 78 protected SqlMapTransactionManager getSqlMapTransactionManager() { 79 SqlMapDaoTransaction trans = (SqlMapDaoTransaction) daoManager.getTransaction(this); 80 return trans.getSqlMap(); 81 } 82 83 98 public Object insert(String id, Object parameterObject) { 99 try { 100 return getSqlMapExecutor().insert(id, parameterObject); 101 } catch (SQLException e) { 102 throw new DaoException("Failed to insert - id [" 103 + id + "], parameterObject [" + parameterObject + "]. Cause: " + e, e); 104 } 105 } 106 107 120 public int update(String id, Object parameterObject) { 121 try { 122 return getSqlMapExecutor().update(id, parameterObject); 123 } catch (SQLException e) { 124 throw new DaoException("Failed to update - id [" 125 + id + "] - parameterObject [" + parameterObject + "]. Cause: " + e, e); 126 } 127 } 128 129 140 public int delete(String id, Object parameterObject) { 141 try { 142 return getSqlMapExecutor().delete(id, parameterObject); 143 } catch (SQLException e) { 144 throw new DaoException("Failed to delete - id [" 145 + id + "] - parameterObject [" + parameterObject + "]. Cause: " + e, e); 146 } 147 } 148 149 160 public Object queryForObject(String id, Object parameterObject) { 161 try { 162 return getSqlMapExecutor().queryForObject(id, parameterObject); 163 } catch (SQLException e) { 164 throw new DaoException("Failed to execute queryForObject - id [" 165 + id + "], parameterObject [" + parameterObject + "]. Cause: " + e, e); 166 } 167 } 168 169 181 public Object queryForObject(String id, Object parameterObject, Object resultObject) { 182 try { 183 return getSqlMapExecutor().queryForObject(id, parameterObject, resultObject); 184 } catch (SQLException e) { 185 throw new DaoException("Failed to queryForObject - id [" 186 + id + "], parameterObject [" + parameterObject + "]. Cause: " + e, e); 187 } 188 } 189 190 201 public List queryForList(String id, Object parameterObject) { 202 try { 203 return getSqlMapExecutor().queryForList(id, parameterObject); 204 } catch (SQLException e) { 205 throw new DaoException("Failed to queryForList - id [" 206 + id + "], parameterObject [" + parameterObject + "]. Cause: " + e, e); 207 } 208 } 209 210 223 public List queryForList(String id, Object parameterObject, int skip, int max) { 224 try { 225 return getSqlMapExecutor().queryForList(id, parameterObject, skip, max); 226 } catch (SQLException e) { 227 throw new DaoException("Failed to queryForList - id [" 228 + id + "], parameterObject [" + parameterObject + "], skip [" 229 + skip + "], max [" + max + "]. Cause: " + e, e); 230 } 231 } 232 233 249 public void queryWithRowHandler(String id, Object parameterObject, RowHandler rowHandler) { 250 try { 251 getSqlMapExecutor().queryWithRowHandler(id, parameterObject, rowHandler); 252 } catch (SQLException e) { 253 throw new DaoException("Failed to queryForList - id [" + id + "], parameterObject [" 254 + parameterObject + "], rowHandler [ " + rowHandler + "]. Cause: " + e, e); 255 } 256 } 257 258 270 public PaginatedList queryForPaginatedList(String id, Object parameterObject, int pageSize) { 271 try { 272 return getSqlMapExecutor().queryForPaginatedList(id, parameterObject, pageSize); 273 } catch (SQLException e) { 274 throw new DaoException("Failed to queryForPaginatedList - id [" + id + "], parameterObject [" 275 + parameterObject + "], pageSize [" + pageSize + "]. Cause: " + e, e); 276 } 277 } 278 279 291 public Map queryForMap(String id, Object parameterObject, String keyProp) { 292 try { 293 return getSqlMapExecutor().queryForMap(id, parameterObject, keyProp); 294 } catch (SQLException e) { 295 throw new DaoException("Failed to queryForMap - id [" + id + "], parameterObject [" 296 + parameterObject + "], keyProp [" + keyProp + "]. Cause: " + e, e); 297 } 298 } 299 300 313 public Map queryForMap(String id, Object parameterObject, String keyProp, String valueProp) { 314 try { 315 return getSqlMapExecutor().queryForMap(id, parameterObject, keyProp, valueProp); 316 } catch (SQLException e) { 317 throw new DaoException("Failed to queryForMap - id [" + id + "], parameterObject [" 318 + parameterObject + "], keyProp [" + keyProp + "], valueProp [" 319 + valueProp + "]. Cause: " + e, e); 320 } 321 } 322 323 328 public void startBatch() { 329 try { 330 getSqlMapExecutor().startBatch(); 331 } catch (SQLException e) { 332 throw new DaoException("Failed to startBatch. Cause: " + e, e); 333 } 334 } 335 336 339 public int executeBatch() { 340 try { 341 return getSqlMapExecutor().executeBatch(); 342 } catch (SQLException e) { 343 throw new DaoException("Failed to executeBatch. Cause: " + e, e); 344 } 345 } 346 347 } 348 | Popular Tags |