Author: oheger
Date: Mon Apr  8 19:58:43 2013
New Revision: 1465756

URL: http://svn.apache.org/r1465756
Log:
Added a builder parameters class for database configuration.

Added:
    
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DatabaseBuilderParametersImpl.java
    
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DatabaseBuilderParametersImplBeanInfo.java
    
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestDatabaseBuilderParametersImpl.java

Added: 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DatabaseBuilderParametersImpl.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DatabaseBuilderParametersImpl.java?rev=1465756&view=auto
==============================================================================
--- 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DatabaseBuilderParametersImpl.java
 (added)
+++ 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DatabaseBuilderParametersImpl.java
 Mon Apr  8 19:58:43 2013
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration.builder;
+
+import javax.sql.DataSource;
+
+/**
+ * <p>
+ * A specialized parameters object for database configurations.
+ * </p>
+ * <p>
+ * This class has properties for defining the database structures the
+ * configuration operates on.
+ * </p>
+ * <p>
+ * This class is not thread-safe. It is intended that an instance is 
constructed
+ * and initialized by a single thread during configuration of a
+ * {@code ConfigurationBuilder}.
+ * </p>
+ *
+ * @version $Id: $
+ * @since 2.0
+ */
+public class DatabaseBuilderParametersImpl extends BasicBuilderParameters
+        implements DatabaseBuilderProperties<DatabaseBuilderParametersImpl>
+{
+    /** Constant for the data source property. */
+    private static final String PROP_DATA_SOURCE = "dataSource";
+
+    /** Constant for the table property. */
+    private static final String PROP_TABLE = "table";
+
+    /** Constant for the key column property. */
+    private static final String PROP_KEY_COLUMN = "keyColumn";
+
+    /** Constant for the value column property. */
+    private static final String PROP_VALUE_COLUMN = "valueColumn";
+
+    /** Constant for the configuration name column property. */
+    private static final String PROP_CONFIG_NAME_COLUMN =
+            "configurationNameColumn";
+
+    /** Constant for the configuration name property. */
+    private static final String PROP_CONFIG_NAME = "configurationName";
+
+    /** Constant for the auto commit property. */
+    private static final String PROP_AUTO_COMMIT = "autoCommit";
+
+    public DatabaseBuilderParametersImpl setDataSource(DataSource src)
+    {
+        storeProperty(PROP_DATA_SOURCE, src);
+        return this;
+    }
+
+    public DatabaseBuilderParametersImpl setTable(String tname)
+    {
+        storeProperty(PROP_TABLE, tname);
+        return this;
+    }
+
+    public DatabaseBuilderParametersImpl setKeyColumn(String name)
+    {
+        storeProperty(PROP_KEY_COLUMN, name);
+        return this;
+    }
+
+    public DatabaseBuilderParametersImpl setValueColumn(String name)
+    {
+        storeProperty(PROP_VALUE_COLUMN, name);
+        return this;
+    }
+
+    public DatabaseBuilderParametersImpl setConfigurationNameColumn(String 
name)
+    {
+        storeProperty(PROP_CONFIG_NAME_COLUMN, name);
+        return this;
+    }
+
+    public DatabaseBuilderParametersImpl setConfigurationName(String name)
+    {
+        storeProperty(PROP_CONFIG_NAME, name);
+        return this;
+    }
+
+    public DatabaseBuilderParametersImpl setAutoCommit(boolean f)
+    {
+        storeProperty(PROP_AUTO_COMMIT, Boolean.valueOf(f));
+        return this;
+    }
+}

Added: 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DatabaseBuilderParametersImplBeanInfo.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DatabaseBuilderParametersImplBeanInfo.java?rev=1465756&view=auto
==============================================================================
--- 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DatabaseBuilderParametersImplBeanInfo.java
 (added)
+++ 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DatabaseBuilderParametersImplBeanInfo.java
 Mon Apr  8 19:58:43 2013
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration.builder;
+
+/**
+ * An additional {@code BeanInfo} class for
+ * {@link DatabaseBuilderParametersImpl}.
+ *
+ * @version $Id$
+ * @since 2.0
+ */
+public class DatabaseBuilderParametersImplBeanInfo extends
+        BuilderParametersBeanInfo
+{
+    /**
+     * Creates a new instance of {@code DatabaseBuilderParametersImplBeanInfo}.
+     */
+    public DatabaseBuilderParametersImplBeanInfo()
+    {
+        super(DatabaseBuilderParametersImpl.class);
+    }
+}

