/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs

https://github.com/wangsying/SpiderJobs · C# · 322 lines · 84 code · 50 blank · 188 comment · 0 complexity · 61f89f9afcd24eed358007100f6bdc7c MD5 · raw file

  1. #region Apache Notice
  2. /*****************************************************************************
  3. * $Header: $
  4. * $Revision: 476843 $
  5. * $Date: 2006-11-19 17:07:45 +0100 (dim., 19 nov. 2006) $
  6. *
  7. * iBATIS.NET Data Mapper
  8. * Copyright (C) 2004 - Gilles Bayon
  9. *
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. *
  23. ********************************************************************************/
  24. #endregion
  25. #region Imports
  26. using System.Collections;
  27. #if dotnet2
  28. using System.Collections.Generic;
  29. #endif
  30. using IBatisNet.DataMapper.Commands;
  31. using IBatisNet.DataMapper.Configuration.Statements;
  32. #endregion
  33. namespace IBatisNet.DataMapper.MappedStatements
  34. {
  35. /// <summary>
  36. ///
  37. /// </summary>
  38. public delegate void ExecuteEventHandler(object sender, ExecuteEventArgs e);
  39. /// <summary>
  40. /// Summary description for IMappedStatement.
  41. /// </summary>
  42. public interface IMappedStatement
  43. {
  44. #region Event
  45. /// <summary>
  46. /// Event launch on exceute query
  47. /// </summary>
  48. event ExecuteEventHandler Execute;
  49. #endregion
  50. #region Properties
  51. /// <summary>
  52. /// The IPreparedCommand to use
  53. /// </summary>
  54. IPreparedCommand PreparedCommand
  55. {
  56. get;
  57. }
  58. /// <summary>
  59. /// Name used to identify the MappedStatement amongst the others.
  60. /// This the name of the SQL statment by default.
  61. /// </summary>
  62. string Id
  63. {
  64. get;
  65. }
  66. /// <summary>
  67. /// The SQL statment used by this MappedStatement
  68. /// </summary>
  69. IStatement Statement
  70. {
  71. get;
  72. }
  73. /// <summary>
  74. /// The SqlMap used by this MappedStatement
  75. /// </summary>
  76. ISqlMapper SqlMap
  77. {
  78. get;
  79. }
  80. #endregion
  81. #region ExecuteQueryForMap
  82. /// <summary>
  83. /// Executes the SQL and retuns all rows selected in a map that is keyed on the property named
  84. /// in the keyProperty parameter. The value at each key will be the value of the property specified
  85. /// in the valueProperty parameter. If valueProperty is null, the entire result object will be entered.
  86. /// </summary>
  87. /// <param name="session">The session used to execute the statement</param>
  88. /// <param name="parameterObject">The object used to set the parameters in the SQL. </param>
  89. /// <param name="keyProperty">The property of the result object to be used as the key. </param>
  90. /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
  91. /// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
  92. ///<exception cref="IBatisNet.DataMapper.Exceptions.DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
  93. IDictionary ExecuteQueryForMap( ISqlMapSession session, object parameterObject, string keyProperty, string valueProperty );
  94. #endregion
  95. #region ExecuteQueryForMap .NET 2.0
  96. #if dotnet2
  97. /// <summary>
  98. /// Executes the SQL and retuns all rows selected in a map that is keyed on the property named
  99. /// in the keyProperty parameter. The value at each key will be the value of the property specified
  100. /// in the valueProperty parameter. If valueProperty is null, the entire result object will be entered.
  101. /// </summary>
  102. /// <param name="session">The session used to execute the statement</param>
  103. /// <param name="parameterObject">The object used to set the parameters in the SQL. </param>
  104. /// <param name="keyProperty">The property of the result object to be used as the key. </param>
  105. /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
  106. /// <returns>A IDictionary of object containing the rows keyed by keyProperty.</returns>
  107. ///<exception cref="IBatisNet.DataMapper.Exceptions.DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
  108. IDictionary<K, V> ExecuteQueryForDictionary<K, V>(ISqlMapSession session, object parameterObject, string keyProperty, string valueProperty);
  109. /// <summary>
  110. /// Runs a query with a custom object that gets a chance
  111. /// to deal with each row as it is processed.
  112. /// </summary>
  113. /// <param name="session">The session used to execute the statement</param>
  114. /// <param name="parameterObject">The object used to set the parameters in the SQL. </param>
  115. /// <param name="keyProperty">The property of the result object to be used as the key. </param>
  116. /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
  117. /// <param name="rowDelegate">A delegate called once per row in the QueryForDictionary method</param>
  118. /// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
  119. /// <exception cref="IBatisNet.DataMapper.Exceptions.DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
  120. IDictionary<K, V> ExecuteQueryForDictionary<K, V>(ISqlMapSession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate<K, V> rowDelegate);
  121. #endif
  122. #endregion
  123. #region ExecuteUpdate
  124. /// <summary>
  125. /// Execute an update statement. Also used for delete statement.
  126. /// Return the number of row effected.
  127. /// </summary>
  128. /// <param name="session">The session used to execute the statement.</param>
  129. /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
  130. /// <returns>The number of row effected.</returns>
  131. int ExecuteUpdate(ISqlMapSession session, object parameterObject );
  132. #endregion
  133. #region ExecuteInsert
  134. /// <summary>
  135. /// Execute an insert statement. Fill the parameter object with
  136. /// the ouput parameters if any, also could return the insert generated key
  137. /// </summary>
  138. /// <param name="session">The session</param>
  139. /// <param name="parameterObject">The parameter object used to fill the statement.</param>
  140. /// <returns>Can return the insert generated key.</returns>
  141. object ExecuteInsert(ISqlMapSession session, object parameterObject );
  142. #endregion
  143. #region ExecuteQueryForList
  144. /// <summary>
  145. /// Executes the SQL and and fill a strongly typed collection.
  146. /// </summary>
  147. /// <param name="session">The session used to execute the statement.</param>
  148. /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
  149. /// <param name="resultObject">A strongly typed collection of result objects.</param>
  150. void ExecuteQueryForList(ISqlMapSession session, object parameterObject, IList resultObject );
  151. /// <summary>
  152. /// Executes the SQL and retuns a subset of the rows selected.
  153. /// </summary>
  154. /// <param name="session">The session used to execute the statement.</param>
  155. /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
  156. /// <param name="skipResults">The number of rows to skip over.</param>
  157. /// <param name="maxResults">The maximum number of rows to return.</param>
  158. /// <returns>A List of result objects.</returns>
  159. IList ExecuteQueryForList( ISqlMapSession session, object parameterObject, int skipResults, int maxResults );
  160. /// <summary>
  161. /// Executes the SQL and retuns all rows selected. This is exactly the same as
  162. /// calling ExecuteQueryForList(session, parameterObject, NO_SKIPPED_RESULTS, NO_MAXIMUM_RESULTS).
  163. /// </summary>
  164. /// <param name="session">The session used to execute the statement.</param>
  165. /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
  166. /// <returns>A List of result objects.</returns>
  167. IList ExecuteQueryForList( ISqlMapSession session, object parameterObject );
  168. #endregion
  169. #region ExecuteQueryForList .NET 2.0
  170. #if dotnet2
  171. /// <summary>
  172. /// Executes the SQL and and fill a strongly typed collection.
  173. /// </summary>
  174. /// <param name="session">The session used to execute the statement.</param>
  175. /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
  176. /// <param name="resultObject">A strongly typed collection of result objects.</param>
  177. void ExecuteQueryForList<T>(ISqlMapSession session, object parameterObject, IList<T> resultObject);
  178. /// <summary>
  179. /// Executes the SQL and retuns a subset of the rows selected.
  180. /// </summary>
  181. /// <param name="session">The session used to execute the statement.</param>
  182. /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
  183. /// <param name="skipResults">The number of rows to skip over.</param>
  184. /// <param name="maxResults">The maximum number of rows to return.</param>
  185. /// <returns>A List of result objects.</returns>
  186. IList<T> ExecuteQueryForList<T>(ISqlMapSession session, object parameterObject, int skipResults, int maxResults);
  187. /// <summary>
  188. /// Executes the SQL and retuns all rows selected. This is exactly the same as
  189. /// calling ExecuteQueryForList(session, parameterObject, NO_SKIPPED_RESULTS, NO_MAXIMUM_RESULTS).
  190. /// </summary>
  191. /// <param name="session">The session used to execute the statement.</param>
  192. /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
  193. /// <returns>A List of result objects.</returns>
  194. IList<T> ExecuteQueryForList<T>(ISqlMapSession session, object parameterObject);
  195. #endif
  196. #endregion
  197. #region ExecuteForObject
  198. /// <summary>
  199. /// Executes an SQL statement that returns a single row as an Object.
  200. /// </summary>
  201. /// <param name="session">The session used to execute the statement.</param>
  202. /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
  203. /// <returns>The object</returns>
  204. object ExecuteQueryForObject( ISqlMapSession session, object parameterObject );
  205. /// <summary>
  206. /// Executes an SQL statement that returns a single row as an Object of the type of
  207. /// the resultObject passed in as a parameter.
  208. /// </summary>
  209. /// <param name="session">The session used to execute the statement.</param>
  210. /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
  211. /// <param name="resultObject">The result object.</param>
  212. /// <returns>The object</returns>
  213. object ExecuteQueryForObject( ISqlMapSession session, object parameterObject, object resultObject );
  214. #endregion
  215. #region ExecuteForObject .NET 2.0
  216. #if dotnet2
  217. /// <summary>
  218. /// Executes an SQL statement that returns a single row as an Object.
  219. /// </summary>
  220. /// <param name="session">The session used to execute the statement.</param>
  221. /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
  222. /// <returns>The object</returns>
  223. T ExecuteQueryForObject<T>(ISqlMapSession session, object parameterObject);
  224. /// <summary>
  225. /// Executes an SQL statement that returns a single row as an Object of the type of
  226. /// the resultObject passed in as a parameter.
  227. /// </summary>
  228. /// <param name="session">The session used to execute the statement.</param>
  229. /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
  230. /// <param name="resultObject">The result object.</param>
  231. /// <returns>The object</returns>
  232. T ExecuteQueryForObject<T>(ISqlMapSession session, object parameterObject, T resultObject);
  233. #endif
  234. #endregion
  235. #region Delegate
  236. /// <summary>
  237. /// Runs a query with a custom object that gets a chance
  238. /// to deal with each row as it is processed.
  239. /// </summary>
  240. /// <param name="session">The session used to execute the statement.</param>
  241. /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
  242. /// <param name="rowDelegate"></param>param>
  243. /// <returns></returns>
  244. IList ExecuteQueryForRowDelegate( ISqlMapSession session, object parameterObject, RowDelegate rowDelegate );
  245. /// <summary>
  246. /// Runs a query with a custom object that gets a chance
  247. /// to deal with each row as it is processed.
  248. /// </summary>
  249. /// <param name="session">The session used to execute the statement</param>
  250. /// <param name="parameterObject">The object used to set the parameters in the SQL. </param>
  251. /// <param name="keyProperty">The property of the result object to be used as the key. </param>
  252. /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
  253. /// <param name="rowDelegate"></param>
  254. /// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
  255. /// <exception cref="IBatisNet.DataMapper.Exceptions.DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
  256. IDictionary ExecuteQueryForMapWithRowDelegate( ISqlMapSession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate rowDelegate );
  257. #endregion
  258. #region ExecuteQueryForRowDelegate .NET 2.0
  259. #if dotnet2
  260. /// <summary>
  261. /// Runs a query with a custom object that gets a chance
  262. /// to deal with each row as it is processed.
  263. /// </summary>
  264. /// <param name="session">The session used to execute the statement.</param>
  265. /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
  266. /// <param name="rowDelegate"></param>param>
  267. /// <returns></returns>
  268. IList<T> ExecuteQueryForRowDelegate<T>(ISqlMapSession session, object parameterObject, RowDelegate<T> rowDelegate);
  269. #endif
  270. #endregion
  271. }
  272. }