cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r662244 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/conf/ main/java/org/apache/cayenne/dba/ main/java/org/apache/cayenne/dba/oracle/ main/java/org/apache/cayenne/map/ test/java/org/apache/...
Date Sun, 01 Jun 2008 16:44:14 GMT
Author: aadamchik
Date: Sun Jun  1 09:44:13 2008
New Revision: 662244

URL: http://svn.apache.org/viewvc?rev=662244&view=rev
Log:
CAY-943 Support multiple cayenne.xml files in the project
(switching to ResourceFinder)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/MultiProjectConfiguration.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8Adapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/oracle/OracleAdapterTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/MultiProjectConfiguration.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/MultiProjectConfiguration.java?rev=662244&r1=662243&r2=662244&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/MultiProjectConfiguration.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/MultiProjectConfiguration.java
Sun Jun  1 09:44:13 2008
@@ -44,7 +44,7 @@
     @Override
     public void initialize() throws Exception {
 
-        logger.debug("initialize starting.");
+        logger.debug("loading configuration");
 
         InputStream in = this.getDomainConfiguration();
         if (in == null) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java?rev=662244&r1=662243&r2=662244&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
Sun Jun  1 09:44:13 2008
@@ -42,6 +42,7 @@
 import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.access.types.ExtendedTypeMap;
 import org.apache.cayenne.access.types.UtilDateType;
+import org.apache.cayenne.conf.ClasspathResourceFinder;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
@@ -79,7 +80,7 @@
         this.setSupportsFkConstraints(true);
 
         this.pkGenerator = createPkGenerator();
-        this.typesHandler = TypesHandler.getHandler(findAdapterResource("/types.xml"));
+        this.typesHandler = TypesHandler.getHandler(findResource("/types.xml"));
         this.extendedTypes = new ExtendedTypeMap();
         this.configureExtendedTypes(extendedTypes);
         this.ejbqlTranslatorFactory = createEJBQLTranslatorFactory();
@@ -104,14 +105,30 @@
      * </p>
      * 
      * @since 1.1
+     * @deprecated since 3.0 replaced with protected method {@link #findResource(String)}.
      */
     public URL findAdapterResource(String name) {
-        Class<?> adapterClass = this.getClass();
+        return findResource(name);
+    }
+
+    /**
+     * * Locates and returns a named adapter resource. A resource can be an XML file, etc.
+     * <p>
+     * This implementation is based on the premise that each adapter is located in its own
+     * Java package and all resources are in the same package as well. Resource lookup is
+     * recursive, so that if DbAdapter is a subclass of another adapter, parent adapter
+     * package is searched as a failover.
+     * </p>
+     * 
+     * @since 3.0
+     */
+    protected URL findResource(String name) {
+        Class<?> adapterClass = getClass();
 
         while (adapterClass != null && JdbcAdapter.class.isAssignableFrom(adapterClass))
{
 
             String path = Util.getPackagePath(adapterClass.getName()) + name;
-            URL url = ResourceLocator.findURLInClasspath(path);
+            URL url = new ClasspathResourceFinder().getResource(path);
             if (url != null) {
                 return url;
             }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8Adapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8Adapter.java?rev=662244&r1=662243&r2=662244&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8Adapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8Adapter.java
Sun Jun  1 09:44:13 2008
@@ -41,14 +41,14 @@
         return query.createSQLAction(new Oracle8ActionBuilder(this, node
                 .getEntityResolver()));
     }
-   
+
     @Override
-    public URL findAdapterResource(String name) {
-        
-        if("/types.xml".equals(name)) {
+    protected URL findResource(String name) {
+
+        if ("/types.xml".equals(name)) {
             name = "/types-oracle8.xml";
         }
-        
-        return super.findAdapterResource(name);
+
+        return super.findResource(name);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java?rev=662244&r1=662243&r2=662244&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
Sun Jun  1 09:44:13 2008
@@ -21,11 +21,13 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.TreeMap;
 
 import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.conf.ResourceFinder;
 import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.project.DataMapFile;
@@ -87,7 +89,7 @@
     public static final String PROCEDURE_TAG = "procedure";
     public static final String PROCEDURE_PARAMETER_TAG = "procedure-parameter";
 
-    //lifecycle listeners and callbacks related
+    // lifecycle listeners and callbacks related
     public static final String ENTITY_LISTENER_TAG = "entity-listener";
     public static final String PRE_PERSIST_TAG = "pre-persist";
     public static final String POST_PERSIST_TAG = "post-persist";
@@ -95,7 +97,7 @@
     public static final String POST_UPDATE_TAG = "post-update";
     public static final String PRE_REMOVE_TAG = "pre-remove";
     public static final String POST_REMOVE_TAG = "post-remove";
-    public static final String POST_LOAD_TAG = "post-load";    
+    public static final String POST_LOAD_TAG = "post-load";
 
     // Query-related
     public static final String QUERY_TAG = "query";
@@ -112,33 +114,32 @@
     public static final String DB_GENERATOR_TYPE_TAG = "db-generator-type";
     public static final String DB_GENERATOR_NAME_TAG = "db-generator-name";
     public static final String DB_KEY_CACHE_SIZE_TAG = "db-key-cache-size";
-    
+
     /**
      * @since 3.0
      */
     public static final String OBJ_ENTITY_ROOT = "obj-entity";
-    
+
     /**
      * @since 3.0
      */
     public static final String DB_ENTITY_ROOT = "db-entity";
-    
+
     /**
      * @since 3.0
      */
     public static final String PROCEDURE_ROOT = "procedure";
-    
+
     /**
      * @since 3.0
      */
     public static final String DATA_MAP_ROOT = "data-map";
-    
+
     /**
      * @since 3.0
      */
     public static final String JAVA_CLASS_ROOT = "java-class";
 
-
     // Reading from XML
     private DataMap dataMap;
     private DbEntity dbEntity;
@@ -327,6 +328,7 @@
         });
 
         startTagOpMap.put(ENTITY_LISTENER_TAG, new StartClosure() {
+
             @Override
             void execute(Attributes attributes) throws SAXException {
                 processStartEntitylistener(attributes);
@@ -334,6 +336,7 @@
         });
 
         startTagOpMap.put(PRE_PERSIST_TAG, new StartClosure() {
+
             @Override
             void execute(Attributes attributes) throws SAXException {
                 processStartPrePersist(attributes);
@@ -341,6 +344,7 @@
         });
 
         startTagOpMap.put(POST_PERSIST_TAG, new StartClosure() {
+
             @Override
             void execute(Attributes attributes) throws SAXException {
                 processStartPostPersist(attributes);
@@ -444,7 +448,7 @@
                 processEndDbAttribute();
             }
         });
-        
+
         endTagOpMap.put(DB_RELATIONSHIP_TAG, new EndClosure() {
 
             @Override
@@ -531,6 +535,7 @@
         });
 
         endTagOpMap.put(ENTITY_LISTENER_TAG, new EndClosure() {
+
             @Override
             void execute() throws SAXException {
                 processEndEntitylistener();
@@ -541,11 +546,11 @@
     private void processStartEntitylistener(Attributes attributes) {
         entityListener = new EntityListener(attributes.getValue("", "class"));
         if (objEntity != null) {
-            //we are inside of obj-entity tag
+            // we are inside of obj-entity tag
             objEntity.addEntityListener(entityListener);
         }
         else if (dataMap != null) {
-            //we are inside of datamap tag
+            // we are inside of datamap tag
             dataMap.addDefaultEntityListener(entityListener);
         }
     }
@@ -554,15 +559,14 @@
         entityListener = null;
     }
 
-
     private void processStartPrePersist(Attributes attributes) {
         String methodName = attributes.getValue("", "method-name");
         if (entityListener != null) {
-            //new "entity-listener" tag as a child of "obj-entity"
+            // new "entity-listener" tag as a child of "obj-entity"
             entityListener.getCallbackMap().getPrePersist().addCallbackMethod(methodName);
         }
         else if (objEntity != null) {
-            //new callback tags - children of "obj-entity"
+            // new callback tags - children of "obj-entity"
             objEntity.getCallbackMap().getPrePersist().addCallbackMethod(methodName);
         }
     }
@@ -570,7 +574,10 @@
     private void processStartPostPersist(Attributes attributes) {
         String methodName = attributes.getValue("", "method-name");
         if (entityListener != null) {
-            entityListener.getCallbackMap().getPostPersist().addCallbackMethod(methodName);
+            entityListener
+                    .getCallbackMap()
+                    .getPostPersist()
+                    .addCallbackMethod(methodName);
         }
         else if (objEntity != null) {
             objEntity.getCallbackMap().getPostPersist().addCallbackMethod(methodName);
@@ -608,7 +615,7 @@
     }
 
     private void processStartPostRemove(Attributes attributes) {
-        String methodName = attributes.getValue("", "method-name"); 
+        String methodName = attributes.getValue("", "method-name");
         if (entityListener != null) {
             entityListener.getCallbackMap().getPostRemove().addCallbackMethod(methodName);
         }
@@ -667,12 +674,20 @@
      */
     public DataMap loadDataMap(String uri) throws CayenneRuntimeException {
         // configure resource locator
-        ResourceLocator locator = configLocator();
-        InputStream in = locator.findResourceStream(uri);
-        if (in == null) {
+        ResourceFinder locator = createResourceFinder();
+        URL url = locator.getResource(uri);
+        if (url == null) {
             throw new CayenneRuntimeException("Can't find data map " + uri);
         }
 
+        InputStream in;
+        try {
+            in = url.openStream();
+        }
+        catch (IOException e) {
+            throw new CayenneRuntimeException(e);
+        }
+        
         try {
             InputSource inSrc = new InputSource(in);
             inSrc.setSystemId(uri);
@@ -715,8 +730,18 @@
     /**
      * Creates, configures and returns ResourceLocator object used to lookup DataMap
      * files.
+     * @deprecated since 3.0 use {@link #createResourceFinder()}.
      */
     protected ResourceLocator configLocator() {
+        return (ResourceLocator) createResourceFinder();
+    }
+    
+    /**
+     * Creates, configures and returns a default ResourceFinder.
+     * 
+     * @since 3.0
+     */
+    protected ResourceFinder createResourceFinder() {
         ResourceLocator locator = new ResourceLocator();
         locator.setSkipAbsolutePath(true);
         locator.setSkipClasspath(false);
@@ -724,6 +749,7 @@
         locator.setSkipHomeDirectory(false);
         return locator;
     }
+    
 
     @Override
     public void startElement(
@@ -849,11 +875,15 @@
         String serverOnly = atts.getValue("", "serverOnly");
         objEntity.setServerOnly(TRUE.equalsIgnoreCase(serverOnly));
 
-        String excludeSuperclassListeners = atts.getValue("", "exclude-superclass-listeners");
-        objEntity.setExcludingSuperclassListeners(TRUE.equalsIgnoreCase(excludeSuperclassListeners));
+        String excludeSuperclassListeners = atts.getValue(
+                "",
+                "exclude-superclass-listeners");
+        objEntity.setExcludingSuperclassListeners(TRUE
+                .equalsIgnoreCase(excludeSuperclassListeners));
 
         String excludeDefaultListeners = atts.getValue("", "exclude-default-listeners");
-        objEntity.setExcludingDefaultListeners(TRUE.equalsIgnoreCase(excludeDefaultListeners));
+        objEntity.setExcludingDefaultListeners(TRUE
+                .equalsIgnoreCase(excludeDefaultListeners));
 
         String lockType = atts.getValue("", "lock-type");
         if ("optimistic".equals(lockType)) {
@@ -955,7 +985,7 @@
                     + " Unable to parse target. Attributes:\n"
                     + printAttributes(atts));
         }
-        
+
         String collectionType = atts.getValue("", "collection-type");
         String mapKey = atts.getValue("", "map-key");
 
@@ -1255,7 +1285,8 @@
         for (int i = 0; i < atts.getLength(); i++) {
             value = atts.getQName(i);
             name = atts.getValue(i);
-            sb.append("Name: ").append(name).append("\tValue: ").append(value).append("\n");
+            sb.append("Name: ").append(name).append("\tValue: ").append(value).append(
+                    "\n");
         }
         return sb;
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/oracle/OracleAdapterTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/oracle/OracleAdapterTest.java?rev=662244&r1=662243&r2=662244&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/oracle/OracleAdapterTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/oracle/OracleAdapterTest.java
Sun Jun  1 09:44:13 2008
@@ -19,7 +19,6 @@
 
 package org.apache.cayenne.dba.oracle;
 
-import java.net.URL;
 import java.sql.Types;
 
 import org.apache.cayenne.map.DataMap;
@@ -45,12 +44,4 @@
         assertEquals(1, types.length);
         assertEquals("TIMESTAMP", types[0]);
     }
-
-    public void testFindAdapterResource() throws Exception {
-
-        URL typesURL = new OracleAdapter().findAdapterResource("/types.xml");
-        assertNotNull(typesURL);
-        assertTrue("Unexpected url:" + typesURL, typesURL.toExternalForm().endsWith(
-                "types.xml"));
-    }
 }



Mime
View raw message