bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1498795 - in /bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303: ApacheValidatorFactory.java ClassValidator.java ConstraintValidation.java ElementDescriptorImpl.java
Date Tue, 02 Jul 2013 06:19:17 GMT
Author: rmannibucau
Date: Tue Jul  2 06:19:17 2013
New Revision: 1498795

URL: http://svn.apache.org/r1498795
Log:
adding basic cache to not validate ValidationAppliesTo each time

Modified:
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java?rev=1498795&r1=1498794&r2=1498795&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
(original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
Tue Jul  2 06:19:17 2013
@@ -118,7 +118,7 @@ public class ApacheValidatorFactory impl
      *
      * @param configuration
      */
-    protected void configure(ConfigurationState configuration) {
+    protected void configure(final ConfigurationState configuration) {
         getProperties().putAll(configuration.getProperties());
         setParameterNameProvider(configuration.getParameterNameProvider());
         setMessageInterpolator(configuration.getMessageInterpolator());

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java?rev=1498795&r1=1498794&r2=1498795&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
(original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
Tue Jul  2 06:19:17 2013
@@ -470,8 +470,11 @@ public class ClassValidator implements C
         // execute all property level validations
         for (final PropertyDescriptor prop : getConstraintsForClass(context.getMetaBean().getBeanClass()).getConstrainedProperties())
{
             final PropertyDescriptorImpl impl = PropertyDescriptorImpl.class.cast(prop);
-            checkValidationAppliesTo(impl.getConstraintDescriptors(), ConstraintTarget.PARAMETERS);
-            checkValidationAppliesTo(impl.getConstraintDescriptors(), ConstraintTarget.RETURN_VALUE);
+            if (!impl.isValidated(impl)) {
+                checkValidationAppliesTo(impl.getConstraintDescriptors(), ConstraintTarget.PARAMETERS);
+                checkValidationAppliesTo(impl.getConstraintDescriptors(), ConstraintTarget.RETURN_VALUE);
+                impl.setValidated(impl); // we don't really care about concurrency here
+            }
 
             final MetaProperty metaProperty = context.getMetaBean().getProperty(prop.getPropertyName());
             context.setMetaProperty(metaProperty);
@@ -485,8 +488,12 @@ public class ClassValidator implements C
         context.setMetaProperty(null);
         for (final Validation validation : context.getMetaBean().getValidations()) {
             if (ConstraintValidation.class.isInstance(validation)) {
-                checkValidationAppliesTo(ConstraintValidation.class.cast(validation).getValidationAppliesTo(),
ConstraintTarget.PARAMETERS);
-                checkValidationAppliesTo(ConstraintValidation.class.cast(validation).getValidationAppliesTo(),
ConstraintTarget.RETURN_VALUE);
+                final ConstraintValidation constraintValidation = ConstraintValidation.class.cast(validation);
+                if (!constraintValidation.isValidated()) {
+                    checkValidationAppliesTo(constraintValidation.getValidationAppliesTo(),
ConstraintTarget.PARAMETERS);
+                    checkValidationAppliesTo(constraintValidation.getValidationAppliesTo(),
ConstraintTarget.RETURN_VALUE);
+                    constraintValidation.setValidated(true);
+                }
             }
             validation.validate(context);
         }
@@ -767,12 +774,15 @@ public class ClassValidator implements C
         }
 
         // validations
-        if (parameterValues.length > 0) {
-            checkValidationAppliesTo(Collections.singleton(constructorDescriptor.getCrossParameterDescriptor()),
ConstraintTarget.IMPLICIT);
-            checkValidationAppliesTo(constructorDescriptor.getParameterDescriptors(), ConstraintTarget.IMPLICIT);
-        } else {
-            checkValidationAppliesTo(Collections.singleton(constructorDescriptor.getCrossParameterDescriptor()),
ConstraintTarget.PARAMETERS);
-            checkValidationAppliesTo(constructorDescriptor.getParameterDescriptors(), ConstraintTarget.PARAMETERS);
+        if (!constructorDescriptor.isValidated(constructor)) {
+            if (parameterValues.length > 0) {
+                checkValidationAppliesTo(Collections.singleton(constructorDescriptor.getCrossParameterDescriptor()),
ConstraintTarget.IMPLICIT);
+                checkValidationAppliesTo(constructorDescriptor.getParameterDescriptors(),
ConstraintTarget.IMPLICIT);
+            } else {
+                checkValidationAppliesTo(Collections.singleton(constructorDescriptor.getCrossParameterDescriptor()),
ConstraintTarget.PARAMETERS);
+                checkValidationAppliesTo(constructorDescriptor.getParameterDescriptors(),
ConstraintTarget.PARAMETERS);
+            }
+            constructorDescriptor.setValidated(constructor);
         }
 
         final Set<ConstraintViolation<T>> violations = new HashSet<ConstraintViolation<T>>();
@@ -887,12 +897,15 @@ public class ClassValidator implements C
             return Collections.emptySet();
         }
 
-        if (method.getParameterTypes().length > 0 && method.getReturnType() !=
Void.TYPE) {
-            checkValidationAppliesTo(Collections.singleton(methodDescriptor.getCrossParameterDescriptor()),
ConstraintTarget.IMPLICIT);
-            checkValidationAppliesTo(methodDescriptor.getParameterDescriptors(), ConstraintTarget.IMPLICIT);
-        } else if (method.getParameterTypes().length == 0) {
-            checkValidationAppliesTo(Collections.singleton(methodDescriptor.getCrossParameterDescriptor()),
ConstraintTarget.PARAMETERS);
-            checkValidationAppliesTo(methodDescriptor.getParameterDescriptors(), ConstraintTarget.PARAMETERS);
+        if (!methodDescriptor.isValidated(method)) {
+            if (method.getParameterTypes().length > 0 && method.getReturnType()
!= Void.TYPE) {
+                checkValidationAppliesTo(Collections.singleton(methodDescriptor.getCrossParameterDescriptor()),
ConstraintTarget.IMPLICIT);
+                checkValidationAppliesTo(methodDescriptor.getParameterDescriptors(), ConstraintTarget.IMPLICIT);
+            } else if (method.getParameterTypes().length == 0) {
+                checkValidationAppliesTo(Collections.singleton(methodDescriptor.getCrossParameterDescriptor()),
ConstraintTarget.PARAMETERS);
+                checkValidationAppliesTo(methodDescriptor.getParameterDescriptors(), ConstraintTarget.PARAMETERS);
+            }
+            methodDescriptor.setValidated(method);
         }
 
         final Set<ConstraintViolation<T>> violations = new HashSet<ConstraintViolation<T>>();

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java?rev=1498795&r1=1498794&r2=1498795&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java
(original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java
Tue Jul  2 06:19:17 2013
@@ -50,6 +50,8 @@ public class ConstraintValidation<T exte
 
     private Set<ConstraintValidation<?>> composedConstraints;
 
+    private boolean validated = false;
+
     /**
      * the owner is the type where the validation comes from. it is used to
      * support implicit grouping.
@@ -395,4 +397,12 @@ public class ConstraintValidation<T exte
     public void setValidationAppliesTo(final ConstraintTarget validationAppliesTo) {
         this.validationAppliesTo = validationAppliesTo;
     }
+
+    public boolean isValidated() {
+        return validated;
+    }
+
+    public void setValidated(final boolean validated) {
+        this.validated = validated;
+    }
 }

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java?rev=1498795&r1=1498794&r2=1498795&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java
(original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java
Tue Jul  2 06:19:17 2013
@@ -24,11 +24,13 @@ import javax.validation.ConstraintDeclar
 import javax.validation.metadata.ConstraintDescriptor;
 import javax.validation.metadata.ElementDescriptor;
 import javax.validation.metadata.GroupConversionDescriptor;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CopyOnWriteArraySet;
 
 /**
@@ -37,6 +39,7 @@ import java.util.concurrent.CopyOnWriteA
 public abstract class ElementDescriptorImpl implements ElementDescriptor {
     private final Set<GroupConversionDescriptor> groupConversions = new CopyOnWriteArraySet<GroupConversionDescriptor>();
     private boolean cascaded;
+    private final Collection<Object> validated = new CopyOnWriteArraySet<Object>();
 
     /**
      * Get a set of {@link ConstraintDescriptor}s from the specified array of
@@ -181,4 +184,12 @@ public abstract class ElementDescriptorI
     public void setCascaded(final boolean cascaded) {
         this.cascaded = cascaded;
     }
+
+    public boolean isValidated(final Object object) {
+        return validated.contains(object);
+    }
+
+    public void setValidated(final Object object) {
+        this.validated.add(object);
+    }
 }



Mime
View raw message