bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1513968 - in /bval/branches/bval-11: bval-core/src/main/java/org/apache/bval/model/Features.java bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java
Date Wed, 14 Aug 2013 17:15:26 GMT
Author: rmannibucau
Date: Wed Aug 14 17:15:26 2013
New Revision: 1513968

URL: http://svn.apache.org/r1513968
Log:
some more caching for BeanDescriptorImpl since we use it in validation phase now

Modified:
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/model/Features.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java

Modified: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/model/Features.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/model/Features.java?rev=1513968&r1=1513967&r2=1513968&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/model/Features.java (original)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/model/Features.java Wed
Aug 14 17:15:26 2013
@@ -36,6 +36,7 @@ public interface Features {
         String UNIQUE_KEY = "uniqueKey";
 
         String EXECUTABLES = "executables";
+        String PROPERTIES = "properties";
     }
 
     /** Features of {@link MetaProperty} */

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java?rev=1513968&r1=1513967&r2=1513968&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java
(original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java
Wed Aug 14 17:15:26 2013
@@ -79,26 +79,38 @@ public class BeanDescriptorImpl extends 
      * The {@link ApacheFactoryContext} (not) used by this
      * {@link BeanDescriptorImpl}
      */
-    private Set<ConstructorDescriptor> constrainedConstructors = new CopyOnWriteArraySet<ConstructorDescriptor>();
-    private Set<MethodDescriptor> containedMethods = new CopyOnWriteArraySet<MethodDescriptor>();
+    private final Set<ConstructorDescriptor> constrainedConstructors;
+    private final Set<MethodDescriptor> containedMethods;
     private final ExecutableMeta meta;
-    private Boolean isBeanConstrained = null;
-    private Boolean hasAnyContraints = null;
+    private final Boolean isBeanConstrained;
+    private final Set<PropertyDescriptor> validatedProperties;
 
-    protected BeanDescriptorImpl(ApacheFactoryContext factoryContext, MetaBean metaBean)
{
+    protected BeanDescriptorImpl(final ApacheFactoryContext factoryContext, final MetaBean
metaBean) {
         super(metaBean, metaBean.getBeanClass(), metaBean.getValidations());
 
+        Set<PropertyDescriptor> procedureDescriptors = metaBean.getFeature(Jsr303Features.Bean.PROPERTIES);
+        if (procedureDescriptors == null) {
+            procedureDescriptors = new HashSet<PropertyDescriptor>();
+            for (final MetaProperty prop : metaBean.getProperties()) {
+                if (prop.getValidations().length > 0
+                    || (prop.getMetaBean() != null || prop.getFeature(Features.Property.REF_CASCADE)
!= null)) {
+                    procedureDescriptors.add(getPropertyDescriptor(prop));
+                }
+            }
+            metaBean.putFeature(Jsr303Features.Bean.PROPERTIES, procedureDescriptors);
+        }
+
         ExecutableMeta executables = metaBean.getFeature(Jsr303Features.Bean.EXECUTABLES);
         if (executables == null) { // caching the result of it is important to avoid to compute
it for each Validator
             executables = new ExecutableMeta(factoryContext, metaBean, getConstraintDescriptors());
             metaBean.putFeature(Jsr303Features.Bean.EXECUTABLES, executables);
         }
 
+        validatedProperties = Collections.unmodifiableSet(procedureDescriptors);
         meta = executables;
         isBeanConstrained = meta.isBeanConstrained;
-        hasAnyContraints = meta.hasAnyContraints;
-        setConstrained(containedMethods, meta.methodConstraints.values());
-        setConstrained(constrainedConstructors, meta.contructorConstraints.values());
+        containedMethods = toConstrained(meta.methodConstraints.values());
+        constrainedConstructors = toConstrained(meta.contructorConstraints.values());
     }
 
     private static void addGroupConvertion(final MetaProperty prop, final PropertyDescriptorImpl
edesc) {
@@ -188,15 +200,6 @@ public class BeanDescriptorImpl extends 
         return isBeanConstrained;
     }
 
-    private boolean hasAnyConstraints() {
-        if (hasAnyContraints == null) {
-            synchronized (this) {
-
-            }
-        }
-        return hasAnyContraints;
-    }
-
     /**
      * Return the property level constraints for a given propertyName or {@code null} if
      * either the property does not exist or has no constraint. The returned
@@ -235,13 +238,6 @@ public class BeanDescriptorImpl extends 
      * @return the property descriptors having at least a constraint defined
      */
     public Set<PropertyDescriptor> getConstrainedProperties() {
-        Set<PropertyDescriptor> validatedProperties = new HashSet<PropertyDescriptor>();
-        for (MetaProperty prop : metaBean.getProperties()) {
-            if (prop.getValidations().length > 0
-                || (prop.getMetaBean() != null || prop.getFeature(Features.Property.REF_CASCADE)
!= null)) {
-                validatedProperties.add(getPropertyDescriptor(prop));
-            }
-        }
         return Collections.unmodifiableSet(validatedProperties);
     }
 
@@ -308,12 +304,14 @@ public class BeanDescriptorImpl extends 
         return "BeanDescriptorImpl{" + "returnType=" + elementClass + '}';
     }
 
-    private <A extends ExecutableDescriptor> void setConstrained(final Set<A>
dest, final Collection<A> src) {
+    private static <A extends ExecutableDescriptor> Set<A> toConstrained(final
Collection<A> src) {
+        final Set<A> dest = new HashSet<A>();
         for (final A d : src) {
             if (d.hasConstrainedParameters() || d.hasConstrainedReturnValue()) {
                 dest.add(d);
             }
         }
+        return Collections.unmodifiableSet(dest);
     }
 
     private static class ExecutableMeta {
@@ -323,7 +321,6 @@ public class BeanDescriptorImpl extends 
         private final Map<String, MethodDescriptor> methodConstraints = new HashMap<String,
MethodDescriptor>();
         private final Map<String, ConstructorDescriptor> contructorConstraints = new
HashMap<String, ConstructorDescriptor>();
         private Boolean isBeanConstrained = null;
-        private Boolean hasAnyContraints = null;
 
         private ExecutableMeta(final ApacheFactoryContext factoryContext, final MetaBean
metaBean1, final Collection<ConstraintDescriptor<?>> constraintDescriptors) {
             this.metaBean = metaBean1;
@@ -332,7 +329,7 @@ public class BeanDescriptorImpl extends 
 
             buildExecutableDescriptors();
 
-            // cache hasAnyContraints
+            boolean hasAnyContraints = false;
             if (!constraintDescriptors.isEmpty()) {
                 hasAnyContraints = true;
             } else {



Mime
View raw message