01: package org.apache.ojb.broker.accesslayer;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * 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:
18: import java.sql.ResultSetMetaData;
19: import java.sql.SQLException;
20:
21: import org.apache.ojb.broker.PersistenceBrokerException;
22: import org.apache.ojb.broker.core.PersistenceBrokerImpl;
23: import org.apache.ojb.broker.metadata.JdbcTypesHelper;
24:
25: /**
26: * ReporQueryRsIterator based on SQL-Statement
27: *
28: * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
29: * @version $Id: SqlBasedReportQueryRsIterator.java,v 1.11.2.2 2005/12/21 22:22:58 tomdz Exp $
30: */
31: public class SqlBasedReportQueryRsIterator extends SqlBasedRsIterator {
32: private ResultSetMetaData rsMetaData;
33: private int columnCount;
34:
35: /**
36: * SqlBasedRsIterator constructor.
37: */
38: public SqlBasedReportQueryRsIterator(RsQueryObject queryObject,
39: PersistenceBrokerImpl broker)
40: throws PersistenceBrokerException {
41:
42: super (queryObject, broker);
43: try {
44: rsMetaData = getRsAndStmt().m_rs.getMetaData();
45: columnCount = rsMetaData.getColumnCount();
46: } catch (SQLException e) {
47: throw new PersistenceBrokerException(e);
48: }
49: }
50:
51: /**
52: * returns an Object[] representing the columns of the current ResultSet row.
53: * There is no OJB object materialization, Proxy generation etc. involved
54: * to maximize performance.
55: */
56: protected Object getObjectFromResultSet()
57: throws PersistenceBrokerException {
58: Object[] result = new Object[columnCount];
59: for (int i = 0; i < columnCount; i++) {
60: try {
61: int jdbcType = rsMetaData.getColumnType(i + 1);
62: Object item = JdbcTypesHelper.getObjectFromColumn(
63: getRsAndStmt().m_rs, new Integer(jdbcType),
64: i + 1);
65: result[i] = item;
66: } catch (SQLException e) {
67: throw new PersistenceBrokerException(e);
68: }
69: }
70: return result;
71: }
72:
73: }
|