commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject cvs commit: jakarta-commons/configuration/src/test/org/apache/commons/configuration TestDatabaseConfiguration.java
Date Mon, 18 Oct 2004 14:05:23 GMT
ebourg      2004/10/18 07:05:23

  Modified:    configuration/src/java/org/apache/commons/configuration
                        AbstractConfiguration.java BaseConfiguration.java
                        Configuration.java DatabaseConfiguration.java
               configuration/xdocs changes.xml
               configuration/src/test/org/apache/commons/configuration
                        TestDatabaseConfiguration.java
  Log:
  Added Configuration.clear()
  
  Revision  Changes    Path
  1.27      +13 -1     jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java
  
  Index: AbstractConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- AbstractConfiguration.java	18 Oct 2004 09:54:37 -0000	1.26
  +++ AbstractConfiguration.java	18 Oct 2004 14:05:22 -0000	1.27
  @@ -329,6 +329,18 @@
       /**
        * {@inheritDoc}
        */
  +    public void clear()
  +    {
  +        Iterator it = getKeys();
  +        while (it.hasNext())
  +        {
  +            clearProperty((String) it.next());
  +        }
  +    }
  +
  +    /**
  +     * {@inheritDoc}
  +     */
       public abstract Iterator getKeys();
   
       /**
  
  
  
  1.9       +9 -3      jakarta-commons/configuration/src/java/org/apache/commons/configuration/BaseConfiguration.java
  
  Index: BaseConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/BaseConfiguration.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- BaseConfiguration.java	5 Jul 2004 09:54:17 -0000	1.8
  +++ BaseConfiguration.java	18 Oct 2004 14:05:23 -0000	1.9
  @@ -60,7 +60,6 @@
           super();
       }
   
  -
       /**
        * Adds a key/value pair to the map.  This routine does no magic morphing.
        * It ensures the keylist is maintained
  @@ -139,7 +138,6 @@
       public boolean containsKey(String key)
       {
           return store.containsKey(key);
  -
       }
   
       /**
  @@ -153,6 +151,14 @@
           {
               store.remove(key);
           }
  +    }
  +
  +    /**
  +     * {@inheritDoc}
  +     */
  +    public void clear()
  +    {
  +        store.clear();
       }
   
       /**
  
  
  
  1.12      +6 -1      jakarta-commons/configuration/src/java/org/apache/commons/configuration/Configuration.java
  
  Index: Configuration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/Configuration.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Configuration.java	18 Oct 2004 09:52:02 -0000	1.11
  +++ Configuration.java	18 Oct 2004 14:05:23 -0000	1.12
  @@ -117,6 +117,11 @@
       void clearProperty(String key);
   
       /**
  +     * Remove all properties from the configuration.
  +     */
  +    void clear();
  +
  +    /**
        * Gets a property from the configuration.
        *
        * @param key property to retrieve
  
  
  
  1.11      +40 -1     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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DatabaseConfiguration.java	20 Sep 2004 09:37:07 -0000	1.10
  +++ DatabaseConfiguration.java	18 Oct 2004 14:05:23 -0000	1.11
  @@ -340,6 +340,45 @@
       /**
        * {@inheritDoc}
        */
  +    public void clear()
  +    {
  +        // build the query
  +        StringBuffer query = new StringBuffer("DELETE FROM " + table);
  +        if (nameColumn != null)
  +        {
  +            query.append(" WHERE " + nameColumn + "=?");
  +        }
  +
  +        Connection conn = null;
  +        PreparedStatement pstmt = null;
  +
  +        try
  +        {
  +            conn = datasource.getConnection();
  +
  +            // bind the parameters
  +            pstmt = conn.prepareStatement(query.toString());
  +            if (nameColumn != null)
  +            {
  +                pstmt.setString(1, name);
  +            }
  +
  +            pstmt.executeUpdate();
  +        }
  +        catch (SQLException e)
  +        {
  +            log.error(e.getMessage(), e);
  +        }
  +        finally
  +        {
  +            // clean up
  +            closeQuietly(conn, pstmt);
  +        }
  +    }
  +
  +    /**
  +     * {@inheritDoc}
  +     */
       public Iterator getKeys()
       {
           Collection keys = new ArrayList();
  
  
  
  1.61      +4 -0      jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- changes.xml	18 Oct 2004 12:50:41 -0000	1.60
  +++ changes.xml	18 Oct 2004 14:05:23 -0000	1.61
  @@ -8,6 +8,10 @@
     <body>
   
       <release version="1.1-dev" date="in CVS">
  +      <action dev="ebourg" type="add" issue="26102">
  +        Added a clear() method to the Configuration interface to remove
  +        all properties.
  +      </action>
         <action dev="ebourg" type="add" issue="26066">
           Added a SystemConfiguration wrapping the system properties.
           ConfigurationFactory recognizes the corresponding &lt;system/&gt;
  
  
  
  1.10      +17 -1     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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestDatabaseConfiguration.java	11 Oct 2004 09:17:09 -0000	1.9
  +++ TestDatabaseConfiguration.java	18 Oct 2004 14:05:23 -0000	1.10
  @@ -152,6 +152,22 @@
           assertFalse("property not cleared", config.containsKey("key"));
       }
   
  +    public void testClearSingle()
  +    {
  +        DatabaseConfiguration config = new DatabaseConfiguration(datasource, "configuration",
"key", "value");
  +        config.clear();
  +
  +        assertTrue("configuration is not cleared", config.isEmpty());
  +    }
  +
  +    public void testClearMultiple()
  +    {
  +        DatabaseConfiguration config = new DatabaseConfiguration(datasource, "configurations",
"name", "key", "value", "test");
  +        config.clear();
  +
  +        assertTrue("configuration is not cleared", config.isEmpty());
  +    }
  +
       public void testGetKeysSingle()
       {
           DatabaseConfiguration config = new DatabaseConfiguration(datasource, "configuration",
"key", "value");
  
  
  

---------------------------------------------------------------------
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