You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by th...@apache.org on 2015/04/13 23:19:23 UTC

svn commit: r1673285 - in /commons/proper/dbutils/trunk/src: main/java/org/apache/commons/dbutils/ main/java/org/apache/commons/dbutils/handlers/ test/java/org/apache/commons/dbutils/handlers/

Author: thecarlhall
Date: Mon Apr 13 21:19:22 2015
New Revision: 1673285

URL: http://svn.apache.org/r1673285
Log:
DBUTILS-82 Applied user-submitted patch and made minor fixes

Modified:
    commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java
    commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
    commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/RowProcessor.java
    commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java
    commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
    commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java
    commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java

Modified: commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java?rev=1673285&r1=1673284&r2=1673285&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java (original)
+++ commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java Mon Apr 13 21:19:22 2015
@@ -119,7 +119,7 @@ public class BasicRowProcessor implement
      * @return the newly created bean
      */
     @Override
-    public <T> T toBean(ResultSet rs, Class<T> type) throws SQLException {
+    public <T> T toBean(ResultSet rs, Class<? extends T> type) throws SQLException {
         return this.convert.toBean(rs, type);
     }
 
@@ -136,7 +136,7 @@ public class BasicRowProcessor implement
      * they were returned by the <code>ResultSet</code>.
      */
     @Override
-    public <T> List<T> toBeanList(ResultSet rs, Class<T> type) throws SQLException {
+    public <T> List<T> toBeanList(ResultSet rs, Class<? extends T> type) throws SQLException {
         return this.convert.toBeanList(rs, type);
     }
 

Modified: commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BeanProcessor.java?rev=1673285&r1=1673284&r2=1673285&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BeanProcessor.java (original)
+++ commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BeanProcessor.java Mon Apr 13 21:19:22 2015
@@ -135,7 +135,7 @@ public class BeanProcessor {
      * @throws SQLException if a database access error occurs
      * @return the newly created bean
      */
-    public <T> T toBean(ResultSet rs, Class<T> type) throws SQLException {
+    public <T> T toBean(ResultSet rs, Class<? extends T> type) throws SQLException {
 
         PropertyDescriptor[] props = this.propertyDescriptors(type);
 
@@ -178,7 +178,7 @@ public class BeanProcessor {
      * @throws SQLException if a database access error occurs
      * @return the newly created List of beans
      */
-    public <T> List<T> toBeanList(ResultSet rs, Class<T> type) throws SQLException {
+    public <T> List<T> toBeanList(ResultSet rs, Class<? extends T> type) throws SQLException {
         List<T> results = new ArrayList<T>();
 
         if (!rs.next()) {

Modified: commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/RowProcessor.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/RowProcessor.java?rev=1673285&r1=1673284&r2=1673285&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/RowProcessor.java (original)
+++ commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/RowProcessor.java Mon Apr 13 21:19:22 2015
@@ -55,7 +55,7 @@ public interface RowProcessor {
      * @throws SQLException if a database access error occurs
      * @return the newly created bean
      */
-    <T> T toBean(ResultSet rs, Class<T> type) throws SQLException;
+    <T> T toBean(ResultSet rs, Class<? extends T> type) throws SQLException;
 
     /**
      * Create a <code>List</code> of JavaBeans from the column values in all
@@ -68,7 +68,7 @@ public interface RowProcessor {
      * @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;
+    <T> List<T> toBeanList(ResultSet rs, Class<? extends T> type) throws SQLException;
 
     /**
      * Create a <code>Map</code> from the column values in one

Modified: commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java?rev=1673285&r1=1673284&r2=1673285&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java (original)
+++ commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java Mon Apr 13 21:19:22 2015
@@ -34,7 +34,7 @@ public class BeanHandler<T> implements R
     /**
      * The Class of beans produced by this handler.
      */
-    private final Class<T> type;
+    private final Class<? extends T> type;
 
     /**
      * The RowProcessor implementation to use when converting rows
@@ -48,7 +48,7 @@ public class BeanHandler<T> implements R
      * @param type The Class that objects returned from <code>handle()</code>
      * are created from.
      */
-    public BeanHandler(Class<T> type) {
+    public BeanHandler(Class<? extends T> type) {
         this(type, ArrayHandler.ROW_PROCESSOR);
     }
 
@@ -60,7 +60,7 @@ public class BeanHandler<T> implements R
      * @param convert The <code>RowProcessor</code> implementation
      * to use when converting rows into beans.
      */
-    public BeanHandler(Class<T> type, RowProcessor convert) {
+    public BeanHandler(Class<? extends T> type, RowProcessor convert) {
         this.type = type;
         this.convert = convert;
     }

Modified: commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java?rev=1673285&r1=1673284&r2=1673285&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java (original)
+++ commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java Mon Apr 13 21:19:22 2015
@@ -36,7 +36,7 @@ public class BeanListHandler<T> implemen
     /**
      * The Class of beans produced by this handler.
      */
-    private final Class<T> type;
+    private final Class<? extends T> type;
 
     /**
      * The RowProcessor implementation to use when converting rows
@@ -50,7 +50,7 @@ public class BeanListHandler<T> implemen
      * @param type The Class that objects returned from <code>handle()</code>
      * are created from.
      */
-    public BeanListHandler(Class<T> type) {
+    public BeanListHandler(Class<? extends T> type) {
         this(type, ArrayHandler.ROW_PROCESSOR);
     }
 
@@ -62,7 +62,7 @@ public class BeanListHandler<T> implemen
      * @param convert The <code>RowProcessor</code> implementation
      * to use when converting rows into beans.
      */
-    public BeanListHandler(Class<T> type, RowProcessor convert) {
+    public BeanListHandler(Class<? extends T> type, RowProcessor convert) {
         this.type = type;
         this.convert = convert;
     }

Modified: commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java?rev=1673285&r1=1673284&r2=1673285&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java (original)
+++ commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java Mon Apr 13 21:19:22 2015
@@ -45,4 +45,37 @@ public class BeanHandlerTest extends Bas
         assertNull(results);
     }
 
+    public void testHandleToSuperClass() throws SQLException {
+        ResultSetHandler<TestBean> h = new BeanHandler<TestBean>(SubTestBean.class);
+        TestBean results = h.handle(this.rs);
+
+        assertNotNull(results);
+        assertEquals("1", results.getOne());
+        assertEquals("2", results.getTwo());
+        assertEquals(TestBean.Ordinal.THREE, results.getThree());
+        assertEquals("not set", results.getDoNotSet());
+    }
+
+    public void testHandleToInterface() throws SQLException {
+        ResultSetHandler<SubTestBeanInterface> h = new BeanHandler<SubTestBeanInterface>(SubTestBean.class);
+        SubTestBeanInterface results = h.handle(this.rs);
+
+        assertNotNull(results);
+        assertEquals("1", results.getOne());
+        assertEquals("2", results.getTwo());
+        assertEquals(TestBean.Ordinal.THREE, results.getThree());
+        assertEquals("not set", results.getDoNotSet());
+    }
+
+    public static interface SubTestBeanInterface {
+        public String getOne();
+
+        public TestBean.Ordinal getThree();
+
+        public String getTwo();
+
+        public String getDoNotSet();
+    }
+
+    public static class SubTestBean extends TestBean implements SubTestBeanInterface { }
 }

Modified: commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java?rev=1673285&r1=1673284&r2=1673285&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java (original)
+++ commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java Mon Apr 13 21:19:22 2015
@@ -64,4 +64,75 @@ public class BeanListHandlerTest extends
         assertTrue(results.isEmpty());
     }
 
+    public void testHandleToSuperClass() throws SQLException {
+        ResultSetHandler<List<TestBean>> h = new BeanListHandler<TestBean>(SubTestBean.class);
+        List<TestBean> results = h.handle(this.rs);
+
+        assertNotNull(results);
+        assertEquals(ROWS, results.size());
+
+        Iterator<TestBean> iter = results.iterator();
+        TestBean row = null;
+        assertTrue(iter.hasNext());
+        row = iter.next();
+        assertSame(SubTestBean.class, row.getClass());
+
+        assertEquals("1", row.getOne());
+        assertEquals("2", row.getTwo());
+        assertEquals(TestBean.Ordinal.THREE, row.getThree());
+        assertEquals("not set", row.getDoNotSet());
+
+        assertTrue(iter.hasNext());
+        row = iter.next();
+        assertSame(SubTestBean.class, row.getClass());
+
+        assertEquals("4", row.getOne());
+        assertEquals("5", row.getTwo());
+        assertEquals(TestBean.Ordinal.SIX, row.getThree());
+        assertEquals("not set", row.getDoNotSet());
+
+        assertFalse(iter.hasNext());
+    }
+
+    public void testHandleToInterface() throws SQLException {
+        ResultSetHandler<List<SubTestBeanInterface>> h = new BeanListHandler<SubTestBeanInterface>(SubTestBean.class);
+        List<SubTestBeanInterface> results = h.handle(this.rs);
+
+        assertNotNull(results);
+        assertEquals(ROWS, results.size());
+
+        Iterator<SubTestBeanInterface> iter = results.iterator();
+        SubTestBeanInterface row = null;
+        assertTrue(iter.hasNext());
+        row = iter.next();
+        assertSame(SubTestBean.class, row.getClass());
+
+        assertEquals("1", row.getOne());
+        assertEquals("2", row.getTwo());
+        assertEquals(TestBean.Ordinal.THREE, row.getThree());
+        assertEquals("not set", row.getDoNotSet());
+
+        assertTrue(iter.hasNext());
+        row = iter.next();
+        assertSame(SubTestBean.class, row.getClass());
+
+        assertEquals("4", row.getOne());
+        assertEquals("5", row.getTwo());
+        assertEquals(TestBean.Ordinal.SIX, row.getThree());
+        assertEquals("not set", row.getDoNotSet());
+
+        assertFalse(iter.hasNext());
+    }
+
+    public static interface SubTestBeanInterface {
+        public String getOne();
+
+        public TestBean.Ordinal getThree();
+
+        public String getTwo();
+
+        public String getDoNotSet();
+    }
+
+    public static class SubTestBean extends TestBean implements SubTestBeanInterface { }
 }



Re: svn commit: r1673285 - in /commons/proper/dbutils/trunk/src: main/java/org/apache/commons/dbutils/ main/java/org/apache/commons/dbutils/handlers/ test/java/org/apache/commons/dbutils/handlers/

Posted by Carl Hall <th...@apache.org>.
Thanks for the reminder!  I updated changes.xml in a later commit.  I will
try to make the update when the relevant work is committed.

On Tue, Apr 14, 2015 at 8:29 AM, Benedikt Ritter <br...@apache.org> wrote:

> Hello Carl,
>
> please remember to add fixes to changes.xml so it is easier for RMs to
> generate release notes :-)
>
> Thank you!
> Benedikt
>
> 2015-04-13 23:19 GMT+02:00 <th...@apache.org>:
>
> > Author: thecarlhall
> > Date: Mon Apr 13 21:19:22 2015
> > New Revision: 1673285
> >
> > URL: http://svn.apache.org/r1673285
> > Log:
> > DBUTILS-82 Applied user-submitted patch and made minor fixes
> >
> > Modified:
> >
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java
> >
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
> >
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/RowProcessor.java
> >
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java
> >
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
> >
> >
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java
> >
> >
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java
> >
> > Modified:
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java
> > URL:
> >
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java?rev=1673285&r1=1673284&r2=1673285&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java
> > (original)
> > +++
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java
> > Mon Apr 13 21:19:22 2015
> > @@ -119,7 +119,7 @@ public class BasicRowProcessor implement
> >       * @return the newly created bean
> >       */
> >      @Override
> > -    public <T> T toBean(ResultSet rs, Class<T> type) throws
> SQLException {
> > +    public <T> T toBean(ResultSet rs, Class<? extends T> type) throws
> > SQLException {
> >          return this.convert.toBean(rs, type);
> >      }
> >
> > @@ -136,7 +136,7 @@ public class BasicRowProcessor implement
> >       * they were returned by the <code>ResultSet</code>.
> >       */
> >      @Override
> > -    public <T> List<T> toBeanList(ResultSet rs, Class<T> type) throws
> > SQLException {
> > +    public <T> List<T> toBeanList(ResultSet rs, Class<? extends T> type)
> > throws SQLException {
> >          return this.convert.toBeanList(rs, type);
> >      }
> >
> >
> > Modified:
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
> > URL:
> >
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BeanProcessor.java?rev=1673285&r1=1673284&r2=1673285&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
> > (original)
> > +++
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
> > Mon Apr 13 21:19:22 2015
> > @@ -135,7 +135,7 @@ public class BeanProcessor {
> >       * @throws SQLException if a database access error occurs
> >       * @return the newly created bean
> >       */
> > -    public <T> T toBean(ResultSet rs, Class<T> type) throws
> SQLException {
> > +    public <T> T toBean(ResultSet rs, Class<? extends T> type) throws
> > SQLException {
> >
> >          PropertyDescriptor[] props = this.propertyDescriptors(type);
> >
> > @@ -178,7 +178,7 @@ public class BeanProcessor {
> >       * @throws SQLException if a database access error occurs
> >       * @return the newly created List of beans
> >       */
> > -    public <T> List<T> toBeanList(ResultSet rs, Class<T> type) throws
> > SQLException {
> > +    public <T> List<T> toBeanList(ResultSet rs, Class<? extends T> type)
> > throws SQLException {
> >          List<T> results = new ArrayList<T>();
> >
> >          if (!rs.next()) {
> >
> > Modified:
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/RowProcessor.java
> > URL:
> >
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/RowProcessor.java?rev=1673285&r1=1673284&r2=1673285&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/RowProcessor.java
> > (original)
> > +++
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/RowProcessor.java
> > Mon Apr 13 21:19:22 2015
> > @@ -55,7 +55,7 @@ public interface RowProcessor {
> >       * @throws SQLException if a database access error occurs
> >       * @return the newly created bean
> >       */
> > -    <T> T toBean(ResultSet rs, Class<T> type) throws SQLException;
> > +    <T> T toBean(ResultSet rs, Class<? extends T> type) throws
> > SQLException;
> >
> >      /**
> >       * Create a <code>List</code> of JavaBeans from the column values in
> > all
> > @@ -68,7 +68,7 @@ public interface RowProcessor {
> >       * @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;
> > +    <T> List<T> toBeanList(ResultSet rs, Class<? extends T> type) throws
> > SQLException;
> >
> >      /**
> >       * Create a <code>Map</code> from the column values in one
> >
> > Modified:
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java
> > URL:
> >
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java?rev=1673285&r1=1673284&r2=1673285&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java
> > (original)
> > +++
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java
> > Mon Apr 13 21:19:22 2015
> > @@ -34,7 +34,7 @@ public class BeanHandler<T> implements R
> >      /**
> >       * The Class of beans produced by this handler.
> >       */
> > -    private final Class<T> type;
> > +    private final Class<? extends T> type;
> >
> >      /**
> >       * The RowProcessor implementation to use when converting rows
> > @@ -48,7 +48,7 @@ public class BeanHandler<T> implements R
> >       * @param type The Class that objects returned from
> > <code>handle()</code>
> >       * are created from.
> >       */
> > -    public BeanHandler(Class<T> type) {
> > +    public BeanHandler(Class<? extends T> type) {
> >          this(type, ArrayHandler.ROW_PROCESSOR);
> >      }
> >
> > @@ -60,7 +60,7 @@ public class BeanHandler<T> implements R
> >       * @param convert The <code>RowProcessor</code> implementation
> >       * to use when converting rows into beans.
> >       */
> > -    public BeanHandler(Class<T> type, RowProcessor convert) {
> > +    public BeanHandler(Class<? extends T> type, RowProcessor convert) {
> >          this.type = type;
> >          this.convert = convert;
> >      }
> >
> > Modified:
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
> > URL:
> >
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java?rev=1673285&r1=1673284&r2=1673285&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
> > (original)
> > +++
> >
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
> > Mon Apr 13 21:19:22 2015
> > @@ -36,7 +36,7 @@ public class BeanListHandler<T> implemen
> >      /**
> >       * The Class of beans produced by this handler.
> >       */
> > -    private final Class<T> type;
> > +    private final Class<? extends T> type;
> >
> >      /**
> >       * The RowProcessor implementation to use when converting rows
> > @@ -50,7 +50,7 @@ public class BeanListHandler<T> implemen
> >       * @param type The Class that objects returned from
> > <code>handle()</code>
> >       * are created from.
> >       */
> > -    public BeanListHandler(Class<T> type) {
> > +    public BeanListHandler(Class<? extends T> type) {
> >          this(type, ArrayHandler.ROW_PROCESSOR);
> >      }
> >
> > @@ -62,7 +62,7 @@ public class BeanListHandler<T> implemen
> >       * @param convert The <code>RowProcessor</code> implementation
> >       * to use when converting rows into beans.
> >       */
> > -    public BeanListHandler(Class<T> type, RowProcessor convert) {
> > +    public BeanListHandler(Class<? extends T> type, RowProcessor
> convert)
> > {
> >          this.type = type;
> >          this.convert = convert;
> >      }
> >
> > Modified:
> >
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java
> > URL:
> >
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java?rev=1673285&r1=1673284&r2=1673285&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java
> > (original)
> > +++
> >
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java
> > Mon Apr 13 21:19:22 2015
> > @@ -45,4 +45,37 @@ public class BeanHandlerTest extends Bas
> >          assertNull(results);
> >      }
> >
> > +    public void testHandleToSuperClass() throws SQLException {
> > +        ResultSetHandler<TestBean> h = new
> > BeanHandler<TestBean>(SubTestBean.class);
> > +        TestBean results = h.handle(this.rs);
> > +
> > +        assertNotNull(results);
> > +        assertEquals("1", results.getOne());
> > +        assertEquals("2", results.getTwo());
> > +        assertEquals(TestBean.Ordinal.THREE, results.getThree());
> > +        assertEquals("not set", results.getDoNotSet());
> > +    }
> > +
> > +    public void testHandleToInterface() throws SQLException {
> > +        ResultSetHandler<SubTestBeanInterface> h = new
> > BeanHandler<SubTestBeanInterface>(SubTestBean.class);
> > +        SubTestBeanInterface results = h.handle(this.rs);
> > +
> > +        assertNotNull(results);
> > +        assertEquals("1", results.getOne());
> > +        assertEquals("2", results.getTwo());
> > +        assertEquals(TestBean.Ordinal.THREE, results.getThree());
> > +        assertEquals("not set", results.getDoNotSet());
> > +    }
> > +
> > +    public static interface SubTestBeanInterface {
> > +        public String getOne();
> > +
> > +        public TestBean.Ordinal getThree();
> > +
> > +        public String getTwo();
> > +
> > +        public String getDoNotSet();
> > +    }
> > +
> > +    public static class SubTestBean extends TestBean implements
> > SubTestBeanInterface { }
> >  }
> >
> > Modified:
> >
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java
> > URL:
> >
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java?rev=1673285&r1=1673284&r2=1673285&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java
> > (original)
> > +++
> >
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java
> > Mon Apr 13 21:19:22 2015
> > @@ -64,4 +64,75 @@ public class BeanListHandlerTest extends
> >          assertTrue(results.isEmpty());
> >      }
> >
> > +    public void testHandleToSuperClass() throws SQLException {
> > +        ResultSetHandler<List<TestBean>> h = new
> > BeanListHandler<TestBean>(SubTestBean.class);
> > +        List<TestBean> results = h.handle(this.rs);
> > +
> > +        assertNotNull(results);
> > +        assertEquals(ROWS, results.size());
> > +
> > +        Iterator<TestBean> iter = results.iterator();
> > +        TestBean row = null;
> > +        assertTrue(iter.hasNext());
> > +        row = iter.next();
> > +        assertSame(SubTestBean.class, row.getClass());
> > +
> > +        assertEquals("1", row.getOne());
> > +        assertEquals("2", row.getTwo());
> > +        assertEquals(TestBean.Ordinal.THREE, row.getThree());
> > +        assertEquals("not set", row.getDoNotSet());
> > +
> > +        assertTrue(iter.hasNext());
> > +        row = iter.next();
> > +        assertSame(SubTestBean.class, row.getClass());
> > +
> > +        assertEquals("4", row.getOne());
> > +        assertEquals("5", row.getTwo());
> > +        assertEquals(TestBean.Ordinal.SIX, row.getThree());
> > +        assertEquals("not set", row.getDoNotSet());
> > +
> > +        assertFalse(iter.hasNext());
> > +    }
> > +
> > +    public void testHandleToInterface() throws SQLException {
> > +        ResultSetHandler<List<SubTestBeanInterface>> h = new
> > BeanListHandler<SubTestBeanInterface>(SubTestBean.class);
> > +        List<SubTestBeanInterface> results = h.handle(this.rs);
> > +
> > +        assertNotNull(results);
> > +        assertEquals(ROWS, results.size());
> > +
> > +        Iterator<SubTestBeanInterface> iter = results.iterator();
> > +        SubTestBeanInterface row = null;
> > +        assertTrue(iter.hasNext());
> > +        row = iter.next();
> > +        assertSame(SubTestBean.class, row.getClass());
> > +
> > +        assertEquals("1", row.getOne());
> > +        assertEquals("2", row.getTwo());
> > +        assertEquals(TestBean.Ordinal.THREE, row.getThree());
> > +        assertEquals("not set", row.getDoNotSet());
> > +
> > +        assertTrue(iter.hasNext());
> > +        row = iter.next();
> > +        assertSame(SubTestBean.class, row.getClass());
> > +
> > +        assertEquals("4", row.getOne());
> > +        assertEquals("5", row.getTwo());
> > +        assertEquals(TestBean.Ordinal.SIX, row.getThree());
> > +        assertEquals("not set", row.getDoNotSet());
> > +
> > +        assertFalse(iter.hasNext());
> > +    }
> > +
> > +    public static interface SubTestBeanInterface {
> > +        public String getOne();
> > +
> > +        public TestBean.Ordinal getThree();
> > +
> > +        public String getTwo();
> > +
> > +        public String getDoNotSet();
> > +    }
> > +
> > +    public static class SubTestBean extends TestBean implements
> > SubTestBeanInterface { }
> >  }
> >
> >
> >
>
>
> --
> http://people.apache.org/~britter/
> http://www.systemoutprintln.de/
> http://twitter.com/BenediktRitter
> http://github.com/britter
>

Re: svn commit: r1673285 - in /commons/proper/dbutils/trunk/src: main/java/org/apache/commons/dbutils/ main/java/org/apache/commons/dbutils/handlers/ test/java/org/apache/commons/dbutils/handlers/

Posted by Benedikt Ritter <br...@apache.org>.
Hello Carl,

please remember to add fixes to changes.xml so it is easier for RMs to
generate release notes :-)

Thank you!
Benedikt

2015-04-13 23:19 GMT+02:00 <th...@apache.org>:

> Author: thecarlhall
> Date: Mon Apr 13 21:19:22 2015
> New Revision: 1673285
>
> URL: http://svn.apache.org/r1673285
> Log:
> DBUTILS-82 Applied user-submitted patch and made minor fixes
>
> Modified:
>
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java
>
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
>
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/RowProcessor.java
>
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java
>
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
>
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java
>
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java
>
> Modified:
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java?rev=1673285&r1=1673284&r2=1673285&view=diff
>
> ==============================================================================
> ---
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java
> (original)
> +++
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java
> Mon Apr 13 21:19:22 2015
> @@ -119,7 +119,7 @@ public class BasicRowProcessor implement
>       * @return the newly created bean
>       */
>      @Override
> -    public <T> T toBean(ResultSet rs, Class<T> type) throws SQLException {
> +    public <T> T toBean(ResultSet rs, Class<? extends T> type) throws
> SQLException {
>          return this.convert.toBean(rs, type);
>      }
>
> @@ -136,7 +136,7 @@ public class BasicRowProcessor implement
>       * they were returned by the <code>ResultSet</code>.
>       */
>      @Override
> -    public <T> List<T> toBeanList(ResultSet rs, Class<T> type) throws
> SQLException {
> +    public <T> List<T> toBeanList(ResultSet rs, Class<? extends T> type)
> throws SQLException {
>          return this.convert.toBeanList(rs, type);
>      }
>
>
> Modified:
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BeanProcessor.java?rev=1673285&r1=1673284&r2=1673285&view=diff
>
> ==============================================================================
> ---
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
> (original)
> +++
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
> Mon Apr 13 21:19:22 2015
> @@ -135,7 +135,7 @@ public class BeanProcessor {
>       * @throws SQLException if a database access error occurs
>       * @return the newly created bean
>       */
> -    public <T> T toBean(ResultSet rs, Class<T> type) throws SQLException {
> +    public <T> T toBean(ResultSet rs, Class<? extends T> type) throws
> SQLException {
>
>          PropertyDescriptor[] props = this.propertyDescriptors(type);
>
> @@ -178,7 +178,7 @@ public class BeanProcessor {
>       * @throws SQLException if a database access error occurs
>       * @return the newly created List of beans
>       */
> -    public <T> List<T> toBeanList(ResultSet rs, Class<T> type) throws
> SQLException {
> +    public <T> List<T> toBeanList(ResultSet rs, Class<? extends T> type)
> throws SQLException {
>          List<T> results = new ArrayList<T>();
>
>          if (!rs.next()) {
>
> Modified:
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/RowProcessor.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/RowProcessor.java?rev=1673285&r1=1673284&r2=1673285&view=diff
>
> ==============================================================================
> ---
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/RowProcessor.java
> (original)
> +++
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/RowProcessor.java
> Mon Apr 13 21:19:22 2015
> @@ -55,7 +55,7 @@ public interface RowProcessor {
>       * @throws SQLException if a database access error occurs
>       * @return the newly created bean
>       */
> -    <T> T toBean(ResultSet rs, Class<T> type) throws SQLException;
> +    <T> T toBean(ResultSet rs, Class<? extends T> type) throws
> SQLException;
>
>      /**
>       * Create a <code>List</code> of JavaBeans from the column values in
> all
> @@ -68,7 +68,7 @@ public interface RowProcessor {
>       * @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;
> +    <T> List<T> toBeanList(ResultSet rs, Class<? extends T> type) throws
> SQLException;
>
>      /**
>       * Create a <code>Map</code> from the column values in one
>
> Modified:
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java?rev=1673285&r1=1673284&r2=1673285&view=diff
>
> ==============================================================================
> ---
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java
> (original)
> +++
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanHandler.java
> Mon Apr 13 21:19:22 2015
> @@ -34,7 +34,7 @@ public class BeanHandler<T> implements R
>      /**
>       * The Class of beans produced by this handler.
>       */
> -    private final Class<T> type;
> +    private final Class<? extends T> type;
>
>      /**
>       * The RowProcessor implementation to use when converting rows
> @@ -48,7 +48,7 @@ public class BeanHandler<T> implements R
>       * @param type The Class that objects returned from
> <code>handle()</code>
>       * are created from.
>       */
> -    public BeanHandler(Class<T> type) {
> +    public BeanHandler(Class<? extends T> type) {
>          this(type, ArrayHandler.ROW_PROCESSOR);
>      }
>
> @@ -60,7 +60,7 @@ public class BeanHandler<T> implements R
>       * @param convert The <code>RowProcessor</code> implementation
>       * to use when converting rows into beans.
>       */
> -    public BeanHandler(Class<T> type, RowProcessor convert) {
> +    public BeanHandler(Class<? extends T> type, RowProcessor convert) {
>          this.type = type;
>          this.convert = convert;
>      }
>
> Modified:
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java?rev=1673285&r1=1673284&r2=1673285&view=diff
>
> ==============================================================================
> ---
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
> (original)
> +++
> commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
> Mon Apr 13 21:19:22 2015
> @@ -36,7 +36,7 @@ public class BeanListHandler<T> implemen
>      /**
>       * The Class of beans produced by this handler.
>       */
> -    private final Class<T> type;
> +    private final Class<? extends T> type;
>
>      /**
>       * The RowProcessor implementation to use when converting rows
> @@ -50,7 +50,7 @@ public class BeanListHandler<T> implemen
>       * @param type The Class that objects returned from
> <code>handle()</code>
>       * are created from.
>       */
> -    public BeanListHandler(Class<T> type) {
> +    public BeanListHandler(Class<? extends T> type) {
>          this(type, ArrayHandler.ROW_PROCESSOR);
>      }
>
> @@ -62,7 +62,7 @@ public class BeanListHandler<T> implemen
>       * @param convert The <code>RowProcessor</code> implementation
>       * to use when converting rows into beans.
>       */
> -    public BeanListHandler(Class<T> type, RowProcessor convert) {
> +    public BeanListHandler(Class<? extends T> type, RowProcessor convert)
> {
>          this.type = type;
>          this.convert = convert;
>      }
>
> Modified:
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java?rev=1673285&r1=1673284&r2=1673285&view=diff
>
> ==============================================================================
> ---
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java
> (original)
> +++
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java
> Mon Apr 13 21:19:22 2015
> @@ -45,4 +45,37 @@ public class BeanHandlerTest extends Bas
>          assertNull(results);
>      }
>
> +    public void testHandleToSuperClass() throws SQLException {
> +        ResultSetHandler<TestBean> h = new
> BeanHandler<TestBean>(SubTestBean.class);
> +        TestBean results = h.handle(this.rs);
> +
> +        assertNotNull(results);
> +        assertEquals("1", results.getOne());
> +        assertEquals("2", results.getTwo());
> +        assertEquals(TestBean.Ordinal.THREE, results.getThree());
> +        assertEquals("not set", results.getDoNotSet());
> +    }
> +
> +    public void testHandleToInterface() throws SQLException {
> +        ResultSetHandler<SubTestBeanInterface> h = new
> BeanHandler<SubTestBeanInterface>(SubTestBean.class);
> +        SubTestBeanInterface results = h.handle(this.rs);
> +
> +        assertNotNull(results);
> +        assertEquals("1", results.getOne());
> +        assertEquals("2", results.getTwo());
> +        assertEquals(TestBean.Ordinal.THREE, results.getThree());
> +        assertEquals("not set", results.getDoNotSet());
> +    }
> +
> +    public static interface SubTestBeanInterface {
> +        public String getOne();
> +
> +        public TestBean.Ordinal getThree();
> +
> +        public String getTwo();
> +
> +        public String getDoNotSet();
> +    }
> +
> +    public static class SubTestBean extends TestBean implements
> SubTestBeanInterface { }
>  }
>
> Modified:
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java?rev=1673285&r1=1673284&r2=1673285&view=diff
>
> ==============================================================================
> ---
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java
> (original)
> +++
> commons/proper/dbutils/trunk/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java
> Mon Apr 13 21:19:22 2015
> @@ -64,4 +64,75 @@ public class BeanListHandlerTest extends
>          assertTrue(results.isEmpty());
>      }
>
> +    public void testHandleToSuperClass() throws SQLException {
> +        ResultSetHandler<List<TestBean>> h = new
> BeanListHandler<TestBean>(SubTestBean.class);
> +        List<TestBean> results = h.handle(this.rs);
> +
> +        assertNotNull(results);
> +        assertEquals(ROWS, results.size());
> +
> +        Iterator<TestBean> iter = results.iterator();
> +        TestBean row = null;
> +        assertTrue(iter.hasNext());
> +        row = iter.next();
> +        assertSame(SubTestBean.class, row.getClass());
> +
> +        assertEquals("1", row.getOne());
> +        assertEquals("2", row.getTwo());
> +        assertEquals(TestBean.Ordinal.THREE, row.getThree());
> +        assertEquals("not set", row.getDoNotSet());
> +
> +        assertTrue(iter.hasNext());
> +        row = iter.next();
> +        assertSame(SubTestBean.class, row.getClass());
> +
> +        assertEquals("4", row.getOne());
> +        assertEquals("5", row.getTwo());
> +        assertEquals(TestBean.Ordinal.SIX, row.getThree());
> +        assertEquals("not set", row.getDoNotSet());
> +
> +        assertFalse(iter.hasNext());
> +    }
> +
> +    public void testHandleToInterface() throws SQLException {
> +        ResultSetHandler<List<SubTestBeanInterface>> h = new
> BeanListHandler<SubTestBeanInterface>(SubTestBean.class);
> +        List<SubTestBeanInterface> results = h.handle(this.rs);
> +
> +        assertNotNull(results);
> +        assertEquals(ROWS, results.size());
> +
> +        Iterator<SubTestBeanInterface> iter = results.iterator();
> +        SubTestBeanInterface row = null;
> +        assertTrue(iter.hasNext());
> +        row = iter.next();
> +        assertSame(SubTestBean.class, row.getClass());
> +
> +        assertEquals("1", row.getOne());
> +        assertEquals("2", row.getTwo());
> +        assertEquals(TestBean.Ordinal.THREE, row.getThree());
> +        assertEquals("not set", row.getDoNotSet());
> +
> +        assertTrue(iter.hasNext());
> +        row = iter.next();
> +        assertSame(SubTestBean.class, row.getClass());
> +
> +        assertEquals("4", row.getOne());
> +        assertEquals("5", row.getTwo());
> +        assertEquals(TestBean.Ordinal.SIX, row.getThree());
> +        assertEquals("not set", row.getDoNotSet());
> +
> +        assertFalse(iter.hasNext());
> +    }
> +
> +    public static interface SubTestBeanInterface {
> +        public String getOne();
> +
> +        public TestBean.Ordinal getThree();
> +
> +        public String getTwo();
> +
> +        public String getDoNotSet();
> +    }
> +
> +    public static class SubTestBean extends TestBean implements
> SubTestBeanInterface { }
>  }
>
>
>


-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter