openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r780915 - in /openjpa/trunk: openjpa-all/ openjpa-persistence/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/validation/ openjpa/
Date Tue, 02 Jun 2009 02:55:16 GMT
Author: dwoods
Date: Tue Jun  2 02:55:15 2009
New Revision: 780915

URL: http://svn.apache.org/viewvc?rev=780915&view=rev
Log:
OPENJPA-1114 Bean Validation APIs should be an optional runtime dependency

Modified:
    openjpa/trunk/openjpa-all/pom.xml
    openjpa/trunk/openjpa-persistence/pom.xml
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/validation/ValidatorImpl.java
    openjpa/trunk/openjpa/pom.xml

Modified: openjpa/trunk/openjpa-all/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-all/pom.xml?rev=780915&r1=780914&r2=780915&view=diff
==============================================================================
--- openjpa/trunk/openjpa-all/pom.xml (original)
+++ openjpa/trunk/openjpa-all/pom.xml Tue Jun  2 02:55:15 2009
@@ -96,15 +96,16 @@
         </dependency>
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
-            <artifactId>geronimo-jms_1.1_spec</artifactId>
+            <artifactId>geronimo-jta_1.1_spec</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
-            <artifactId>geronimo-jta_1.1_spec</artifactId>
+            <artifactId>geronimo-jpa_2.0_spec</artifactId>
         </dependency>
+        <!-- optional runtime dependencies -->
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
-            <artifactId>geronimo-jpa_2.0_spec</artifactId>
+            <artifactId>geronimo-jms_1.1_spec</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>

Modified: openjpa/trunk/openjpa-persistence/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/pom.xml?rev=780915&r1=780914&r2=780915&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/pom.xml (original)
+++ openjpa/trunk/openjpa-persistence/pom.xml Tue Jun  2 02:55:15 2009
@@ -46,6 +46,7 @@
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-validation_1.0_spec</artifactId>
+            <scope>provided</scope>
         </dependency>        
     </dependencies>
     

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java?rev=780915&r1=780914&r2=780915&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
Tue Jun  2 02:55:15 2009
@@ -44,6 +44,7 @@
 import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
 import org.apache.openjpa.conf.OpenJPAProductDerivation;
 import org.apache.openjpa.conf.Specification;
+import org.apache.openjpa.event.LifecycleEventManager;
 import org.apache.openjpa.kernel.MixedLockLevels;
 import org.apache.openjpa.lib.conf.AbstractProductDerivation;
 import org.apache.openjpa.lib.conf.Configuration;
@@ -180,36 +181,10 @@
             compatibility.setFlushBeforeDetach(true);
             compatibility.setCopyOnDetach(true);
         } else {
-            // only try creating a ValidatingLifecycleEventManager if needed
-            if (!ValidatorImpl.skipValidation(conf.getValidationMode())) {
-                try {
-                    Validator val = new ValidatorImpl(
-                        conf.getValidationFactoryInstance(),
-                        conf.getValidationMode());
-                    // we have a Validator, so try to create a VLEM
-                    conf.setLifecycleEventManager(
-                        new ValidatingLifecycleEventManager(val));
-                } catch (RuntimeException e) {
-                    if (ValidatorImpl.validationRequired(
-                        conf.getValidationMode())) {
-                        // fatal error - ValidationMode requires a Validator
-                        conf.getConfigurationLog().error(
-                            _loc.get("vlem-creation-error"), e);
-                        // rethrow as a WrappedException
-                        throw new ValidationException(e);
-                    } else {
-                        // unexpected, but validation is optional,
-                        // so just log it as a warning
-                        conf.getConfigurationLog().warn(
-                            _loc.get("vlem-creation-warn", e.getMessage()));
-                    }
-                }
-            } else {
-                conf.getConfigurationLog().trace(
-                    "Validation has been disabled by supplied mode.");
-            }
-            // make sure we have at least a LifecycleEventManager created
-            conf.getLifecycleEventManagerInstance();
+            // see if we can/need to create a ValidatingLifecycleEventManager
+            // Note: BrokerImpl uses the instantiating getter, which will create
+            //   a normal LifecycleEventManager if a VLEM wasn't created.
+            conf.setLifecycleEventManager(createVLEM(conf));
         }
         return true;
     }
@@ -565,6 +540,76 @@
         }
 
     }
