jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marti...@apache.org
Subject svn commit: r888298 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/config/ main/resources/org/apache/jackrabbit/core/config/ test/java/org/apache/jackrabbit/core/config/ test/java/org/apache/jackrabbit/core/util/db/ te...
Date Tue, 08 Dec 2009 09:23:53 GMT
Author: martijnh
Date: Tue Dec  8 09:23:53 2009
New Revision: 888298

URL: http://svn.apache.org/viewvc?rev=888298&view=rev
Log:
JCR-2422 Add the new DataSource element to the repository DTD

* Applied proposed patch.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/DataSourceConfig.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
    jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/config/repository-2.0-elements.dtd
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/config/DataSourceConfigTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/util/db/ConnectionFactoryTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/repository-descriptor-overlay/repository.xml

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/DataSourceConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/DataSourceConfig.java?rev=888298&r1=888297&r2=888298&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/DataSourceConfig.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/DataSourceConfig.java
Tue Dec  8 09:23:53 2009
@@ -29,8 +29,6 @@
  */
 public class DataSourceConfig {
 
-    public static final String LOGICAL_NAME = "logicalName";
-
     public static final String DRIVER = "driver";
 
     public static final String URL = "url";
@@ -53,8 +51,8 @@
      * @param props the properties (key and values must be strings)
      * @throws ConfigurationException on error
      */
-    public void addDataSourceDefinition(Properties props) throws ConfigurationException {
-        DataSourceDefinition def = new DataSourceDefinition(props);
+    public void addDataSourceDefinition(String name, Properties props) throws ConfigurationException
{
+        DataSourceDefinition def = new DataSourceDefinition(name, props);
         for (DataSourceDefinition existing : defs) {
             if (existing.getLogicalName().equals(def.getLogicalName())) {
                 throw new ConfigurationException("Duplicate logicalName for a DataSource:
"
@@ -77,11 +75,10 @@
     public static final class DataSourceDefinition {
 
         private static final List<String> allPropNames =
-            Arrays
-                .asList(LOGICAL_NAME, DRIVER, URL, USER, PASSWORD, DB_TYPE, VALIDATION_QUERY,
MAX_POOL_SIZE);
+            Arrays.asList(DRIVER, URL, USER, PASSWORD, DB_TYPE, VALIDATION_QUERY, MAX_POOL_SIZE);
 
         private static final List<String> allJndiPropNames =
-            Arrays.asList(LOGICAL_NAME, DRIVER, URL, USER, PASSWORD, DB_TYPE);
+            Arrays.asList(DRIVER, URL, USER, PASSWORD, DB_TYPE);
 
         private final String logicalName;
 
@@ -104,11 +101,12 @@
          * throws a {@link ConfigurationException} when the set of properties does not
          * satisfy some validity constraints.
          * 
+         * @param name the logical name of the data source
          * @param props the properties (string keys and values)
          * @throws ConfigurationException on error
          */
-        public DataSourceDefinition(Properties props) throws ConfigurationException {
-            this.logicalName = (String) props.getProperty(LOGICAL_NAME);
+        public DataSourceDefinition(String name, Properties props) throws ConfigurationException
{
+            this.logicalName = name;
             this.driver = (String) props.getProperty(DRIVER);
             this.url = (String) props.getProperty(URL);
             this.user = (String) props.getProperty(USER);
@@ -126,7 +124,7 @@
 
         private void verify(Properties props) throws ConfigurationException {
             // Check required properties
-            if (logicalName == null || "".equals(logicalName)) {
+            if (logicalName == null || "".equals(logicalName.trim())) {
                 throw new ConfigurationException("DataSource logical name must not be null
or empty");
             }
             if (driver == null || "".equals(driver)) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java?rev=888298&r1=888297&r2=888298&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
Tue Dec  8 09:23:53 2009
@@ -894,11 +894,23 @@
     }
 
     /**
-     * TODO
-     * 
-     * @param parent
-     * @return
-     * @throws ConfigurationException
+     * Parses the DataSources configuration under the given parent. It has the following
format:
+     * <pre>
+     *   &lt;DataSources&gt;
+     *     &lt;DataSource name="..."&gt;
+     *       &lt;param name="..." value="..."&gt;
+     *       ...
+     *     &lt;/DataSource&gt;
+     *     &lt;DataSource name="..."&gt;
+     *       &lt;param name="..." value="..."&gt;
+     *       ...
+     *     &lt;/DataSource&gt;
+     *   &lt;/DataSources&gt;
+     * </pre>
+     * <p/>
+     * @param parent the parent of the DataSources element
+     * @return a {@link DataSourceConfig} for the repository
+     * @throws ConfigurationException on error
      */
     protected DataSourceConfig parseDataSourceConfig(Element parent)
             throws ConfigurationException {
@@ -916,8 +928,9 @@
                     if (child2.getNodeType() == Node.ELEMENT_NODE
                             && DATASOURCE_ELEMENT.equals(child2.getNodeName())) {
                         Element dsdef = (Element) child2;
+                        String logicalName = getAttribute(dsdef, "name");
                         Properties props = parseParameters(dsdef);
-                        dsc.addDataSourceDefinition(props);
+                        dsc.addDataSourceDefinition(logicalName, props);
                     }
                 }
             }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/config/repository-2.0-elements.dtd
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/config/repository-2.0-elements.dtd?rev=888298&r1=888297&r2=888298&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/config/repository-2.0-elements.dtd
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/config/repository-2.0-elements.dtd
Tue Dec  8 09:23:53 2009
@@ -16,7 +16,14 @@
 -->
 
 <!ENTITY % jackrabbit-repository-elements
-         "Cluster|FileSystem|DataStore|Security|Workspaces|Workspace|Versioning|SearchIndex|RepositoryLockMechanism">
+         "DataSources|Cluster|FileSystem|DataStore|Security|Workspaces|Workspace|Versioning|SearchIndex|RepositoryLockMechanism">
+
+<!--
+    The DataSources element configures the data sources of the repository.
+-->
+<!ELEMENT DataSources (DataSource*)>
+<!ELEMENT DataSource (param*)>
+<!ATTLIST DataSource name CDATA #REQUIRED>
 
 <!--
     a virtual file system

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/config/DataSourceConfigTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/config/DataSourceConfigTest.java?rev=888298&r1=888297&r2=888298&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/config/DataSourceConfigTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/config/DataSourceConfigTest.java
Tue Dec  8 09:23:53 2009
@@ -34,12 +34,10 @@
     public void setUp() {
         cfg = new DataSourceConfig();
         minimalProps = new Properties();
-        minimalProps.put(DataSourceConfig.LOGICAL_NAME, "ds");
         minimalProps.put(DataSourceConfig.DRIVER, "org.apache.derby.jdbc.EmbeddedDriver");
         minimalProps.put(DataSourceConfig.URL, "url");
         minimalProps.put(DataSourceConfig.DB_TYPE, "dbType");
         minimalProps2 = new Properties();
-        minimalProps2.put(DataSourceConfig.LOGICAL_NAME, "ds2");
         minimalProps2.put(DataSourceConfig.DRIVER, "org.apache.derby.jdbc.EmbeddedDriver");
         minimalProps2.put(DataSourceConfig.URL, "url2");
         minimalProps2.put(DataSourceConfig.DB_TYPE, "dbType2");
@@ -50,7 +48,7 @@
     }
 
     public void testMinimalRegularConfig() throws ConfigurationException {
-        cfg.addDataSourceDefinition(minimalProps);
+        cfg.addDataSourceDefinition("ds", minimalProps);
         DataSourceDefinition def = cfg.getDefinitions().get(0);
         assertEquals("ds", def.getLogicalName());
         assertEquals("org.apache.derby.jdbc.EmbeddedDriver", def.getDriver());
@@ -64,15 +62,15 @@
     }
 
     public void testMultipleDefs() throws ConfigurationException {
-        cfg.addDataSourceDefinition(minimalProps);
-        cfg.addDataSourceDefinition(minimalProps2);
+        cfg.addDataSourceDefinition("ds1", minimalProps);
+        cfg.addDataSourceDefinition("ds2", minimalProps2);
         assertEquals(2, cfg.getDefinitions().size());
     }
 
     public void testTooMinimalConfig() {
         try {
             minimalProps.remove(DataSourceConfig.URL);
-            cfg.addDataSourceDefinition(minimalProps);
+            cfg.addDataSourceDefinition("ds", minimalProps);
             fail();
         } catch (ConfigurationException e) {
             // expected
@@ -82,7 +80,7 @@
     public void testInvalidProperty() {
         try {
             minimalProps.put("unknown property", "value");
-            cfg.addDataSourceDefinition(minimalProps);
+            cfg.addDataSourceDefinition("ds", minimalProps);
             fail();
         } catch (ConfigurationException e) {
             // expected
@@ -92,7 +90,7 @@
     public void testUnparseableProperty() {
         try {
             minimalProps.put(DataSourceConfig.MAX_POOL_SIZE, "no int");
-            cfg.addDataSourceDefinition(minimalProps);
+            cfg.addDataSourceDefinition("ds", minimalProps);
             fail();
         } catch (ConfigurationException e) {
             // expected
@@ -100,16 +98,33 @@
     }
 
     public void testDuplicateLogicalName() throws ConfigurationException {
-        cfg.addDataSourceDefinition(minimalProps);
-        minimalProps2.put(DataSourceConfig.LOGICAL_NAME, "ds");
+        cfg.addDataSourceDefinition("ds", minimalProps);
         try {
-            cfg.addDataSourceDefinition(minimalProps2);
+            cfg.addDataSourceDefinition("ds", minimalProps2);
             fail();
         } catch (ConfigurationException e) {
             // expected
         }
     }
-    
+
+    public void testEmptyLogicalName() throws ConfigurationException {
+        try {
+            cfg.addDataSourceDefinition("  ", minimalProps);
+            fail();
+        } catch (ConfigurationException e) {
+            // expected
+        }
+    }
+
+    public void testNullLogicalName() throws ConfigurationException {
+        try {
+            cfg.addDataSourceDefinition(null, minimalProps);
+            fail();
+        } catch (ConfigurationException e) {
+            // expected
+        }
+    }
+
     /**
      * It only makes sense to configure driver, url, username, password and dbType for
      * a DataSource which is to be obtained from JNDI.
@@ -120,7 +135,7 @@
         minimalProps.put(DataSourceConfig.DRIVER, "javax.naming.InitialContext");
         minimalProps.put(DataSourceConfig.MAX_POOL_SIZE, "10");
         try {
-            cfg.addDataSourceDefinition(minimalProps);
+            cfg.addDataSourceDefinition("ds", minimalProps);
             fail();
         } catch (ConfigurationException e) {
             // expected

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/util/db/ConnectionFactoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/util/db/ConnectionFactoryTest.java?rev=888298&r1=888297&r2=888298&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/util/db/ConnectionFactoryTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/util/db/ConnectionFactoryTest.java
Tue Dec  8 09:23:53 2009
@@ -168,13 +168,12 @@
         final String name = "some random name to not interfere with integration tests...";
         DataSourceConfig dsc = new DataSourceConfig();
         Properties props = new Properties();
-        props.put(DataSourceConfig.LOGICAL_NAME, name);
         props.put(DataSourceConfig.DRIVER, DRIVER);
         props.put(DataSourceConfig.URL, url);
         props.put(DataSourceConfig.DB_TYPE, "dbType");
         props.put(DataSourceConfig.MAX_POOL_SIZE, Integer.toString(maxCons));
         props.put(DataSourceConfig.VALIDATION_QUERY, validationQuery);
-        dsc.addDataSourceDefinition(props);
+        dsc.addDataSourceDefinition(name, props);
         connectionFactory.registerDataSources(dsc);
         return name;
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/repository-descriptor-overlay/repository.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/repository-descriptor-overlay/repository.xml?rev=888298&r1=888297&r2=888298&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/repository-descriptor-overlay/repository.xml
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/repository-descriptor-overlay/repository.xml
Tue Dec  8 09:23:53 2009
@@ -15,14 +15,13 @@
    See the License for the specific language governing permissions and
    limitations under the License.
   -->
-<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.6//EN"
-                            "http://jackrabbit.apache.org/dtd/repository-1.6.dtd">
+<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 2.0//EN"
+                            "http://jackrabbit.apache.org/dtd/repository-2.0.dtd">
 <!-- Example Repository Configuration File -->
 <Repository>
 
     <DataSources>
-        <DataSource>
-            <param name="logicalName" value="ds1"/>
+        <DataSource name="ds1">
             <param name="driver" value="@config.db.driver@"/>
             <param name="url" value="@config.db.url@"/>
             <param name="user" value="@config.db.user@"/>



Mime
View raw message