1 /***
2 * @(#)IbatisService.java
3 *
4 * JFoxSOAF, Service-Oriented Application Framework
5 *
6 * Copyright(c) JFoxSOAF Team
7 *
8 * Licensed under the GNU LGPL, Version 2.1 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.gnu.org/copyleft/lesser.html
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 * For more information, please visit:
21 * http://www.jfox.cn/confluence/display/JFoxSOAF/Home
22 * http://www.huihoo.org/jfox/jfoxsoaf
23 */
24
25 package org.huihoo.jfox.soaf.services.persistence;
26
27 import java.sql.SQLException;
28 import java.util.List;
29 import java.util.Map;
30
31 import org.huihoo.jfox.soaf.exception.DAOException;
32
33 import com.ibatis.common.util.PaginatedList;
34 import com.ibatis.dao.client.DaoManager;
35 import com.ibatis.sqlmap.client.SqlMapException;
36 import com.ibatis.sqlmap.client.SqlMapSession;
37 import com.ibatis.sqlmap.client.event.RowHandler;
38
39 /***
40 * <p>
41 * Ibatis persistence service wrapper.
42 * </p>
43 *
44 * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
45 * @version $Revision: 1.6 $ $Date: 2005/05/22 06:50:29 $
46 * @version Revision: 1.0
47 */
48
49 public interface IbatisService {
50
51 /***
52 * Get DaoManager.
53 *
54 * @return
55 * @throws SqlMapException
56 */
57 public DaoManager getDaoManager() throws SqlMapException;
58
59 /***
60 * Returns a single threaded SqlMapSession implementation for use by one
61 * user.
62 *
63 * @see org.huihoo.jfox.soaf.services.persistence.IbatisService#openSession()
64 */
65 public SqlMapSession openSession() throws SQLException;
66
67 /***
68 * Commits the currently started transaction.
69 *
70 * @throws SQLException
71 */
72 public void commit() throws SQLException;
73
74 /***
75 * Close session.
76 */
77 public void closeSession() throws SQLException;
78
79 /***
80 * Executes a mapped SQL INSERT statement. Insert is a bit different from
81 * other update methods, as it provides facilities for returning the primary
82 * key of the newly inserted row (rather than the effected rows). This
83 * functionality is of course optional.
84 *
85 * @param id
86 * @param parameterObject
87 * @return The primary key of the newly inserted row. This might be
88 * automatically generated by the RDBMS, or selected from a sequence
89 * table or other source.
90 * @throws SQLException
91 * @throws DAOException
92 */
93 public Object insert(String id, Object parameterObject)
94 throws SQLException, DAOException;
95
96 /***
97 * Executes a mapped SQL UPDATE statement. Update can also be used for any
98 * other update statement type, such as inserts and deletes. Update returns
99 * the number of rows effected.
100 *
101 * @param id
102 * @param parameterObject
103 * @return The number of rows effected.
104 * @throws SQLException
105 * @throws DAOException
106 */
107 public int update(String id, Object parameterObject) throws SQLException,
108 DAOException;
109
110 /***
111 * Executes a mapped SQL DELETE statement. Delete returns the number of rows
112 * effected.
113 *
114 * @param id
115 * @param parameterObject
116 * @return The number of rows effected
117 * @throws SQLException
118 * @throws DAOException
119 */
120 public int delete(String id, Object parameterObject) throws SQLException,
121 DAOException;
122
123 /***
124 * Executes a mapped SQL SELECT statement that returns data to populate a
125 * single object instance. <p/>The parameter object is generally used to
126 * supply the input data for the WHERE clause parameter(s) of the SELECT
127 * statement.
128 *
129 * @param id
130 * The name of the statement to execute.
131 * @param parameterObject
132 * The parameter object (e.g. JavaBean, Map, XML etc.).
133 * @return The single result object populated with the result set data.
134 */
135 public Object queryForObject(String id, Object parameterObject)
136 throws SQLException, DAOException;
137
138 /***
139 * Executes a mapped SQL SELECT statement that returns data to populate the
140 * supplied result object.
141 *
142 * @param id
143 * @param parameterObject
144 * @param resultObject
145 * @return The single result object as supplied by the resultObject
146 * parameter, populated with the result set data.
147 * @throws SQLException
148 * @throws DAOException
149 */
150 public Object queryForObject(String id, Object parameterObject,
151 Object resultObject) throws SQLException, DAOException;
152
153 /***
154 * Executes a mapped SQL SELECT statement that returns data to populate a
155 * number of result objects.
156 *
157 * @param id
158 * @param parameterObject
159 * @return A List of result objects.
160 * @throws SQLException
161 * @throws DAOException
162 */
163 public List queryForList(String id, Object parameterObject)
164 throws SQLException, DAOException;
165
166 /***
167 * Executes a mapped SQL SELECT statement that returns data to populate a
168 * number of result objects within a certain range.
169 *
170 * @param id
171 * @param parameterObject
172 * @param skip
173 * @param max
174 * @return A List of result objects.
175 * @throws SQLException
176 * @throws DAOException
177 */
178 public List queryForList(String id, Object parameterObject, int skip,
179 int max) throws SQLException, DAOException;
180
181 /***
182 * Executes a mapped SQL SELECT statement that returns a number of result
183 * objects that will be handled one at a time by a RowHandler.
184 *
185 * @param id
186 * @param parameterObject
187 * @param rowHandler
188 * @throws SQLException
189 * @throws DAOException
190 */
191 public void queryWithRowHandler(String id, Object parameterObject,
192 RowHandler rowHandler) throws SQLException, DAOException;
193
194 /***
195 * Executes a mapped SQL SELECT statement that returns data to populate a
196 * number of result objects a page at a time.
197 *
198 * @param id
199 * @param parameterObject
200 * @param pageSize
201 * @return A PaginatedList of result objects.
202 * @throws SQLException
203 * @throws DAOException
204 */
205 public PaginatedList queryForPaginatedList(String id,
206 Object parameterObject, int pageSize) throws SQLException,
207 DAOException;
208
209 /***
210 * Executes a mapped SQL SELECT statement that returns data to populate a
211 * number of result objects that will be keyed into a Map.
212 *
213 * @param id
214 * @param parameterObject
215 * @param keyProp
216 * @return A Map keyed by keyProp with values being the result object
217 * instance.
218 * @throws SQLException
219 * @throws DAOException
220 */
221 public Map queryForMap(String id, Object parameterObject, String keyProp)
222 throws SQLException, DAOException;
223
224 /***
225 * Executes a mapped SQL SELECT statement that returns data to populate a
226 * number of result objects from which one property will be keyed into a
227 * Map.
228 *
229 * @param id
230 * @param parameterObject
231 * @param keyProp
232 * @param valueProp
233 * @return A Map keyed by keyProp with values of valueProp.
234 * @throws SQLException
235 * @throws DAOException
236 */
237 public Map queryForMap(String id, Object parameterObject, String keyProp,
238 String valueProp) throws SQLException, DAOException;
239
240 }