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 2013/04/08 22:00:12 UTC

svn commit: r1465759 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/ test/java/org/apache/commons/configuration/ test/java/org/apache/commons/configuration/event/

Author: oheger
Date: Mon Apr  8 20:00:12 2013
New Revision: 1465759

URL: http://svn.apache.org/r1465759
Log:
Made DatabaseConfiguration compatible with the builder approach.

There are now set methods for the properties defining the database structures
the configuration operates on. The values of these properties can also be
queried which was requested by [CONFIGURATION-535].

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/DatabaseConfigurationTestHelper.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDatabaseConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/TestDatabaseConfigurationEvents.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java?rev=1465759&r1=1465758&r2=1465759&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java Mon Apr  8 20:00:12 2013
@@ -36,7 +36,15 @@ import org.apache.commons.logging.LogFac
  * table containing at least one column for the keys, and one column for the
  * values. It's possible to store several configurations in the same table by
  * adding a column containing the name of the configuration. The name of the
- * table and the columns is specified in the constructor.
+ * table and the columns have to be specified using the corresponding
+ * properties.
+ * <p>
+ * The recommended way to create an instance of {@code DatabaseConfiguration}
+ * is to use a <em>configuration builder</em>. The builder is configured with
+ * a special parameters object defining the database structures used by the
+ * configuration. Such an object can be created using the {@code database()}
+ * method of the {@code Parameters} class. See the examples below for more
+ * details.
  *
  * <h4>Example 1 - One configuration per table</h4>
  *
@@ -48,8 +56,16 @@ import org.apache.commons.logging.LogFac
  *
  * INSERT INTO myconfig (key, value) VALUES ('foo', 'bar');
  *
- *
- * Configuration config = new DatabaseConfiguration(datasource, "myconfig", "key", "value");
+ * BasicConfigurationBuilder<DatabaseConfiguration> builder =
+ *     new BasicConfigurationBuilder<DatabaseConfiguration>(DatabaseConfiguration.class);
+ * builder.configure(
+ *     Parameters.database()
+ *         .setDataSource(dataSource)
+ *         .setTable("myconfig")
+ *         .setKeyColumn("key")
+ *         .setValueColumn("value")
+ * );
+ * Configuration config = builder.getConfiguration();
  * String value = config.getString("foo");
  * </pre>
  *
@@ -66,12 +82,19 @@ import org.apache.commons.logging.LogFac
  * INSERT INTO myconfigs (name, key, value) VALUES ('config1', 'key1', 'value1');
  * INSERT INTO myconfigs (name, key, value) VALUES ('config2', 'key2', 'value2');
  *
- *
- * Configuration config1 = new DatabaseConfiguration(datasource, "myconfigs", "name", "key", "value", "config1");
+ * BasicConfigurationBuilder<DatabaseConfiguration> builder =
+ *     new BasicConfigurationBuilder<DatabaseConfiguration>(DatabaseConfiguration.class);
+ * builder.configure(
+ *     Parameters.database()
+ *         .setDataSource(dataSource)
+ *         .setTable("myconfigs")
+ *         .setKeyColumn("key")
+ *         .setValueColumn("value")
+ *         .setConfigurationNameColumn("name")
+ *         .setConfigurationName("config1")
+ * );
+ * Configuration config1 = new DatabaseConfiguration(dataSource, "myconfigs", "name", "key", "value", "config1");
  * String value1 = conf.getString("key1");
- *
- * Configuration config2 = new DatabaseConfiguration(datasource, "myconfigs", "name", "key", "value", "config2");
- * String value2 = conf.getString("key2");
  * </pre>
  * The configuration can be instructed to perform commits after database updates.
  * This is achieved by setting the {@code commits} parameter of the
@@ -102,100 +125,155 @@ public class DatabaseConfiguration exten
     /** Constant for the statement used by getKeys.*/
     private static final String SQL_GET_KEYS = "SELECT DISTINCT %s FROM %s WHERE 1 = 1";
 
-    /** The datasource to connect to the database. */
-    private final DataSource datasource;
+    /** The data source to connect to the database. */
+    private DataSource dataSource;
 
-    /** The name of the table containing the configurations. */
-    private final String table;
+    /** The configurationName of the table containing the configurations. */
+    private String table;
 
-    /** The column containing the name of the configuration. */
-    private final String nameColumn;
+    /** The column containing the configurationName of the configuration. */
+    private String configurationNameColumn;
 
     /** The column containing the keys. */
-    private final String keyColumn;
+    private String keyColumn;
 
     /** The column containing the values. */
-    private final String valueColumn;
+    private String valueColumn;
 
-    /** The name of the configuration. */
-    private final String name;
+    /** The configurationName of the configuration. */
+    private String configurationName;
 
     /** A flag whether commits should be performed by this configuration. */
