commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wspe...@apache.org
Subject svn commit: r1205492 - in /commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers: ColumnListHandler.java KeyedHandler.java ScalarHandler.java
Date Wed, 23 Nov 2011 17:06:28 GMT
Author: wspeirs
Date: Wed Nov 23 17:06:27 2011
New Revision: 1205492

URL: http://svn.apache.org/viewvc?rev=1205492&view=rev
Log:
- Added generics to a few handlers: patch from DBUTILS-66

Modified:
    commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java
    commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/KeyedHandler.java
    commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/ScalarHandler.java

Modified: commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java?rev=1205492&r1=1205491&r2=1205492&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java
(original)
+++ commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java
Wed Nov 23 17:06:27 2011
@@ -24,10 +24,11 @@ import java.sql.SQLException;
  * <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 extends AbstractListHandler<Object> {
+public class ColumnListHandler<T> extends AbstractListHandler<T> {
 
     /**
      * The column number to retrieve.
@@ -90,11 +91,11 @@ public class ColumnListHandler extends A
      * @see org.apache.commons.dbutils.handlers.AbstractListHandler#handle(ResultSet)
      */
     @Override
-    protected Object handleRow(ResultSet rs) throws SQLException {
+    protected T handleRow(ResultSet rs) throws SQLException {
         if (this.columnName == null) {
-            return rs.getObject(this.columnIndex);
+            return (T) rs.getObject(this.columnIndex);
         } else {
-            return rs.getObject(this.columnName);
+            return (T) rs.getObject(this.columnName);
         }
    }
 

Modified: commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/KeyedHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/KeyedHandler.java?rev=1205492&r1=1205491&r2=1205492&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/KeyedHandler.java
(original)
+++ commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/KeyedHandler.java
Wed Nov 23 17:06:27 2011
@@ -45,10 +45,11 @@ import org.apache.commons.dbutils.RowPro
  * </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 extends AbstractKeyedHandler<Object, Map<String, Object>>
{
+public class KeyedHandler<K> extends AbstractKeyedHandler<K, Map<String, Object>>
{
 
     /**
      * The RowProcessor implementation to use when converting rows
@@ -131,9 +132,10 @@ public class KeyedHandler extends Abstra
      * @throws SQLException if a database access error occurs
      */
     @Override
-    protected Object createKey(ResultSet rs) throws SQLException {
-        return (columnName == null) ? rs.getObject(columnIndex) : rs
-                .getObject(columnName);
+    protected K createKey(ResultSet rs) throws SQLException {
+        return (columnName == null) ?
+               (K) rs.getObject(columnIndex) :
+               (K) rs.getObject(columnName);
     }
 
     /**

Modified: commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/ScalarHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/ScalarHandler.java?rev=1205492&r1=1205491&r2=1205492&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/ScalarHandler.java
(original)
+++ commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/ScalarHandler.java
Wed Nov 23 17:06:27 2011
@@ -25,9 +25,10 @@ import org.apache.commons.dbutils.Result
  * <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 implements ResultSetHandler<Object> {
+public class ScalarHandler<T> implements ResultSetHandler<T> {
 
     /**
      * The column number to retrieve.
@@ -91,13 +92,13 @@ public class ScalarHandler implements Re
      *
      * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet)
      */
-    public Object handle(ResultSet rs) throws SQLException {
+    public T handle(ResultSet rs) throws SQLException {
 
         if (rs.next()) {
             if (this.columnName == null) {
-                return rs.getObject(this.columnIndex);
+                return (T) rs.getObject(this.columnIndex);
             } else {
-                return rs.getObject(this.columnName);
+                return (T) rs.getObject(this.columnName);
             }
 
         } else {



Mime
View raw message