KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jdbc > object > MappingSqlQuery


1 /*
2  * Copyright 2002-2005 the original author or authors.
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
17 package org.springframework.jdbc.object;
18
19 import java.sql.ResultSet JavaDoc;
20 import java.sql.SQLException JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import javax.sql.DataSource JavaDoc;
24
25 /**
26  * Reusable query in which concrete subclasses must implement the abstract
27  * mapRow(ResultSet, int) method to convert each row of the JDBC ResultSet
28  * into an object.
29  *
30  * <p>Simplifies MappingSqlQueryWithParameters API by dropping parameters and
31  * context. Most subclasses won't care about parameters. If you don't use
32  * contextual information, subclass this instead of MappingSqlQueryWithParameters.
33  *
34  * @author Rod Johnson
35  * @author Thomas Risberg
36  * @author Jean-Pierre Pawlak
37  * @see MappingSqlQueryWithParameters
38  */

39 public abstract class MappingSqlQuery extends MappingSqlQueryWithParameters {
40
41     /**
42      * Constructor that allows use as a JavaBean.
43      */

44     public MappingSqlQuery() {
45     }
46
47     /**
48      * Convenient constructor with DataSource and SQL string.
49      * @param ds DataSource to use to obtain connections
50      * @param sql SQL to run
51      */

52     public MappingSqlQuery(DataSource JavaDoc ds, String JavaDoc sql) {
53         super(ds, sql);
54     }
55
56     /**
57      * This method is implemented to invoke the simpler mapRow
58      * template method, ignoring parameters.
59      * @see #mapRow(ResultSet, int)
60      */

61     protected final Object JavaDoc mapRow(ResultSet JavaDoc rs, int rowNum, Object JavaDoc[] parameters, Map JavaDoc context)
62             throws SQLException JavaDoc {
63
64         return mapRow(rs, rowNum);
65     }
66
67     /**
68      * Subclasses must implement this method to convert each row of the
69      * ResultSet into an object of the result type.
70      * <p>Subclasses of this class, as opposed to direct subclasses of
71      * MappingSqlQueryWithParameters, don't need to concern themselves
72      * with the parameters to the execute method of the query object.
73      * @param rs ResultSet we're working through
74      * @param rowNum row number (from 0) we're up to
75      * @return an object of the result type
76      * @throws SQLException if there's an error extracting data.
77      * Subclasses can simply not catch SQLExceptions, relying on the
78      * framework to clean up.
79      */

80     protected abstract Object JavaDoc mapRow(ResultSet JavaDoc rs, int rowNum) throws SQLException JavaDoc;
81
82 }
83
Popular Tags