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 project.xml
Date Sun, 18 Jan 2004 16:15:46 GMT
epugh       2004/01/18 08:15:46

  Modified:    configuration/xdocs changes.xml
               configuration project.xml
  Added:       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:
  DatabaseConfiguration and test case contributed by Emmanuel
  
  Revision  Changes    Path
  1.4       +9 -0      jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- changes.xml	16 Jan 2004 14:56:45 -0000	1.3
  +++ changes.xml	18 Jan 2004 16:15:46 -0000	1.4
  @@ -7,6 +7,15 @@
   
     <body>
       <release version="1.0-dev-4" date="">
  +	 <action dev="ebourg" type="add">
  +      	New DatabaseConfiguration that uses a database to store the properties. It supports
2 table structures :
  +      	<ul>
  +		<li>one table per configuration (2 colums key/value)</li>
  +		<li>one table for multiple configurations (2 columns key/value + 1 column 
  +for the name of the configuration)</li>
  +		</ul>
  +      	
  +     </action>      	
   	 <action dev="oheger" type="add">
         	ConfigurationFactory now supports the hierarchicalDom4j element in configuration

         	definition file
  
  
  
  1.1                  jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestDatabaseConfiguration.java
  
  Index: TestDatabaseConfiguration.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2004 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.commons.configuration;
  
  import java.io.FileInputStream;
  import java.util.Iterator;
  import javax.sql.DataSource;
  
  import junit.framework.TestCase;
  import org.apache.commons.dbcp.BasicDataSource;
  import org.dbunit.database.DatabaseConnection;
  import org.dbunit.database.IDatabaseConnection;
  import org.dbunit.dataset.IDataSet;
  import org.dbunit.dataset.xml.XmlDataSet;
  import org.dbunit.operation.DatabaseOperation;
  
  /**
   * Test for database stored configurations.
   *
   * @author Emmanuel Bourg
   * @version $Revision: 1.1 $, $Date: 2004/01/18 16:15:46 $
   */
  public class TestDatabaseConfiguration extends TestCase
  {
      private DataSource datasource;
      private IDataSet dataSet;
  
      protected void setUp() throws Exception
      {
          // set up the datasource
          BasicDataSource datasource = new BasicDataSource();
          datasource.setDriverClassName("org.hsqldb.jdbcDriver");
          datasource.setUrl("jdbc:hsqldb:conf/testdb");
          datasource.setUsername("sa");
          datasource.setPassword("");
  
          this.datasource = datasource;
  
          // prepare the database
          IDatabaseConnection connection = new DatabaseConnection(datasource.getConnection());
          dataSet = new XmlDataSet(new FileInputStream("conf/dataset.xml"));
  
          try
          {
              DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
          }
          finally
          {
              connection.close();
          }
      }
  
      public void testAddPropertyDirectSingle()
      {
          DatabaseConfiguration config = new DatabaseConfiguration(datasource, "configuration",
"key", "value");
          config.addPropertyDirect("key", "value");
  
          assertTrue("missing property", config.containsKey("key"));
      }
  
      public void testAddPropertyDirectMultiple()
      {
          DatabaseConfiguration config = new DatabaseConfiguration(datasource, "configurations",
"name", "key", "value", "test");
          config.addPropertyDirect("key", "value");
  
          assertTrue("missing property", config.containsKey("key"));
      }
  
      public void testGetPropertyDirectSingle()
      {
          DatabaseConfiguration config = new DatabaseConfiguration(datasource, "configuration",
"key", "value");
  
          assertEquals("property1", "value1", config.getPropertyDirect("key1"));
          assertEquals("property2", "value2", config.getPropertyDirect("key2"));
          assertEquals("unknown property", null, config.getPropertyDirect("key3"));
      }
  
      public void testGetPropertyDirectMultiple()
      {
          DatabaseConfiguration config = new DatabaseConfiguration(datasource, "configurations",
"name", "key", "value", "test");
  
          assertEquals("property1", "value1", config.getProperty("key1"));
          assertEquals("property2", "value2", config.getProperty("key2"));
          assertEquals("unknown property", null, config.getProperty("key3"));
      }
  
      public void testClearPropertySingle()
      {
          DatabaseConfiguration config = new DatabaseConfiguration(datasource, "configuration",
"key", "value");
          config.clearProperty("key");
  
          assertFalse("property not cleared", config.containsKey("key"));
      }
  
      public void testClearPropertyMultiple()
      {
          DatabaseConfiguration config = new DatabaseConfiguration(datasource, "configurations",
"name", "key", "value", "test");
          config.clearProperty("key");
  
          assertFalse("property not cleared", config.containsKey("key"));
      }
  
      public void testGetKeysSingle()
      {
          DatabaseConfiguration config = new DatabaseConfiguration(datasource, "configuration",
"key", "value");
          Iterator it = config.getKeys();
  
          assertEquals("1st key", "key1", it.next());
          assertEquals("2nd key", "key2", it.next());
      }
  
      public void testGetKeysMultiple()
      {
          DatabaseConfiguration config = new DatabaseConfiguration(datasource, "configurations",
"name", "key", "value", "test");
          Iterator it = config.getKeys();
  
          assertEquals("1st key", "key1", it.next());
          assertEquals("2nd key", "key2", it.next());
      }
  
      public void testContainsKeySingle()
      {
          DatabaseConfiguration config = new DatabaseConfiguration(datasource, "configuration",
"key", "value");
          assertTrue("missing key1", config.containsKey("key1"));
          assertTrue("missing key2", config.containsKey("key2"));
      }
  
      public void testContainsKeyMultiple()
      {
          DatabaseConfiguration config = new DatabaseConfiguration(datasource, "configurations",
"name", "key", "value", "test");
          assertTrue("missing key1", config.containsKey("key1"));
          assertTrue("missing key2", config.containsKey("key2"));
      }
  
      public void testIsEmptySingle()
      {
          DatabaseConfiguration config1 = new DatabaseConfiguration(datasource, "configuration",
"key", "value");
          assertFalse("The configuration is empty", config1.isEmpty());
      }
  
      public void testIsEmptyMultiple()
      {
          DatabaseConfiguration config1 = new DatabaseConfiguration(datasource, "configurations",
"name", "key", "value", "test");
          assertFalse("The configuration named 'test' is empty", config1.isEmpty());
  
          DatabaseConfiguration config2 = new DatabaseConfiguration(datasource, "configurations",
"name", "key", "value", "testIsEmpty");
          assertTrue("The configuration named 'testIsEmpty' is not empty", config2.isEmpty());
      }
  
  }
  
  
  
  1.1                  jakarta-commons/configuration/conf/testdb.script
  
  Index: testdb.script
  ===================================================================
  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))
  GRANT ALL ON CLASS "java.lang.Math" TO PUBLIC
  GRANT ALL ON CLASS "org.hsqldb.Library" TO PUBLIC
  CREATE USER SA PASSWORD "" ADMIN
  CREATE ALIAS DAYNAME FOR "org.hsqldb.Library.dayname"
  CREATE ALIAS SPACE FOR "org.hsqldb.Library.space"
  CREATE ALIAS SUBSTRING FOR "org.hsqldb.Library.substring"
  CREATE ALIAS HEXTORAW FOR "org.hsqldb.Library.hexToRaw"
  CREATE ALIAS SQRT FOR "java.lang.Math.sqrt"
  CREATE ALIAS ABS FOR "org.hsqldb.Library.abs"
  CREATE ALIAS POWER FOR "java.lang.Math.pow"
  CREATE ALIAS CHAR FOR "org.hsqldb.Library.character"
  CREATE ALIAS CONCAT FOR "org.hsqldb.Library.concat"
  CREATE ALIAS PI FOR "org.hsqldb.Library.pi"
  CREATE ALIAS RAWTOHEX FOR "org.hsqldb.Library.rawToHex"
  CREATE ALIAS SECOND FOR "org.hsqldb.Library.second"
  CREATE ALIAS TRUNCATE FOR "org.hsqldb.Library.truncate"
  CREATE ALIAS MONTH FOR "org.hsqldb.Library.month"
  CREATE ALIAS LOWER FOR "org.hsqldb.Library.lcase"
  CREATE ALIAS ATAN2 FOR "java.lang.Math.atan2"
  CREATE ALIAS REPEAT FOR "org.hsqldb.Library.repeat"
  CREATE ALIAS DAYOFMONTH FOR "org.hsqldb.Library.dayofmonth"
  CREATE ALIAS TAN FOR "java.lang.Math.tan"
  CREATE ALIAS RADIANS FOR "java.lang.Math.toRadians"
  CREATE ALIAS FLOOR FOR "java.lang.Math.floor"
  CREATE ALIAS NOW FOR "org.hsqldb.Library.now"
  CREATE ALIAS ACOS FOR "java.lang.Math.acos"
  CREATE ALIAS DAYOFWEEK FOR "org.hsqldb.Library.dayofweek"
  CREATE ALIAS CEILING FOR "java.lang.Math.ceil"
  CREATE ALIAS DAYOFYEAR FOR "org.hsqldb.Library.dayofyear"
  CREATE ALIAS LCASE FOR "org.hsqldb.Library.lcase"
  CREATE ALIAS WEEK FOR "org.hsqldb.Library.week"
  CREATE ALIAS SOUNDEX FOR "org.hsqldb.Library.soundex"
  CREATE ALIAS ASIN FOR "java.lang.Math.asin"
  CREATE ALIAS LOCATE FOR "org.hsqldb.Library.locate"
  CREATE ALIAS EXP FOR "java.lang.Math.exp"
  CREATE ALIAS MONTHNAME FOR "org.hsqldb.Library.monthname"
  CREATE ALIAS YEAR FOR "org.hsqldb.Library.year"
  CREATE ALIAS LEFT FOR "org.hsqldb.Library.left"
  CREATE ALIAS ROUNDMAGIC FOR "org.hsqldb.Library.roundMagic"
  CREATE ALIAS BITOR FOR "org.hsqldb.Library.bitor"
  CREATE ALIAS LTRIM FOR "org.hsqldb.Library.ltrim"
  CREATE ALIAS COT FOR "org.hsqldb.Library.cot"
  CREATE ALIAS COS FOR "java.lang.Math.cos"
  CREATE ALIAS MOD FOR "org.hsqldb.Library.mod"
  CREATE ALIAS SIGN FOR "org.hsqldb.Library.sign"
  CREATE ALIAS DEGREES FOR "java.lang.Math.toDegrees"
  CREATE ALIAS LOG FOR "java.lang.Math.log"
  CREATE ALIAS SIN FOR "java.lang.Math.sin"
  CREATE ALIAS CURTIME FOR "org.hsqldb.Library.curtime"
  CREATE ALIAS DIFFERENCE FOR "org.hsqldb.Library.difference"
  CREATE ALIAS INSERT FOR "org.hsqldb.Library.insert"
  CREATE ALIAS SUBSTR FOR "org.hsqldb.Library.substring"
  CREATE ALIAS DATABASE FOR "org.hsqldb.Library.database"
  CREATE ALIAS MINUTE FOR "org.hsqldb.Library.minute"
  CREATE ALIAS HOUR FOR "org.hsqldb.Library.hour"
  CREATE ALIAS IDENTITY FOR "org.hsqldb.Library.identity"
  CREATE ALIAS QUARTER FOR "org.hsqldb.Library.quarter"
  CREATE ALIAS CURDATE FOR "org.hsqldb.Library.curdate"
  CREATE ALIAS BITAND FOR "org.hsqldb.Library.bitand"
  CREATE ALIAS USER FOR "org.hsqldb.Library.user"
  CREATE ALIAS UCASE FOR "org.hsqldb.Library.ucase"
  CREATE ALIAS RTRIM FOR "org.hsqldb.Library.rtrim"
  CREATE ALIAS LOG10 FOR "org.hsqldb.Library.log10"
  CREATE ALIAS RIGHT FOR "org.hsqldb.Library.right"
  CREATE ALIAS ATAN FOR "java.lang.Math.atan"
  CREATE ALIAS UPPER FOR "org.hsqldb.Library.ucase"
  CREATE ALIAS ASCII FOR "org.hsqldb.Library.ascii"
  CREATE ALIAS RAND FOR "java.lang.Math.random"
  CREATE ALIAS LENGTH FOR "org.hsqldb.Library.length"
  CREATE ALIAS ROUND FOR "org.hsqldb.Library.round"
  CREATE ALIAS REPLACE FOR "org.hsqldb.Library.replace"
  INSERT INTO CONFIGURATION VALUES('key1','value1')
  INSERT INTO CONFIGURATION VALUES('key2','value2')
  INSERT INTO CONFIGURATIONS VALUES('test','key1','value1')
  INSERT INTO CONFIGURATIONS VALUES('test','key2','value2')
  /*C1*/CONNECT USER sa PASSWORD ""
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key1'
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key2'
  DELETE FROM CONFIGURATION WHERE KEY='key1'
  DELETE FROM CONFIGURATION WHERE KEY='key2'
  INSERT INTO CONFIGURATION VALUES('key1','value1')
  INSERT INTO CONFIGURATION VALUES('key2','value2')
  INSERT INTO CONFIGURATIONS VALUES('test','key1','value1')
  INSERT INTO CONFIGURATIONS VALUES('test','key2','value2')
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  INSERT INTO CONFIGURATION VALUES('key','value')
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  /*C2*/CONNECT USER sa PASSWORD ""
  CONNECT USER sa PASSWORD ""
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key1'
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key2'
  DELETE FROM CONFIGURATION WHERE KEY='key'
  DELETE FROM CONFIGURATION WHERE KEY='key1'
  DELETE FROM CONFIGURATION WHERE KEY='key2'
  INSERT INTO CONFIGURATION VALUES('key1','value1')
  INSERT INTO CONFIGURATION VALUES('key2','value2')
  INSERT INTO CONFIGURATIONS VALUES('test','key1','value1')
  INSERT INTO CONFIGURATIONS VALUES('test','key2','value2')
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  INSERT INTO CONFIGURATIONS VALUES('test','key','value')
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  /*C3*/CONNECT USER sa PASSWORD ""
  CONNECT USER sa PASSWORD ""
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key'
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key1'
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key2'
  DELETE FROM CONFIGURATION WHERE KEY='key1'
  DELETE FROM CONFIGURATION WHERE KEY='key2'
  INSERT INTO CONFIGURATION VALUES('key1','value1')
  INSERT INTO CONFIGURATION VALUES('key2','value2')
  INSERT INTO CONFIGURATIONS VALUES('test','key1','value1')
  INSERT INTO CONFIGURATIONS VALUES('test','key2','value2')
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  /*C4*/CONNECT USER sa PASSWORD ""
  CONNECT USER sa PASSWORD ""
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key1'
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key2'
  DELETE FROM CONFIGURATION WHERE KEY='key1'
  DELETE FROM CONFIGURATION WHERE KEY='key2'
  INSERT INTO CONFIGURATION VALUES('key1','value1')
  INSERT INTO CONFIGURATION VALUES('key2','value2')
  INSERT INTO CONFIGURATIONS VALUES('test','key1','value1')
  INSERT INTO CONFIGURATIONS VALUES('test','key2','value2')
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  /*C5*/CONNECT USER sa PASSWORD ""
  CONNECT USER sa PASSWORD ""
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key1'
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key2'
  DELETE FROM CONFIGURATION WHERE KEY='key1'
  DELETE FROM CONFIGURATION WHERE KEY='key2'
  INSERT INTO CONFIGURATION VALUES('key1','value1')
  INSERT INTO CONFIGURATION VALUES('key2','value2')
  INSERT INTO CONFIGURATIONS VALUES('test','key1','value1')
  INSERT INTO CONFIGURATIONS VALUES('test','key2','value2')
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  /*C6*/CONNECT USER sa PASSWORD ""
  CONNECT USER sa PASSWORD ""
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key1'
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key2'
  DELETE FROM CONFIGURATION WHERE KEY='key1'
  DELETE FROM CONFIGURATION WHERE KEY='key2'
  INSERT INTO CONFIGURATION VALUES('key1','value1')
  INSERT INTO CONFIGURATION VALUES('key2','value2')
  INSERT INTO CONFIGURATIONS VALUES('test','key1','value1')
  INSERT INTO CONFIGURATIONS VALUES('test','key2','value2')
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  /*C7*/CONNECT USER sa PASSWORD ""
  CONNECT USER sa PASSWORD ""
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key1'
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key2'
  DELETE FROM CONFIGURATION WHERE KEY='key1'
  DELETE FROM CONFIGURATION WHERE KEY='key2'
  INSERT INTO CONFIGURATION VALUES('key1','value1')
  INSERT INTO CONFIGURATION VALUES('key2','value2')
  INSERT INTO CONFIGURATIONS VALUES('test','key1','value1')
  INSERT INTO CONFIGURATIONS VALUES('test','key2','value2')
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  /*C8*/CONNECT USER sa PASSWORD ""
  CONNECT USER sa PASSWORD ""
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key1'
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key2'
  DELETE FROM CONFIGURATION WHERE KEY='key1'
  DELETE FROM CONFIGURATION WHERE KEY='key2'
  INSERT INTO CONFIGURATION VALUES('key1','value1')
  INSERT INTO CONFIGURATION VALUES('key2','value2')
  INSERT INTO CONFIGURATIONS VALUES('test','key1','value1')
  INSERT INTO CONFIGURATIONS VALUES('test','key2','value2')
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  /*C9*/CONNECT USER sa PASSWORD ""
  CONNECT USER sa PASSWORD ""
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key1'
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key2'
  DELETE FROM CONFIGURATION WHERE KEY='key1'
  DELETE FROM CONFIGURATION WHERE KEY='key2'
  INSERT INTO CONFIGURATION VALUES('key1','value1')
  INSERT INTO CONFIGURATION VALUES('key2','value2')
  INSERT INTO CONFIGURATIONS VALUES('test','key1','value1')
  INSERT INTO CONFIGURATIONS VALUES('test','key2','value2')
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  /*C10*/CONNECT USER sa PASSWORD ""
  CONNECT USER sa PASSWORD ""
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key1'
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key2'
  DELETE FROM CONFIGURATION WHERE KEY='key1'
  DELETE FROM CONFIGURATION WHERE KEY='key2'
  INSERT INTO CONFIGURATION VALUES('key1','value1')
  INSERT INTO CONFIGURATION VALUES('key2','value2')
  INSERT INTO CONFIGURATIONS VALUES('test','key1','value1')
  INSERT INTO CONFIGURATIONS VALUES('test','key2','value2')
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  /*C11*/CONNECT USER sa PASSWORD ""
  CONNECT USER sa PASSWORD ""
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key1'
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key2'
  DELETE FROM CONFIGURATION WHERE KEY='key1'
  DELETE FROM CONFIGURATION WHERE KEY='key2'
  INSERT INTO CONFIGURATION VALUES('key1','value1')
  INSERT INTO CONFIGURATION VALUES('key2','value2')
  INSERT INTO CONFIGURATIONS VALUES('test','key1','value1')
  INSERT INTO CONFIGURATIONS VALUES('test','key2','value2')
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  /*C12*/CONNECT USER sa PASSWORD ""
  CONNECT USER sa PASSWORD ""
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key1'
  DELETE FROM CONFIGURATIONS WHERE NAME='test' AND KEY='key2'
  DELETE FROM CONFIGURATION WHERE KEY='key1'
  DELETE FROM CONFIGURATION WHERE KEY='key2'
  INSERT INTO CONFIGURATION VALUES('key1','value1')
  INSERT INTO CONFIGURATION VALUES('key2','value2')
  INSERT INTO CONFIGURATIONS VALUES('test','key1','value1')
  INSERT INTO CONFIGURATIONS VALUES('test','key2','value2')
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  SET AUTOCOMMIT TRUE
  SET READONLY FALSE
  SET AUTOCOMMIT TRUE
  
  
  
  1.1                  jakarta-commons/configuration/conf/dataset.xml
  
  Index: dataset.xml
  ===================================================================
  <?xml version="1.0"?>
  <!DOCTYPE dataset SYSTEM "dataset.dtd">
  
  <!-- dbunit DataSet for the TestDatabaseConfiguration test -->
  <dataset>
  
      <table name="configuration">
          <column>key</column>
          <column>value</column>
          <row>
              <value>key1</value>
              <value>value1</value>
          </row>
          <row>
              <value>key2</value>
              <value>value2</value>
          </row>
      </table>
  
      <table name="configurations">
          <column>name</column>
          <column>key</column>
          <column>value</column>
          <row>
              <value>test</value>
              <value>key1</value>
              <value>value1</value>
          </row>
          <row>
              <value>test</value>
              <value>key2</value>
              <value>value2</value>
          </row>
      </table>
  
  </dataset>
  
  
  
  1.1                  jakarta-commons/configuration/src/java/org/apache/commons/configuration/DatabaseConfiguration.java
  
  Index: DatabaseConfiguration.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2004 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.commons.configuration;
  
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Iterator;
  import javax.sql.DataSource;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * Configuration stored in a database.
   *
   * @author Emmanuel Bourg
   * @version $Revision: 1.1 $, $Date: 2004/01/18 16:15:46 $
   */
  public class DatabaseConfiguration extends AbstractConfiguration
  {
      private DataSource datasource;
  
      /** The name of the table containing the configurations. */
      private String table;
  
      /** The column containing the name of the configuration. */
      private String nameColumn;
  
      /** The column containing the keys. */
      private String keyColumn;
  
      /** The column containing the values. */
      private String valueColumn;
  
      /** The name of the configuration. */
      private String name;
  
      private static Log log = LogFactory.getLog(DatabaseConfiguration.class);
  
      /**
       * Build a configuration from a table containing multiple configurations.
       *
       * @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
       */
      public DatabaseConfiguration(DataSource datasource, String table, String nameColumn,
String keyColumn, String valueColumn, String name)
      {
          this.datasource = datasource;
          this.table = table;
          this.nameColumn = nameColumn;
          this.keyColumn = keyColumn;
          this.valueColumn = valueColumn;
          this.name = name;
      }
  
      /**
       * Build a configuration from a table.
       *
       * @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
       */
      public DatabaseConfiguration(DataSource datasource, String table, String keyColumn,
String valueColumn)
      {
          this(datasource, table, null, keyColumn, valueColumn, null);
      }
  
      protected Object getPropertyDirect(String key)
      {
          Object result = null;
  
          // build the query
          StringBuffer query = new StringBuffer("SELECT * FROM " + table + " WHERE " + keyColumn
+ "=?");
          if (nameColumn != null)
          {
              query.append(" AND " + nameColumn + "=?");
          }
  
          Connection conn = null;
          PreparedStatement pstmt = null;
  
          try
          {
              conn = datasource.getConnection();
  
              // bind the parameters
              pstmt = conn.prepareStatement(query.toString());
              pstmt.setString(1, key);
              if (nameColumn != null)
              {
                  pstmt.setString(2, name);
              }
  
              ResultSet rs = pstmt.executeQuery();
  
              if (rs.next())
              {
                  result = rs.getObject(valueColumn);
              }
          }
          catch (SQLException e)
          {
              log.error(e.getMessage(), e);
          }
          finally
          {
              try
              {
                  if (pstmt != null) { pstmt.close(); }
                  if (conn != null) { conn.close(); }
              }
              catch (SQLException e)
              {
                  log.error(e.getMessage(), e);
              }
          }
  
          return result;
      }
  
      protected void addPropertyDirect(String key, Object obj)
      {
          // build the query
          StringBuffer query = new StringBuffer("INSERT INTO " + table);
          if (nameColumn != null)
          {
              query.append(" (" + nameColumn + ", " + keyColumn + ", " + valueColumn + ")
VALUES (?, ?, ?)");
          }
          else
          {
              query.append(" (" + keyColumn + ", " + valueColumn + ") VALUES (?, ?)");
          }
  
          Connection conn = null;
          PreparedStatement pstmt = null;
  
          try
          {
              conn = datasource.getConnection();
  
              // bind the parameters
              pstmt = conn.prepareStatement(query.toString());
              int index = 1;
              if (nameColumn != null)
              {
                  pstmt.setString(index++, name);
              }
              pstmt.setString(index++, key);
              pstmt.setString(index++, (String) obj);
  
              pstmt.executeUpdate();
          }
          catch (SQLException e)
          {
              log.error(e.getMessage(), e);
          }
          finally
          {
              // clean up
              try
              {
                  if (pstmt != null) { pstmt.close(); }
                  if (conn != null) { conn.close(); }
              }
              catch (SQLException e)
              {
                  log.error(e.getMessage(), e);
              }
          }
      }
  
      public boolean isEmpty()
      {
          boolean empty = false;
  
          // build the query
          StringBuffer query = new StringBuffer("SELECT count(*) 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);
              }
  
              ResultSet rs = pstmt.executeQuery();
  
              if (rs.next())
              {
                  empty = (rs.getInt(1) == 0);
              }
          }
          catch (SQLException e)
          {
              log.error(e.getMessage(), e);
          }
          finally
          {
              // clean up
              try
              {
                  if (pstmt != null) { pstmt.close(); }
                  if (conn != null) { conn.close(); }
              }
              catch (SQLException e)
              {
                  log.error(e.getMessage(), e);
              }
          }
  
          return empty;
      }
  
      public boolean containsKey(String key)
      {
          boolean found = false;
  
          // build the query
          StringBuffer query = new StringBuffer("SELECT * FROM " + table + " WHERE " + keyColumn
+ "=?");
          if (nameColumn != null)
          {
              query.append(" AND " + nameColumn + "=?");
          }
  
          Connection conn = null;
          PreparedStatement pstmt = null;
  
          try
          {
              conn = datasource.getConnection();
  
              // bind the parameters
              pstmt = conn.prepareStatement(query.toString());
              pstmt.setString(1, key);
              if (nameColumn != null)
              {
                  pstmt.setString(2, name);
              }
  
              ResultSet rs = pstmt.executeQuery();
  
              found = rs.next();
          }
          catch (SQLException e)
          {
              log.error(e.getMessage(), e);
          }
          finally
          {
              // clean up
              try
              {
                  if (pstmt != null) { pstmt.close(); }
                  if (conn != null) { conn.close(); }
              }
              catch (SQLException e)
              {
                  log.error(e.getMessage(), e);
              }
          }
  
          return found;
      }
  
      public void clearProperty(String key)
      {
          // build the query
          StringBuffer query = new StringBuffer("DELETE FROM " + table + " WHERE " + keyColumn
+ "=?");
          if (nameColumn != null)
          {
              query.append(" AND " + nameColumn + "=?");
          }
  
          Connection conn = null;
          PreparedStatement pstmt = null;
  
          try
          {
              conn = datasource.getConnection();
  
              // bind the parameters
              pstmt = conn.prepareStatement(query.toString());
              pstmt.setString(1, key);
              if (nameColumn != null)
              {
                  pstmt.setString(2, name);
              }
  
              pstmt.executeUpdate();
          }
          catch (SQLException e)
          {
              log.error(e.getMessage(), e);
          }
          finally
          {
              // clean up
              try
              {
                  if (pstmt != null) { pstmt.close(); }
                  if (conn != null) { conn.close(); }
              }
              catch (SQLException e)
              {
                  log.error(e.getMessage(), e);
              }
          }
      }
  
      public Iterator getKeys()
      {
          Collection keys = new ArrayList();
  
          // build the query
          StringBuffer query = new StringBuffer("SELECT " + keyColumn + " 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);
              }
  
              ResultSet rs = pstmt.executeQuery();
  
              while (rs.next())
              {
                  keys.add(rs.getString(1));
              }
          }
          catch (SQLException e)
          {
              log.error(e.getMessage(), e);
          }
          finally
          {
              // clean up
              try
              {
                  if (pstmt != null) { pstmt.close(); }
                  if (conn != null) { conn.close(); }
              }
              catch (SQLException e)
              {
                  log.error(e.getMessage(), e);
              }
          }
  
          return keys.iterator();
      }
  }
  
  
  
  1.6       +39 -8     jakarta-commons/configuration/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/project.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- project.xml	16 Jan 2004 17:32:37 -0000	1.5
  +++ project.xml	18 Jan 2004 16:15:46 -0000	1.6
  @@ -158,25 +158,23 @@
           <war.bundle>true</war.bundle>
         </properties>            
       </dependency>
  +
       <dependency>
         <id>commons-digester</id>      
         <version>1.5</version>
         <properties>        
           <war.bundle>true</war.bundle>
         </properties>            
  -    </dependency>                    
  +    </dependency>
  +
       <dependency>
         <id>commons-beanutils</id>      
         <version>1.7-dev</version>
         <properties>        
           <war.bundle>true</war.bundle>
         </properties>            
  -    </dependency>                        
  -    <dependency>
  -      <id>junit</id>
  -      <version>3.8.1</version>
  -      <url>http://www.junit.org</url>
       </dependency>
  +
       <dependency>
         <id>xerces</id>
         <version>2.2.1</version>
  @@ -194,12 +192,45 @@
           <war.bundle>true</war.bundle>
         </properties>  
       </dependency>
  +
       <!-- Needed for testing -->
       <dependency>
  +      <id>junit</id>
  +      <version>3.8.1</version>
  +      <url>http://www.junit.org</url>
  +    </dependency>
  +
  +    <dependency>
         <id>simple-jndi</id>
         <version>0.8</version>
         <url>http://www.osjava.org/simple-jndi/</url> 
  -    </dependency>    
  +    </dependency>
  +
  +    <dependency>
  +      <id>commons-dbcp</id>
  +      <version>1.1</version>
  +    </dependency>
  +
  +    <dependency>
  +      <id>commons-pool</id>
  +      <version>1.1</version>
  +    </dependency>
  +
  +    <dependency>
  +      <id>hsqldb</id>
  +      <version>1.7.1</version>
  +    </dependency>
  +
  +    <dependency>
  +      <id>dbunit</id>
  +      <version>1.5.5</version>
  +    </dependency>
  +
  +    <dependency>
  +      <id>exml</id>
  +      <version>dbunit1.5.1</version>
  +    </dependency>
  +
     </dependencies>
   
     <build>
  
  
  

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