该问题,我百度了下,根本没发现什么有价值的文章;还是看源代码(详见最后附录)中的注释,最有效了!
insert,返回值是:新插入行的主键(primary key);需要包含<selectKey>语句,才会返回主键,否则返回值为null。
update/delete,返回值是:更新或删除的行数;无需指明resultClass;但如果有约束异常而删除失败,只能去捕捉异常。
queryForObject,返回的是:一个实例对象或null;需要包含<select>语句,并且指明resultMap;
queryForList,返回的是:实例对象的列表;需要包含<select>语句,并且指明resultMap;

我的配置文件如下(desktop_common_sqlMap.xml):

  1. <typeAlias alias="UnlockTagInfo" type="com.desktop.common.bean.UnlockTagInfo" />
  2. <resultMap class="UnlockTagInfo" id="UnlockTagInfoResult">
  3. <result column="id" property="id" jdbcType="INTEGER" />
  4. <result column="name" property="name" jdbcType="VARCHAR" />
  5. <result column="description" property="description" jdbcType="VARCHAR" />
  6. <result column="priority" property="priority" jdbcType="INTEGER" />
  7. </resultMap>
  8. <insert id="insertUnlockTagInfo" parameterClass="map">
  9. <selectKey resultClass="int" keyProperty="id">
  10. select
  11. nextval('desktop_unlock_tag_id_seq') as id
  12. </selectKey>
  13. insert into
  14. desktop_unlock_tag(id,name,description,priority)
  15. values(#id:INTEGER#,#name:VARCHAR#,#description:VARCHAR#,#priority:INTEGER#)
  16. </insert>
  17. <update id="updateUnlockTagInfo" parameterClass="map">
  18. update
  19. desktop_unlock_tag
  20. set modify_time=now(),priority=#priority:INTEGER#,
  21. name=#name:VARCHAR#,description=#description:VARCHAR#
  22. where
  23. id=#id:INTEGER#
  24. </update>
  25. <delete id="deleteUnlockTagInfo" parameterClass="int">
  26. delete from
  27. desktop_unlock_tag
  28. where id=#value:INTEGER#
  29. </delete>
  30. <select id="countUnlockTagInfo" resultClass="int">
  31. select count(*)
  32. from
  33. desktop_unlock_tag
  34. </select>
  35. <sql id="selectUnlockTagInfo">
  36. select
  37. id,name,description,priority
  38. from
  39. desktop_unlock_tag
  40. </sql>
  41. <select id="findUnlockTagInfoById" parameterClass="int"
  42. resultMap="UnlockTagInfoResult">
  43. <include refid="selectUnlockTagInfo" />
  44. where id=#id:INTEGER#
  45. </select>
  46. <select id="listUnlockTagInfo" parameterClass="map"
  47. resultMap="UnlockTagInfoResult">
  48. <include refid="selectUnlockTagInfo" />
  49. order by
  50. modify_time desc limit #size:INTEGER#
  51. offset #start:INTEGER#
  52. </select>
	<typeAlias alias="UnlockTagInfo" type="com.desktop.common.bean.UnlockTagInfo" />
<resultMap class="UnlockTagInfo" id="UnlockTagInfoResult">
<result column="id" property="id" jdbcType="INTEGER" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="description" property="description" jdbcType="VARCHAR" />
<result column="priority" property="priority" jdbcType="INTEGER" />
</resultMap>
<insert id="insertUnlockTagInfo" parameterClass="map">
<selectKey resultClass="int" keyProperty="id">
select
nextval('desktop_unlock_tag_id_seq') as id
</selectKey>
insert into
desktop_unlock_tag(id,name,description,priority)
values(#id:INTEGER#,#name:VARCHAR#,#description:VARCHAR#,#priority:INTEGER#)
</insert>
<update id="updateUnlockTagInfo" parameterClass="map">
update
desktop_unlock_tag
set modify_time=now(),priority=#priority:INTEGER#,
name=#name:VARCHAR#,description=#description:VARCHAR#
where
id=#id:INTEGER#
</update>
<delete id="deleteUnlockTagInfo" parameterClass="int">
delete from
desktop_unlock_tag
where id=#value:INTEGER#
</delete>
<select id="countUnlockTagInfo" resultClass="int">
select count(*)
from
desktop_unlock_tag
</select>
<sql id="selectUnlockTagInfo">
select
id,name,description,priority
from
desktop_unlock_tag
</sql>
<select id="findUnlockTagInfoById" parameterClass="int"
resultMap="UnlockTagInfoResult">
<include refid="selectUnlockTagInfo" />
where id=#id:INTEGER#
</select>
<select id="listUnlockTagInfo" parameterClass="map"
resultMap="UnlockTagInfoResult">
<include refid="selectUnlockTagInfo" />
order by
modify_time desc limit #size:INTEGER#
offset #start:INTEGER#
</select>

我的DAO源码如下:

  1. public class UnlockTagDaoImpl extends SqlMapClientDaoSupport implements
  2. UnlockTagDao {
  3. @Override
  4. public Integer addItem(String name, String desc, Integer priority) {
  5. SqlMapClientTemplate template = this.getSqlMapClientTemplate();
  6. Map<String, Object> args = new HashMap<String, Object>();
  7. args.put("name", name);
  8. args.put("description", desc);
  9. args.put("priority", priority);
  10. Object key = template.insert("DesktopCommon.insertUnlockTagInfo", args);
  11. return (Integer) key;
  12. }
  13. @Override
  14. public boolean updateItem(Integer id, String name, String description,
  15. Integer priority) {
  16. SqlMapClientTemplate template = this.getSqlMapClientTemplate();
  17. Map<String, Object> args = new HashMap<String, Object>();
  18. args.put("id", id);
  19. args.put("name", name);
  20. args.put("description", description);
  21. args.put("priority", priority);
  22. try {
  23. int c = template.update("DesktopCommon.updateUnlockTagInfo", args);
  24. if (c > 0) {
  25. return true;
  26. }
  27. return false;
  28. } catch (Exception e) {
  29. return false;
  30. }
  31. }
  32. @Override
  33. public boolean deleteItem(Integer id) {
  34. SqlMapClientTemplate template = this.getSqlMapClientTemplate();
  35. try {
  36. int c = template.delete("DesktopCommon.deleteUnlockTagInfo", id);
  37. if (c > 0) {
  38. return true;
  39. }
  40. return false;
  41. } catch (Exception e) {
  42. return false;
  43. }
  44. }
  45. @Override
  46. public UnlockTagInfo findItemById(Integer id) {
  47. SqlMapClientTemplate template = this.getSqlMapClientTemplate();
  48. UnlockTagInfo item = (UnlockTagInfo) template.queryForObject(
  49. "DesktopCommon.findUnlockTagInfoById", id);
  50. return item;
  51. }
  52. @Override
  53. public PagedList<UnlockTagInfo> listAll(Integer nStart, Integer nSize,
  54. boolean bCountTotal) {
  55. SqlMapClientTemplate template = this.getSqlMapClientTemplate();
  56. PagedList<UnlockTagInfo> result = new PagedList<UnlockTagInfo>();
  57. if (bCountTotal) {
  58. int total = (Integer) template
  59. .queryForObject("DesktopCommon.countUnlockTagInfo");
  60. result.setTotal(total);
  61. }
  62. Map<String, Integer> args = new HashMap<String, Integer>();
  63. args.put("start", nStart);
  64. args.put("size", nSize);
  65. @SuppressWarnings("unchecked")
  66. List<UnlockTagInfo> items = template.queryForList(
  67. "DesktopCommon.listUnlockTagInfo", args);
  68. result.setData(items);
  69. return result;
  70. }
  71. }
public class UnlockTagDaoImpl extends SqlMapClientDaoSupport implements
UnlockTagDao {
@Override
public Integer addItem(String name, String desc, Integer priority) {
SqlMapClientTemplate template = this.getSqlMapClientTemplate();
Map<String, Object> args = new HashMap<String, Object>();
args.put("name", name);
args.put("description", desc);
args.put("priority", priority);
Object key = template.insert("DesktopCommon.insertUnlockTagInfo", args);
return (Integer) key;
}
@Override
public boolean updateItem(Integer id, String name, String description,
Integer priority) {
SqlMapClientTemplate template = this.getSqlMapClientTemplate();
Map&lt;String, Object&gt; args = new HashMap&lt;String, Object&gt;();
args.put("id", id);
args.put("name", name);
args.put("description", description);
args.put("priority", priority);
try {
int c = template.update("DesktopCommon.updateUnlockTagInfo", args);
if (c &gt; 0) {
return true;
}
return false;
} catch (Exception e) {
return false;
}
} @Override
public boolean deleteItem(Integer id) {
SqlMapClientTemplate template = this.getSqlMapClientTemplate();
try {
int c = template.delete("DesktopCommon.deleteUnlockTagInfo", id);
if (c &gt; 0) {
return true;
}
return false;
} catch (Exception e) {
return false;
}
} @Override
public UnlockTagInfo findItemById(Integer id) {
SqlMapClientTemplate template = this.getSqlMapClientTemplate();
UnlockTagInfo item = (UnlockTagInfo) template.queryForObject(
"DesktopCommon.findUnlockTagInfoById", id);
return item;
} @Override
public PagedList&lt;UnlockTagInfo&gt; listAll(Integer nStart, Integer nSize,
boolean bCountTotal) {
SqlMapClientTemplate template = this.getSqlMapClientTemplate();
PagedList&lt;UnlockTagInfo&gt; result = new PagedList&lt;UnlockTagInfo&gt;();
if (bCountTotal) {
int total = (Integer) template
.queryForObject("DesktopCommon.countUnlockTagInfo");
result.setTotal(total);
}
Map&lt;String, Integer&gt; args = new HashMap&lt;String, Integer&gt;();
args.put("start", nStart);
args.put("size", nSize);
@SuppressWarnings("unchecked")
List&lt;UnlockTagInfo&gt; items = template.queryForList(
"DesktopCommon.listUnlockTagInfo", args);
result.setData(items);
return result;
}

}

关于ibatis的接口,参见其源码(com\ibatis\sqlmap\client\SqlMapExecutor.java):

  1. /*
  2. *  Copyright 2004 Clinton Begin
  3. *
  4. *  Licensed under the Apache License, Version 2.0 (the "License");
  5. *  you may not use this file except in compliance with the License.
  6. *  You may obtain a copy of the License at
  7. *
  8. *      http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. *  Unless required by applicable law or agreed to in writing, software
  11. *  distributed under the License is distributed on an "AS IS" BASIS,
  12. *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. *  See the License for the specific language governing permissions and
  14. *  limitations under the License.
  15. */
  16. package com.ibatis.sqlmap.client;
  17. import com.ibatis.common.util.PaginatedList;
  18. import com.ibatis.sqlmap.client.event.RowHandler;
  19. import com.ibatis.sqlmap.engine.execution.BatchException;
  20. import java.sql.SQLException;
  21. import java.util.List;
  22. import java.util.Map;
  23. /**
  24. * This interface declares all methods involved with executing statements
  25. * and batches for an SQL Map.
  26. *
  27. * @see SqlMapSession
  28. * @see SqlMapClient
  29. */
  30. public interface SqlMapExecutor {
  31. /**
  32. * Executes a mapped SQL INSERT statement.
  33. * Insert is a bit different from other update methods, as it
  34. * provides facilities for returning the primary key of the
  35. * newly inserted row (rather than the effected rows).  This
  36. * functionality is of course optional.
  37. * <p/>
  38. * The parameter object is generally used to supply the input
  39. * data for the INSERT values.
  40. *
  41. * @param id              The name of the statement to execute.
  42. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  43. * @return The primary key of the newly inserted row.  This might be automatically
  44. *         generated by the RDBMS, or selected from a sequence table or other source.
  45. * @throws java.sql.SQLException If an error occurs.
  46. */
  47. Object insert(String id, Object parameterObject) throws SQLException;
  48. /**
  49. * Executes a mapped SQL INSERT statement.
  50. * Insert is a bit different from other update methods, as it
  51. * provides facilities for returning the primary key of the
  52. * newly inserted row (rather than the effected rows).  This
  53. * functionality is of course optional.
  54. * <p/>
  55. * This overload assumes no parameter is needed.
  56. *
  57. * @param id              The name of the statement to execute.
  58. * @return The primary key of the newly inserted row.  This might be automatically
  59. *         generated by the RDBMS, or selected from a sequence table or other source.
  60. * @throws java.sql.SQLException If an error occurs.
  61. */
  62. Object insert(String id) throws SQLException;
  63. /**
  64. * Executes a mapped SQL UPDATE statement.
  65. * Update can also be used for any other update statement type,
  66. * such as inserts and deletes.  Update returns the number of
  67. * rows effected.
  68. * <p/>
  69. * The parameter object is generally used to supply the input
  70. * data for the UPDATE values as well as the WHERE clause parameter(s).
  71. *
  72. * @param id              The name of the statement to execute.
  73. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  74. * @return The number of rows effected.
  75. * @throws java.sql.SQLException If an error occurs.
  76. */
  77. int update(String id, Object parameterObject) throws SQLException;
  78. /**
  79. * Executes a mapped SQL UPDATE statement.
  80. * Update can also be used for any other update statement type,
  81. * such as inserts and deletes.  Update returns the number of
  82. * rows effected.
  83. * <p/>
  84. * This overload assumes no parameter is needed.
  85. *
  86. * @param id              The name of the statement to execute.
  87. * @return The number of rows effected.
  88. * @throws java.sql.SQLException If an error occurs.
  89. */
  90. int update(String id) throws SQLException;
  91. /**
  92. * Executes a mapped SQL DELETE statement.
  93. * Delete returns the number of rows effected.
  94. * <p/>
  95. * The parameter object is generally used to supply the input
  96. * data for the WHERE clause parameter(s) of the DELETE statement.
  97. *
  98. * @param id              The name of the statement to execute.
  99. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  100. * @return The number of rows effected.
  101. * @throws java.sql.SQLException If an error occurs.
  102. */
  103. int delete(String id, Object parameterObject) throws SQLException;
  104. /**
  105. * Executes a mapped SQL DELETE statement.
  106. * Delete returns the number of rows effected.
  107. * <p/>
  108. * This overload assumes no parameter is needed.
  109. *
  110. * @param id              The name of the statement to execute.
  111. * @return The number of rows effected.
  112. * @throws java.sql.SQLException If an error occurs.
  113. */
  114. int delete(String id) throws SQLException;
  115. /**
  116. * Executes a mapped SQL SELECT statement that returns data to populate
  117. * a single object instance.
  118. * <p/>
  119. * The parameter object is generally used to supply the input
  120. * data for the WHERE clause parameter(s) of the SELECT statement.
  121. *
  122. * @param id              The name of the statement to execute.
  123. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  124. * @return The single result object populated with the result set data,
  125. *         or null if no result was found
  126. * @throws java.sql.SQLException If more than one result was found, or if any other error occurs.
  127. */
  128. Object queryForObject(String id, Object parameterObject) throws SQLException;
  129. /**
  130. * Executes a mapped SQL SELECT statement that returns data to populate
  131. * a single object instance.
  132. * <p/>
  133. * This overload assumes no parameter is needed.
  134. *
  135. * @param id              The name of the statement to execute.
  136. * @return The single result object populated with the result set data,
  137. *         or null if no result was found
  138. * @throws java.sql.SQLException If more than one result was found, or if any other error occurs.
  139. */
  140. Object queryForObject(String id) throws SQLException;
  141. /**
  142. * Executes a mapped SQL SELECT statement that returns data to populate
  143. * the supplied result object.
  144. * <p/>
  145. * The parameter object is generally used to supply the input
  146. * data for the WHERE clause parameter(s) of the SELECT statement.
  147. *
  148. * @param id              The name of the statement to execute.
  149. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  150. * @param resultObject    The result object instance that should be populated with result data.
  151. * @return The single result object as supplied by the resultObject parameter, populated with the result set data,
  152. *         or null if no result was found
  153. * @throws java.sql.SQLException If more than one result was found, or if any other error occurs.
  154. */
  155. Object queryForObject(String id, Object parameterObject, Object resultObject) throws SQLException;
  156. /**
  157. * Executes a mapped SQL SELECT statement that returns data to populate
  158. * a number of result objects.
  159. * <p/>
  160. * The parameter object is generally used to supply the input
  161. * data for the WHERE clause parameter(s) of the SELECT statement.
  162. *
  163. * @param id              The name of the statement to execute.
  164. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  165. * @return A List of result objects.
  166. * @throws java.sql.SQLException If an error occurs.
  167. */
  168. List queryForList(String id, Object parameterObject) throws SQLException;
  169. /**
  170. * Executes a mapped SQL SELECT statement that returns data to populate
  171. * a number of result objects.
  172. * <p/>
  173. * This overload assumes no parameter is needed.
  174. *
  175. * @param id              The name of the statement to execute.
  176. * @return A List of result objects.
  177. * @throws java.sql.SQLException If an error occurs.
  178. */
  179. List queryForList(String id) throws SQLException;
  180. /**
  181. * Executes a mapped SQL SELECT statement that returns data to populate
  182. * a number of result objects within a certain range.
  183. * <p/>
  184. * The parameter object is generally used to supply the input
  185. * data for the WHERE clause parameter(s) of the SELECT statement.
  186. *
  187. * @param id              The name of the statement to execute.
  188. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  189. * @param skip            The number of results to ignore.
  190. * @param max             The maximum number of results to return.
  191. * @return A List of result objects.
  192. * @throws java.sql.SQLException If an error occurs.
  193. */
  194. List queryForList(String id, Object parameterObject, int skip, int max) throws SQLException;
  195. /**
  196. * Executes a mapped SQL SELECT statement that returns data to populate
  197. * a number of result objects within a certain range.
  198. * <p/>
  199. * This overload assumes no parameter is needed.
  200. *
  201. * @param id              The name of the statement to execute.
  202. * @param skip            The number of results to ignore.
  203. * @param max             The maximum number of results to return.
  204. * @return A List of result objects.
  205. * @throws java.sql.SQLException If an error occurs.
  206. */
  207. List queryForList(String id, int skip, int max) throws SQLException;
  208. /**
  209. * Executes a mapped SQL SELECT statement that returns a number of
  210. * result objects that will be handled one at a time by a
  211. * RowHandler.
  212. * <p/>
  213. * This is generally a good approach to take when dealing with large sets
  214. * of records (i.e. hundreds, thousands...) that need to be processed without
  215. * eating up all of the system resources.
  216. * <p/>
  217. * The parameter object is generally used to supply the input
  218. * data for the WHERE clause parameter(s) of the SELECT statement.
  219. *
  220. * @param id              The name of the statement to execute.
  221. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  222. * @param rowHandler      A RowHandler instance
  223. * @throws java.sql.SQLException If an error occurs.
  224. */
  225. void queryWithRowHandler(String id, Object parameterObject, RowHandler rowHandler) throws SQLException;
  226. /**
  227. * Executes a mapped SQL SELECT statement that returns a number of
  228. * result objects that will be handled one at a time by a
  229. * RowHandler.
  230. * <p/>
  231. * This is generally a good approach to take when dealing with large sets
  232. * of records (i.e. hundreds, thousands...) that need to be processed without
  233. * eating up all of the system resources.
  234. * <p/>
  235. * This overload assumes no parameter is needed.
  236. *
  237. * @param id              The name of the statement to execute.
  238. * @param rowHandler      A RowHandler instance
  239. * @throws java.sql.SQLException If an error occurs.
  240. */
  241. void queryWithRowHandler(String id, RowHandler rowHandler) throws SQLException;
  242. /**
  243. * Executes a mapped SQL SELECT statement that returns data to populate
  244. * a number of result objects a page at a time.
  245. * <p/>
  246. * The parameter object is generally used to supply the input
  247. * data for the WHERE clause parameter(s) of the SELECT statement.
  248. *
  249. * @param id              The name of the statement to execute.
  250. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  251. * @param pageSize        The maximum number of result objects each page can hold.
  252. * @return A PaginatedList of result objects.
  253. * @throws java.sql.SQLException If an error occurs.
  254. * @deprecated All paginated list features have been deprecated
  255. */
  256. PaginatedList queryForPaginatedList(String id, Object parameterObject, int pageSize) throws SQLException;
  257. /**
  258. * Executes a mapped SQL SELECT statement that returns data to populate
  259. * a number of result objects a page at a time.
  260. * <p/>
  261. * This overload assumes no parameter is needed.
  262. *
  263. * @param id              The name of the statement to execute.
  264. * @param pageSize        The maximum number of result objects each page can hold.
  265. * @return A PaginatedList of result objects.
  266. * @throws java.sql.SQLException If an error occurs.
  267. * @deprecated All paginated list features have been deprecated
  268. */
  269. PaginatedList queryForPaginatedList(String id, int pageSize) throws SQLException;
  270. /**
  271. * Executes a mapped SQL SELECT statement that returns data to populate
  272. * a number of result objects that will be keyed into a Map.
  273. * <p/>
  274. * The parameter object is generally used to supply the input
  275. * data for the WHERE clause parameter(s) of the SELECT statement.
  276. *
  277. * @param id              The name of the statement to execute.
  278. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  279. * @param keyProp         The property to be used as the key in the Map.
  280. * @return A Map keyed by keyProp with values being the result object instance.
  281. * @throws java.sql.SQLException If an error occurs.
  282. */
  283. Map queryForMap(String id, Object parameterObject, String keyProp) throws SQLException;
  284. /**
  285. * Executes a mapped SQL SELECT statement that returns data to populate
  286. * a number of result objects from which one property will be keyed into a Map.
  287. * <p/>
  288. * The parameter object is generally used to supply the input
  289. * data for the WHERE clause parameter(s) of the SELECT statement.
  290. *
  291. * @param id              The name of the statement to execute.
  292. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  293. * @param keyProp         The property to be used as the key in the Map.
  294. * @param valueProp       The property to be used as the value in the Map.
  295. * @return A Map keyed by keyProp with values of valueProp.
  296. * @throws java.sql.SQLException If an error occurs.
  297. */
  298. Map queryForMap(String id, Object parameterObject, String keyProp, String valueProp) throws SQLException;
  299. /**
  300. * Starts a batch in which update statements will be cached before being sent to
  301. * the database all at once. This can improve overall performance of updates update
  302. * when dealing with numerous updates (e.g. inserting 1:M related data).
  303. *
  304. * @throws java.sql.SQLException If the batch could not be started.
  305. */
  306. void startBatch() throws SQLException;
  307. /**
  308. * Executes (flushes) all statements currently batched.
  309. *
  310. * @return the number of rows updated in the batch
  311. * @throws java.sql.SQLException If the batch could not be executed or if any of the statements
  312. *                               fails.
  313. */
  314. int executeBatch() throws SQLException;
  315. /**
  316. * Executes (flushes) all statements currently batched.
  317. *
  318. * @return a List of BatchResult objects.  There will be one element in the
  319. *  list for each sub-batch executed.  A sub-batch is created by adding a statement
  320. *  to the batch that does not equal the prior statement.
  321. * @throws SQLException if a database access error occurs, or the drive
  322. *   does not support batch statements
  323. * @throws BatchException if the driver throws BatchUpdateException
  324. * @see com.ibatis.sqlmap.engine.execution.BatchException
  325. */
  326. List executeBatchDetailed() throws SQLException, BatchException;
  327. }
/*
* Copyright 2004 Clinton Begin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ibatis.sqlmap.client; import com.ibatis.common.util.PaginatedList;

import com.ibatis.sqlmap.client.event.RowHandler;

import com.ibatis.sqlmap.engine.execution.BatchException; import java.sql.SQLException;

import java.util.List;

import java.util.Map; /**
  • This interface declares all methods involved with executing statements
  • and batches for an SQL Map.
  • @see SqlMapSession
  • @see SqlMapClient

    */

    public interface SqlMapExecutor {
/**
  • Executes a mapped SQL INSERT statement.
  • Insert is a bit different from other update methods, as it
  • provides facilities for returning the primary key of the
  • newly inserted row (rather than the effected rows). This
  • functionality is of course optional.
  • <p/>
  • The parameter object is generally used to supply the input
  • data for the INSERT values.
  • @param id The name of the statement to execute.
  • @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  • @return The primary key of the newly inserted row. This might be automatically
  •     generated by the RDBMS, or selected from a sequence table or other source.
  • @throws java.sql.SQLException If an error occurs.

    */

    Object insert(String id, Object parameterObject) throws SQLException;

/**

  • Executes a mapped SQL INSERT statement.
  • Insert is a bit different from other update methods, as it
  • provides facilities for returning the primary key of the
  • newly inserted row (rather than the effected rows). This
  • functionality is of course optional.
  • <p/>
  • This overload assumes no parameter is needed.
  • @param id The name of the statement to execute.
  • @return The primary key of the newly inserted row. This might be automatically
  •     generated by the RDBMS, or selected from a sequence table or other source.
  • @throws java.sql.SQLException If an error occurs.

    */

    Object insert(String id) throws SQLException;

/**

  • Executes a mapped SQL UPDATE statement.
  • Update can also be used for any other update statement type,
  • such as inserts and deletes. Update returns the number of
  • rows effected.
  • <p/>
  • The parameter object is generally used to supply the input
  • data for the UPDATE values as well as the WHERE clause parameter(s).
  • @param id The name of the statement to execute.
  • @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  • @return The number of rows effected.
  • @throws java.sql.SQLException If an error occurs.

    */

    int update(String id, Object parameterObject) throws SQLException;

/**

  • Executes a mapped SQL UPDATE statement.
  • Update can also be used for any other update statement type,
  • such as inserts and deletes. Update returns the number of
  • rows effected.
  • <p/>
  • This overload assumes no parameter is needed.
  • @param id The name of the statement to execute.
  • @return The number of rows effected.
  • @throws java.sql.SQLException If an error occurs.

    */

    int update(String id) throws SQLException;

/**

  • Executes a mapped SQL DELETE statement.
  • Delete returns the number of rows effected.
  • <p/>
  • The parameter object is generally used to supply the input
  • data for the WHERE clause parameter(s) of the DELETE statement.
  • @param id The name of the statement to execute.
  • @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  • @return The number of rows effected.
  • @throws java.sql.SQLException If an error occurs.

    */

    int delete(String id, Object parameterObject) throws SQLException;

/**

  • Executes a mapped SQL DELETE statement.
  • Delete returns the number of rows effected.
  • <p/>
  • This overload assumes no parameter is needed.
  • @param id The name of the statement to execute.
  • @return The number of rows effected.
  • @throws java.sql.SQLException If an error occurs.

    */

    int delete(String id) throws SQLException;

/**

  • Executes a mapped SQL SELECT statement that returns data to populate
  • a single object instance.
  • <p/>
  • The parameter object is generally used to supply the input
  • data for the WHERE clause parameter(s) of the SELECT statement.
  • @param id The name of the statement to execute.
  • @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  • @return The single result object populated with the result set data,
  •     or null if no result was found
  • @throws java.sql.SQLException If more than one result was found, or if any other error occurs.

    */

    Object queryForObject(String id, Object parameterObject) throws SQLException;

/**

  • Executes a mapped SQL SELECT statement that returns data to populate
  • a single object instance.
  • <p/>
  • This overload assumes no parameter is needed.
  • @param id The name of the statement to execute.
  • @return The single result object populated with the result set data,
  •     or null if no result was found
  • @throws java.sql.SQLException If more than one result was found, or if any other error occurs.

    */

    Object queryForObject(String id) throws SQLException;

/**

  • Executes a mapped SQL SELECT statement that returns data to populate
  • the supplied result object.
  • <p/>
  • The parameter object is generally used to supply the input
  • data for the WHERE clause parameter(s) of the SELECT statement.
  • @param id The name of the statement to execute.
  • @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  • @param resultObject The result object instance that should be populated with result data.
  • @return The single result object as supplied by the resultObject parameter, populated with the result set data,
  •     or null if no result was found
  • @throws java.sql.SQLException If more than one result was found, or if any other error occurs.

    */

    Object queryForObject(String id, Object parameterObject, Object resultObject) throws SQLException;

/**

  • Executes a mapped SQL SELECT statement that returns data to populate
  • a number of result objects.
  • <p/>
  • The parameter object is generally used to supply the input
  • data for the WHERE clause parameter(s) of the SELECT statement.
  • @param id The name of the statement to execute.
  • @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  • @return A List of result objects.
  • @throws java.sql.SQLException If an error occurs.

    */

    List queryForList(String id, Object parameterObject) throws SQLException;

/**

  • Executes a mapped SQL SELECT statement that returns data to populate
  • a number of result objects.
  • <p/>
  • This overload assumes no parameter is needed.
  • @param id The name of the statement to execute.
  • @return A List of result objects.
  • @throws java.sql.SQLException If an error occurs.

    */

    List queryForList(String id) throws SQLException;

/**

  • Executes a mapped SQL SELECT statement that returns data to populate
  • a number of result objects within a certain range.
  • <p/>
  • The parameter object is generally used to supply the input
  • data for the WHERE clause parameter(s) of the SELECT statement.
  • @param id The name of the statement to execute.
  • @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  • @param skip The number of results to ignore.
  • @param max The maximum number of results to return.
  • @return A List of result objects.
  • @throws java.sql.SQLException If an error occurs.

    */

    List queryForList(String id, Object parameterObject, int skip, int max) throws SQLException;

/**

  • Executes a mapped SQL SELECT statement that returns data to populate
  • a number of result objects within a certain range.
  • <p/>
  • This overload assumes no parameter is needed.
  • @param id The name of the statement to execute.
  • @param skip The number of results to ignore.
  • @param max The maximum number of results to return.
  • @return A List of result objects.
  • @throws java.sql.SQLException If an error occurs.

    */

    List queryForList(String id, int skip, int max) throws SQLException;

/**

  • Executes a mapped SQL SELECT statement that returns a number of
  • result objects that will be handled one at a time by a
  • RowHandler.
  • <p/>
  • This is generally a good approach to take when dealing with large sets
  • of records (i.e. hundreds, thousands...) that need to be processed without
  • eating up all of the system resources.
  • <p/>
  • The parameter object is generally used to supply the input
  • data for the WHERE clause parameter(s) of the SELECT statement.
  • @param id The name of the statement to execute.
  • @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  • @param rowHandler A RowHandler instance
  • @throws java.sql.SQLException If an error occurs.

    */

    void queryWithRowHandler(String id, Object parameterObject, RowHandler rowHandler) throws SQLException;

/**

  • Executes a mapped SQL SELECT statement that returns a number of
  • result objects that will be handled one at a time by a
  • RowHandler.
  • <p/>
  • This is generally a good approach to take when dealing with large sets
  • of records (i.e. hundreds, thousands...) that need to be processed without
  • eating up all of the system resources.
  • <p/>
  • This overload assumes no parameter is needed.
  • @param id The name of the statement to execute.
  • @param rowHandler A RowHandler instance
  • @throws java.sql.SQLException If an error occurs.

    */

    void queryWithRowHandler(String id, RowHandler rowHandler) throws SQLException;

/**

  • Executes a mapped SQL SELECT statement that returns data to populate
  • a number of result objects a page at a time.
  • <p/>
  • The parameter object is generally used to supply the input
  • data for the WHERE clause parameter(s) of the SELECT statement.
  • @param id The name of the statement to execute.
  • @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  • @param pageSize The maximum number of result objects each page can hold.
  • @return A PaginatedList of result objects.
  • @throws java.sql.SQLException If an error occurs.
  • @deprecated All paginated list features have been deprecated

    */

    PaginatedList queryForPaginatedList(String id, Object parameterObject, int pageSize) throws SQLException;

/**

  • Executes a mapped SQL SELECT statement that returns data to populate
  • a number of result objects a page at a time.
  • <p/>
  • This overload assumes no parameter is needed.
  • @param id The name of the statement to execute.
  • @param pageSize The maximum number of result objects each page can hold.
  • @return A PaginatedList of result objects.
  • @throws java.sql.SQLException If an error occurs.
  • @deprecated All paginated list features have been deprecated

    */

    PaginatedList queryForPaginatedList(String id, int pageSize) throws SQLException;

/**

  • Executes a mapped SQL SELECT statement that returns data to populate
  • a number of result objects that will be keyed into a Map.
  • <p/>
  • The parameter object is generally used to supply the input
  • data for the WHERE clause parameter(s) of the SELECT statement.
  • @param id The name of the statement to execute.
  • @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  • @param keyProp The property to be used as the key in the Map.
  • @return A Map keyed by keyProp with values being the result object instance.
  • @throws java.sql.SQLException If an error occurs.

    */

    Map queryForMap(String id, Object parameterObject, String keyProp) throws SQLException;

/**

  • Executes a mapped SQL SELECT statement that returns data to populate
  • a number of result objects from which one property will be keyed into a Map.
  • <p/>
  • The parameter object is generally used to supply the input
  • data for the WHERE clause parameter(s) of the SELECT statement.
  • @param id The name of the statement to execute.
  • @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
  • @param keyProp The property to be used as the key in the Map.
  • @param valueProp The property to be used as the value in the Map.
  • @return A Map keyed by keyProp with values of valueProp.
  • @throws java.sql.SQLException If an error occurs.

    */

    Map queryForMap(String id, Object parameterObject, String keyProp, String valueProp) throws SQLException;

/**

  • Starts a batch in which update statements will be cached before being sent to
  • the database all at once. This can improve overall performance of updates update
  • when dealing with numerous updates (e.g. inserting 1:M related data).
  • @throws java.sql.SQLException If the batch could not be started.

    */

    void startBatch() throws SQLException;

/**

  • Executes (flushes) all statements currently batched.
  • @return the number of rows updated in the batch
  • @throws java.sql.SQLException If the batch could not be executed or if any of the statements
  •                           fails.

*/

int executeBatch() throws SQLException;

/**

  • Executes (flushes) all statements currently batched.
  • @return a List of BatchResult objects. There will be one element in the
  • list for each sub-batch executed. A sub-batch is created by adding a statement
  • to the batch that does not equal the prior statement.
  • @throws SQLException if a database access error occurs, or the drive
  • does not support batch statements
  • @throws BatchException if the driver throws BatchUpdateException
  • @see com.ibatis.sqlmap.engine.execution.BatchException

    */

    List executeBatchDetailed() throws SQLException, BatchException;

    }

Mybatis/Ibatis,数据库操作的返回值的更多相关文章

  1. 【转】Mybatis/Ibatis,数据库操作的返回值

    该问题,我百度了下,根本没发现什么有价值的文章:还是看源代码(详见最后附录)中的注释,最有效了!insert,返回值是:新插入行的主键(primary key):需要包含<selectKey&g ...

  2. 【转】 Mybatis/Ibatis,数据库操作的返回值

    该问题,我百度了下,根本没发现什么有价值的文章:还是看源代码(详见最后附录)中的注释,最有效了!insert,返回值是:新插入行的主键(primary key):需要包含<selectKey&g ...

  3. Mybatis数据库操作的返回值

    mybatis配置 <!-- 配置mybatis --> <bean id="sqlSessionFactory" class="org.mybatis ...

  4. MyBatis的数据库操作

    MyBatis的数据库操作 大学毕业有一段时间了,作为一名没有任何开发工作经验的大专毕业生想找到一份软件开发的工作确实很难,但我运气还算不错,应聘上一份java web开发的工作.作为一名新人,老板给 ...

  5. 【mybatis】mybatis中insert操作,返回自增id

    需求是这样的: mybatis中insert操作,返回自增id,因为这个自增id需要给后续业务用到. 原本是这样的: 将insert语句传入,正常执行insert操作,返回int永远是 0[失败] 或 ...

  6. 关于C#操作数据库ExecuteNonQuery()的返回值问题

    ) { retValue = AccessCon.ExecuteSql(sql = "update salesData set sellingPrize='" + man.Sell ...

  7. Mybatis(二)简化Mybatis实现数据库操作

    要操作的数据库: 一.与数据库对应的bean类 public class User { private String username; private String sex; private Str ...

  8. Mybatis在insert操作时返回主键

    今天在写项目的时候,遇到一个需求,就是在像数据库插入数据的时候,要保留插入数据的主键,以便后续进行级联时,可以将该主键作为另张表的外键. 但是在正常情况下我们使用插入语句返回的是int型,含义是影响该 ...

  9. MyBatis insert/delete/update 的返回值

    insert,返回值是:新插入行的主键(primary key):需要包含<selectKey>语句,才会返回主键,否则返回值为null. <insert id="inse ...

随机推荐

  1. 实体类No default constructor found 找不到默认构造函数;

    root cause org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [c ...

  2. 破逼Json,该死的Json库,操了

    jansson,就这个库,破几把玩意,本来很简单的Json,就是简单的字符串操作,ATL一个CString就能解决,QT的QSting也能解决,DELPHI的String也能解决.而这B,非把那么简单 ...

  3. 关系数据库(ch.2)

    2.1.1 关系 域 笛卡儿积 关系 candiate key 如果一组属性值可以唯一的标识一个元祖,但是他的子集不行,那么这是一个候选码 关系可以由三种类型 基本关系 查询关系 视图 为关系附加如下 ...

  4. Leetcode96.Unique Binary Search Trees不同的二叉搜索树

    给定一个整数 n,求以 1 ... n 为节点组成的二叉搜索树有多少种? 示例: 输入: 3 输出: 5 解释: 给定 n = 3, 一共有 5 种不同结构的二叉搜索树: 假设n个节点存在二叉排序树的 ...

  5. wamp httpd-vhosts.conf

    配置Apache的httpd.conf文件 Include conf/extra/httpd-vhosts.conf 修改apache的vhost文件 <VirtualHost *:> D ...

  6. Apache httpd问题汇总

    1.Apache服务器下载到本地解压到路径下:C:\ProgramFiles\Apache 后,启动时报错:serverroot must be a valid directory 解决办法:1.打开 ...

  7. C++学习笔记----3.2 C++引用在本质上是什么,它和指针到底有什么区别

    从概念上讲.指针从本质上讲就是存放变量地址的一个变量,在逻辑上是独立的,它可以被改变,包括其所指向的地址的改变和其指向的地址中所存放的数据的改变. 而引用是一个别名,它在逻辑上不是独立的,它的存在具有 ...

  8. D3D10/11中的遮挡查询的使用

    原文:D3D10/11中的遮挡查询的使用       在D3D10/11中,有D3D10_QUERY/D3D11_QUERY接口,通过QUERY接口,我们可以查询GPU的一些状态,比如GPU的时间戳信 ...

  9. 两篇论文之CNN中正交操作

    CNN的权值正交性和特征正交性,在一定程度上是和特征表达的差异性存在一定联系的. 下面两篇论文,一篇是在训练中对权值添加正交正则提高训练稳定性,一篇是对特征添加正交性的损失抑制过拟合. 第一篇:Ort ...

  10. webpack配置vue项目

    npm init 安装webpack,webpack-cli 新建src目录,在src目录下新建main.js