cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r448322 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src: main/java/org/apache/cayenne/ main/java/org/apache/cayenne/access/types/ test/java/org/apache/cayenne/access/types/
Date Wed, 20 Sep 2006 20:11:39 GMT
Author: aadamchik
Date: Wed Sep 20 13:11:38 2006
New Revision: 448322

URL: http://svn.apache.org/viewvc?view=rev&rev=448322
Log:
CAY-657

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/CayenneDataObject.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/AbstractType.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/BigIntegerType.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/BooleanType.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ByteArrayType.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/CalendarType.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/CharType.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ExtendedType.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ExtendedTypeDecorator.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/UtilDateType.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/VoidType.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/types/AbstractTypeTst.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/CayenneDataObject.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/CayenneDataObject.java?view=diff&rev=448322&r1=448321&r2=448322
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/CayenneDataObject.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/CayenneDataObject.java
Wed Sep 20 13:11:38 2006
@@ -22,6 +22,7 @@
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.lang.reflect.Array;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -31,7 +32,6 @@
 
 import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.access.DataNode;
-import org.apache.cayenne.access.types.ExtendedTypeMap;
 import org.apache.cayenne.conf.Configuration;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbJoin;
@@ -514,15 +514,6 @@
                     "No ObjEntity mapping found for DataObject " + getClass().getName());
         }
 
-        DataNode node = getDataContext().getParentDataDomain().lookupDataNode(
-                objEntity.getDataMap());
-        if (node == null) {
-            throw new CayenneRuntimeException("No DataNode found for objEntity: "
-                    + objEntity.getName());
-        }
-
-        ExtendedTypeMap types = node.getAdapter().getExtendedTypes();
-
         // validate mandatory attributes
 
         // handling a special case - meaningful mandatory FK... defer failures until
@@ -555,17 +546,39 @@
                 }
             }
 
-            if (value != null) {
-
-                // TODO: should we pass null values for validation as well?
-                // if so, class can be obtained from ObjAttribute...
+            // validate length
+            if (value != null && dbAttribute.getMaxLength() > 0) {
 
-                types.getRegisteredType(value.getClass()).validateProperty(
-                        this,
-                        objAttribute.getName(),
-                        value,
-                        dbAttribute,
-                        validationResult);
+                if (value.getClass().isArray()) {
+                    int len = Array.getLength(value);
+                    if (len > dbAttribute.getMaxLength()) {
+                        String message = "\""
+                                + objAttribute.getName()
+                                + "\" exceeds maximum allowed length ("
+                                + dbAttribute.getMaxLength()
+                                + " bytes): "
+                                + len;
+                        validationResult.addFailure(new BeanValidationFailure(
+                                this,
+                                objAttribute.getName(),
+                                message));
+                    }
+                }
+                else if (value instanceof CharSequence) {
+                    int len = ((CharSequence) value).length();
+                    if (len > dbAttribute.getMaxLength()) {
+                        String message = "\""
+                                + objAttribute.getName()
+                                + "\" exceeds maximum allowed length ("
+                                + dbAttribute.getMaxLength()
+                                + " chars): "
+                                + len;
+                        validationResult.addFailure(new BeanValidationFailure(
+                                this,
+                                objAttribute.getName(),
+                                message));
+                    }
+                }
             }
         }
 

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/AbstractType.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/AbstractType.java?view=diff&rev=448322&r1=448321&r2=448322
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/AbstractType.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/AbstractType.java
Wed Sep 20 13:11:38 2006
@@ -42,6 +42,7 @@
      * Helper method for ExtendedType implementors to check for null required values.
      * 
      * @since 1.2
+     * @deprecated since 3.0 as validation should not be done at the DataNode level.
      */
     public static boolean validateNull(
             Object source,
@@ -90,6 +91,8 @@
     /**
      * Always returns true. Simplifies subclass implementation, as only some of the types
      * can perform the validation.
+     * 
+     * @deprecated since 3.0 as validation should not be done at the DataNode level.
      */
     public boolean validateProperty(
             Object source,

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/BigIntegerType.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/BigIntegerType.java?view=diff&rev=448322&r1=448321&r2=448322
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/BigIntegerType.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/BigIntegerType.java
Wed Sep 20 13:11:38 2006
@@ -76,6 +76,9 @@
         }
     }
 
