001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  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    package org.apache.commons.dbutils.handlers;
018    
019    import java.sql.ResultSet;
020    import java.sql.SQLException;
021    
022    import org.apache.commons.dbutils.RowProcessor;
023    
024    /**
025     * <code>ResultSetHandler</code> implementation that converts the
026     * <code>ResultSet</code> into a <code>List</code> of <code>Object[]</code>s.
027     * This class is thread safe.
028     *
029     * @see org.apache.commons.dbutils.ResultSetHandler
030     */
031    public class ArrayListHandler extends AbstractListHandler<Object[]> {
032    
033        /**
034         * The RowProcessor implementation to use when converting rows
035         * into Object[]s.
036         */
037        private final RowProcessor convert;
038    
039        /**
040         * Creates a new instance of ArrayListHandler using a
041         * <code>BasicRowProcessor</code> for conversions.
042         */
043        public ArrayListHandler() {
044            this(ArrayHandler.ROW_PROCESSOR);
045        }
046    
047        /**
048         * Creates a new instance of ArrayListHandler.
049         *
050         * @param convert The <code>RowProcessor</code> implementation
051         * to use when converting rows into Object[]s.
052         */
053        public ArrayListHandler(RowProcessor convert) {
054            super();
055            this.convert = convert;
056        }
057    
058    
059        /**
060         * Convert row's columns into an <code>Object[]</code>.
061         * @param rs <code>ResultSet</code> to process.
062         * @return <code>Object[]</code>, never <code>null</code>.
063         *
064         * @throws SQLException if a database access error occurs
065         * @see org.apache.commons.dbutils.handlers.AbstractListHandler#handle(ResultSet)
066         */
067        @Override
068        protected Object[] handleRow(ResultSet rs) throws SQLException {
069            return this.convert.toArray(rs);
070        }
071    
072    }