http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/RowProcessor.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/RowProcessor.java b/src/main/java/org/apache/commons/dbutils/RowProcessor.java deleted file mode 100644 index 02e9382..0000000 --- a/src/main/java/org/apache/commons/dbutils/RowProcessor.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; -import java.util.Map; - -/** - * <code>RowProcessor</code> implementations convert - * <code>ResultSet</code> rows into various other objects. Implementations - * can extend <code>BasicRowProcessor</code> to protect themselves - * from changes to this interface. - * - * @see BasicRowProcessor - */ -public interface RowProcessor { - - /** - * Create an <code>Object[]</code> from the column values in one - * <code>ResultSet</code> row. The <code>ResultSet</code> should be - * positioned on a valid row before passing it to this method. - * Implementations of this method must not alter the row position of - * the <code>ResultSet</code>. - * - * @param rs ResultSet that supplies the array data - * @throws SQLException if a database access error occurs - * @return the newly created array - */ - Object[] toArray(ResultSet rs) throws SQLException; - - /** - * Create a JavaBean from the column values in one <code>ResultSet</code> - * row. The <code>ResultSet</code> should be positioned on a valid row before - * passing it to this method. Implementations of this method must not - * alter the row position of the <code>ResultSet</code>. - * @param <T> The type of bean to create - * @param rs ResultSet that supplies the bean data - * @param type Class from which to create the bean instance - * @throws SQLException if a database access error occurs - * @return the newly created bean - */ - <T> T toBean(ResultSet rs, Class<T> type) throws SQLException; - - /** - * Create a <code>List</code> of JavaBeans from the column values in all - * <code>ResultSet</code> rows. <code>ResultSet.next()</code> should - * <strong>not</strong> be called before passing it to this method. - * @param <T> The type of bean to create - * @param rs ResultSet that supplies the bean data - * @param type Class from which to create the bean instance - * @throws SQLException if a database access error occurs - * @return A <code>List</code> of beans with the given type in the order - * they were returned by the <code>ResultSet</code>. - */ - <T> List<T> toBeanList(ResultSet rs, Class<T> type) throws SQLException; - - /** - * Create a <code>Map</code> from the column values in one - * <code>ResultSet</code> row. The <code>ResultSet</code> should be - * positioned on a valid row before - * passing it to this method. Implementations of this method must not - * alter the row position of the <code>ResultSet</code>. - * - * @param rs ResultSet that supplies the map data - * @throws SQLException if a database access error occurs - * @return the newly created Map - */ - Map<String, Object> toMap(ResultSet rs) throws SQLException; - -}
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/UpdateExecutor.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/UpdateExecutor.java b/src/main/java/org/apache/commons/dbutils/UpdateExecutor.java deleted file mode 100644 index 9cfaf2f..0000000 --- a/src/main/java/org/apache/commons/dbutils/UpdateExecutor.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.sql.Connection; -import java.sql.SQLException; - - -public class UpdateExecutor extends AbstractExecutor<UpdateExecutor> { - - private final boolean closeConn; - - public UpdateExecutor(final Connection conn, final String sql, final boolean closeConnection) throws SQLException { - super(conn, sql); - this.closeConn = closeConnection; - } - - /** - * Calls update after checking the parameters to ensure nothing is null. - * @return The number of rows updated. - * @throws SQLException If there are database or parameter errors. - */ - public int execute() throws SQLException { - // throw an exception if there are unmapped parameters - this.throwIfUnmappedParams(); - - try { - return getStatement().executeUpdate(); - } catch (SQLException e) { - this.rethrow(e); - - } finally { - close(getStatement()); - if (closeConn) { - close(getConnection()); - } - } - - // we get here only if something is thrown - return 0; - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/handlers/AbstractKeyedHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/handlers/AbstractKeyedHandler.java b/src/main/java/org/apache/commons/dbutils/handlers/AbstractKeyedHandler.java deleted file mode 100644 index 2fc8d5d..0000000 --- a/src/main/java/org/apache/commons/dbutils/handlers/AbstractKeyedHandler.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.handlers; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.dbutils.ResultSetHandler; - -/** - * <p> - * <code>ResultSetHandler</code> implementation that returns a Map. - * <code>ResultSet</code> rows are converted into objects (Vs) which are then stored - * in a Map under the given keys (Ks). - * </p> - * - * @param <K> the type of keys maintained by the returned map - * @param <V> the type of mapped values - * @see org.apache.commons.dbutils.ResultSetHandler - * @since DbUtils 1.3 - */ -public abstract class AbstractKeyedHandler<K, V> implements ResultSetHandler<Map<K, V>> { - - - /** - * Convert each row's columns into a Map and store then - * in a <code>Map</code> under <code>ResultSet.getObject(key)</code> key. - * @param rs <code>ResultSet</code> to process. - * @return A <code>Map</code>, never <code>null</code>. - * @throws SQLException if a database access error occurs - * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet) - */ - @Override - public Map<K, V> handle(ResultSet rs) throws SQLException { - Map<K, V> result = createMap(); - while (rs.next()) { - result.put(createKey(rs), createRow(rs)); - } - return result; - } - - /** - * This factory method is called by <code>handle()</code> to create the Map - * to store records in. This implementation returns a <code>HashMap</code> - * instance. - * - * @return Map to store records in - */ - protected Map<K, V> createMap() { - return new HashMap<K, V>(); - } - - /** - * This factory method is called by <code>handle()</code> to retrieve the - * key value from the current <code>ResultSet</code> row. - * @param rs ResultSet to create a key from - * @return K from the configured key column name/index - * @throws SQLException if a database access error occurs - */ - protected abstract K createKey(ResultSet rs) throws SQLException; - - /** - * This factory method is called by <code>handle()</code> to store the - * current <code>ResultSet</code> row in some object. - * @param rs ResultSet to create a row from - * @return V object created from the current row - * @throws SQLException if a database access error occurs - */ - protected abstract V createRow(ResultSet rs) throws SQLException; - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/handlers/AbstractListHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/handlers/AbstractListHandler.java b/src/main/java/org/apache/commons/dbutils/handlers/AbstractListHandler.java deleted file mode 100644 index 504b58e..0000000 --- a/src/main/java/org/apache/commons/dbutils/handlers/AbstractListHandler.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.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 <code>ResultSetHandler</code> - * classes that convert <code>ResultSet</code> into <code>List</code>. - * - * @param <T> the target List generic type - * @see org.apache.commons.dbutils.ResultSetHandler - */ -public abstract class AbstractListHandler<T> implements ResultSetHandler<List<T>> { - /** - * Whole <code>ResultSet</code> handler. It produce <code>List</code> as - * result. To convert individual rows into Java objects it uses - * <code>handleRow(ResultSet)</code> method. - * - * @see #handleRow(ResultSet) - * @param rs <code>ResultSet</code> to process. - * @return a list of all rows in the result set - * @throws SQLException error occurs - */ - @Override - public List<T> handle(ResultSet rs) throws SQLException { - List<T> rows = new ArrayList<T>(); - while (rs.next()) { - rows.add(this.handleRow(rs)); - } - return rows; - } - - /** - * Row handler. Method converts current row into some Java object. - * - * @param rs <code>ResultSet</code> to process. - * @return row processing result - * @throws SQLException error occurs - */ - protected abstract T handleRow(ResultSet rs) throws SQLException; -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/handlers/ArrayHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/handlers/ArrayHandler.java b/src/main/java/org/apache/commons/dbutils/handlers/ArrayHandler.java deleted file mode 100644 index 8c82210..0000000 --- a/src/main/java/org/apache/commons/dbutils/handlers/ArrayHandler.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.handlers; - -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.apache.commons.dbutils.BasicRowProcessor; -import org.apache.commons.dbutils.ResultSetHandler; -import org.apache.commons.dbutils.RowProcessor; - -/** - * <code>ResultSetHandler</code> implementation that converts a - * <code>ResultSet</code> into an <code>Object[]</code>. This class is - * thread safe. - * - * @see org.apache.commons.dbutils.ResultSetHandler - */ -public class ArrayHandler implements ResultSetHandler<Object[]> { - - /** - * Singleton processor instance that handlers share to save memory. Notice - * the default scoping to allow only classes in this package to use this - * instance. - */ - static final RowProcessor ROW_PROCESSOR = new BasicRowProcessor(); - - /** - * The RowProcessor implementation to use when converting rows - * into arrays. - */ - private final RowProcessor convert; - - /** - * Creates a new instance of ArrayHandler using a - * <code>BasicRowProcessor</code> for conversion. - */ - public ArrayHandler() { - this(ROW_PROCESSOR); - } - - /** - * Creates a new instance of ArrayHandler. - * - * @param convert The <code>RowProcessor</code> implementation - * to use when converting rows into arrays. - */ - public ArrayHandler(RowProcessor convert) { - super(); - this.convert = convert; - } - - /** - * Places the column values from the first row in an <code>Object[]</code>. - * @param rs <code>ResultSet</code> to process. - * @return An Object[] or <code>null</code> if there are no rows in the - * <code>ResultSet</code>. - * - * @throws SQLException if a database access error occurs - * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet) - */ - @Override - public Object[] handle(ResultSet rs) throws SQLException { - return rs.next() ? this.convert.toArray(rs) : null; - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java b/src/main/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java deleted file mode 100644 index d2359cf..0000000 --- a/src/main/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.handlers; - -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.apache.commons.dbutils.RowProcessor; - -/** - * <code>ResultSetHandler</code> implementation that converts the - * <code>ResultSet</code> into a <code>List</code> of <code>Object[]</code>s. - * This class is thread safe. - * - * @see org.apache.commons.dbutils.ResultSetHandler - */ -public class ArrayListHandler extends AbstractListHandler<Object[]> { - - /** - * The RowProcessor implementation to use when converting rows - * into Object[]s. - */ - private final RowProcessor convert; - - /** - * Creates a new instance of ArrayListHandler using a - * <code>BasicRowProcessor</code> for conversions. - */ - public ArrayListHandler() { - this(ArrayHandler.ROW_PROCESSOR); - } - - /** - * Creates a new instance of ArrayListHandler. - * - * @param convert The <code>RowProcessor</code> implementation - * to use when converting rows into Object[]s. - */ - public ArrayListHandler(RowProcessor convert) { - super(); - this.convert = convert; - } - - - /** - * Convert row's columns into an <code>Object[]</code>. - * @param rs <code>ResultSet</code> to process. - * @return <code>Object[]</code>, never <code>null</code>. - * - * @throws SQLException if a database access error occurs - * @see org.apache.commons.dbutils.handlers.AbstractListHandler#handle(ResultSet) - */ - @Override - protected Object[] handleRow(ResultSet rs) throws SQLException { - return this.convert.toArray(rs); - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java b/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java deleted file mode 100644 index daa3027..0000000 --- a/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.handlers; - -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.apache.commons.dbutils.ResultSetHandler; -import org.apache.commons.dbutils.RowProcessor; - -/** - * <code>ResultSetHandler</code> implementation that converts the first - * <code>ResultSet</code> row into a JavaBean. This class is thread safe. - * - * @param <T> the target bean type - * @see org.apache.commons.dbutils.ResultSetHandler - */ -public class BeanHandler<T> implements ResultSetHandler<T> { - - /** - * The Class of beans produced by this handler. - */ - private final Class<T> type; - - /** - * The RowProcessor implementation to use when converting rows - * into beans. - */ - private final RowProcessor convert; - - /** - * Creates a new instance of BeanHandler. - * - * @param type The Class that objects returned from <code>handle()</code> - * are created from. - */ - public BeanHandler(Class<T> type) { - this(type, ArrayHandler.ROW_PROCESSOR); - } - - /** - * Creates a new instance of BeanHandler. - * - * @param type The Class that objects returned from <code>handle()</code> - * are created from. - * @param convert The <code>RowProcessor</code> implementation - * to use when converting rows into beans. - */ - public BeanHandler(Class<T> type, RowProcessor convert) { - this.type = type; - this.convert = convert; - } - - /** - * Convert the first row of the <code>ResultSet</code> into a bean with the - * <code>Class</code> given in the constructor. - * @param rs <code>ResultSet</code> to process. - * @return An initialized JavaBean or <code>null</code> if there were no - * rows in the <code>ResultSet</code>. - * - * @throws SQLException if a database access error occurs - * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet) - */ - @Override - public T handle(ResultSet rs) throws SQLException { - return rs.next() ? this.convert.toBean(rs, this.type) : null; - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java b/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java deleted file mode 100644 index 1541a66..0000000 --- a/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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.handlers; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; - -import org.apache.commons.dbutils.ResultSetHandler; -import org.apache.commons.dbutils.RowProcessor; - -/** - * <code>ResultSetHandler</code> implementation that converts a - * <code>ResultSet</code> into a <code>List</code> of beans. This class is - * thread safe. - * - * @param <T> the target bean type - * @see org.apache.commons.dbutils.ResultSetHandler - */ -public class BeanListHandler<T> implements ResultSetHandler<List<T>> { - - /** - * The Class of beans produced by this handler. - */ - private final Class<T> type; - - /** - * The RowProcessor implementation to use when converting rows - * into beans. - */ - private final RowProcessor convert; - - /** - * Creates a new instance of BeanListHandler. - * - * @param type The Class that objects returned from <code>handle()</code> - * are created from. - */ - public BeanListHandler(Class<T> type) { - this(type, ArrayHandler.ROW_PROCESSOR); - } - - /** - * Creates a new instance of BeanListHandler. - * - * @param type The Class that objects returned from <code>handle()</code> - * are created from. - * @param convert The <code>RowProcessor</code> implementation - * to use when converting rows into beans. - */ - public BeanListHandler(Class<T> type, RowProcessor convert) { - this.type = type; - this.convert = convert; - } - - /** - * Convert the whole <code>ResultSet</code> into a List of beans with - * the <code>Class</code> given in the constructor. - * - * @param rs The <code>ResultSet</code> to handle. - * - * @return A List of beans, never <code>null</code>. - * - * @throws SQLException if a database access error occurs - * @see org.apache.commons.dbutils.RowProcessor#toBeanList(ResultSet, Class) - */ - @Override - public List<T> handle(ResultSet rs) throws SQLException { - return this.convert.toBeanList(rs, type); - } -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/handlers/BeanMapHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/handlers/BeanMapHandler.java b/src/main/java/org/apache/commons/dbutils/handlers/BeanMapHandler.java deleted file mode 100644 index 32a1e1c..0000000 --- a/src/main/java/org/apache/commons/dbutils/handlers/BeanMapHandler.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * 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.handlers; - -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.apache.commons.dbutils.RowProcessor; - -/** - * <p> - * <code>ResultSetHandler</code> implementation that returns a Map of Beans. - * <code>ResultSet</code> rows are converted into Beans which are then stored in - * a Map under the given key. - * </p> - * <p> - * If you had a Person table with a primary key column called ID, you could - * retrieve rows from the table like this: - * - * <pre> - * ResultSetHandler<Map<Long, Person>> h = new BeanMapdHandler<Long, Person>(Person.class, "id"); - * Map&ltLong, Person> found = queryRunner.query("select id, name, age from person", h); - * Person jane = found.get(1L); // jane's id is 1 - * String janesName = jane.getName(); - * Integer janesAge = jane.getAge(); - * </pre> - * - * Note that the "id" passed to BeanMapHandler can be in any case. The data type - * returned for id is dependent upon how your JDBC driver converts SQL column - * types from the Person table into Java types. The "name" and "age" columns are - * converted according to their property descriptors by DbUtils. - * </p> - * <p> - * This class is thread safe. - * </p> - * - * @param <K> - * the type of keys maintained by the returned map - * @param <V> - * the type of the bean - * @see org.apache.commons.dbutils.ResultSetHandler - * @since DbUtils 1.5 - */ -public class BeanMapHandler<K, V> extends AbstractKeyedHandler<K, V> { - - /** - * The Class of beans produced by this handler. - */ - private final Class<V> type; - - /** - * The RowProcessor implementation to use when converting rows into Objects. - */ - private final RowProcessor convert; - - /** - * The column index to retrieve key values from. Defaults to 1. - */ - private final int columnIndex; - - /** - * The column name to retrieve key values from. Either columnName or - * columnIndex will be used but never both. - */ - private final String columnName; - - /** - * Creates a new instance of BeanMapHandler. The value of the first column - * of each row will be a key in the Map. - * - * @param type - * The Class that objects returned from <code>createRow()</code> - * are created from. - */ - public BeanMapHandler(Class<V> type) { - this(type, ArrayHandler.ROW_PROCESSOR, 1, null); - } - - /** - * Creates a new instance of BeanMapHandler. The value of the first column - * of each row will be a key in the Map. - * - * @param type - * The Class that objects returned from <code>createRow()</code> - * are created from. - * @param convert - * The <code>RowProcessor</code> implementation to use when - * converting rows into Beans - */ - public BeanMapHandler(Class<V> type, RowProcessor convert) { - this(type, convert, 1, null); - } - - /** - * Creates a new instance of BeanMapHandler. - * - * @param type - * The Class that objects returned from <code>createRow()</code> - * are created from. - * @param columnIndex - * The values to use as keys in the Map are retrieved from the - * column at this index. - */ - public BeanMapHandler(Class<V> type, int columnIndex) { - this(type, ArrayHandler.ROW_PROCESSOR, columnIndex, null); - } - - /** - * Creates a new instance of BeanMapHandler. - * - * @param type - * The Class that objects returned from <code>createRow()</code> - * are created from. - * @param columnName - * The values to use as keys in the Map are retrieved from the - * column with this name. - */ - public BeanMapHandler(Class<V> type, String columnName) { - this(type, ArrayHandler.ROW_PROCESSOR, 1, columnName); - } - - /** - * Private Helper - * - * @param convert - * The <code>RowProcessor</code> implementation to use when - * converting rows into Beans - * @param columnIndex - * The values to use as keys in the Map are retrieved from the - * column at this index. - * @param columnName - * The values to use as keys in the Map are retrieved from the - * column with this name. - */ - private BeanMapHandler(Class<V> type, RowProcessor convert, - int columnIndex, String columnName) { - super(); - this.type = type; - this.convert = convert; - this.columnIndex = columnIndex; - this.columnName = columnName; - } - - /** - * This factory method is called by <code>handle()</code> to retrieve the - * key value from the current <code>ResultSet</code> row. - * @param rs ResultSet to create a key from - * - * @return K from the configured key column name/index - * - * @throws SQLException if a database access error occurs - * @throws ClassCastException if the class datatype does not match the column type - * - * @see org.apache.commons.dbutils.handlers.AbstractKeyedHandler#createKey(ResultSet) - */ - // We assume that the user has picked the correct type to match the column - // so getObject will return the appropriate type and the cast will succeed. - @SuppressWarnings("unchecked") - @Override - protected K createKey(ResultSet rs) throws SQLException { - return (columnName == null) ? - (K) rs.getObject(columnIndex) : - (K) rs.getObject(columnName); - } - - @Override - protected V createRow(ResultSet rs) throws SQLException { - return this.convert.toBean(rs, type); - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java b/src/main/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java deleted file mode 100644 index 4f3e506..0000000 --- a/src/main/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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.handlers; - -import java.sql.ResultSet; -import java.sql.SQLException; - -/** - * <code>ResultSetHandler</code> implementation that converts one - * <code>ResultSet</code> column into a <code>List</code> of - * <code>Object</code>s. This class is thread safe. - * - * @param <T> The type of the column. - * @see org.apache.commons.dbutils.ResultSetHandler - * @since DbUtils 1.1 - */ -public class ColumnListHandler<T> extends AbstractListHandler<T> { - - /** - * The column number to retrieve. - */ - private final int columnIndex; - - /** - * The column name to retrieve. Either columnName or columnIndex - * will be used but never both. - */ - private final String columnName; - - /** - * Creates a new instance of ColumnListHandler. The first column of each - * row will be returned from <code>handle()</code>. - */ - public ColumnListHandler() { - this(1, null); - } - - /** - * Creates a new instance of ColumnListHandler. - * - * @param columnIndex The index of the column to retrieve from the - * <code>ResultSet</code>. - */ - public ColumnListHandler(int columnIndex) { - this(columnIndex, null); - } - - /** - * Creates a new instance of ColumnListHandler. - * - * @param columnName The name of the column to retrieve from the - * <code>ResultSet</code>. - */ - public ColumnListHandler(String columnName) { - this(1, columnName); - } - - /** Private Helper - * @param columnIndex The index of the column to retrieve from the - * <code>ResultSet</code>. - * @param columnName The name of the column to retrieve from the - * <code>ResultSet</code>. - */ - private ColumnListHandler(int columnIndex, String columnName) { - super(); - this.columnIndex = columnIndex; - this.columnName = columnName; - } - - /** - * Returns one <code>ResultSet</code> column value as <code>Object</code>. - * @param rs <code>ResultSet</code> to process. - * @return <code>Object</code>, never <code>null</code>. - * - * @throws SQLException if a database access error occurs - * @throws ClassCastException if the class datatype does not match the column type - * - * @see org.apache.commons.dbutils.handlers.AbstractListHandler#handle(ResultSet) - */ - // We assume that the user has picked the correct type to match the column - // so getObject will return the appropriate type and the cast will succeed. - @SuppressWarnings("unchecked") - @Override - protected T handleRow(ResultSet rs) throws SQLException { - if (this.columnName == null) { - return (T) rs.getObject(this.columnIndex); - } - return (T) rs.getObject(this.columnName); - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/handlers/KeyedHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/handlers/KeyedHandler.java b/src/main/java/org/apache/commons/dbutils/handlers/KeyedHandler.java deleted file mode 100644 index 6ef9bbe..0000000 --- a/src/main/java/org/apache/commons/dbutils/handlers/KeyedHandler.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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.handlers; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Map; - -import org.apache.commons.dbutils.RowProcessor; - -/** - * <p> - * <code>ResultSetHandler</code> implementation that returns a Map of Maps. - * <code>ResultSet</code> rows are converted into Maps which are then stored - * in a Map under the given key. - * </p> - * <p> - * If you had a Person table with a primary key column called ID, you could - * retrieve rows from the table like this: - * <pre> - * ResultSetHandler h = new KeyedHandler("id"); - * Map found = (Map) queryRunner.query("select id, name, age from person", h); - * Map jane = (Map) found.get(new Long(1)); // jane's id is 1 - * String janesName = (String) jane.get("name"); - * Integer janesAge = (Integer) jane.get("age"); - * </pre> - * Note that the "id" passed to KeyedHandler and "name" and "age" passed to the - * returned Map's get() method can be in any case. The data types returned for - * name and age are dependent upon how your JDBC driver converts SQL column - * types from the Person table into Java types. - * </p> - * <p>This class is thread safe.</p> - * - * @param <K> The type of the key - * @see org.apache.commons.dbutils.ResultSetHandler - * @since DbUtils 1.1 - */ -public class KeyedHandler<K> extends AbstractKeyedHandler<K, Map<String, Object>> { - - /** - * The RowProcessor implementation to use when converting rows - * into Objects. - */ - protected final RowProcessor convert; - - /** - * The column index to retrieve key values from. Defaults to 1. - */ - protected final int columnIndex; - - /** - * The column name to retrieve key values from. Either columnName or - * columnIndex will be used but never both. - */ - protected final String columnName; - - /** - * Creates a new instance of KeyedHandler. The value of the first column - * of each row will be a key in the Map. - */ - public KeyedHandler() { - this(ArrayHandler.ROW_PROCESSOR, 1, null); - } - - /** - * Creates a new instance of KeyedHandler. The value of the first column - * of each row will be a key in the Map. - * - * @param convert The <code>RowProcessor</code> implementation - * to use when converting rows into Maps - */ - public KeyedHandler(RowProcessor convert) { - this(convert, 1, null); - } - - /** - * Creates a new instance of KeyedHandler. - * - * @param columnIndex The values to use as keys in the Map are - * retrieved from the column at this index. - */ - public KeyedHandler(int columnIndex) { - this(ArrayHandler.ROW_PROCESSOR, columnIndex, null); - } - - /** - * Creates a new instance of KeyedHandler. - * - * @param columnName The values to use as keys in the Map are - * retrieved from the column with this name. - */ - public KeyedHandler(String columnName) { - this(ArrayHandler.ROW_PROCESSOR, 1, columnName); - } - - /** Private Helper - * @param convert The <code>RowProcessor</code> implementation - * to use when converting rows into Maps - * @param columnIndex The values to use as keys in the Map are - * retrieved from the column at this index. - * @param columnName The values to use as keys in the Map are - * retrieved from the column with this name. - */ - private KeyedHandler(RowProcessor convert, int columnIndex, - String columnName) { - super(); - this.convert = convert; - this.columnIndex = columnIndex; - this.columnName = columnName; - } - /** - * This factory method is called by <code>handle()</code> to retrieve the - * key value from the current <code>ResultSet</code> row. This - * implementation returns <code>ResultSet.getObject()</code> for the - * configured key column name or index. - * @param rs ResultSet to create a key from - * @return Object from the configured key column name/index - * - * @throws SQLException if a database access error occurs - * @throws ClassCastException if the class datatype does not match the column type - */ - // We assume that the user has picked the correct type to match the column - // so getObject will return the appropriate type and the cast will succeed. - @SuppressWarnings("unchecked") - @Override - protected K createKey(ResultSet rs) throws SQLException { - return (columnName == null) ? - (K) rs.getObject(columnIndex) : - (K) rs.getObject(columnName); - } - - /** - * This factory method is called by <code>handle()</code> to store the - * current <code>ResultSet</code> row in some object. This - * implementation returns a <code>Map</code> with case insensitive column - * names as keys. Calls to <code>map.get("COL")</code> and - * <code>map.get("col")</code> return the same value. - * @param rs ResultSet to create a row from - * @return Object typed Map containing column names to values - * @throws SQLException if a database access error occurs - */ - @Override - protected Map<String, Object> createRow(ResultSet rs) throws SQLException { - return this.convert.toMap(rs); - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/handlers/MapHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/handlers/MapHandler.java b/src/main/java/org/apache/commons/dbutils/handlers/MapHandler.java deleted file mode 100644 index db00345..0000000 --- a/src/main/java/org/apache/commons/dbutils/handlers/MapHandler.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.handlers; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Map; - -import org.apache.commons.dbutils.ResultSetHandler; -import org.apache.commons.dbutils.RowProcessor; - -/** - * <code>ResultSetHandler</code> implementation that converts the first - * <code>ResultSet</code> row into a <code>Map</code>. This class is thread - * safe. - * - * @see org.apache.commons.dbutils.ResultSetHandler - */ -public class MapHandler implements ResultSetHandler<Map<String, Object>> { - - /** - * The RowProcessor implementation to use when converting rows - * into Maps. - */ - private final RowProcessor convert; - - /** - * Creates a new instance of MapHandler using a - * <code>BasicRowProcessor</code> for conversion. - */ - public MapHandler() { - this(ArrayHandler.ROW_PROCESSOR); - } - - /** - * Creates a new instance of MapHandler. - * - * @param convert The <code>RowProcessor</code> implementation - * to use when converting rows into Maps. - */ - public MapHandler(RowProcessor convert) { - super(); - this.convert = convert; - } - - /** - * Converts the first row in the <code>ResultSet</code> into a - * <code>Map</code>. - * @param rs <code>ResultSet</code> to process. - * @return A <code>Map</code> with the values from the first row or - * <code>null</code> if there are no rows in the <code>ResultSet</code>. - * - * @throws SQLException if a database access error occurs - * - * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet) - */ - @Override - public Map<String, Object> handle(ResultSet rs) throws SQLException { - return rs.next() ? this.convert.toMap(rs) : null; - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/handlers/MapListHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/handlers/MapListHandler.java b/src/main/java/org/apache/commons/dbutils/handlers/MapListHandler.java deleted file mode 100644 index a055f2a..0000000 --- a/src/main/java/org/apache/commons/dbutils/handlers/MapListHandler.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.handlers; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Map; - -import org.apache.commons.dbutils.RowProcessor; - -/** - * <code>ResultSetHandler</code> implementation that converts a - * <code>ResultSet</code> into a <code>List</code> of <code>Map</code>s. - * This class is thread safe. - * - * @see org.apache.commons.dbutils.ResultSetHandler - */ -public class MapListHandler extends AbstractListHandler<Map<String, Object>> { - - /** - * The RowProcessor implementation to use when converting rows - * into Maps. - */ - private final RowProcessor convert; - - /** - * Creates a new instance of MapListHandler using a - * <code>BasicRowProcessor</code> for conversion. - */ - public MapListHandler() { - this(ArrayHandler.ROW_PROCESSOR); - } - - /** - * Creates a new instance of MapListHandler. - * - * @param convert The <code>RowProcessor</code> implementation - * to use when converting rows into Maps. - */ - public MapListHandler(RowProcessor convert) { - super(); - this.convert = convert; - } - - /** - * Converts the <code>ResultSet</code> row into a <code>Map</code> object. - * @param rs <code>ResultSet</code> to process. - * @return A <code>Map</code>, never null. - * - * @throws SQLException if a database access error occurs - * - * @see org.apache.commons.dbutils.handlers.AbstractListHandler#handle(ResultSet) - */ - @Override - protected Map<String, Object> handleRow(ResultSet rs) throws SQLException { - return this.convert.toMap(rs); - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/handlers/ScalarHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/handlers/ScalarHandler.java b/src/main/java/org/apache/commons/dbutils/handlers/ScalarHandler.java deleted file mode 100644 index 4b70604..0000000 --- a/src/main/java/org/apache/commons/dbutils/handlers/ScalarHandler.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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.handlers; - -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.apache.commons.dbutils.ResultSetHandler; - -/** - * <code>ResultSetHandler</code> implementation that converts one - * <code>ResultSet</code> column into an Object. This class is thread safe. - * - * @param <T> The type of the scalar - * @see org.apache.commons.dbutils.ResultSetHandler - */ -public class ScalarHandler<T> implements ResultSetHandler<T> { - - /** - * The column number to retrieve. - */ - private final int columnIndex; - - /** - * The column name to retrieve. Either columnName or columnIndex - * will be used but never both. - */ - private final String columnName; - - /** - * Creates a new instance of ScalarHandler. The first column will - * be returned from <code>handle()</code>. - */ - public ScalarHandler() { - this(1, null); - } - - /** - * Creates a new instance of ScalarHandler. - * - * @param columnIndex The index of the column to retrieve from the - * <code>ResultSet</code>. - */ - public ScalarHandler(int columnIndex) { - this(columnIndex, null); - } - - /** - * Creates a new instance of ScalarHandler. - * - * @param columnName The name of the column to retrieve from the - * <code>ResultSet</code>. - */ - public ScalarHandler(String columnName) { - this(1, columnName); - } - - /** Helper constructor - * @param columnIndex The index of the column to retrieve from the - * <code>ResultSet</code>. - * @param columnName The name of the column to retrieve from the - * <code>ResultSet</code>. - */ - private ScalarHandler(int columnIndex, String columnName) { - this.columnIndex = columnIndex; - this.columnName = columnName; - } - - /** - * Returns one <code>ResultSet</code> column as an object via the - * <code>ResultSet.getObject()</code> method that performs type - * conversions. - * @param rs <code>ResultSet</code> to process. - * @return The column or <code>null</code> if there are no rows in - * the <code>ResultSet</code>. - * - * @throws SQLException if a database access error occurs - * @throws ClassCastException if the class datatype does not match the column type - * - * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet) - */ - // We assume that the user has picked the correct type to match the column - // so getObject will return the appropriate type and the cast will succeed. - @SuppressWarnings("unchecked") - @Override - public T handle(ResultSet rs) throws SQLException { - - if (rs.next()) { - if (this.columnName == null) { - return (T) rs.getObject(this.columnIndex); - } - return (T) rs.getObject(this.columnName); - } - return null; - } -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/handlers/package-info.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/handlers/package-info.java b/src/main/java/org/apache/commons/dbutils/handlers/package-info.java deleted file mode 100644 index 5a3b16a..0000000 --- a/src/main/java/org/apache/commons/dbutils/handlers/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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. - */ - -/** - * Implementations of the org.apache.commons.dbutils.ResultSetHandler interface. - */ -package org.apache.commons.dbutils.handlers; http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/package-info.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/package-info.java b/src/main/java/org/apache/commons/dbutils/package-info.java deleted file mode 100644 index ad08013..0000000 --- a/src/main/java/org/apache/commons/dbutils/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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. - */ - -/** - * DbUtils is a small set of classes designed to make working with JDBC easier. JDBC resource cleanup code is mundane, - * error prone work so these classes abstract out all of the cleanup tasks from your code leaving you with what you - * really wanted to do with JDBC in the first place: query and update data. - * - * This package contains the core classes and interfaces - DbUtils, QueryRunner and the ResultSetHandler interface - * should be your first items of interest. - */ -package org.apache.commons.dbutils; http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java b/src/main/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java deleted file mode 100644 index a83735c..0000000 --- a/src/main/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java +++ /dev/null @@ -1,608 +0,0 @@ -/* - * 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.wrappers; - -import java.io.InputStream; -import java.io.Reader; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.Date; -import java.sql.Ref; -import java.sql.ResultSet; -import java.sql.Time; -import java.sql.Timestamp; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.dbutils.ProxyFactory; - -/** - * Decorates a <code>ResultSet</code> with checks for a SQL NULL value on each - * <code>getXXX</code> method. If a column value obtained by a - * <code>getXXX</code> method is not SQL NULL, the column value is returned. If - * the column value is SQL null, an alternate value is returned. The alternate - * value defaults to the Java <code>null</code> value, which can be overridden - * for instances of the class. - * - * <p> - * Usage example: - * <blockquote> - * <pre> - * Connection conn = // somehow get a connection - * Statement stmt = conn.createStatement(); - * ResultSet rs = stmt.executeQuery("SELECT col1, col2 FROM table1"); - * - * // Wrap the result set for SQL NULL checking - * SqlNullCheckedResultSet wrapper = new SqlNullCheckedResultSet(rs); - * wrapper.setNullString("---N/A---"); // Set null string - * wrapper.setNullInt(-999); // Set null integer - * rs = ProxyFactory.instance().createResultSet(wrapper); - * - * while (rs.next()) { - * // If col1 is SQL NULL, value returned will be "---N/A---" - * String col1 = rs.getString("col1"); - * // If col2 is SQL NULL, value returned will be -999 - * int col2 = rs.getInt("col2"); - * } - * rs.close(); - * </pre> - * </blockquote> - * </p> - * <p>Unlike some other classes in DbUtils, this class is NOT thread-safe.</p> - */ -public class SqlNullCheckedResultSet implements InvocationHandler { - - /** - * Maps normal method names (ie. "getBigDecimal") to the corresponding null - * Method object (ie. getNullBigDecimal). - */ - private static final Map<String, Method> nullMethods = new HashMap<String, Method>(); - - /** - * The {@code getNull} string prefix. - * @since 1.4 - */ - private static final String GET_NULL_PREFIX = "getNull"; - - static { - Method[] methods = SqlNullCheckedResultSet.class.getMethods(); - for (int i = 0; i < methods.length; i++) { - String methodName = methods[i].getName(); - - if (methodName.startsWith(GET_NULL_PREFIX)) { - String normalName = "get" + methodName.substring(GET_NULL_PREFIX.length()); - nullMethods.put(normalName, methods[i]); - } - } - } - - /** - * The factory to create proxies with. - */ - private static final ProxyFactory factory = ProxyFactory.instance(); - - /** - * Wraps the <code>ResultSet</code> in an instance of this class. This is - * equivalent to: - * <pre> - * ProxyFactory.instance().createResultSet(new SqlNullCheckedResultSet(rs)); - * </pre> - * - * @param rs The <code>ResultSet</code> to wrap. - * @return wrapped ResultSet - */ - public static ResultSet wrap(ResultSet rs) { - return factory.createResultSet(new SqlNullCheckedResultSet(rs)); - } - - private InputStream nullAsciiStream = null; - private BigDecimal nullBigDecimal = null; - private InputStream nullBinaryStream = null; - private Blob nullBlob = null; - private boolean nullBoolean = false; - private byte nullByte = 0; - private byte[] nullBytes = null; - private Reader nullCharacterStream = null; - private Clob nullClob = null; - private Date nullDate = null; - private double nullDouble = 0.0; - private float nullFloat = 0.0f; - private int nullInt = 0; - private long nullLong = 0; - private Object nullObject = null; - private Ref nullRef = null; - private short nullShort = 0; - private String nullString = null; - private Time nullTime = null; - private Timestamp nullTimestamp = null; - private URL nullURL = null; - - /** - * The wrapped result. - */ - private final ResultSet rs; - - /** - * Constructs a new instance of - * <code>SqlNullCheckedResultSet</code> - * to wrap the specified <code>ResultSet</code>. - * @param rs ResultSet to wrap - */ - public SqlNullCheckedResultSet(ResultSet rs) { - super(); - this.rs = rs; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getAsciiStream</code> method. - * - * @return the value - */ - public InputStream getNullAsciiStream() { - return this.nullAsciiStream; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getBigDecimal</code> method. - * - * @return the value - */ - public BigDecimal getNullBigDecimal() { - return this.nullBigDecimal; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getBinaryStream</code> method. - * - * @return the value - */ - public InputStream getNullBinaryStream() { - return this.nullBinaryStream; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getBlob</code> method. - * - * @return the value - */ - public Blob getNullBlob() { - return this.nullBlob; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getBoolean</code> method. - * - * @return the value - */ - public boolean getNullBoolean() { - return this.nullBoolean; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getByte</code> method. - * - * @return the value - */ - public byte getNullByte() { - return this.nullByte; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getBytes</code> method. - * - * @return the value - */ - public byte[] getNullBytes() { - if (this.nullBytes == null) { - return null; - } - byte[] copy = new byte[this.nullBytes.length]; - System.arraycopy(this.nullBytes, 0, copy, 0, this.nullBytes.length); - return copy; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getCharacterStream</code> method. - * - * @return the value - */ - public Reader getNullCharacterStream() { - return this.nullCharacterStream; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getClob</code> method. - * - * @return the value - */ - public Clob getNullClob() { - return this.nullClob; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getDate</code> method. - * - * @return the value - */ - public Date getNullDate() { - return this.nullDate; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getDouble</code> method. - * - * @return the value - */ - public double getNullDouble() { - return this.nullDouble; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getFloat</code> method. - * - * @return the value - */ - public float getNullFloat() { - return this.nullFloat; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getInt</code> method. - * - * @return the value - */ - public int getNullInt() { - return this.nullInt; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getLong</code> method. - * - * @return the value - */ - public long getNullLong() { - return this.nullLong; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getObject</code> method. - * - * @return the value - */ - public Object getNullObject() { - return this.nullObject; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getRef</code> method. - * - * @return the value - */ - public Ref getNullRef() { - return this.nullRef; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getShort</code> method. - * - * @return the value - */ - public short getNullShort() { - return this.nullShort; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getString</code> method. - * - * @return the value - */ - public String getNullString() { - return this.nullString; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getTime</code> method. - * - * @return the value - */ - public Time getNullTime() { - return this.nullTime; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getTimestamp</code> method. - * - * @return the value - */ - public Timestamp getNullTimestamp() { - return this.nullTimestamp; - } - - /** - * Returns the value when a SQL null is encountered as the result of - * invoking a <code>getURL</code> method. - * - * @return the value - */ - public URL getNullURL() { - return this.nullURL; - } - - /** - * Intercepts calls to <code>get*</code> methods and calls the appropriate - * <code>getNull*</code> method if the <code>ResultSet</code> returned - * <code>null</code>. - * - * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) - * @param proxy Not used; all method calls go to the internal result set - * @param method The method to invoke on the result set - * @param args The arguments to pass to the result set - * @return null checked result - * @throws Throwable error - */ - @Override - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { - - Object result = method.invoke(this.rs, args); - - Method nullMethod = nullMethods.get(method.getName()); - - // Check nullMethod != null first so that we don't call wasNull() - // before a true getter method was invoked on the ResultSet. - return (nullMethod != null && this.rs.wasNull()) - ? nullMethod.invoke(this, (Object[]) null) - : result; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getAsciiStream</code> method. - * - * @param nullAsciiStream the value - */ - public void setNullAsciiStream(InputStream nullAsciiStream) { - this.nullAsciiStream = nullAsciiStream; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getBigDecimal</code> method. - * - * @param nullBigDecimal the value - */ - public void setNullBigDecimal(BigDecimal nullBigDecimal) { - this.nullBigDecimal = nullBigDecimal; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getBinaryStream</code> method. - * - * @param nullBinaryStream the value - */ - public void setNullBinaryStream(InputStream nullBinaryStream) { - this.nullBinaryStream = nullBinaryStream; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getBlob</code> method. - * - * @param nullBlob the value - */ - public void setNullBlob(Blob nullBlob) { - this.nullBlob = nullBlob; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getBoolean</code> method. - * - * @param nullBoolean the value - */ - public void setNullBoolean(boolean nullBoolean) { - this.nullBoolean = nullBoolean; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getByte</code> method. - * - * @param nullByte the value - */ - public void setNullByte(byte nullByte) { - this.nullByte = nullByte; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getBytes</code> method. - * - * @param nullBytes the value - */ - public void setNullBytes(byte[] nullBytes) { - byte[] copy = new byte[nullBytes.length]; - System.arraycopy(nullBytes, 0, copy, 0, nullBytes.length); - this.nullBytes = copy; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getCharacterStream</code> method. - * - * @param nullCharacterStream the value - */ - public void setNullCharacterStream(Reader nullCharacterStream) { - this.nullCharacterStream = nullCharacterStream; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getClob</code> method. - * - * @param nullClob the value - */ - public void setNullClob(Clob nullClob) { - this.nullClob = nullClob; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getDate</code> method. - * - * @param nullDate the value - */ - public void setNullDate(Date nullDate) { - this.nullDate = nullDate; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getDouble</code> method. - * - * @param nullDouble the value - */ - public void setNullDouble(double nullDouble) { - this.nullDouble = nullDouble; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getFloat</code> method. - * - * @param nullFloat the value - */ - public void setNullFloat(float nullFloat) { - this.nullFloat = nullFloat; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getInt</code> method. - * - * @param nullInt the value - */ - public void setNullInt(int nullInt) { - this.nullInt = nullInt; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getLong</code> method. - * - * @param nullLong the value - */ - public void setNullLong(long nullLong) { - this.nullLong = nullLong; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getObject</code> method. - * - * @param nullObject the value - */ - public void setNullObject(Object nullObject) { - this.nullObject = nullObject; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getRef</code> method. - * - * @param nullRef the value - */ - public void setNullRef(Ref nullRef) { - this.nullRef = nullRef; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getShort</code> method. - * - * @param nullShort the value - */ - public void setNullShort(short nullShort) { - this.nullShort = nullShort; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getString</code> method. - * - * @param nullString the value - */ - public void setNullString(String nullString) { - this.nullString = nullString; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getTime</code> method. - * - * @param nullTime the value - */ - public void setNullTime(Time nullTime) { - this.nullTime = nullTime; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getTimestamp</code> method. - * - * @param nullTimestamp the value - */ - public void setNullTimestamp(Timestamp nullTimestamp) { - this.nullTimestamp = nullTimestamp; - } - - /** - * Sets the value to return when a SQL null is encountered as the result of - * invoking a <code>getURL</code> method. - * - * @param nullURL the value - */ - public void setNullURL(URL nullURL) { - this.nullURL = nullURL; - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/wrappers/StringTrimmedResultSet.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/wrappers/StringTrimmedResultSet.java b/src/main/java/org/apache/commons/dbutils/wrappers/StringTrimmedResultSet.java deleted file mode 100644 index 830ef72..0000000 --- a/src/main/java/org/apache/commons/dbutils/wrappers/StringTrimmedResultSet.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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.wrappers; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.sql.ResultSet; - -import org.apache.commons.dbutils.ProxyFactory; - -/** - * Wraps a <code>ResultSet</code> to trim strings returned by the - * <code>getString()</code> and <code>getObject()</code> methods. - * - * <p> - * Usage Example: - * This example shows how to decorate ResultSets so processing continues as - * normal but all Strings are trimmed before being returned from the - * <code>ResultSet</code>. - * </p> - * - * <pre> - * ResultSet rs = // somehow get a ResultSet; - * - * // Substitute wrapped ResultSet with additional behavior for real ResultSet - * rs = StringTrimmedResultSet.wrap(rs); - * - * // Pass wrapped ResultSet to processor - * List list = new BasicRowProcessor().toBeanList(rs); - * </pre> - */ -public class StringTrimmedResultSet implements InvocationHandler { - - /** - * The factory to create proxies with. - */ - private static final ProxyFactory factory = ProxyFactory.instance(); - - /** - * Wraps the <code>ResultSet</code> in an instance of this class. This is - * equivalent to: - * <pre> - * ProxyFactory.instance().createResultSet(new StringTrimmedResultSet(rs)); - * </pre> - * - * @param rs The <code>ResultSet</code> to wrap. - * @return wrapped ResultSet - */ - public static ResultSet wrap(ResultSet rs) { - return factory.createResultSet(new StringTrimmedResultSet(rs)); - } - - /** - * The wrapped result. - */ - private final ResultSet rs; - - /** - * Constructs a new instance of <code>StringTrimmedResultSet</code> - * to wrap the specified <code>ResultSet</code>. - * @param rs ResultSet to wrap - */ - public StringTrimmedResultSet(ResultSet rs) { - super(); - this.rs = rs; - } - - /** - * Intercept calls to the <code>getString()</code> and - * <code>getObject()</code> methods and trim any Strings before they're - * returned. - * - * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) - * @param proxy Not used; all method calls go to the internal result set - * @param method The method to invoke on the result set - * @param args The arguments to pass to the result set - * @return string trimmed result - * @throws Throwable error - */ - @Override - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { - - Object result = method.invoke(this.rs, args); - - if ((method.getName().equals("getObject") - || method.getName().equals("getString")) - && result instanceof String) { - result = ((String) result).trim(); - } - - return result; - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/main/java/org/apache/commons/dbutils/wrappers/package-info.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils/wrappers/package-info.java b/src/main/java/org/apache/commons/dbutils/wrappers/package-info.java deleted file mode 100644 index 70ef2aa..0000000 --- a/src/main/java/org/apache/commons/dbutils/wrappers/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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. - */ - -/** - * Wrappers that add functionality to java.sql classes. - */ -package org.apache.commons.dbutils.wrappers;
