On 21 September 2012 14:59, <[email protected]> wrote:
> Author: simonetripodi
> Date: Fri Sep 21 13:59:46 2012
> New Revision: 1388495
>
> URL: http://svn.apache.org/viewvc?rev=1388495&view=rev
> Log:
> [DBUTILS-97] Add an Abstract ResultSetHandler implementation in order to
> reduce redundant 'resultSet' variable invocation
>
> Added:
>
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BaseResultSetHandler.java
> (with props)
>
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/BaseResultSetHandlerTestCase.java
> (with props)
> Modified:
> commons/proper/dbutils/trunk/src/changes/changes.xml
>
> Modified: commons/proper/dbutils/trunk/src/changes/changes.xml
> URL:
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/changes/changes.xml?rev=1388495&r1=1388494&r2=1388495&view=diff
> ==============================================================================
> --- commons/proper/dbutils/trunk/src/changes/changes.xml (original)
> +++ commons/proper/dbutils/trunk/src/changes/changes.xml Fri Sep 21 13:59:46
> 2012
> @@ -47,6 +47,9 @@ The <action> type attribute can be add,u
> <action dev="simonetripodi" due-to="Moandji Ezana" type="add"
> issue="DBUTILS-98">
> Add missing JavaDoc to QueryRunner#insert
> </action>
> + <action dev="simonetripodi" type="add" issue="DBUTILS-97">
> + Add an Abstract ResultSetHandler implementation in order to reduce
> redundant 'resultSet' variable invocation
> + </action>
> <action dev="wspeirs" due-to="Moandji Ezana" type="add"
> issue="DBUTILS-87">
> Added insert methods to QueryRunner and AsyncQueryRunner that return
> the generated key.
> </action>
>
> Added:
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BaseResultSetHandler.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BaseResultSetHandler.java?rev=1388495&view=auto
> ==============================================================================
> ---
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BaseResultSetHandler.java
> (added)
> +++
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BaseResultSetHandler.java
> Fri Sep 21 13:59:46 2012
> @@ -0,0 +1,1969 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements. See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You 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;
> +
> +import java.io.InputStream;
> +import java.io.Reader;
> +import java.math.BigDecimal;
> +import java.net.URL;
> +import java.sql.Array;
> +import java.sql.Blob;
> +import java.sql.Clob;
> +import java.sql.Date;
> +import java.sql.NClob;
> +import java.sql.Ref;
> +import java.sql.ResultSet;
> +import java.sql.ResultSetMetaData;
> +import java.sql.RowId;
> +import java.sql.SQLException;
> +import java.sql.SQLWarning;
> +import java.sql.SQLXML;
> +import java.sql.Statement;
> +import java.sql.Time;
> +import java.sql.Timestamp;
> +import java.util.Calendar;
> +import java.util.Map;
> +
> +/**
> + * Extensions of this class convert ResultSets into other objects.
> + *
> + * According to the <i>DRY</i> principle (Don't Repeat Yourself), repeating
> <code>resultSet</code>
> + * variable inside the {@link ResultSetHandler#handle(ResultSet)} over and
> over for each iteration
> + * can get a little tedious, <code>AbstractResultSetHandler</code>
> implicitly gives users access to
> + * <code>ResultSet</code>'s methods.
> + *
> + * <b>NOTE</b> This class is <i>NOT</i> thread safe!
> + *
> + * @param <T> the target type the input ResultSet will be converted to.
> + * @since 1.6
> + */
> +public abstract class BaseResultSetHandler<T> implements ResultSetHandler<T>
> {
> +
> + /**
> + * The adapted ResultSet.
> + */
> + private ResultSet rs;
> +
> + /**
> + * {@inheritDoc}
> + */
> + @Override
> + public final T handle(ResultSet rs) throws SQLException {
> + if (this.rs != null) {
> + throw new IllegalStateException("Re-entry not allowed!");
> + }
> +
> + this.rs = rs;
> +
> + try {
> + return handle();
> + } finally {
> + this.rs = null;
> + }
> + }
> +
> + /**
> + * Turn the <code>ResultSet</code> into an Object.
> + *
> + * @return An Object initialized with <code>ResultSet</code> data
> + * @throws SQLException if a database access error occurs
> + * @see {@link ResultSetHandler#handle(ResultSet)}
> + */
> + protected abstract T handle() throws SQLException;
> +
> + /**
> + * @param row
> + * @return
> + * @throws SQLException
> + * @see java.sql.ResultSet#absolute(int)
> + */
> + protected final boolean absolute(int row) throws SQLException {
> + return rs.absolute(row);
> + }
> +
> + /**
> + * @throws SQLException
> + * @see java.sql.ResultSet#afterLast()
> + */
> + protected final void afterLast() throws SQLException {
> + rs.afterLast();
> + }
> +
> + /**
> + * @throws SQLException
> + * @see java.sql.ResultSet#beforeFirst()
> + */
> + protected final void beforeFirst() throws SQLException {
> + rs.beforeFirst();
> + }
> +
> + /**
> + * @throws SQLException
> + * @see java.sql.ResultSet#cancelRowUpdates()
> + */
> + protected final void cancelRowUpdates() throws SQLException {
> + rs.cancelRowUpdates();
> + }
> +
> + /**
> + * @throws SQLException
> + * @see java.sql.ResultSet#clearWarnings()
> + */
> + protected final void clearWarnings() throws SQLException {
> + rs.clearWarnings();
> + }
> +
> + /**
> + * @throws SQLException
> + * @see java.sql.ResultSet#close()
> + */
> + protected final void close() throws SQLException {
> + rs.close();
> + }
> +
> + /**
> + * @throws SQLException
> + * @see java.sql.ResultSet#deleteRow()
> + */
> + protected final void deleteRow() throws SQLException {
> + rs.deleteRow();
> + }
> +
> + /**
> + * @param columnLabel
> + * @return
> + * @throws SQLException
> + * @see java.sql.ResultSet#findColumn(java.lang.String)
> + */
> + protected final int findColumn(String columnLabel) throws SQLException {
> + return rs.findColumn(columnLabel);
> + }
> +
> + /**
> + * @return
> + * @throws SQLException
> + * @see java.sql.ResultSet#first()
> + */
> + protected final boolean first() throws SQLException {
> + return rs.first();
> + }
> +
> + /**
> + * @param columnIndex
> + * @return
> + * @throws SQLException
> + * @see java.sql.ResultSet#getArray(int)
> + */
> + protected final Array getArray(int columnIndex) throws SQLException {
> + return rs.getArray(columnIndex);
> + }
> +
> + /**
> + * @param columnLabel
> + * @return
> + * @throws SQLException
> + * @see java.sql.ResultSet#getArray(java.lang.String)
> + */
> + protected final Array getArray(String columnLabel) throws SQLException {
> + return rs.getArray(columnLabel);
> + }
> +
> + /**
> + * @param columnIndex
> + * @return
> + * @throws SQLException
> + * @see java.sql.ResultSet#getAsciiStream(int)
> + */
> + protected final InputStream getAsciiStream(int columnIndex) throws
> SQLException {
> + return rs.getAsciiStream(columnIndex);
> + }
> +
> + /**
> + * @param columnLabel
> + * @return
> + * @throws SQLException
> + * @see java.sql.ResultSet#getAsciiStream(java.lang.String)
> + */
> + protected final InputStream getAsciiStream(String columnLabel) throws
> SQLException {
> + return rs.getAsciiStream(columnLabel);
> + }
> +
> + /**
> + * @param columnIndex
> + * @param scale
> + * @return
> + * @throws SQLException
> + * @deprecated
> + * @see java.sql.ResultSet#getBigDecimal(int, int)
> + */
Why add a new class with already deprecated methods?
If they are to be kept, then one needs to add the @Deprecated annotation.
Also, the @deprecated Javadoc entry should state what to use instead.
> + protected final BigDecimal getBigDecimal(int columnIndex, int scale)
> throws SQLException {
> + return rs.getBigDecimal(columnIndex, scale);
> + }
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]