01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19:
20: package org.apache.beehive.controls.system.jdbc;
21:
22: import com.sun.rowset.CachedRowSetImpl;
23: import org.apache.beehive.controls.api.ControlException;
24: import org.apache.beehive.controls.api.context.ControlBeanContext;
25: import org.apache.beehive.controls.system.jdbc.JdbcControl.SQL;
26:
27: import javax.sql.RowSet;
28: import java.lang.reflect.Method;
29: import java.sql.ResultSet;
30: import java.sql.SQLException;
31: import java.util.Calendar;
32:
33: /**
34: * Default ResultSetMapper implementation for RowSets.
35: */
36: public class DefaultRowSetResultSetMapper extends ResultSetMapper {
37:
38: /**
39: * Map a ResultSet to a RowSet. Type of RowSet is defined by the SQL annotation for the method.
40: *
41: * @param context A ControlBeanContext instance.
42: * @param m Method assoicated with this call.
43: * @param resultSet Result set to map.
44: * @param cal A Calendar instance for resolving date/time values.
45: * @return A RowSet object.
46: */
47: public RowSet mapToResultType(ControlBeanContext context, Method m,
48: ResultSet resultSet, Calendar cal) {
49: final SQL methodSQL = (SQL) context.getMethodPropertySet(m,
50: SQL.class);
51: final int maxrows = methodSQL.maxRows();
52:
53: try {
54: CachedRowSetImpl rows = new CachedRowSetImpl();
55:
56: if (maxrows > 0) {
57: rows.setMaxRows(maxrows);
58: }
59:
60: rows.populate(resultSet);
61: return rows;
62: } catch (SQLException e) {
63: throw new ControlException(e.getMessage(), e);
64: }
65: }
66:
67: /**
68: * Can the ResultSet which this mapper uses be closed by the database control?
69: *
70: * @return always false
71: */
72: public boolean canCloseResultSet() {
73: return false;
74: }
75: }
|