You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by "Rainer Döbele (JIRA)" <em...@incubator.apache.org> on 2013/02/04 15:08:12 UTC
[jira] [Closed] (EMPIREDB-42) Extend DBReader to provide query
results in a hash set
[ https://issues.apache.org/jira/browse/EMPIREDB-42?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Rainer Döbele closed EMPIREDB-42.
---------------------------------
Cleanup of unclosed issues.
> Extend DBReader to provide query results in a hash set
> ------------------------------------------------------
>
> Key: EMPIREDB-42
> URL: https://issues.apache.org/jira/browse/EMPIREDB-42
> Project: Empire-DB
> Issue Type: Improvement
> Components: Core
> Affects Versions: empire-db-2.0.5-incubating
> Reporter: Rainer Döbele
> Assignee: Rainer Döbele
> Priority: Minor
> Fix For: empire-db-2.0.5-incubating
>
>
> Suggestion made by eike on July 4th 2009:
> ===================================================================
> --- 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);
> }
>
> /**
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira