hello

i'm new to this list and i'd like to thank you first for sharing this
project. it looks like a very interesting approach to me in the world
of hibernate &co.

i'm right now trying on with empire-db and as i'm going to need to
fill java.util.Set type of collections i did a tiny bit of change to
the DBReader class so it will populate any Collection that is put in
as a parameter. this will not break the existing api. 

i will attach the diff just in case you find it useful.

regards
eike
Index: src/main/java/org/apache/empire/db/DBReader.java
===================================================================
--- src/main/java/org/apache/empire/db/DBReader.java	(revision 791026)
+++ src/main/java/org/apache/empire/db/DBReader.java	(working copy)
@@ -24,7 +24,9 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -623,17 +625,19 @@
     }
 
     /**
-     * Returns the result of a query as a list of objects resticted
-     * to a maximum number of objects (unless maxCount is -1).
+     * Returns the result of a query as a collection of objects 
+     * restricted to a maximum number of objects (unless 
+     * maxCount is -1).
      * 
      * @param c the class type of the objects in the list
      * @param maxCount the maximum number of objects
-     * @param <T> the type of the objects in the list
+     * @param <T> the implementation type of {...@link Collection}
+     * @param <S> the type of the objects in the list
      * 
      * @return the list of <T>
      */
     @SuppressWarnings("unchecked")
-    public <T> ArrayList<T> getBeanList(Class<T> c, int maxCount)
+    public <T extends Collection<S>, S> T getBeanList(T list, Class<S> c, int maxCount)
     {
         // Check Recordset
         if (rset == null)
@@ -653,19 +657,19 @@
             Object[] args = (ctor!=null) ? new Object[getFieldCount()] : null; 
             
             // Create a list of beans
-            ArrayList<T> list = new ArrayList<T>();
+            
             while (moveNext() && maxCount != 0)
             { // Create bean an init
                 if (ctor!=null)
                 {   // Use Constructor
                     for (int i = 0; i < getFieldCount(); i++)
                         args[i] = getValue(i);
-                    T bean = (T)ctor.newInstance(args);
+                    S bean = (S)ctor.newInstance(args);
                     list.add(bean);
                 }
                 else
                 {   // Use Property Setters
-                    T bean = c.newInstance();
+                    S bean = c.newInstance();
                     if (getBeanProperties(bean)==false)
                         return null;
                     list.add(bean);
@@ -692,6 +696,33 @@
     }
 
     /**
+     * Returns the result of a query as a list of objects restricted
+     * to a maximum number of objects (unless maxCount is -1).
+     * 
+     * @param c the class type of the objects in the list
+     * @param maxCount the maximum number of objects
+     * @param <T> the type of the objects in the list
+     * 
+     * @return the list of <T>
+     */
+    public <T> ArrayList<T> getBeanList(Class<T> c, int maxCount) {
+    	return getBeanList(new ArrayList<T>(), c, maxCount);
+    }
+    
+    /**
+     * Returns the result of a query as a set of objects restricted
+     * to a maximum number of objects (unless maxCount=-1)
+     * 
+     * @param <T> the type of the objects in the set
+     * @param c the class type of the objects in the set
+     * @param maxCount the maximum size of the list
+     * @return
+     */
+    public <T> HashSet<T> getBeanSet(Class<T> c, int maxCount) {
+    	return getBeanList(new HashSet<T>(), c, maxCount);
+    }
+    
+    /**
      * Returns the result of a query as a list of objects.
      * 
      * @param c the class type of the objects in the list
@@ -701,7 +732,7 @@
      */
     public <T> ArrayList<T> getBeanList(Class<T> c)
     {
-        return getBeanList(c, -1);
+        return getBeanList(new ArrayList<T>(), c, -1);
     }
 
     /**

Reply via email to