-    private final boolean doCommits;
+    private boolean autoCommit;
+
+    /**
+     * Creates a new instance of {@code DatabaseConfiguration}.
+     */
+    public DatabaseConfiguration()
+    {
+        setLogger(LogFactory.getLog(getClass()));
+        addErrorLogListener();
+    }
+
+    /**
+     * Returns the {@code DataSource} for obtaining database connections.
+     *
+     * @return the {@code DataSource}
+     */
+    public DataSource getDataSource()
+    {
+        return dataSource;
+    }
 
     /**
-     * Build a configuration from a table containing multiple configurations.
-     * No commits are performed by the new configuration instance.
+     * Sets the {@code DataSource} for obtaining database connections.
      *
-     * @param datasource    the datasource to connect to the database
-     * @param table         the name of the table containing the configurations
-     * @param nameColumn    the column containing the name of the configuration
-     * @param keyColumn     the column containing the keys of the configuration
-     * @param valueColumn   the column containing the values of the configuration
-     * @param name          the name of the configuration
+     * @param dataSource the {@code DataSource}
      */
-    public DatabaseConfiguration(DataSource datasource, String table, String nameColumn,
-            String keyColumn, String valueColumn, String name)
+    public void setDataSource(DataSource dataSource)
     {
-        this(datasource, table, nameColumn, keyColumn, valueColumn, name, false);
+        this.dataSource = dataSource;
     }
 
     /**
-     * Creates a new instance of {@code DatabaseConfiguration} that operates on
-     * a database table containing multiple configurations.
+     * Returns the name of the table containing configuration data.
      *
-     * @param datasource the {@code DataSource} to connect to the database
-     * @param table the name of the table containing the configurations
-     * @param nameColumn the column containing the name of the configuration
-     * @param keyColumn the column containing the keys of the configuration
-     * @param valueColumn the column containing the values of the configuration
-     * @param name the name of the configuration
-     * @param commits a flag whether the configuration should perform a commit
-     *        after a database update
+     * @return the name of the table to be queried
      */
-    public DatabaseConfiguration(DataSource datasource, String table,
-            String nameColumn, String keyColumn, String valueColumn,
-            String name, boolean commits)
+    public String getTable()
+    {
+        return table;
+    }
+
+    /**
+     * Sets the name of the table containing configuration data.
+     *
+     * @param table the table name
+     */
+    public void setTable(String table)
     {
-        this.datasource = datasource;
         this.table = table;
-        this.nameColumn = nameColumn;
+    }
+
+    /**
+     * Returns the name of the table column with the configuration name.
+     *
+     * @return the name of the configuration name column
+     */
+    public String getConfigurationNameColumn()
+    {
+        return configurationNameColumn;
+    }
+
+    /**
+     * Sets the name of the table column with the configuration name.
+     *
+     * @param configurationNameColumn the name of the column with the
+     *        configuration name
+     */
+    public void setConfigurationNameColumn(String configurationNameColumn)
+    {
+        this.configurationNameColumn = configurationNameColumn;
+    }
+
+    /**
+     * Returns the name of the column containing the configuration keys.
+     *
+     * @return the name of the key column
+     */
+    public String getKeyColumn()
+    {
+        return keyColumn;
+    }
+
+    /**
+     * Sets the name of the column containing the configuration keys.
+     *
+     * @param keyColumn the name of the key column
+     */
+    public void setKeyColumn(String keyColumn)
+    {
         this.keyColumn = keyColumn;
+    }
+
+    /**
+     * Returns the name of the column containing the configuration values.
+     *
+     * @return the name of the value column
+     */
+    public String getValueColumn()
+    {
+        return valueColumn;
+    }
+
+    /**
+     * Sets the name of the column containing the configuration values.
+     *
+     * @param valueColumn the name of the value column
+     */
+    public void setValueColumn(String valueColumn)
+    {
         this.valueColumn = valueColumn;
-        this.name = name;
-        doCommits = commits;
-        setLogger(LogFactory.getLog(getClass()));
-        addErrorLogListener();  // log errors per default
     }
 
     /**
-     * Build a configuration from a table.
+     * Returns the name of this configuration instance.
      *
-     * @param datasource    the datasource to connect to the database
-     * @param table         the name of the table containing the configurations
-     * @param keyColumn     the column containing the keys of the configuration
-     * @param valueColumn   the column containing the values of the configuration
+     * @return the name of this configuration
      */
-    public DatabaseConfiguration(DataSource datasource, String table, String keyColumn, String valueColumn)
+    public String getConfigurationName()
     {
-        this(datasource, table, null, keyColumn, valueColumn, null);
+        return configurationName;
     }
 
     /**
-     * Creates a new instance of {@code DatabaseConfiguration} that
-     * operates on a database table containing a single configuration only.
+     * Sets the name of this configuration instance.
      *
-     * @param datasource the {@code DataSource} to connect to the database
-     * @param table the name of the table containing the configurations
-     * @param keyColumn the column containing the keys of the configuration
-     * @param valueColumn the column containing the values of the configuration
-     * @param commits a flag whether the configuration should perform a commit
-     *        after a database update
+     * @param configurationName the name of this configuration
      */