+    
+    /**
+     * Try creating a ValidatingLifecycleEventManager based on the configured
+     * validation mode. This allows the Bean Validation Spec API to be an
+     * optional runtime dependency.
+     * @param conf
+     * @return ValidatingLifecycleEventManager if appropriate
+     * @throws ValidationException - a WrappedException for fatal errors
+     */
+    /**
+     * @param conf
+     * @throws ValidationException
+     */
+    private LifecycleEventManager createVLEM(OpenJPAConfigurationImpl conf) 
+        throws ValidationException {
+        LifecycleEventManager lem = null;
+        // only try creating a ValidatingLifecycleEventManager if needed
+        if (!String.valueOf(ValidationMode.NONE).equalsIgnoreCase(
+            conf.getValidationMode())) {
+            // we'll use this in the exception handlers
+            boolean bValRequired = String.valueOf(ValidationMode.CALLBACK)
+                .equalsIgnoreCase(conf.getValidationMode());
+            // see if the javax.validation spec api is available
+            try {
+                @SuppressWarnings("unused")
+                Class<?> c = Class.forName(
+                    "javax.validation.ValidationException");
+            } catch (ClassNotFoundException e) {
+                if (bValRequired) {
+                    // fatal error - ValidationMode requires a validator
+                    conf.getConfigurationLog().error(
+                        _loc.get("vlem-creation-error"), e);
+                    // rethrow as a WrappedException
+                    throw new ValidationException(new RuntimeException(e));
+                } else {
+                    // no optional validation provider, so just trace output
+                    conf.getConfigurationLog().trace(
+                        _loc.get("vlem-creation-warn", e.getMessage()));
+                    return lem;
+                }
+            }
+            // we have the javax.validation APIs
+            try {
+                // try loading a validation provider
+                Validator val = new ValidatorImpl(
+                    conf.getValidationFactoryInstance(),
+                    conf.getValidationMode());
+                // we have a Validator, so try to create a VLEM
+                lem = new ValidatingLifecycleEventManager(val);
+            } catch (RuntimeException e) {
+                if (bValRequired) {
+                    // fatal error - ValidationMode requires a validator
+                    conf.getConfigurationLog().error(
+                        _loc.get("vlem-creation-error"), e);
+                    // rethrow as a WrappedException
+                    throw new ValidationException(e);
+                } else {
+                    // unexpected, but validation is optional,
+                    // so just log it as a warning
+                    conf.getConfigurationLog().warn(
+                        _loc.get("vlem-creation-warn", e.getMessage()));
+                }
+            }
+        } else {
+            conf.getConfigurationLog().trace(
+                "Validation has been disabled by supplied mode.");
+        }
+        return lem;
+    }
+
     /**
      * Custom configuration provider.   
      */

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/validation/ValidatorImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/validation/ValidatorImpl.java?rev=780915&r1=780914&r2=780915&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/validation/ValidatorImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/validation/ValidatorImpl.java
Tue Jun  2 02:55:15 2009
@@ -65,26 +65,6 @@
     }
 
     /**
-     * Is a Validator required based on the given validation mode?
-     * Keeping validation mode logic in a single class...
-     * @param mode
-     * @return true if a Validator is required
-     */
-    public static boolean validationRequired(String mode) {
-        return String.valueOf(ValidationMode.CALLBACK).equalsIgnoreCase(mode);
-    }
-    
-    /**
-     * Skip creating a Validator based on the given validation mode?
-     * Keeping validation mode logic in a single class...
-     * @param mode
-     * @return true if a Validator should not be created
-     */
-    public static boolean skipValidation(String mode) {
-        return String.valueOf(ValidationMode.NONE).equalsIgnoreCase(mode);
-    }
-    
-    /**
      * Default constructor.  Builds a default validator factory, if available
      * and creates the validator.
      * Returns an Exception if a Validator could not be created.

Modified: openjpa/trunk/openjpa/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa/pom.xml?rev=780915&r1=780914&r2=780915&view=diff
==============================================================================
--- openjpa/trunk/openjpa/pom.xml (original)
+++ openjpa/trunk/openjpa/pom.xml Tue Jun  2 02:55:15 2009
@@ -130,7 +130,7 @@
                         <!-- OSGi Bundle Metadata -->
                         <Private-Package>org.openjpa.lib.ant*,org.apache.jdbc.ant*,META-INF*</Private-Package>
                         <Export-Package>!META-INF*,!org.openjpa.lib.ant*,!org.apache.jdbc.ant*,org.apache.openjpa*</Export-Package>
-                        <Import-Package>com.ibm.*;resolution:=optional,org.postgresql.*;resolution:=optional,org.apache.tools.ant.*;resolution:=optional,org.apache.log4j.*;resolution:=optional,javax.activation.xa*;resolution:=optional,javax.jms.*;resolution:=optional,javax.transaction.*;resolution:=optional,javax.xml.bind.*;resolution:=optional,serp.*;resolution:=optional,*</Import-Package>
+                        <Import-Package>com.ibm.*;resolution:=optional,org.postgresql.*;resolution:=optional,org.apache.tools.ant.*;resolution:=optional,org.apache.log4j.*;resolution:=optional,javax.activation.xa*;resolution:=optional,javax.jms.*;resolution:=optional,javax.transaction.*;resolution:=optional,javax.validation.*;resolution:=optional,javax.xml.bind.*;resolution:=optional,serp.*;resolution:=optional,*</Import-Package>
                         <!-- Eclipse metadata -->
                         <Eclipse-Autostart>false</Eclipse-Autostart>
                         <Bundle-ClassPath>.</Bundle-ClassPath>



Mime
View raw message