Added: 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestDatabaseBuilderParametersImpl.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestDatabaseBuilderParametersImpl.java?rev=1465756&view=auto
==============================================================================
--- 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestDatabaseBuilderParametersImpl.java
 (added)
+++ 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestDatabaseBuilderParametersImpl.java
 Mon Apr  8 19:58:43 2013
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration.builder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+import org.apache.commons.beanutils.PropertyUtils;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test class for {@code DatabaseBuilderParametersImpl}.
+ *
+ * @version $Id: $
+ */
+public class TestDatabaseBuilderParametersImpl
+{
+    /** The parameters object to be tested. */
+    private DatabaseBuilderParametersImpl params;
+
+    @Before
+    public void setUp() throws Exception
+    {
+        params = new DatabaseBuilderParametersImpl();
+    }
+
+    /**
+     * Tests whether the data source property can be set.
+     */
+    @Test
+    public void testSetDataSource()
+    {
+        DataSource src = EasyMock.createMock(DataSource.class);
+        EasyMock.replay(src);
+        assertSame("Wrong result", params, params.setDataSource(src));
+        assertSame("Data source not set", src,
+                params.getParameters().get("dataSource"));
+    }
+
+    /**
+     * Tests whether the table name can be set.
+     */
+    @Test
+    public void testSetTable()
+    {
+        String table = "TestTable";
+        assertSame("Wrong result", params, params.setTable(table));
+        assertEquals("Wrong table name", table,
+                params.getParameters().get("table"));
+    }
+
+    /**
+     * Tests whether the key column name can be set.
+     */
+    @Test
+    public void testSetKeyColumn()
+    {
+        String colName = "KEY_COLUMN";
+        assertSame("Wrong result", params, params.setKeyColumn(colName));
+        assertEquals("Wrong key column name", colName, params.getParameters()
+                .get("keyColumn"));
+    }
+
+    /**
+     * Tests whether the value column name can be set.
+     */
+    @Test
+    public void testSetValueColumn()
+    {
+        String colName = "VALUE_COLUMN";
+        assertSame("Wrong result", params, params.setValueColumn(colName));
+        assertEquals("Wrong value column name", colName, params.getParameters()
+                .get("valueColumn"));
+    }
+
+    /**
+     * Tests whether the configuration name column can be set.
+     */
+    @Test
+    public void testSetConfigurationNameColumn()
+    {
+        String colName = "CONFIG_COLUMN";
+        assertSame("Wrong result", params,
+                params.setConfigurationNameColumn(colName));
+        assertEquals("Wrong configuration name column", colName, params
+                .getParameters().get("configurationNameColumn"));
+    }
+
+    /**
+     * Tests whether the configuration name can be set.
+     */
+    @Test
+    public void testSetConfigurationName()
+    {
+        String confName = "TestConfiguration";
+        assertSame("Wrong result", params,
+                params.setConfigurationName(confName));
+        assertEquals("Wrong configuration name", confName, params
+                .getParameters().get("configurationName"));
+    }
+
+    /**
+     * Tests whether the auto commit flag can be set.
+     */
+    @Test
+    public void testSetAutoCommit()
+    {
+        assertSame("Wrong result", params, params.setAutoCommit(true));
+        assertEquals("Wrong auto commit flag", Boolean.TRUE, params
+                .getParameters().get("autoCommit"));
+    }
+
+    /**
+     * Tests whether properties can be set through BeanUtils.
+     */
+    @Test
+    public void testBeanProperties() throws Exception
+    {
+        PropertyUtils.setProperty(params, "table", "testTable");
+        PropertyUtils.setProperty(params, "autoCommit", Boolean.FALSE);
+        Map<String, Object> map = params.getParameters();
+        assertEquals("Wrong table name", "testTable", map.get("table"));
+        assertEquals("Wrong auto commit", Boolean.FALSE, 
map.get("autoCommit"));
+    }
+}


Reply via email to