You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2008/02/02 21:18:34 UTC

svn commit: r617881 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/DatabaseConfiguration.java test/java/org/apache/commons/configuration2/TestDatabaseConfiguration.java

Author: oheger
Date: Sat Feb  2 12:18:33 2008
New Revision: 617881

URL: http://svn.apache.org/viewvc?rev=617881&view=rev
Log:
Removed dependency to commons-collections from DatabaseConfiguration and some Java 1.5 related changes

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DatabaseConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestDatabaseConfiguration.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DatabaseConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DatabaseConfiguration.java?rev=617881&r1=617880&r2=617881&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DatabaseConfiguration.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DatabaseConfiguration.java Sat Feb  2 12:18:33 2008
@@ -29,7 +29,6 @@
 
 import javax.sql.DataSource;
 
-import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.logging.LogFactory;
 
 /**
@@ -152,7 +151,7 @@
         Object result = null;
 
         // build the query
-        StringBuffer query = new StringBuffer("SELECT * FROM ");
+        StringBuilder query = new StringBuilder("SELECT * FROM ");
         query.append(table).append(" WHERE ");
         query.append(keyColumn).append("=?");
         if (nameColumn != null)
@@ -177,7 +176,7 @@
 
             ResultSet rs = pstmt.executeQuery();
 
-            List results = new ArrayList();
+            List<Object> results = new ArrayList<Object>();
             while (rs.next())
             {
                 Object value = rs.getObject(valueColumn);
@@ -187,8 +186,8 @@
                 }
                 else
                 {
-                    // Split value if it containts the list delimiter
-                    CollectionUtils.addAll(results, PropertyConverter.toIterator(value, getListDelimiter()));
+                    // Split value if it contains the list delimiter
+                    results.addAll(PropertyConverter.flatten(value, getListDelimiter()));
                 }
             }
 
@@ -222,7 +221,7 @@
     protected void addPropertyDirect(String key, Object obj)
     {
         // build the query
-        StringBuffer query = new StringBuffer("INSERT INTO " + table);
+        StringBuilder query = new StringBuilder("INSERT INTO " + table);
         if (nameColumn != null)
         {
             query.append(" (" + nameColumn + ", " + keyColumn + ", " + valueColumn + ") VALUES (?, ?, ?)");
@@ -305,7 +304,7 @@
         boolean empty = true;
 
         // build the query
-        StringBuffer query = new StringBuffer("SELECT count(*) FROM " + table);
+        StringBuilder query = new StringBuilder("SELECT count(*) FROM " + table);
         if (nameColumn != null)
         {
             query.append(" WHERE " + nameColumn + "=?");
@@ -360,7 +359,7 @@
         boolean found = false;
 
         // build the query
-        StringBuffer query = new StringBuffer("SELECT * FROM " + table + " WHERE " + keyColumn + "=?");
+        StringBuilder query = new StringBuilder("SELECT * FROM " + table + " WHERE " + keyColumn + "=?");
         if (nameColumn != null)
         {
             query.append(" AND " + nameColumn + "=?");
@@ -410,7 +409,7 @@
     public void clearProperty(String key)
     {
         // build the query
-        StringBuffer query = new StringBuffer("DELETE FROM " + table + " WHERE " + keyColumn + "=?");
+        StringBuilder query = new StringBuilder("DELETE FROM " + table + " WHERE " + keyColumn + "=?");
         if (nameColumn != null)
         {
             query.append(" AND " + nameColumn + "=?");
@@ -454,7 +453,7 @@
     public void clear()
     {
         // build the query
-        StringBuffer query = new StringBuffer("DELETE FROM " + table);
+        StringBuilder query = new StringBuilder("DELETE FROM " + table);
         if (nameColumn != null)
         {
             query.append(" WHERE " + nameColumn + "=?");
@@ -497,12 +496,12 @@
      * @return an iterator with the contained keys (an empty iterator in case
      * of an error)
      */
-    public Iterator getKeys()
+    public Iterator<String> getKeys()
     {
-        Collection keys = new ArrayList();
+        Collection<String> keys = new ArrayList<String>();
 
         // build the query
-        StringBuffer query = new StringBuffer("SELECT DISTINCT " + keyColumn + " FROM " + table);
+        StringBuilder query = new StringBuilder("SELECT DISTINCT " + keyColumn + " FROM " + table);
         if (nameColumn != null)
         {
             query.append(" WHERE " + nameColumn + "=?");

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestDatabaseConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestDatabaseConfiguration.java?rev=617881&r1=617880&r2=617881&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestDatabaseConfiguration.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestDatabaseConfiguration.java Sat Feb  2 12:18:33 2008
@@ -275,7 +275,7 @@
     public void testGetKeysSingle()
     {
         Configuration config = setUpConfig();
-        Iterator it = config.getKeys();
+        Iterator<?> it = config.getKeys();
 
         assertEquals("1st key", "key1", it.next());
         assertEquals("2nd key", "key2", it.next());
@@ -284,7 +284,7 @@
     public void testGetKeysMultiple()
     {
         Configuration config = setUpMultiConfig();
-        Iterator it = config.getKeys();
+        Iterator<?> it = config.getKeys();
 
         assertEquals("1st key", "key1", it.next());
         assertEquals("2nd key", "key2", it.next());
@@ -322,14 +322,14 @@
     public void testGetList()
     {
         Configuration config1 = new DatabaseConfiguration(datasource, "configurationList", COL_KEY, COL_VALUE);
-        List list = config1.getList("key3");
+        List<?> list = config1.getList("key3");
         assertEquals(3,list.size());
     }
 
     public void testGetKeys()
     {
         Configuration config1 = new DatabaseConfiguration(datasource, "configurationList", COL_KEY, COL_VALUE);
-        Iterator i = config1.getKeys();
+        Iterator<?> i = config1.getKeys();
         assertTrue(i.hasNext());
         Object key = i.next();
         assertEquals("key3",key.toString());
@@ -416,7 +416,7 @@
      */
     public void testGetKeysError()
     {
-        Iterator it = setUpErrorConfig().getKeys();
+        Iterator<?> it = setUpErrorConfig().getKeys();
         checkErrorListener(AbstractConfiguration.EVENT_READ_PROPERTY, null, null);
         assertFalse("Iteration is not empty", it.hasNext());
     }
@@ -429,7 +429,7 @@
     {
         DatabaseConfiguration config = setUpConfig();
         config.setListDelimiter(';');
-        List values = config.getList("keyMulti");
+        List<?> values = config.getList("keyMulti");
         assertEquals("Wrong number of list elements", 3, values.size());
         assertEquals("Wrong list element 0", "a", values.get(0));
         assertEquals("Wrong list element 2", "c", values.get(2));