001    package org.apache.ojb.broker.accesslayer;
002    
003    /* Copyright 2002-2005 The Apache Software Foundation
004     *
005     * Licensed under the Apache License, Version 2.0 (the "License");
006     * you may not use this file except in compliance with the License.
007     * You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    import java.sql.ResultSetMetaData;
019    import java.sql.SQLException;
020    
021    import org.apache.ojb.broker.PersistenceBrokerException;
022    import org.apache.ojb.broker.core.PersistenceBrokerImpl;
023    import org.apache.ojb.broker.metadata.JdbcTypesHelper;
024    
025    /**
026     * ReporQueryRsIterator based on SQL-Statement
027     *
028     * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
029     * @version $Id: SqlBasedReportQueryRsIterator.java,v 1.1 2007-08-24 22:17:30 ewestfal Exp $
030     */
031    public class SqlBasedReportQueryRsIterator extends SqlBasedRsIterator
032    {
033        private ResultSetMetaData rsMetaData;
034        private int columnCount;
035    
036        /**
037         * SqlBasedRsIterator constructor.
038         */
039        public SqlBasedReportQueryRsIterator(RsQueryObject queryObject, PersistenceBrokerImpl broker)
040                throws PersistenceBrokerException
041        {
042    
043            super(queryObject, broker);
044            try
045            {
046                rsMetaData = getRsAndStmt().m_rs.getMetaData();
047                columnCount = rsMetaData.getColumnCount();
048            }
049            catch (SQLException e)
050            {
051                throw new PersistenceBrokerException(e);
052            }
053        }
054    
055        /**
056         * returns an Object[] representing the columns of the current ResultSet row.
057         * There is no OJB object materialization, Proxy generation etc. involved
058         * to maximize performance.
059         */
060        protected Object getObjectFromResultSet() throws PersistenceBrokerException
061        {
062            Object[] result = new Object[columnCount];
063            for (int i = 0; i < columnCount; i++)
064            {
065                try
066                {
067                    int jdbcType = rsMetaData.getColumnType(i + 1);
068                    Object item = JdbcTypesHelper.getObjectFromColumn(getRsAndStmt().m_rs, new Integer(jdbcType), i + 1);
069                    result[i] = item;
070                }
071                catch (SQLException e)
072                {
073                    throw new PersistenceBrokerException(e);
074                }
075            }
076            return result;
077        }
078    
079    }