-    public DatabaseConfiguration(DataSource datasource, String table,
-            String keyColumn, String valueColumn, boolean commits)
+    public void setConfigurationName(String configurationName)
     {
-        this(datasource, table, null, keyColumn, valueColumn, null, commits);
+        this.configurationName = configurationName;
     }
 
     /**
@@ -204,9 +282,20 @@ public class DatabaseConfiguration exten
      *
      * @return a flag whether commits are performed
      */
-    public boolean isDoCommits()
+    public boolean isAutoCommit()
+    {
+        return autoCommit;
+    }
+
+    /**
+     * Sets the auto commit flag. If set to <b>true</b>, this configuration
+     * performs a commit after each database update.
+     *
+     * @param autoCommit the auto commit flag
+     */
+    public void setAutoCommit(boolean autoCommit)
     {
-        return doCommits;
+        this.autoCommit = autoCommit;
     }
 
     /**
@@ -284,12 +373,12 @@ public class DatabaseConfiguration exten
                 query.append(table).append(" (");
                 query.append(keyColumn).append(", ");
                 query.append(valueColumn);
-                if (nameColumn != null)
+                if (configurationNameColumn != null)
                 {
-                    query.append(", ").append(nameColumn);
+                    query.append(", ").append(configurationNameColumn);
                 }
                 query.append(") VALUES (?, ?");
-                if (nameColumn != null)
+                if (configurationNameColumn != null)
                 {
                     query.append(", ?");
                 }
@@ -297,9 +386,9 @@ public class DatabaseConfiguration exten
 
                 PreparedStatement pstmt = initStatement(query.toString(),
                         false, key, String.valueOf(obj));
-                if (nameColumn != null)
+                if (configurationNameColumn != null)
                 {
-                    pstmt.setString(3, name);
+                    pstmt.setString(3, configurationName);
                 }
 
                 pstmt.executeUpdate();
@@ -484,7 +573,7 @@ public class DatabaseConfiguration exten
      */
     public DataSource getDatasource()
     {
-        return datasource;
+        return dataSource;
     }
 
     /**
@@ -495,7 +584,7 @@ public class DatabaseConfiguration exten
      * @param stmt The statement to close
      * @param rs the result set to close
      */
