commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ep...@apache.org
Subject cvs commit: jakarta-commons/configuration/src/java/org/apache/commons/configuration DatabaseConfiguration.java
Date Sat, 24 Jul 2004 16:26:10 GMT
epugh       2004/07/24 09:26:10

  Modified:    configuration/src/test/org/apache/commons/configuration
                        TestDatabaseConfiguration.java
               configuration/conf testdb.script dataset.xml
               configuration/src/java/org/apache/commons/configuration
                        DatabaseConfiguration.java
  Log:
  BUG29734 DatabaseConfiguration doesn't support List properties
  
  Revision  Changes    Path
  1.6       +30 -3     jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestDatabaseConfiguration.java
  
  Index: TestDatabaseConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestDatabaseConfiguration.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestDatabaseConfiguration.java	27 Feb 2004 17:41:34 -0000	1.5
  +++ TestDatabaseConfiguration.java	24 Jul 2004 16:26:10 -0000	1.6
  @@ -19,6 +19,8 @@
   import java.io.FileInputStream;
   import java.sql.SQLException;
   import java.util.Iterator;
  +import java.util.List;
  +
   import javax.sql.DataSource;
   
   import junit.framework.TestCase;
  @@ -30,17 +32,25 @@
   import org.dbunit.operation.DatabaseOperation;
   
   /**
  - * Test for database stored configurations.
  + * Test for database stored configurations.  Note, when running this Unit 
  + * Test in Eclipse it sometimes takes a couple tries.  Otherwise you ma get
  + * database is already in use by another process errors.
    *
    * @version $Revision$, $Date$
    */
   public class TestDatabaseConfiguration extends TestCase
   {
       private DataSource datasource;
  -    private IDataSet dataSet;
  +    private IDataSet dataSet;	
   
       protected void setUp() throws Exception
       {
  +    	/*
  +    	 * Thread.sleep may or may not help with the database is already in
  +    	 * use exception.
  +    	 */
  +    	//Thread.sleep(1000);
  +    	
           // set up the datasource
           BasicDataSource datasource = new BasicDataSource();
           datasource.setDriverClassName("org.hsqldb.jdbcDriver");
  @@ -166,5 +176,22 @@
           DatabaseConfiguration config2 = new DatabaseConfiguration(datasource, "configurations",
"name", "key", "value", "testIsEmpty");
           assertTrue("The configuration named 'testIsEmpty' is not empty", config2.isEmpty());
       }
  +    
  +    public void testGetList()
  +    {
  +        DatabaseConfiguration config1 = new DatabaseConfiguration(datasource, "configurationList",
"key", "value");
  +        List list = config1.getList("key3");
  +        assertEquals(3,list.size());
  +    }    
  +    
  +    public void testGetKeys()
  +    {
  +        DatabaseConfiguration config1 = new DatabaseConfiguration(datasource, "configurationList",
"key", "value");
  +        Iterator i = config1.getKeys();
  +        assertTrue(i.hasNext());
  +        Object key = i.next();
  +        assertEquals("key3",key.toString());
  +        assertFalse(i.hasNext());
  +    }     
   
   }
  
  
  
  1.2       +1 -0      jakarta-commons/configuration/conf/testdb.script
  
  Index: testdb.script
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/conf/testdb.script,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- testdb.script	18 Jan 2004 16:15:46 -0000	1.1
  +++ testdb.script	24 Jul 2004 16:26:10 -0000	1.2
  @@ -1,5 +1,6 @@
   CREATE TABLE CONFIGURATION(KEY VARCHAR NOT NULL PRIMARY KEY,VALUE VARCHAR)
   CREATE TABLE CONFIGURATIONS(NAME VARCHAR NOT NULL,KEY VARCHAR NOT NULL,VALUE VARCHAR,CONSTRAINT
SYS_PK_CONFIGURATIONS PRIMARY KEY(NAME,KEY))
  +CREATE TABLE CONFIGURATIONLIST(ID VARCHAR NOT NULL PRIMARY KEY, KEY VARCHAR NOT NULL,VALUE
VARCHAR)
   GRANT ALL ON CLASS "java.lang.Math" TO PUBLIC
   GRANT ALL ON CLASS "org.hsqldb.Library" TO PUBLIC
   CREATE USER SA PASSWORD "" ADMIN
  
  
  
  1.2       +21 -1     jakarta-commons/configuration/conf/dataset.xml
  
  Index: dataset.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/conf/dataset.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- dataset.xml	18 Jan 2004 16:15:46 -0000	1.1
  +++ dataset.xml	24 Jul 2004 16:26:10 -0000	1.2
  @@ -14,7 +14,7 @@
           <row>
               <value>key2</value>
               <value>value2</value>
  -        </row>
  +        </row>		
       </table>
   
       <table name="configurations">
  @@ -32,5 +32,25 @@
               <value>value2</value>
           </row>
       </table>
  +    <table name="configurationList">
  +		<column>id</column>
  +        <column>key</column>
  +        <column>value</column>
  +        <row>
  +			<value>1</value>
  +            <value>key3</value>
  +            <value>value1</value>
  +        </row>		
  +        <row>
  +			<value>2</value>
  +            <value>key3</value>
  +            <value>value2</value>
  +        </row>			
  +        <row>
  +			<value>3</value>			
  +            <value>key3</value>
  +            <value>value3</value>
  +        </row>			
  +    </table>	
   
   </dataset>
  
  
  
  1.8       +13 -2     jakarta-commons/configuration/src/java/org/apache/commons/configuration/DatabaseConfiguration.java
  
  Index: DatabaseConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/DatabaseConfiguration.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DatabaseConfiguration.java	24 Jun 2004 14:01:03 -0000	1.7
  +++ DatabaseConfiguration.java	24 Jul 2004 16:26:10 -0000	1.8
  @@ -24,6 +24,8 @@
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Iterator;
  +import java.util.List;
  +
   import javax.sql.DataSource;
   
   import org.apache.commons.logging.Log;
  @@ -129,6 +131,15 @@
               {
                   result = rs.getObject(valueColumn);
               }
  +            if(rs.next()){
  +            	List results = new ArrayList();
  +            	results.add(result);
  +            	results.add(rs.getObject(valueColumn));
  +            	while (rs.next()){
  +            		results.add(rs.getObject(valueColumn));
  +            	}
  +            	result = results;
  +            }
           }
           catch (SQLException e)
           {
  @@ -330,7 +341,7 @@
           Collection keys = new ArrayList();
   
           // build the query
  -        StringBuffer query = new StringBuffer("SELECT " + keyColumn + " FROM " + table);
  +        StringBuffer query = new StringBuffer("SELECT DISTINCT " + keyColumn + " FROM "
+ table);
           if (nameColumn != null)
           {
               query.append(" WHERE " + nameColumn + "=?");
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message