+    /**
+     * @deprecated since 3.0 as validation should not be done at the DataNode level.
+     */
     public boolean validateProperty(
             Object source,
             String property,

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/BooleanType.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/BooleanType.java?view=diff&rev=448322&r1=448321&r2=448322
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/BooleanType.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/BooleanType.java
Wed Sep 20 13:11:38 2006
@@ -42,6 +42,9 @@
         return Boolean.class.getName();
     }
 
+    /**
+     * @deprecated since 3.0 as validation should not be done at the DataNode level.
+     */
     public boolean validateProperty(
             Object source,
             String property,

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ByteArrayType.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ByteArrayType.java?view=diff&rev=448322&r1=448321&r2=448322
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ByteArrayType.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ByteArrayType.java
Wed Sep 20 13:11:38 2006
@@ -84,6 +84,7 @@
      * Validates byte[] property.
      * 
      * @since 1.1
+     * @deprecated since 3.0 as validation should not be done at the DataNode level.
      */
     public boolean validateProperty(
             Object source,

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/CalendarType.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/CalendarType.java?view=diff&rev=448322&r1=448321&r2=448322
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/CalendarType.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/CalendarType.java
Wed Sep 20 13:11:38 2006
@@ -176,6 +176,9 @@
                             + TypesMapping.getSqlNameByType(type));
     }
 
+    /**
+     * @deprecated since 3.0 as validation should not be done at the DataNode level.
+     */
     public boolean validateProperty(
             Object source,
             String property,

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/CharType.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/CharType.java?view=diff&rev=448322&r1=448321&r2=448322
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/CharType.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/CharType.java
Wed Sep 20 13:11:38 2006
@@ -65,6 +65,7 @@
      * Validates string property.
      * 
      * @since 1.1
+     * @deprecated since 3.0 as validation should not be done at the DataNode level.
      */
     public boolean validateProperty(
             Object source,

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ExtendedType.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ExtendedType.java?view=diff&rev=448322&r1=448321&r2=448322
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ExtendedType.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ExtendedType.java
Wed Sep 20 13:11:38 2006
@@ -46,6 +46,7 @@
      * <code>false</code> is returned.
      * 
      * @since 1.1
+     * @deprecated since 3.0 as validation should not be done at the DataNode level.
      */
     boolean validateProperty(
             Object source,

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ExtendedTypeDecorator.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ExtendedTypeDecorator.java?view=diff&rev=448322&r1=448321&r2=448322
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ExtendedTypeDecorator.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ExtendedTypeDecorator.java
Wed Sep 20 13:11:38 2006
@@ -63,6 +63,9 @@
         decorated.setJdbcObject(statement, fromJavaObject(value), pos, type, precision);
     }
 
+    /**
+     * @deprecated since 3.0 as validation should not be done at the DataNode level.
+     */
     public boolean validateProperty(
             Object source,
             String property,

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/UtilDateType.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/UtilDateType.java?view=diff&rev=448322&r1=448321&r2=448322
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/UtilDateType.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/UtilDateType.java
Wed Sep 20 13:11:38 2006
@@ -50,6 +50,7 @@
      * validations at the moment.
      * 
      * @since 1.1
+     * @deprecated since 3.0 as validation should not be done at the DataNode level.
      */
     public boolean validateProperty(
             Object source,

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/VoidType.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/VoidType.java?view=diff&rev=448322&r1=448321&r2=448322
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/VoidType.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/VoidType.java
Wed Sep 20 13:11:38 2006
@@ -39,6 +39,9 @@
         return Void.TYPE.getName();
     }
 
+    /**
+     * @deprecated since 3.0 as validation should not be done at the DataNode level.
+     */
     public boolean validateProperty(
             Object source,
             String property,

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/types/AbstractTypeTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/types/AbstractTypeTst.java?view=diff&rev=448322&r1=448321&r2=448322
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/types/AbstractTypeTst.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/types/AbstractTypeTst.java
Wed Sep 20 13:11:38 2006
@@ -34,6 +34,9 @@
  */
 public class AbstractTypeTst extends TestCase {
 
+    /**
+     * @deprecated since 3.0 as validation should not be done at the DataNode level.
+     */
     public void testValidateProperty() {
 
         // should always return true... not sure how else to test it?



Mime
View raw message