cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1568609 - in /cayenne/main/trunk/cayenne-server/src: main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java test/java/org/apache/cayenne/configuration/server/ServerRuntime_ConfigFree_Test.java
Date Sat, 15 Feb 2014 10:33:24 GMT
Author: aadamchik
Date: Sat Feb 15 10:33:24 2014
New Revision: 1568609

URL: http://svn.apache.org/r1568609
Log:
Config-free ServerRuntime

Added:
    cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntime_ConfigFree_Test.java
Modified:
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java?rev=1568609&r1=1568608&r2=1568609&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
Sat Feb 15 10:33:24 2014
@@ -52,12 +52,15 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 /**
- * A {@link DataChannel} provider that provides a single instance of DataDomain configured
- * per configuration supplied via injected {@link DataChannelDescriptorLoader}.
+ * A {@link DataChannel} provider that provides a single instance of DataDomain
+ * configured per configuration supplied via injected
+ * {@link DataChannelDescriptorLoader}.
  * 
  * @since 3.1
  */
 public class DataDomainProvider implements Provider<DataDomain> {
+    
+    private static final String DEFAULT_NAME = "cayenne";
 
     private static Log logger = LogFactory.getLog(DataDomainProvider.class);
 
@@ -105,15 +108,10 @@ public class DataDomainProvider implemen
 
         try {
             return createAndInitDataDomain();
-        }
-        catch (ConfigurationException e) {
+        } catch (ConfigurationException e) {
             throw e;
-        }
-        catch (Exception e) {
-            throw new DataDomainLoadException(
-                    "Error loading DataChannel: '%s'",
-                    e,
-                    e.getMessage());
+        } catch (Exception e) {
+            throw new DataDomainLoadException("Error loading DataChannel: '%s'", e, e.getMessage());
         }
     }
 
