You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2007/03/15 01:52:54 UTC

svn commit: r518398 - /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java

Author: arminw
Date: Wed Mar 14 17:52:54 2007
New Revision: 518398

URL: http://svn.apache.org/viewvc?view=rev&rev=518398
Log:
add convenience methods to check for 'null' fields

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java?view=diff&rev=518398&r1=518397&r2=518398
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java Wed Mar 14 17:52:54 2007
@@ -331,7 +331,8 @@
     }
 
     /**
-     * Returns the NullCheck instance used for this field.
+     * Returns the {@link NullCheck} instance used for this field.
+     *
      * @return NullCheck instance for this field
      */
     public NullCheck getNullCheck()
@@ -343,10 +344,55 @@
         }
         return nullCheck;
     }
+
+    /**
+     * Returns wether the given object value represents 'null'
+     * for the specified field. Convenient method for:
+     * <br/>
+     * <code>
+     * fieldDescriptor.getNullCheck().representsNull(fieldDescriptor, aValue);
+     * </code>
+     *
+     * @param aValue the value to check if it represents 'null'
+     * @return true if and only if aValue represents null
+     */
+    public boolean representsNull(Object aValue)
+    {
+        // if no explicit class is specified use the default implementation
+        if (nullCheck == null)
+        {
+        	nullCheck = new NullCheckDefaultImpl();
+        }
+        return nullCheck.representsNull(this, aValue);
+    }
+
+    /**
+     * Returns wether the associated object value for this field of
+     * the specified persistence  capable object represents 'null'.
+     * Convenient method for:
+     * <br/>
+     * <code>
+     * <pre>
+     * Object aValue = fieldDescriptor.getPersistentField().get(obj);
+     * boolean result = fieldDescriptor.getNullCheck().representsNull(fieldDescriptor, aValue);
+     * </pre>
+     * </code>
+     *
+     * @param obj the persistence capable object to check if the value
+     * associated with this field represents 'null'
+     * @return true if and only if the value represents null
+     */
+    public boolean representsNullAssociatedValue(Object obj)
+    {
+        return representsNull(getPersistentField().get(obj));
+    }
     
     /**
-     * Creates the NullCheck implementation to use for this field.
+     * Creates the {@link NullCheck} implementation to use for this field.
+     *
      * @param nullCheckClassName FQCN of the NullCheck implementation to instantiate
+     * @see #representsNull(Object)
+     * @see #getNullCheck()
      */
     public void setNullCheckClassName(String nullCheckClassName)
     {
@@ -354,10 +400,15 @@
         {
             this.nullCheck = (NullCheck) ClassHelper.newInstance(nullCheckClassName);
         }
+        catch(ClassNotFoundException e)
+        {
+            throw new MetadataException(
+                    "Could not find NullCheck class '" + nullCheckClassName + "'", e);
+        }
         catch (Exception e)
         {
             throw new MetadataException(
-                    "Could not instantiate NullCheck class using default constructor", e);
+                    "Could not instantiate NullCheck class '" + nullCheckClassName + "' using default constructor", e);
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org