BaseDAOImpl.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. package com.huimv.xt.dao;
  2. import java.sql.SQLException;
  3. import java.util.Date;
  4. import java.util.List;
  5. import java.util.Map;
  6. import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
  7. /**
  8. * BaseDAO基础接口实现
  9. * @author hongjun.hu
  10. * @version 1.0
  11. */
  12. public class BaseDAOImpl extends SqlMapClientDaoSupport implements BaseDAO {
  13. /**
  14. * 单表操作:根据动态条件记数记录集
  15. * @param nameSpace 命名空间串
  16. * @param example example实例
  17. * @return 数量
  18. * @throws SQLException
  19. */
  20. public int countByExample(String nameSpace, Object example)
  21. throws SQLException {
  22. Integer count = (Integer) getSqlMapClientTemplate().queryForObject(
  23. nameSpace + ".abatorgenerated_countByExample", example);
  24. return count;
  25. }
  26. /**
  27. * 数据删除
  28. * @param sqlMapId sqlMap标识
  29. * @param parameterObject 参数对象
  30. * @return 插入对象
  31. * @throws SQLException
  32. */
  33. public int delete(String sqlMapId, Object parameterObject)
  34. throws SQLException {
  35. return getSqlMapClientTemplate().delete(sqlMapId, parameterObject);
  36. }
  37. /**
  38. * 单表操作:根据动态条件删除记录集
  39. * @param nameSpace 命名空间串
  40. * @param example example实例
  41. * @return 删除返回
  42. * @throws SQLException
  43. */
  44. public int deleteByExample(String nameSpace, Object example)
  45. throws SQLException {
  46. int rows = getSqlMapClientTemplate().delete(
  47. nameSpace + ".abatorgenerated_deleteByExample", example);
  48. return rows;
  49. }
  50. /**
  51. * 单表操作:根据主键删除记录集
  52. * @param nameSpace 命名空间串
  53. * @param id 主键
  54. * @return 删除返回
  55. * @throws SQLException
  56. */
  57. public int deleteByPrimaryKey(String nameSpace, Long id)
  58. throws SQLException {
  59. int rows = getSqlMapClientTemplate().delete(
  60. nameSpace + ".abatorgenerated_deleteByPrimaryKey", id);
  61. return rows;
  62. }
  63. /**
  64. * 得到当前数据时间 get.database.date位于XT_CZYH_SqlMap 中
  65. * @return 日期
  66. * @throws SQLException
  67. */
  68. public Date getCurrentDate() throws SQLException {
  69. Date date = (Date) getSqlMapClientTemplate().queryForObject(
  70. "get.database.date", null);
  71. return date;
  72. }
  73. /**
  74. * 数据插入
  75. * @param sqlMapId sqlMap标识
  76. * @param parameterObject 参数对象
  77. * @return Object 插入对象
  78. * @throws SQLException
  79. */
  80. public Object insert(String sqlMapId, Object parameterObject)
  81. throws SQLException {
  82. return getSqlMapClientTemplate().insert(sqlMapId, parameterObject);
  83. }
  84. /**
  85. * 单表操作:插入记录集
  86. * @param nameSpace 命名空间串
  87. * @param record 实体
  88. * @throws SQLException
  89. */
  90. public void insertRecord(String nameSpace, Object record)
  91. throws SQLException {
  92. getSqlMapClientTemplate().insert(nameSpace + ".abatorgenerated_insert",
  93. record);
  94. }
  95. /**
  96. * 数据查询并返回全部列表
  97. * @param sqlMapId sqlMap标识
  98. * @param parameterObject 参数对象
  99. * @return 对象集合
  100. * @throws SQLException
  101. */
  102. @SuppressWarnings("rawtypes")
  103. public List queryForList(String sqlMapId, Object parameterObject)
  104. throws SQLException {
  105. return getSqlMapClientTemplate()
  106. .queryForList(sqlMapId, parameterObject);
  107. }
  108. /**
  109. * 数据查询并返回指定记录集大小的一个列表
  110. * @param sqlMapId sqlMap标识
  111. * @param parameterObject 参数对象
  112. * @param skipResults - 记录位移量
  113. * @param maxResults - 记录集大小
  114. * @return List 对象List
  115. * @throws SQLException
  116. */
  117. @SuppressWarnings("rawtypes")
  118. public List queryForList(String sqlMapId, Object parameterObject,
  119. int skipResults, int maxResults) throws SQLException {
  120. return getSqlMapClientTemplate().queryForList(sqlMapId,
  121. parameterObject, skipResults, maxResults);
  122. }
  123. /**
  124. * 数据查询并返回指定指keyProperty的一个Map对象
  125. * @param sqlMapId sqlMap标识
  126. * @param parameterObject 参数对象
  127. * @param keyProperty Mapkey
  128. * @return Map<String,Object> map对象
  129. * @throws SQLException
  130. */
  131. @SuppressWarnings("rawtypes")
  132. public Map queryForMap(String sqlMapId, Object parameterObject,
  133. String keyProperty) throws SQLException {
  134. return getSqlMapClientTemplate().queryForMap(sqlMapId, parameterObject,
  135. keyProperty);
  136. }
  137. /**
  138. * 数据查询并返回指定keyProperty和valueProperty的一个Map对象
  139. * @param sqlMapId sqlMap标识
  140. * @param parameterObject 参数对象
  141. * @param keyProperty keyProperty
  142. * @param valueProperty valueProperty
  143. * @return Map对象
  144. * @throws SQLException
  145. */
  146. @SuppressWarnings("rawtypes")
  147. public Map queryForMap(String sqlMapId, Object parameterObject,
  148. String keyProperty, String valueProperty) throws SQLException {
  149. return getSqlMapClientTemplate().queryForMap(sqlMapId + ".updateUser",
  150. parameterObject, keyProperty, valueProperty);
  151. }
  152. /**
  153. * 数据查询并返回一个对象
  154. * @param sqlMapId sqlMap标识
  155. * @param parameterObject 参数对象
  156. * @return 插入对象
  157. * @throws SQLException
  158. */
  159. public Object queryForObject(String sqlMapId, Object parameterObject)
  160. throws SQLException {
  161. return getSqlMapClientTemplate().queryForObject(sqlMapId,
  162. parameterObject);
  163. }
  164. /**
  165. * 数据查询并返回指定的对象
  166. * @param sqlMapId sqlMap标识
  167. * @param parameterObject 参数对象
  168. * @param resultObject 指定的对象
  169. * @return 插入对象
  170. * @throws SQLException
  171. */
  172. public Object queryForObject(String sqlMapId, Object parameterObject,
  173. Object resultObject) throws SQLException {
  174. return getSqlMapClientTemplate().queryForObject(sqlMapId,
  175. parameterObject, resultObject);
  176. }
  177. /**
  178. * 单表操作:根据条件动态查询记录集
  179. * @param nameSpace sql命名空间
  180. * @param example example
  181. * @return List
  182. * @throws SQLException
  183. */
  184. @SuppressWarnings("rawtypes")
  185. public List selectByExample(String nameSpace, Object example)
  186. throws SQLException {
  187. List list = getSqlMapClientTemplate().queryForList(
  188. nameSpace + ".abatorgenerated_selectByExample", example);
  189. return list;
  190. }
  191. /**
  192. * 单表操作:根据主键查询记录集
  193. * @param nameSpace sql命名空间
  194. * @param id PrimaryKey
  195. * @return Object
  196. * @throws SQLException
  197. */
  198. public Object selectByPrimaryKey(String nameSpace, Long id)
  199. throws SQLException {
  200. Object record = getSqlMapClientTemplate().queryForObject(
  201. nameSpace + ".abatorgenerated_selectByPrimaryKey", id);
  202. return record;
  203. }
  204. /**
  205. * 数据更新
  206. * @param sqlMapId sqlMap标识
  207. * @param parameterObject 参数对象
  208. * @return 插入对象
  209. * @throws SQLException
  210. */
  211. public int update(String sqlMapId, Object parameterObject)
  212. throws SQLException {
  213. return getSqlMapClientTemplate().update(sqlMapId, parameterObject);
  214. }
  215. /**
  216. * 单表操作:根据主键更新记录集
  217. * @param nameSpace sql命名空间
  218. * @param record 对象实体
  219. * @return 更新返回代码值
  220. * @throws SQLException
  221. */
  222. public int updateByPrimaryKey(String nameSpace, Object record)
  223. throws SQLException {
  224. int rows = getSqlMapClientTemplate().update(
  225. nameSpace + ".abatorgenerated_updateByPrimaryKey", record);
  226. return rows;
  227. }
  228. /**
  229. * 单表操作:根据主键更新记录集
  230. * @param nameSpace sql命名空间
  231. * @param record 对象实体
  232. * @return 更新返回代码值
  233. * @throws SQLException
  234. */
  235. public int updateByPrimaryKeySelective(String nameSpace, Object record)
  236. throws SQLException {
  237. int rows = getSqlMapClientTemplate().update(
  238. nameSpace + ".abatorgenerated_updateByPrimaryKeySelective", record);
  239. return rows;
  240. }
  241. }