KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jdbc > core > SqlRowSetResultSetExtractor


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.core;
18
19 import java.sql.ResultSet JavaDoc;
20 import java.sql.SQLException JavaDoc;
21
22 import javax.sql.rowset.CachedRowSet JavaDoc;
23
24 import com.sun.rowset.CachedRowSetImpl;
25
26 import org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet;
27 import org.springframework.jdbc.support.rowset.SqlRowSet;
28
29 /**
30  * ResultSetExtractor implementation that returns a Spring SqlRowSet
31  * representation for each given ResultSet.
32  *
33  * <p>The default implementation uses a standard JDBC CachedRowSet underneath.
34  * This means that JDBC RowSet support needs to be available at runtime:
35  * by default, Sun's <code>com.sun.rowset.CachedRowSetImpl</code> class is
36  * used, which is part of JDK 1.5+ and also available separately as part of
37  * Sun's JDBC RowSet Implementations download (rowset.jar).
38  *
39  * @author Juergen Hoeller
40  * @since 1.2
41  * @see #newCachedRowSet
42  * @see org.springframework.jdbc.support.rowset.SqlRowSet
43  * @see JdbcTemplate#queryForRowSet(String)
44  * @see javax.sql.rowset.CachedRowSet
45  */

46 public class SqlRowSetResultSetExtractor implements ResultSetExtractor {
47
48     public Object JavaDoc extractData(ResultSet JavaDoc rs) throws SQLException JavaDoc {
49         return createSqlRowSet(rs);
50     }
51
52     /**
53      * Create a SqlRowSet that wraps the given ResultSet,
54      * representing its data in a disconnected fashion.
55      * <p>This implementation creates a Spring ResultSetWrappingSqlRowSet
56      * instance that wraps a standard JDBC CachedRowSet instance.
57      * Can be overridden to use a different implementation.
58      * @param rs the original ResultSet (connected)
59      * @return the disconnected SqlRowSet
60      * @throws SQLException if thrown by JDBC methods
61      * @see #newCachedRowSet
62      * @see org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet
63      */

64     protected SqlRowSet createSqlRowSet(ResultSet JavaDoc rs) throws SQLException JavaDoc {
65         CachedRowSet JavaDoc rowSet = newCachedRowSet();
66         rowSet.populate(rs);
67         return new ResultSetWrappingSqlRowSet(rowSet);
68     }
69
70     /**
71      * Create a new CachedRowSet instance, to be populated by
72      * the <code>createSqlRowSet</code> implementation.
73      * <p>The default implementation creates a new instance of
74      * Sun's <code>com.sun.rowset.CachedRowSetImpl</code> class,
75      * which is part of JDK 1.5+ and also available separately
76      * as part of Sun's JDBC RowSet Implementations download.
77      * @return a new CachedRowSet instance
78      * @throws SQLException if thrown by JDBC methods
79      * @see #createSqlRowSet
80      * @see com.sun.rowset.CachedRowSetImpl
81      */

82     protected CachedRowSet JavaDoc newCachedRowSet() throws SQLException JavaDoc {
83         return new CachedRowSetImpl();
84     }
85
86 }
87
Popular Tags