-    private void close(Connection conn, Statement stmt, ResultSet rs)
+    protected void close(Connection conn, Statement stmt, ResultSet rs)
     {
         try
         {
@@ -555,7 +644,7 @@ public class DatabaseConfiguration exten
         /** The type of the event to send in case of an error. */
         private final int errorEventType;
 
-        /** The property name for an error event. */
+        /** The property configurationName for an error event. */
         private final String errorPropertyName;
 
         /** The property value for an error event. */
@@ -566,7 +655,7 @@ public class DatabaseConfiguration exten
          * the properties related to the error event.
          *
          * @param errEvType the type of the error event
-         * @param errPropName the property name for the error event
+         * @param errPropName the property configurationName for the error event
          * @param errPropVal the property value for the error event
          */
         protected JdbcOperation(int errEvType, String errPropName,
@@ -595,7 +684,7 @@ public class DatabaseConfiguration exten
                 conn = getDatasource().getConnection();
                 result = performOperation();
 
-                if (isDoCommits())
+                if (isAutoCommit())
                 {
                     conn.commit();
                 }
@@ -629,7 +718,7 @@ public class DatabaseConfiguration exten
          * specified SQL statement.
          *
          * @param sql the statement to be executed
-         * @param nameCol a flag whether the name column should be taken into
+         * @param nameCol a flag whether the configurationName column should be taken into
          *        account
          * @return the prepared statement object
          * @throws SQLException if an SQL error occurs
@@ -638,10 +727,10 @@ public class DatabaseConfiguration exten
                 throws SQLException
         {
             String statement;
-            if (nameCol && nameColumn != null)
+            if (nameCol && configurationNameColumn != null)
             {
                 StringBuilder buf = new StringBuilder(sql);
-                buf.append(" AND ").append(nameColumn).append("=?");
+                buf.append(" AND ").append(configurationNameColumn).append("=?");
                 statement = buf.toString();
             }
             else
@@ -660,7 +749,7 @@ public class DatabaseConfiguration exten
          * initializes the statement's parameters.
          *
          * @param sql the statement to be executed
-         * @param nameCol a flag whether the name column should be taken into
+         * @param nameCol a flag whether the configurationName column should be taken into
          *        account
          * @param params the parameters for the statement
          * @return the initialized statement object
@@ -676,9 +765,9 @@ public class DatabaseConfiguration exten
             {
                 ps.setObject(idx++, param);
             }
-            if (nameCol && nameColumn != null)
+            if (nameCol && configurationNameColumn != null)
             {
-                ps.setString(idx, name);
+                ps.setString(idx, configurationName);
             }
 
             return ps;
@@ -689,7 +778,7 @@ public class DatabaseConfiguration exten
          * executes it. The resulting {@code ResultSet} is returned.
          *
          * @param sql the statement to be executed
-         * @param nameCol a flag whether the name column should be taken into
+         * @param nameCol a flag whether the configurationName column should be taken into
          *        account
          * @param params the parameters for the statement
          * @return the {@code ResultSet} produced by the query

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/DatabaseConfigurationTestHelper.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/DatabaseConfigurationTestHelper.java?rev=1465759&r1=1465758&r2=1465759&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/DatabaseConfigurationTestHelper.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/DatabaseConfigurationTestHelper.java Mon Apr  8 20:00:12 2013
@@ -22,6 +22,9 @@ import java.sql.Connection;
 
 import javax.sql.DataSource;
 
+import org.apache.commons.configuration.builder.BasicConfigurationBuilder;
+import org.apache.commons.configuration.builder.fluent.DatabaseBuilderParameters;
+import org.apache.commons.configuration.builder.fluent.Parameters;
 import org.apache.commons.configuration.test.HsqlDB;
 import org.apache.commons.dbcp.BasicDataSource;
 import org.dbunit.database.DatabaseConnection;
@@ -77,14 +80,14 @@ public class DatabaseConfigurationTestHe
     private DataSource datasource;
 
     /**
-     * The auto-commit mode for the connections created by the managed data
-     * source.
+     * The auto-commit mode for the configuration instances created by this
+     * helper.
      */
-    private boolean autoCommit = true;
+    private boolean autoCommit;
 
     /**
-     * Returns the auto-commit mode of the connections created by the managed
-     * data source.
+     * Returns the auto-commit mode of the configuration instances created by
+     * this helper.
      *
      * @return the auto-commit mode
      */
@@ -94,8 +97,8 @@ public class DatabaseConfigurationTestHe
     }
 
     /**
-     * Sets the auto-commit mode of the connections created by the managed data
-     * source.
+     * Sets the auto-commit mode of the configuration instances created by this
+     * helper.
      *
      * @param autoCommit the auto-commit mode
      */
@@ -133,38 +136,105 @@ public class DatabaseConfigurationTestHe
     }
 
     /**
-     * Creates a database configuration with default values.
+     * Returns a parameters object with default settings.
      *
-     * @return the configuration
+     * @return the parameters object
      */
-    public DatabaseConfiguration setUpConfig()
+    public DatabaseBuilderParameters setUpDefaultParameters()
     {
-        return new DatabaseConfiguration(getDatasource(), TABLE, COL_KEY,
-                COL_VALUE, !isAutoCommit());
+        return Parameters.database().setDataSource(getDatasource())
+                .setTable(TABLE).setKeyColumn(COL_KEY)
+                .setValueColumn(COL_VALUE).setAutoCommit(isAutoCommit());
     }
 
     /**
-     * Creates a database configuration that supports multiple configurations in
-     * a table with default values.
+     * Returns a parameters object with settings for a configuration table
+     * containing the data of multiple configurations.
+     *
+     * @param configName the name of the configuration instance or <b>null</b>
+     *        for the default name
+     * @return the parameters object
+     */
+    public DatabaseBuilderParameters setUpMultiParameters(String configName)
+    {
+        return setUpDefaultParameters()
+                .setTable(TABLE_MULTI)
+                .setConfigurationNameColumn(COL_NAME)
+                .setConfigurationName(
+                        (configName != null) ? configName : CONFIG_NAME);
+    }
+
+    /**
+     * Creates a configuration instance of the specified class with the given
+     * parameters.
+     *
+     * @param <T> the type of the result configuration
+     * @param configCls the configuration class
+     * @param params the parameters object
+     * @return the newly created configuration instance
+     * @throws ConfigurationException if an error occurs
+     */
+    public <T extends DatabaseConfiguration> T createConfig(Class<T> configCls,
+            DatabaseBuilderParameters params) throws ConfigurationException
+    {
+        return new BasicConfigurationBuilder<T>(configCls).configure(params)
+                .getConfiguration();
+    }
+
+    /**
+     * Creates a database configuration with default settings of the specified
+     * class.
+     *
+     * @param <T> the type of the result configuration
+     * @param configCls the configuration class
+     * @return the newly created configuration instance
+     * @throws ConfigurationException if an error occurs
+     */
+    public <T extends DatabaseConfiguration> T setUpConfig(Class<T> configCls)
+            throws ConfigurationException
+    {
+        return createConfig(configCls, setUpDefaultParameters());
+    }
+
+    /**
+     * Creates a database configuration with default settings.
      *
      * @return the configuration
+     * @throws ConfigurationException if an error occurs
      */
-    public DatabaseConfiguration setUpMultiConfig()
+    public DatabaseConfiguration setUpConfig() throws ConfigurationException
     {
-        return setUpMultiConfig(CONFIG_NAME);
+        return setUpConfig(DatabaseConfiguration.class);
+    }
+
+    /**
+     * Creates a configuration with support for multiple configuration instances
+     * in a single table of the specified class.
+     *
+     * @param <T> the type of the result configuration
+     * @param configCls the configuration class
+     * @param configName the name of the configuration instance or <b>null</b>
+     *        for the default name
+     * @return the newly created configuration instance
+     * @throws ConfigurationException if an error occurs
+     */
+    public <T extends DatabaseConfiguration> T setUpMultiConfig(
+            Class<T> configCls, String configName)
+            throws ConfigurationException
+    {
+        return createConfig(configCls, setUpMultiParameters(configName));
     }
 
     /**
      * Creates a database configuration that supports multiple configurations in
-     * a table and sets the specified configuration name.
+     * a table with default values.
      *
-     * @param configName the name of the configuration
      * @return the configuration
+     * @throws ConfigurationException if an error occurs
      */
-    public DatabaseConfiguration setUpMultiConfig(String configName)
+    public DatabaseConfiguration setUpMultiConfig() throws ConfigurationException
     {
-        return new DatabaseConfiguration(getDatasource(), TABLE_MULTI,
-                COL_NAME, COL_KEY, COL_VALUE, configName, !isAutoCommit());
+        return setUpMultiConfig(DatabaseConfiguration.class, null);
     }
 
     /**
@@ -204,7 +274,7 @@ public class DatabaseConfigurationTestHe
         ds.setUrl(DATABASE_URL);
         ds.setUsername(DATABASE_USERNAME);
         ds.setPassword(DATABASE_PASSWORD);
-        ds.setDefaultAutoCommit(isAutoCommit());
+        ds.setDefaultAutoCommit(!isAutoCommit());
 
         // prepare the database
         Connection conn = ds.getConnection();

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDatabaseConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDatabaseConfiguration.java?rev=1465759&r1=1465758&r2=1465759&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDatabaseConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDatabaseConfiguration.java Mon Apr  8 20:00:12 2013
@@ -27,6 +27,7 @@ import java.util.List;
 
 import javax.sql.DataSource;
 
+import org.apache.commons.configuration.builder.fluent.DatabaseBuilderParameters;
 import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Before;
@@ -80,13 +81,12 @@ public class TestDatabaseConfiguration
      * Creates a database configuration with default values.
      *
      * @return the configuration
+     * @throws ConfigurationException if an error occurs
      */
     private PotentialErrorDatabaseConfiguration setUpConfig()
+            throws ConfigurationException
     {
-        return new PotentialErrorDatabaseConfiguration(helper.getDatasource(),
-                DatabaseConfigurationTestHelper.TABLE,
-                DatabaseConfigurationTestHelper.COL_KEY,
-                DatabaseConfigurationTestHelper.COL_VALUE);
+        return helper.setUpConfig(PotentialErrorDatabaseConfiguration.class);
     }
 
     /**
@@ -108,8 +108,10 @@ public class TestDatabaseConfiguration
      * error listener.
      *
      * @return the initialized configuration
+     * @throws ConfigurationException if an error occurs
      */
     private PotentialErrorDatabaseConfiguration setUpErrorConfig()
+            throws ConfigurationException
     {
         PotentialErrorDatabaseConfiguration config = setUpConfig();
         setUpErrorListener(config);
@@ -135,37 +137,8 @@ public class TestDatabaseConfiguration
         listener = null; // mark as checked
     }
 
-    /**
-     * Tests the default value of the doCommits property.
-     */
-    @Test
-    public void testDoCommitsDefault()
-    {
-        DatabaseConfiguration config = new DatabaseConfiguration(helper
-                .getDatasource(), DatabaseConfigurationTestHelper.TABLE,
-                DatabaseConfigurationTestHelper.COL_KEY,
-                DatabaseConfigurationTestHelper.COL_VALUE);
-        assertFalse("Wrong commits flag", config.isDoCommits());
-    }
-
-    /**
-     * Tests the default value of the doCommits property for multiple
-     * configurations in a table.
-     */
     @Test
-    public void testDoCommitsDefaultMulti()
-    {
-        DatabaseConfiguration config = new DatabaseConfiguration(helper
-                .getDatasource(), DatabaseConfigurationTestHelper.TABLE,
-                DatabaseConfigurationTestHelper.COL_NAME,
-                DatabaseConfigurationTestHelper.COL_KEY,
-                DatabaseConfigurationTestHelper.COL_VALUE,
-                DatabaseConfigurationTestHelper.CONFIG_NAME);
-        assertFalse("Wrong commits flag", config.isDoCommits());
-    }
-
-    @Test
-    public void testAddPropertyDirectSingle()
+    public void testAddPropertyDirectSingle() throws ConfigurationException
     {
         DatabaseConfiguration config = helper.setUpConfig();
         config.addPropertyDirect("key", "value");
@@ -177,7 +150,7 @@ public class TestDatabaseConfiguration
      * Tests whether a commit is performed after a property was added.
      */
     @Test
-    public void testAddPropertyDirectCommit()
+    public void testAddPropertyDirectCommit() throws ConfigurationException
     {
         helper.setAutoCommit(false);
         DatabaseConfiguration config = helper.setUpConfig();
@@ -186,7 +159,7 @@ public class TestDatabaseConfiguration
     }
 
     @Test
-    public void testAddPropertyDirectMultiple()
+    public void testAddPropertyDirectMultiple() throws ConfigurationException
     {
         DatabaseConfiguration config = helper.setUpMultiConfig();
         config.addPropertyDirect("key", "value");
@@ -195,7 +168,7 @@ public class TestDatabaseConfiguration
     }
 
     @Test
-    public void testAddNonStringProperty()
+    public void testAddNonStringProperty() throws ConfigurationException
     {
         DatabaseConfiguration config = helper.setUpConfig();
         config.addPropertyDirect("boolean", Boolean.TRUE);
@@ -204,7 +177,7 @@ public class TestDatabaseConfiguration
     }
 
     @Test
-    public void testGetPropertyDirectSingle()
+    public void testGetPropertyDirectSingle() throws ConfigurationException
     {
         Configuration config = setUpConfig();
 
@@ -214,7 +187,7 @@ public class TestDatabaseConfiguration
     }
 
     @Test
-    public void testGetPropertyDirectMultiple()
+    public void testGetPropertyDirectMultiple() throws ConfigurationException
     {
         Configuration config = helper.setUpMultiConfig();
 
@@ -224,7 +197,7 @@ public class TestDatabaseConfiguration
     }
 
     @Test
-    public void testClearPropertySingle()
+    public void testClearPropertySingle() throws ConfigurationException
     {
         Configuration config = helper.setUpConfig();
         config.clearProperty("key1");
@@ -233,7 +206,7 @@ public class TestDatabaseConfiguration
     }
 
     @Test
-    public void testClearPropertyMultiple()
+    public void testClearPropertyMultiple() throws ConfigurationException
     {
         Configuration config = helper.setUpMultiConfig();
         config.clearProperty("key1");
@@ -246,10 +219,12 @@ public class TestDatabaseConfiguration
      * properties.
      */
     @Test
-    public void testClearPropertyMultipleOtherConfig()
+    public void testClearPropertyMultipleOtherConfig() throws ConfigurationException
     {
         DatabaseConfiguration config = helper.setUpMultiConfig();
-        DatabaseConfiguration config2 = helper.setUpMultiConfig(CONFIG_NAME2);
+        DatabaseConfiguration config2 =
+                helper.setUpMultiConfig(DatabaseConfiguration.class,
+                        CONFIG_NAME2);
         config2.addProperty("key1", "some test");
         config.clearProperty("key1");
         assertFalse("property not cleared", config.containsKey("key1"));
@@ -261,7 +236,7 @@ public class TestDatabaseConfiguration
      * Tests whether a commit is performed after a property was cleared.
      */
     @Test
-    public void testClearPropertyCommit()
+    public void testClearPropertyCommit() throws ConfigurationException
     {
         helper.setAutoCommit(false);
         Configuration config = helper.setUpConfig();
@@ -270,7 +245,7 @@ public class TestDatabaseConfiguration
     }
 
     @Test
-    public void testClearSingle()
+    public void testClearSingle() throws ConfigurationException
     {
         Configuration config = helper.setUpConfig();
         config.clear();
@@ -279,7 +254,7 @@ public class TestDatabaseConfiguration
     }
 
     @Test
-    public void testClearMultiple()
+    public void testClearMultiple() throws ConfigurationException
     {
         Configuration config = helper.setUpMultiConfig();
         config.clear();
@@ -291,7 +266,7 @@ public class TestDatabaseConfiguration
      * Tests whether a commit is performed after a clear operation.
      */
     @Test
-    public void testClearCommit()
+    public void testClearCommit() throws ConfigurationException
     {
         helper.setAutoCommit(false);
         Configuration config = helper.setUpConfig();
@@ -300,7 +275,7 @@ public class TestDatabaseConfiguration
     }
 
     @Test
-    public void testGetKeysSingle()
+    public void testGetKeysSingle() throws ConfigurationException
     {
         Configuration config = setUpConfig();
         Iterator<String> it = config.getKeys();
@@ -310,7 +285,7 @@ public class TestDatabaseConfiguration
     }
 
     @Test
-    public void testGetKeysMultiple()
+    public void testGetKeysMultiple() throws ConfigurationException
     {
         Configuration config = helper.setUpMultiConfig();
         Iterator<String> it = config.getKeys();
@@ -320,7 +295,7 @@ public class TestDatabaseConfiguration
     }
 
     @Test
-    public void testContainsKeySingle()
+    public void testContainsKeySingle() throws ConfigurationException
     {
         Configuration config = setUpConfig();
         assertTrue("missing key1", config.containsKey("key1"));
@@ -328,7 +303,7 @@ public class TestDatabaseConfiguration
     }
 
     @Test
-    public void testContainsKeyMultiple()
+    public void testContainsKeyMultiple() throws ConfigurationException
     {
         Configuration config = helper.setUpMultiConfig();
         assertTrue("missing key1", config.containsKey("key1"));
@@ -336,34 +311,36 @@ public class TestDatabaseConfiguration
     }
 
     @Test
-    public void testIsEmptySingle()
+    public void testIsEmptySingle() throws ConfigurationException
     {
         Configuration config1 = setUpConfig();
         assertFalse("The configuration is empty", config1.isEmpty());
     }
 
     @Test
-    public void testIsEmptyMultiple()
+    public void testIsEmptyMultiple() throws ConfigurationException
     {
         Configuration config1 = helper.setUpMultiConfig();
         assertFalse("The configuration named 'test' is empty", config1.isEmpty());
 
-        Configuration config2 = new DatabaseConfiguration(helper.getDatasource(), DatabaseConfigurationTestHelper.TABLE_MULTI, DatabaseConfigurationTestHelper.COL_NAME, DatabaseConfigurationTestHelper.COL_KEY, DatabaseConfigurationTestHelper.COL_VALUE, "testIsEmpty");
+        Configuration config2 = helper.setUpMultiConfig(DatabaseConfiguration.class, "testIsEmpty");
         assertTrue("The configuration named 'testIsEmpty' is not empty", config2.isEmpty());
     }
 
     @Test
-    public void testGetList()
+    public void testGetList() throws ConfigurationException
     {
-        Configuration config1 = new DatabaseConfiguration(helper.getDatasource(), "configurationList", DatabaseConfigurationTestHelper.COL_KEY, DatabaseConfigurationTestHelper.COL_VALUE);
+        DatabaseBuilderParameters params = helper.setUpDefaultParameters().setTable("configurationList");
+        Configuration config1 = helper.createConfig(DatabaseConfiguration.class, params);
         List<Object> list = config1.getList("key3");
         assertEquals(3,list.size());
     }
 
     @Test
-    public void testGetKeys()
+    public void testGetKeys() throws ConfigurationException
     {
-        Configuration config1 = new DatabaseConfiguration(helper.getDatasource(), "configurationList", DatabaseConfigurationTestHelper.COL_KEY, DatabaseConfigurationTestHelper.COL_VALUE);
+        DatabaseBuilderParameters params = helper.setUpDefaultParameters().setTable("configurationList");
+        Configuration config1 = helper.createConfig(DatabaseConfiguration.class, params);
         Iterator<String> i = config1.getKeys();
         assertTrue(i.hasNext());
         Object key = i.next();
@@ -372,7 +349,7 @@ public class TestDatabaseConfiguration
     }
 
     @Test
-    public void testClearSubset()
+    public void testClearSubset() throws ConfigurationException
     {
         Configuration config = setUpConfig();
 
@@ -388,9 +365,9 @@ public class TestDatabaseConfiguration
      * that is used for logging.
      */
     @Test
-    public void testLogErrorListener()
+    public void testLogErrorListener() throws ConfigurationException
     {
-        DatabaseConfiguration config = new DatabaseConfiguration(helper.getDatasource(), DatabaseConfigurationTestHelper.TABLE, DatabaseConfigurationTestHelper.COL_KEY, DatabaseConfigurationTestHelper.COL_VALUE);
+        DatabaseConfiguration config = helper.setUpConfig();
         assertEquals("No error listener registered", 1, config.getErrorListeners().size());
     }
 
@@ -398,7 +375,7 @@ public class TestDatabaseConfiguration
      * Tests handling of errors in getProperty().
      */
     @Test
-    public void testGetPropertyError()
+    public void testGetPropertyError() throws ConfigurationException
     {
         setUpErrorConfig().getProperty("key1");
         checkErrorListener(AbstractConfiguration.EVENT_READ_PROPERTY, "key1", null);
@@ -408,7 +385,7 @@ public class TestDatabaseConfiguration
      * Tests handling of errors in addPropertyDirect().
      */
     @Test
-    public void testAddPropertyError()
+    public void testAddPropertyError() throws ConfigurationException
     {
         setUpErrorConfig().addProperty("key1", "value");
         checkErrorListener(AbstractConfiguration.EVENT_ADD_PROPERTY, "key1", "value");
@@ -418,7 +395,7 @@ public class TestDatabaseConfiguration
      * Tests handling of errors in isEmpty().
      */
     @Test
-    public void testIsEmptyError()
+    public void testIsEmptyError() throws ConfigurationException
     {
         assertTrue("Wrong return value for failure", setUpErrorConfig().isEmpty());
         checkErrorListener(AbstractConfiguration.EVENT_READ_PROPERTY, null, null);
@@ -428,7 +405,7 @@ public class TestDatabaseConfiguration
      * Tests handling of errors in containsKey().
      */
     @Test
-    public void testContainsKeyError()
+    public void testContainsKeyError() throws ConfigurationException
     {
         assertFalse("Wrong return value for failure", setUpErrorConfig().containsKey("key1"));
         checkErrorListener(AbstractConfiguration.EVENT_READ_PROPERTY, "key1", null);
@@ -438,7 +415,7 @@ public class TestDatabaseConfiguration
      * Tests handling of errors in clearProperty().
      */
     @Test
-    public void testClearPropertyError()
+    public void testClearPropertyError() throws ConfigurationException
     {
         setUpErrorConfig().clearProperty("key1");
         checkErrorListener(AbstractConfiguration.EVENT_CLEAR_PROPERTY, "key1", null);
@@ -448,7 +425,7 @@ public class TestDatabaseConfiguration
      * Tests handling of errors in clear().
      */
     @Test
-    public void testClearError()
+    public void testClearError() throws ConfigurationException
     {
         setUpErrorConfig().clear();
         checkErrorListener(AbstractConfiguration.EVENT_CLEAR, null, null);
@@ -458,7 +435,7 @@ public class TestDatabaseConfiguration
      * Tests handling of errors in getKeys().
      */
     @Test
-    public void testGetKeysError()
+    public void testGetKeysError() throws ConfigurationException
     {
         Iterator<String> it = setUpErrorConfig().getKeys();
         checkErrorListener(AbstractConfiguration.EVENT_READ_PROPERTY, null, null);
@@ -470,10 +447,11 @@ public class TestDatabaseConfiguration
      * delimiter. Multiple values should be returned.
      */
     @Test
-    public void testGetListWithDelimiter()
+    public void testGetListWithDelimiter() throws ConfigurationException
     {
         DatabaseConfiguration config = setUpConfig();
         config.setListDelimiter(';');
+        config.setDelimiterParsingDisabled(false);
         List<Object> values = config.getList("keyMulti");
         assertEquals("Wrong number of list elements", 3, values.size());
         assertEquals("Wrong list element 0", "a", values.get(0));
@@ -485,7 +463,7 @@ public class TestDatabaseConfiguration
      * delimiter parsing is disabled.
      */
     @Test
-    public void testGetListWithDelimiterParsingDisabled()
+    public void testGetListWithDelimiterParsingDisabled() throws ConfigurationException
     {
         DatabaseConfiguration config = setUpConfig();
         config.setListDelimiter(';');
@@ -498,10 +476,11 @@ public class TestDatabaseConfiguration
      * is queried multiple values should be returned.
      */
     @Test
-    public void testAddWithDelimiter()
+    public void testAddWithDelimiter() throws ConfigurationException
     {
         DatabaseConfiguration config = setUpConfig();
         config.setListDelimiter(';');
+        config.setDelimiterParsingDisabled(false);
         config.addProperty("keyList", "1;2;3");
         String[] values = config.getStringArray("keyList");
         assertEquals("Wrong number of property values", 3, values.length);
@@ -512,10 +491,11 @@ public class TestDatabaseConfiguration
      * Tests setProperty() if the property value contains the list delimiter.
      */
     @Test
-    public void testSetPropertyWithDelimiter()
+    public void testSetPropertyWithDelimiter() throws ConfigurationException
     {
         DatabaseConfiguration config = helper.setUpMultiConfig();
         config.setListDelimiter(';');
+        config.setDelimiterParsingDisabled(false);
         config.setProperty("keyList", "1;2;3");
         String[] values = config.getStringArray("keyList");
         assertEquals("Wrong number of property values", 3, values.length);
@@ -527,17 +507,11 @@ public class TestDatabaseConfiguration
      * configured to throw an exception when obtaining a connection. This way
      * database exceptions can be simulated.
      */
-    static class PotentialErrorDatabaseConfiguration extends DatabaseConfiguration
+    public static class PotentialErrorDatabaseConfiguration extends DatabaseConfiguration
     {
         /** A flag whether a getConnection() call should fail. */
         boolean failOnConnect;
 
-        public PotentialErrorDatabaseConfiguration(DataSource datasource,
-                String table, String keyColumn, String valueColumn)
-        {
-            super(datasource, table, keyColumn, valueColumn);
-        }
-
         @Override
         public DataSource getDatasource()
         {

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/TestDatabaseConfigurationEvents.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/TestDatabaseConfigurationEvents.java?rev=1465759&r1=1465758&r2=1465759&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/TestDatabaseConfigurationEvents.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/TestDatabaseConfigurationEvents.java Mon Apr  8 20:00:12 2013
@@ -17,6 +17,7 @@
 package org.apache.commons.configuration.event;
 
 import org.apache.commons.configuration.AbstractConfiguration;
+import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.DatabaseConfigurationTestHelper;
 import org.junit.After;
 import org.junit.Before;
@@ -51,6 +52,13 @@ public class TestDatabaseConfigurationEv
     @Override
     protected AbstractConfiguration createConfiguration()
     {
-        return helper.setUpConfig();
+        try
+        {
+            return helper.setUpConfig();
+        }
+        catch (ConfigurationException e)
+        {
+            throw new AssertionError(e);
+        }
     }
 }