Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 39208 invoked from network); 3 Nov 2006 20:22:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Nov 2006 20:22:47 -0000 Received: (qmail 85947 invoked by uid 500); 3 Nov 2006 20:22:53 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 85850 invoked by uid 500); 3 Nov 2006 20:22:52 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 85817 invoked by uid 99); 3 Nov 2006 20:22:52 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Nov 2006 12:22:52 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Nov 2006 12:22:40 -0800 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id E3FAB7142DC for ; Fri, 3 Nov 2006 12:22:17 -0800 (PST) Message-ID: <8544191.1162585337931.JavaMail.root@brutus> Date: Fri, 3 Nov 2006 12:22:17 -0800 (PST) From: "Henri Yandell (JIRA)" To: commons-dev@jakarta.apache.org Subject: [jira] Resolved: (DBUTILS-16) [dbutils] ResultSetRowProcessor abstract handler and some classes rework MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ http://issues.apache.org/jira/browse/DBUTILS-16?page=all ] Henri Yandell resolved DBUTILS-16. ---------------------------------- Resolution: Fixed svn ci -m "Applying the code refactoring in #DBUTILS-16 - the new abstract class is currently not public. In a later release we can decide whe ther to make it public or not (this is recorded in #DBUTILS-33" Sending src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java Sending src/java/org/apache/commons/dbutils/handlers/BeanListHandler.java Sending src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java Sending src/java/org/apache/commons/dbutils/handlers/MapListHandler.java Transmitting file data .... Committed revision 470975. > [dbutils] ResultSetRowProcessor abstract handler and some classes rework > ------------------------------------------------------------------------ > > Key: DBUTILS-16 > URL: http://issues.apache.org/jira/browse/DBUTILS-16 > Project: Commons DbUtils > Issue Type: Improvement > Environment: Operating System: All > Platform: All > Reporter: Mikhail Krivoshein > Priority: Minor > Fix For: 1.1 > > Attachments: DBUTILS-16.patch, GenericListHandler.patch, GenericListHandler_2.patch > > > Index: ArrayListHandler.java > =================================================================== > RCS file: /home/cvspublic/jakarta- > commons/dbutils/src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.ja > va,v > retrieving revision 1.4 > diff -u -r1.4 ArrayListHandler.java > --- ArrayListHandler.java 28 Feb 2004 00:12:22 -0000 1.4 > +++ ArrayListHandler.java 4 Jun 2004 13:24:00 -0000 > @@ -1,82 +1,68 @@ > /* > * Copyright 2003-2004 The Apache Software Foundation > - * > - * Licensed under the Apache License, Version 2.0 (the "License"); > - * you may not use this file except in compliance with the License. > - * You may obtain a copy of the License at > - * > - * http://www.apache.org/licenses/LICENSE-2.0 > - * > + * > + * Licensed under the Apache License, Version 2.0 (the "License"); you may not > + * use this file except in compliance with the License. You may obtain a copy > + * of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > * Unless required by applicable law or agreed to in writing, software > - * distributed under the License is distributed on an "AS IS" BASIS, > - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > - * See the License for the specific language governing permissions and > - * limitations under the License. > + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT > + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the > + * License for the specific language governing permissions and limitations > + * under the License. > */ > package org.apache.commons.dbutils.handlers; > > import java.sql.ResultSet; > import java.sql.SQLException; > -import java.util.ArrayList; > -import java.util.List; > > -import org.apache.commons.dbutils.ResultSetHandler; > import org.apache.commons.dbutils.RowProcessor; > > /** > - * ResultSetHandler implementation that converts the > - * ResultSet into a List of Object[]s. > - * This class is thread safe. > + * ResultSetHandler implementation that converts the > ResultSet > + * into a List of Object[]s. This class is > + * thread safe. > * > * @see ResultSetHandler > */ > -public class ArrayListHandler implements ResultSetHandler { > - > - /** > - * The RowProcessor implementation to use when converting rows > - * into Object[]s. > - */ > - private RowProcessor convert = ArrayHandler.ROW_PROCESSOR; > - > - /** > - * Creates a new instance of ArrayListHandler using a > - * BasicRowProcessor for conversions. > - */ > - public ArrayListHandler() { > - super(); > - } > - > - /** > - * Creates a new instance of ArrayListHandler. > - * > - * @param convert The RowProcessor implementation > - * to use when converting rows into Object[]s. > - */ > - public ArrayListHandler(RowProcessor convert) { > - super(); > - this.convert = convert; > - } > - > - /** > - * Convert each row's columns into an Object[] and store them > - * in a List in the same order they are returned from the > - * ResultSet.next() method. > - * > - * @return A List of Object[]s, never > - * null. > - * > - * @throws SQLException > - * @see org.apache.commons.dbutils.ResultSetHandler#handle > (java.sql.ResultSet) > - */ > - public Object handle(ResultSet rs) throws SQLException { > - > - List result = new ArrayList(); > - > - while (rs.next()) { > - result.add(this.convert.toArray(rs)); > - } > - > - return result; > - } > +public class ArrayListHandler extends ResultSetRowProcessor { > > + /** > + * The RowProcessor implementation to use when converting rows into > + * Object[]s. > + */ > + private RowProcessor convert = ArrayHandler.ROW_PROCESSOR; > + > + /** > + * Creates a new instance of ArrayListHandler using a > BasicRowProcessor > + * for conversions. > + */ > + public ArrayListHandler() { > + super(); > + } > + > + /** > + * Creates a new instance of ArrayListHandler. > + * > + * @param convert The RowProcessor implementation to use > when > + * converting rows into Object[]s. > + */ > + public ArrayListHandler(RowProcessor convert) { > + super(); > + this.convert = convert; > + } > + > + /** > + * Convert row's columns into an Object[]. > + * > + * @return Object[], never null. > + * > + * @throws SQLException > + * @see org.apache.commons.dbutils.handlers.ResultSetRowProcessor#handle > (ResultSet) > + */ > + protected Object handleRow(ResultSet rs) throws SQLException { > + return this.convert.toArray(rs); > + } > } > Index: ColumnListHandler.java > =================================================================== > RCS file: /home/cvspublic/jakarta- > commons/dbutils/src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.j > ava,v > retrieving revision 1.1 > diff -u -r1.1 ColumnListHandler.java > --- ColumnListHandler.java 9 Mar 2004 03:05:51 -0000 1.1 > +++ ColumnListHandler.java 4 Jun 2004 13:24:01 -0000 > @@ -1,100 +1,85 @@ > /* > * Copyright 2004 The Apache Software Foundation > - * > - * Licensed under the Apache License, Version 2.0 (the "License"); > - * you may not use this file except in compliance with the License. > - * You may obtain a copy of the License at > - * > - * http://www.apache.org/licenses/LICENSE-2.0 > - * > + * > + * Licensed under the Apache License, Version 2.0 (the "License"); you may not > + * use this file except in compliance with the License. You may obtain a copy > + * of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > * Unless required by applicable law or agreed to in writing, software > - * distributed under the License is distributed on an "AS IS" BASIS, > - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > - * See the License for the specific language governing permissions and > - * limitations under the License. > + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT > + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the > + * License for the specific language governing permissions and limitations > + * under the License. > */ > > package org.apache.commons.dbutils.handlers; > > import java.sql.ResultSet; > import java.sql.SQLException; > -import java.util.ArrayList; > -import java.util.List; > - > -import org.apache.commons.dbutils.ResultSetHandler; > > /** > - * ResultSetHandler implementation that converts one > - * ResultSet column into a List of > - * Objects. This class is thread safe. > + * ResultSetHandler implementation that converts one > ResultSet > + * column into a List of Objects. This class is > + * thread safe. > * > * @see ResultSetHandler > * @since DbUtils 1.1 > */ > -public class ColumnListHandler implements ResultSetHandler { > +public class ColumnListHandler extends ResultSetRowProcessor { > > - /** > - * The column number to retrieve. > - */ > - private int columnIndex = 1; > - > - /** > - * The column name to retrieve. Either columnName or columnIndex > - * will be used but never both. > - */ > - private String columnName = null; > - > - /** > - * Creates a new instance of ColumnListHandler. The first column of each > - * row will be returned from handle(). > - */ > - public ColumnListHandler() { > - super(); > - } > - > - /** > - * Creates a new instance of ColumnListHandler. > - * > - * @param columnIndex The index of the column to retrieve from the > - * ResultSet. > - */ > - public ColumnListHandler(int columnIndex) { > - this.columnIndex = columnIndex; > - } > - > - /** > - * Creates a new instance of ColumnListHandler. > - * > - * @param columnName The name of the column to retrieve from the > - * ResultSet. > - */ > - public ColumnListHandler(String columnName) { > - this.columnName = columnName; > - } > - > - /** > - * Returns one ResultSet column as a List of > - * Objects. The elements are added to the List > via > - * the ResultSet.getObject() method. > - * > - * @return A List of Objects, never > - * null. > - * > - * @throws SQLException > - * > - * @see org.apache.commons.dbutils.ResultSetHandler#handle > (java.sql.ResultSet) > - */ > - public Object handle(ResultSet rs) throws SQLException { > - > - List result = new ArrayList(); > - > - while (rs.next()) { > - if (this.columnName == null) { > - result.add(rs.getObject(this.columnIndex)); > - } else { > - result.add(rs.getObject(this.columnName)); > - } > - } > - return result; > - } > + /** > + * The column number to retrieve. > + */ > + private int columnIndex = 1; > + > + /** > + * The column name to retrieve. Either columnName or columnIndex will > be used > + * but never both. > + */ > + private String columnName = null; > + > + /** > + * Creates a new instance of ColumnListHandler. The first column of > each row > + * will be returned from handle(). > + */ > + public ColumnListHandler() { > + super(); > + } > + > + /** > + * Creates a new instance of ColumnListHandler. > + * > + * @param columnIndex The index of the column to retrieve from the > ResultSet. > + */ > + public ColumnListHandler(int columnIndex) { > + this.columnIndex = columnIndex; > + } > + > + /** > + * Creates a new instance of ColumnListHandler. > + * > + * @param columnName The name of the column to retrieve from the > ResultSet. > + */ > + public ColumnListHandler(String columnName) { > + this.columnName = columnName; > + } > + > + /** > + * Returns one ResultSet column value as > Object. > + * > + * @return Object, never null. > + * > + * @throws SQLException > + * > + * @see org.apache.commons.dbutils.handlers.ResultSetRowProcessor#handle > (ResultSet) > + */ > + protected Object handleRow(ResultSet rs) throws SQLException { > + if (this.columnName == null) { > + return rs.getObject(this.columnIndex); > + } else { > + return rs.getObject(this.columnName); > + } > + } > } > Index: MapListHandler.java > =================================================================== > RCS file: /home/cvspublic/jakarta- > commons/dbutils/src/java/org/apache/commons/dbutils/handlers/MapListHandler.java > ,v > retrieving revision 1.4 > diff -u -r1.4 MapListHandler.java > --- MapListHandler.java 28 Feb 2004 00:12:22 -0000 1.4 > +++ MapListHandler.java 4 Jun 2004 13:24:01 -0000 > @@ -17,10 +17,7 @@ > > import java.sql.ResultSet; > import java.sql.SQLException; > -import java.util.ArrayList; > -import java.util.List; > > -import org.apache.commons.dbutils.ResultSetHandler; > import org.apache.commons.dbutils.RowProcessor; > > /** > @@ -30,7 +27,7 @@ > * > * @see ResultSetHandler > */ > -public class MapListHandler implements ResultSetHandler { > +public class MapListHandler extends ResultSetRowProcessor { > > /** > * The RowProcessor implementation to use when converting rows > @@ -58,24 +55,16 @@ > } > > /** > - * Converts the ResultSet rows into a List of > - * Map objects. > + * Converts the ResultSet row into a Map object. > * > - * @return A List of Maps, never null. > + * @return A Map, never null. > * > * @throws SQLException > * > - * @see org.apache.commons.dbutils.ResultSetHandler#handle > (java.sql.ResultSet) > + * @see org.apache.commons.dbutils.handlers.ResultSetRowProcessor#handle > (ResultSet) > */ > - public Object handle(ResultSet rs) throws SQLException { > - > - List results = new ArrayList(); > - > - while (rs.next()) { > - results.add(this.convert.toMap(rs)); > - } > - > - return results; > - } > + protected Object handleRow(ResultSet rs) throws SQLException { > + return this.convert.toMap(rs); > + } > > } > Index: src/java/org/apache/commons/dbutils/handlers/ResultSetRowProcessor.java > =================================================================== > RCS file: > src/java/org/apache/commons/dbutils/handlers/ResultSetRowProcessor.java > diff -N src/java/org/apache/commons/dbutils/handlers/ResultSetRowProcessor.java > --- /dev/null 1 Jan 1970 00:00:00 -0000 > +++ src/java/org/apache/commons/dbutils/handlers/ResultSetRowProcessor.java > 1 Jan 1970 00:00:00 -0000 > @@ -0,0 +1,53 @@ > +/* > + * Copyright 2003-2004 The Apache Software Foundation > + * > + * Licensed under the Apache License, Version 2.0 (the "License"); you may not > + * use this file except in compliance with the License. You may obtain a copy > + * of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, software > + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT > + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the > + * License for the specific language governing permissions and limitations > + * under the License. > + */ > +package org.apache.commons.dbutils.handlers; > + > +import java.sql.ResultSet; > +import java.sql.SQLException; > +import java.util.ArrayList; > +import java.util.List; > + > +import org.apache.commons.dbutils.ResultSetHandler; > + > +/** > + * Abstract class that simplify development of ResultSetHandler > + * classes that convert ResultSet into List. > + */ > +public abstract class ResultSetRowProcessor implements ResultSetHandler { > + /** > + * Whole ResultSet handler. It produce List as > + * result. To convert individual rows into Java objects it uses > handleRow(ResultSet) > + * method. > + * > + * @see #handleRow(ResultSet) > + */ > + public Object handle(ResultSet rs) throws SQLException { > + List rows = new ArrayList(); > + while (rs.next()) { > + rows.add(this.handleRow(rs)); > + } > + return rows; > + } > + > + /** > + * Row handler. Method converts current row into some Java object. > + * > + * @param rs ResultSet to process. > + * @return row processing result > + * @throws SQLException error occurs > + */ > + protected abstract Object handleRow(ResultSet rs) throws SQLException; > +} -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org