openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r454184 - in /incubator/openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/ openjpa-lib/src/main/java/org/apache/openjpa/lib/util/
Date Sun, 08 Oct 2006 18:17:29 GMT
Author: awhite
Date: Sun Oct  8 11:17:28 2006
New Revision: 454184

URL: http://svn.apache.org/viewvc?view=rev&rev=454184
Log:
Make the inability to instantiate an auxiliary enhancer non-fatal.  Also cache
auxiliary enhancers statically to speed up enhancement.


Modified:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Services.java

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java?view=diff&rev=454184&r1=454183&r2=454184
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
Sun Oct  8 11:17:28 2006
@@ -109,6 +109,22 @@
 
     private static final Localizer _loc = Localizer.forPackage
         (PCEnhancer.class);
+    private static final AuxiliaryEnhancer[] _auxEnhancers;
+    static {
+        Class[] classes = Services.getImplementorClasses(
+            AuxiliaryEnhancer.class, 
+            AuxiliaryEnhancer.class.getClassLoader());
+        List auxEnhancers = new ArrayList(classes.length);
+        for (int i = 0; i < classes.length; i++) {
+            try {
+                auxEnhancers.add(classes[i].newInstance());
+		    } catch (Throwable t) {
+                // aux enhancer may rely on non-existant spec classes, etc
+		    }
+		}
+    	_auxEnhancers = (AuxiliaryEnhancer[]) auxEnhancers.toArray
+            (new AuxiliaryEnhancer[auxEnhancers.size()]);
+    }
 
     private final BCClass _pc;
     private final MetaDataRepository _repos;
@@ -118,7 +134,6 @@
 
     private boolean _defCons = true;
     private boolean _fail = false;
-    private AuxiliaryEnhancer[] _auxEnhancers = null;
     private File _dir = null;
     private BytecodeWriter _writer = null;
     private Map _backingFields = null;
@@ -2639,35 +2654,17 @@
 
     /**
      * Gets the auxiliary enhancers registered as {@link Services services}.
-     * Multi-call safe -- the first call locates the auxiliary enhancers,
-     * subsequent calls merely returns the existing set.
-     * 
-     * @return array of auxiliary enhancers. empty array if none is registered.
      */
     public AuxiliaryEnhancer[] getAuxiliaryEnhancers() {
-		if (_auxEnhancers == null) {
-		    try {
-                Class[] classes = Services.getImplementorClasses(
-                    AuxiliaryEnhancer.class, 
-                    AuxiliaryEnhancer.class.getClassLoader());
-                _auxEnhancers = new AuxiliaryEnhancer[classes.length];
-                for (int i = 0; i < _auxEnhancers.length; i++)
-                    _auxEnhancers[i] = (AuxiliaryEnhancer) classes[i].
-                        newInstance();
-		    } catch (Throwable t) {
-			    throw new GeneralException(t);
-		    }
-		}
-    	return _auxEnhancers;	
+		return _auxEnhancers;
     }
     
     /**
      * Allow any registered auxiliary code generators to run.
      */
     private void runAuxiliaryEnhancers() {
-    	AuxiliaryEnhancer[] auxEnhancers = getAuxiliaryEnhancers();
-    	for (int i = 0; i < auxEnhancers.length; i++)
-    		auxEnhancers[i].run(_pc, _meta);
+    	for (int i = 0; i < _auxEnhancers.length; i++)
+    		_auxEnhancers[i].run(_pc, _meta);
     }
     
     /**
@@ -2677,9 +2674,8 @@
      * @return true if any of the auxiliary enhancers skips the given method
      */
     private boolean skipEnhance(BCMethod method) {
-    	AuxiliaryEnhancer[] auxEnhancers = getAuxiliaryEnhancers();
-    	for (int i = 0; i < auxEnhancers.length; i++)
-    		if (auxEnhancers[i].skipEnhance(method))
+    	for (int i = 0; i < _auxEnhancers.length; i++)
+    		if (_auxEnhancers[i].skipEnhance(method))
     			return true;
     	return false;
     }

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties?view=diff&rev=454184&r1=454183&r2=454184
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
Sun Oct  8 11:17:28 2006
@@ -2,9 +2,9 @@
 runtime-enhance-pcclasses: You have enabled runtime enhancement, but have not \
 	specified the set of persistent classes.  OpenJPA must look for metadata for \
 	every loaded class, which might increase class load times significantly.
-running-all-classes: No targets were given.  Running on all classes listed in \
-	org.apache.openjpa.PersistentClasses, or all metadata files in classpath directories if
\
-	the property is not specified.
+running-all-classes: No targets were given.  Running on all classes in your \
+    persistent classes list, or all metadata files in classpath directories if \
+	you have not listed your persistent classes.
 detach-custom-ser: Type "{0}" is set to detach on serialize, but implements \
 	a custom readObject and/or writeObject method.  You cannot use custom \
 	serialization with detachment. 

Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Services.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Services.java?view=diff&rev=454184&r1=454183&r2=454184
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Services.java
(original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Services.java
Sun Oct  8 11:17:28 2006
@@ -124,8 +124,7 @@
                     }
                 }
             }
-        }
-        finally {
+        } finally {
             try {
                 in.close();
             } catch (IOException ioe) {



Mime
View raw message