empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1209887 - in /incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire: commons/StringUtils.java db/DBDatabase.java
Date Sat, 03 Dec 2011 11:26:48 GMT
Author: doebele
Date: Sat Dec  3 11:26:48 2011
New Revision: 1209887

URL: http://svn.apache.org/viewvc?rev=1209887&view=rev
Log:
EMPIREDB-126
additional overload for DBDatabase.queryOptionList to allow provision of an Options object.

Modified:
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java?rev=1209887&r1=1209886&r2=1209887&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
Sat Dec  3 11:26:48 2011
@@ -145,7 +145,7 @@ public class StringUtils
             StringBuilder buf = new StringBuilder();
             for (int i = 0; i < array.length; i++)
             {
-                if (i > 0)
+                if (i>0 && separator!=null)
                     buf.append(separator);
                 buf.append(array[i]);
             }

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java?rev=1209887&r1=1209886&r2=1209887&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
Sat Dec  3 11:26:48 2011
@@ -895,14 +895,14 @@ public abstract class DBDatabase extends
     }
     
     /**
-     * Returns a list of key value pairs from an sql query.
+     * Fills an option list provided with the result from a query.
      * The option list is filled with the values of the first and second column.
      * 
      * @param sqlCmd the SQL statement
      * @param conn a valid connection to the database.
      * @return an Options object containing a set a of values and their corresponding names

      */
-    public Options queryOptionList(String sqlCmd, Connection conn)
+    public int queryOptionList(String sqlCmd, Connection conn, Options result)
     {   // Execute the  Statement
         checkOpen();
         ResultSet rs = null;
@@ -918,17 +918,18 @@ public abstract class DBDatabase extends
             if (rs.getMetaData().getColumnCount()<2)
                 throw new InvalidArgumentException("sqlCmd", sqlCmd);
             // Check Result
-            Options result = new Options();
+            int count = 0;
             while (rs.next())
             {
                 Object value = rs.getObject(1);
                 String text  = rs.getString(2);
                 result.add(value, text, true);
+                count++;
             }
             // No Value
             if (log.isInfoEnabled())
-                log.info("queryOptionList retured " + result.size() + " items. Query completed
in " + (System.currentTimeMillis() - start) + " ms");
-            return result;
+                log.info("queryOptionList retured " + count + " items. Query completed in
" + (System.currentTimeMillis() - start) + " ms");
+            return count;
         } catch (SQLException sqle) 
         {   // Error
             throw new QueryFailedException(this, sqlCmd, sqle);
@@ -939,6 +940,21 @@ public abstract class DBDatabase extends
     }
 
     /**
+     * Returns a list of key value pairs from an sql query.
+     * The option list is filled with the values of the first and second column.
+     * 
+     * @param sqlCmd the SQL statement
+     * @param conn a valid connection to the database.
+     * @return an Options object containing a set a of values and their corresponding names

+     */
+    public Options queryOptionList(String sqlCmd, Connection conn)
+    {   // Execute the  Statement
+        Options options = new Options();
+        queryOptionList(sqlCmd, conn, options);
+        return options; 
+    }
+    
+    /**
      * Adds the result of a query to a given collection.<br/>
      * The individual rows will be added as an array of objects (object[])
      * <p>This function should only be used for small lists.



Mime
View raw message