@@ -123,65 +121,18 @@ public class DataDomainProvider implemen
 
     protected DataDomain createAndInitDataDomain() throws Exception {
 
-        if (locations == null || locations.isEmpty()) {
-            throw new DataDomainLoadException("No configuration location(s) available");
-        }
-
-        long t0 = System.currentTimeMillis();
-        if (logger.isDebugEnabled()) {
-            logger.debug("starting configuration loading: " + locations);
-        }
-
-        DataChannelDescriptor[] descriptors = new DataChannelDescriptor[locations.size()];
-
-        for (int i = 0; i < locations.size(); i++) {
-
-            String location = locations.get(i);
-
-            Collection<Resource> configurations = resourceLocator.findResources(location);
-
-            if (configurations.isEmpty()) {
-                throw new DataDomainLoadException(
-                        "Configuration resource \"%s\" is not found.",
-                        location);
-            }
-
-            Resource configurationResource = configurations.iterator().next();
-
-            // no support for multiple configs yet, but this is not a hard error
-            if (configurations.size() > 1) {
-                logger.info("found "
-                        + configurations.size()
-                        + " configurations for "
-                        + location
-                        + ", will use the first one: "
-                        + configurationResource.getURL());
-            }
-
-            ConfigurationTree<DataChannelDescriptor> tree = loader
-                    .load(configurationResource);
-            if (!tree.getLoadFailures().isEmpty()) {
-                // TODO: andrus 03/10/2010 - log the errors before throwing?
-                throw new DataDomainLoadException(
-                        tree,
-                        "Error loading DataChannelDescriptor");
-            }
+        DataChannelDescriptor descriptor;
 
-            descriptors[i] = tree.getRootNode();
+        if (locations.isEmpty()) {
+            descriptor = new DataChannelDescriptor();
+            descriptor.setName(DEFAULT_NAME);
+        } else {
+            descriptor = descriptorFromConfigs();
         }
 
-        long t1 = System.currentTimeMillis();
-
-        if (logger.isDebugEnabled()) {
-            logger.debug("finished configuration loading in " + (t1 - t0) + " ms.");
-        }
-
-        DataChannelDescriptor descriptor = descriptorMerger.merge(descriptors);
         DataDomain dataDomain = createDataDomain(descriptor.getName());
 
-        dataDomain.setMaxIdQualifierSize(runtimeProperties.getInt(
-                Constants.SERVER_MAX_ID_QUALIFIER_SIZE_PROPERTY,
-                -1));
+        dataDomain.setMaxIdQualifierSize(runtimeProperties.getInt(Constants.SERVER_MAX_ID_QUALIFIER_SIZE_PROPERTY,
-1));
 
         dataDomain.setQueryCache(new NestedQueryCache(queryCache));
         dataDomain.setEntitySorter(injector.getInstance(EntitySorter.class));
@@ -208,18 +159,13 @@ public class DataDomainProvider implemen
             dataNode.setDataSource(dataSource);
 
             // schema update strategy
-            String schemaUpdateStrategyType = nodeDescriptor
-                    .getSchemaUpdateStrategyType();
+            String schemaUpdateStrategyType = nodeDescriptor.getSchemaUpdateStrategyType();
 
             if (schemaUpdateStrategyType == null) {
                 dataNode.setSchemaUpdateStrategy(defaultSchemaUpdateStrategy);
-                dataNode.setSchemaUpdateStrategyName(defaultSchemaUpdateStrategy
-                        .getClass()
-                        .getName());
-            }
-            else {
-                SchemaUpdateStrategy strategy = objectFactory.newInstance(
-                        SchemaUpdateStrategy.class,
+                dataNode.setSchemaUpdateStrategyName(defaultSchemaUpdateStrategy.getClass().getName());
+            } else {
+                SchemaUpdateStrategy strategy = objectFactory.newInstance(SchemaUpdateStrategy.class,
                         schemaUpdateStrategyType);
                 dataNode.setSchemaUpdateStrategyName(schemaUpdateStrategyType);
                 dataNode.setSchemaUpdateStrategy(strategy);
@@ -251,9 +197,7 @@ public class DataDomainProvider implemen
         }
 
         if (defaultNode != null) {
-            logger.info("setting DataNode '"
-                    + defaultNode.getName()
-                    + "' as default, used by all unlinked DataMaps");
+            logger.info("setting DataNode '" + defaultNode.getName() + "' as default, used
by all unlinked DataMaps");
 
             dataDomain.setDefaultNode(defaultNode);
         }
@@ -264,4 +208,50 @@ public class DataDomainProvider implemen
 
         return dataDomain;
     }
+
+    private DataChannelDescriptor descriptorFromConfigs() {
+
+        long t0 = System.currentTimeMillis();
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("starting configuration loading: " + locations);
+        }
+
+        DataChannelDescriptor[] descriptors = new DataChannelDescriptor[locations.size()];
+
+        for (int i = 0; i < locations.size(); i++) {
+
+            String location = locations.get(i);
+
+            Collection<Resource> configurations = resourceLocator.findResources(location);
+
+            if (configurations.isEmpty()) {
+                throw new DataDomainLoadException("Configuration resource \"%s\" is not found.",
location);
+            }
+
+            Resource configurationResource = configurations.iterator().next();
+
+            // no support for multiple configs yet, but this is not a hard error
+            if (configurations.size() > 1) {
+                logger.info("found " + configurations.size() + " configurations for " + location
+                        + ", will use the first one: " + configurationResource.getURL());
+            }
+
+            ConfigurationTree<DataChannelDescriptor> tree = loader.load(configurationResource);
+            if (!tree.getLoadFailures().isEmpty()) {
+                // TODO: andrus 03/10/2010 - log the errors before throwing?
+                throw new DataDomainLoadException(tree, "Error loading DataChannelDescriptor");
+            }
+
+            descriptors[i] = tree.getRootNode();
+        }
+
+        long t1 = System.currentTimeMillis();
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("finished configuration loading in " + (t1 - t0) + " ms.");
+        }
+
+        return descriptorMerger.merge(descriptors);
+    }
 }

Added: cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntime_ConfigFree_Test.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntime_ConfigFree_Test.java?rev=1568609&view=auto
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntime_ConfigFree_Test.java
(added)
+++ cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntime_ConfigFree_Test.java
Sat Feb 15 10:33:24 2014
@@ -0,0 +1,60 @@
+/*****************************************************************
+ *   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.cayenne.configuration.server;
+
+import java.util.List;
+
+import org.apache.cayenne.DataRow;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.SQLSelect;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class ServerRuntime_ConfigFree_Test extends ServerCase {
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST_GROUP");
+        dbHelper.deleteAll("ARTIST");
+        dbHelper.deleteAll("EXHIBIT");
+        dbHelper.deleteAll("GALLERY");
+
+        TableHelper tArtist = new TableHelper(dbHelper, "ARTIST");
+        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+        tArtist.insert(33001, "AA1");
+        tArtist.insert(33002, "AA2");
+    }
+
+    public void testRunSQL() {
+
+        ServerRuntime runtime = new ServerRuntimeBuilder().build();
+
+        List<DataRow> result = SQLSelect.dataRowQuery("SELECT * FROM ARTIST").select(runtime.newContext());
+        assertEquals(2, result.size());
+    }
+}



Mime
View raw message