01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
17: package org.araneaframework.backend.list.helper;
18:
19: import java.sql.ResultSet;
20: import java.sql.SQLException;
21:
22: /**
23: * Callback interface used by JdbcTemplate's query methods.
24: * Implementations of this interface perform the actual work of extracting
25: * results, but don't need to worry about exception handling. SQLExceptions
26: * will be caught and handled correctly by the JdbcTemplate class.
27: *
28: * <p>In contrast to a ResultSetExtractor, a RowCallbackHandler object is
29: * typically stateful: It keeps the result state within the object, to be
30: * available for later inspection. See RowCountCallbackHandler's javadoc
31: * for a usage example with JdbcTemplate.
32: *
33: * <p>The ResultReader subinterface allows to make a results list available
34: * in a uniform manner. JdbcTemplate's query methods will return the results
35: * list in that case, else returning null (-> result state is solely
36: * available from RowCallbackHandler object).
37: *
38: * <p>A convenient out-of-the-box implementation of RowCallbackHandler is the
39: * RowMapperResultReader adapter which delegates row mapping to a RowMapper.
40: * Note that a RowMapper object is typically stateless and thus reusable;
41: * just the RowMapperResultReader adapter is stateful.
42: *
43: * @author Rod Johnson
44: * @see ResultReader
45: */
46: public interface RowCallbackHandler {
47:
48: /**
49: * Implementations must implement this method to process each row of data
50: * in the ResultSet. This method should not call next() on the ResultSet,
51: * but extract the current values. Exactly what the implementation chooses
52: * to do is up to it; a trivial implementation might simply count rows,
53: * while another implementation might build an XML document.
54: * @param rs the ResultSet to process
55: * @throws SQLException if a SQLException is encountered getting
56: * column values (that is, there's no need to catch SQLException)
57: */
58: void processRow(ResultSet rs) throws SQLException;
59: }
|