KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > system > jdbc > DefaultRowSetResultSetMapper


1 /*
2  * Copyright 2005 The Apache Software Foundation.
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  * $Header:$
17  */

18
19 package org.apache.beehive.controls.system.jdbc;
20
21 import com.sun.rowset.CachedRowSetImpl;
22 import org.apache.beehive.controls.api.ControlException;
23 import org.apache.beehive.controls.api.context.ControlBeanContext;
24 import org.apache.beehive.controls.system.jdbc.JdbcControl.SQL;
25
26 import javax.sql.RowSet JavaDoc;
27 import java.lang.reflect.Method JavaDoc;
28 import java.sql.ResultSet JavaDoc;
29 import java.sql.SQLException JavaDoc;
30 import java.util.Calendar JavaDoc;
31
32 /**
33  * Default ResultSetMapper implementation for RowSets.
34  */

35 public class DefaultRowSetResultSetMapper extends ResultSetMapper {
36
37     private static final TypeMappingsFactory _tmf = TypeMappingsFactory.getInstance();
38
39     /**
40      * Map a ResultSet to a RowSet. Type of RowSet is defined by the SQL annotation for the method.
41      *
42      * @param context A ControlBeanContext instance.
43      * @param m Method assoicated with this call.
44      * @param resultSet Result set to map.
45      * @param cal A Calendar instance for resolving date/time values.
46      * @return A RowSet object.
47      */

48     public RowSet JavaDoc mapToResultType(ControlBeanContext context, Method JavaDoc m, ResultSet JavaDoc resultSet, Calendar JavaDoc cal) {
49         final SQL methodSQL = (SQL) context.getMethodPropertySet(m, SQL.class);
50         final int maxrows = methodSQL.maxRows();
51
52         try {
53             CachedRowSetImpl rows = new CachedRowSetImpl();
54
55             if (maxrows > 0) {
56                 rows.setMaxRows(maxrows);
57             }
58
59             rows.populate(resultSet);
60             return rows;
61         } catch (SQLException JavaDoc e) {
62             throw new ControlException(e.getMessage(), e);
63         }
64     }
65
66     /**
67      * Can the ResultSet which this mapper uses be closed by the database control?
68      *
69      * @return always false
70      */

71     public boolean canCloseResultSet() { return false; }
72 }
73
Popular Tags