1 /***
2 * @(#)JdbcService.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.Connection;
28 import java.sql.SQLException;
29
30 import javax.sql.DataSource;
31
32 import org.apache.commons.dbutils.ResultSetHandler;
33 import org.huihoo.jfox.soaf.exception.DAOException;
34
35 /***
36 * <p>
37 * JDBC persistence service wrapper.
38 * </p>
39 *
40 * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
41 * @version $Revision: 1.6 $ $Date: 2005/05/22 06:50:29 $
42 * @version Revision: 1.0
43 */
44 public interface JdbcService {
45
46 /***
47 * Set DataSource
48 *
49 * @param dataSource
50 */
51 public void setDataSource(DataSource dataSource);
52
53 /***
54 * Execute an SQL SELECT query with a single replacement parameter. The
55 * caller is responsible for connection cleanup.
56 *
57 * @param conn
58 * The connection to execute the query in.
59 * @param sql
60 * The query to execute.
61 * @param param
62 * The replacement parameter.
63 * @param rsh
64 * The handler that converts the results into an object.
65 * @return The object returned by the handler.
66 * @throws SQLException
67 */
68 public Object query(Connection conn, String sql, Object param,
69 ResultSetHandler rsh) throws DAOException;
70
71 /***
72 * Execute an SQL SELECT query with replacement parameters. The caller is
73 * responsible for connection cleanup.
74 *
75 * @param conn
76 * The connection to execute the query in.
77 * @param sql
78 * The query to execute.
79 * @param params
80 * The replacement parameters.
81 * @param rsh
82 * The handler that converts the results into an object.
83 * @return The object returned by the handler.
84 * @throws SQLException
85 */
86 public Object query(Connection conn, String sql, Object[] params,
87 ResultSetHandler rsh) throws DAOException;
88
89 /***
90 * Execute an SQL SELECT query without any replacement parameters. The
91 * caller is responsible for connection cleanup.
92 *
93 * @param conn
94 * The connection to execute the query in.
95 * @param sql
96 * The query to execute.
97 * @param rsh
98 * The handler that converts the results into an object.
99 * @return The object returned by the handler.
100 * @throws SQLException
101 */
102 public Object query(Connection conn, String sql, ResultSetHandler rsh)
103 throws DAOException;
104
105 /***
106 * Executes the given SELECT SQL with a single replacement parameter. The
107 * <code>Connection</code> is retrieved from the <code>DataSource</code>.
108 *
109 * @param sql
110 * The SQL statement to execute.
111 * @param param
112 * The replacement parameter.
113 * @param rsh
114 * The handler used to create the result object from the
115 * <code>ResultSet</code>.
116 *
117 * @return An object generated by the handler.
118 * @throws DAOException
119 */
120 public Object query(String sql, Object param, ResultSetHandler rsh)
121 throws DAOException;
122
123 /***
124 * Executes the given SELECT SQL query and returns a result object. The
125 * <code>Connection</code> is retrieved from the <code>DataSource</code>.
126 *
127 * @param sql
128 * The SQL statement to execute.
129 * @param params
130 * Initialize the PreparedStatement's IN parameters with this
131 * array.
132 *
133 * @param rsh
134 * The handler used to create the result object from the
135 * <code>ResultSet</code>.
136 *
137 * @return An object generated by the handler.
138 * @throws DAOException
139 */
140 public Object query(String sql, Object[] params, ResultSetHandler rsh)
141 throws DAOException;
142
143 /***
144 * Executes the given SELECT SQL without any replacement parameters. The
145 * <code>Connection</code> is retrieved from the <code>DataSource</code>
146 * set in the constructor.
147 *
148 * @param sql
149 * The SQL statement to execute.
150 * @param rsh
151 * The handler used to create the result object from the
152 * <code>ResultSet</code>.
153 *
154 * @return An object generated by the handler.
155 * @throws DAOException
156 */
157 public Object query(String sql, ResultSetHandler rsh) throws DAOException;
158
159 /***
160 * Execute an SQL INSERT, UPDATE, or DELETE query without replacement
161 * parameters.
162 *
163 * @param conn
164 * The connection to use to run the query.
165 * @param sql
166 * The SQL to execute.
167 * @return The number of rows updated.
168 * @throws SQLException
169 */
170 public int update(Connection conn, String sql) throws DAOException;
171
172 /***
173 * Execute an SQL INSERT, UPDATE, or DELETE query with a single replacement
174 * parameter.
175 *
176 * @param conn
177 * The connection to use to run the query.
178 * @param sql
179 * The SQL to execute.
180 * @param param
181 * The replacement parameter.
182 * @return The number of rows updated.
183 * @throws SQLException
184 */
185 public int update(Connection conn, String sql, Object param)
186 throws DAOException;
187
188 /***
189 * Execute an SQL INSERT, UPDATE, or DELETE query.
190 *
191 * @param conn
192 * The connection to use to run the query.
193 * @param sql
194 * The SQL to execute.
195 * @param params
196 * The query replacement parameters.
197 * @return The number of rows updated.
198 * @throws DAOException
199 */
200 public int update(Connection conn, String sql, Object[] params)
201 throws DAOException;
202
203 /***
204 * Executes the given INSERT, UPDATE, or DELETE SQL statement without any
205 * replacement parameters. The <code>Connection</code> is retrieved from
206 * the <code>DataSource</code>.
207 *
208 * @param sql
209 * The SQL statement to execute.
210 * @throws DAOException
211 * @return The number of rows updated.
212 */
213 public int update(String sql) throws DAOException;
214
215 /***
216 * Executes the given INSERT, UPDATE, or DELETE SQL statement with a single
217 * replacement parameter. The <code>Connection</code> is retrieved from
218 * the <code>DataSource</code> set in the constructor.
219 *
220 * @param sql
221 * The SQL statement to execute.
222 * @param param
223 * The replacement parameter.
224 * @throws DAOException
225 * @return The number of rows updated.
226 */
227 public int update(String sql, Object param) throws DAOException;
228
229 /***
230 * Executes the given INSERT, UPDATE, or DELETE SQL statement. The
231 * <code>Connection</code> is retrieved from the <code>DataSource</code>
232 * set in the constructor.
233 *
234 * @param sql
235 * The SQL statement to execute.
236 * @param params
237 * Initializes the PreparedStatement's IN (i.e. '?') parameters.
238 * @throws DAOException
239 * @return The number of rows updated.
240 */
241 public int update(String sql, Object[] params) throws DAOException;
242
243 }