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:53:31 UTC

svn commit: r518399 - /db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java

Author: arminw
Date: Wed Mar 14 17:53:30 2007
New Revision: 518399

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

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

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java?view=diff&rev=518399&r1=518398&r2=518399
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java Wed Mar 14 17:53:30 2007
@@ -342,7 +342,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()
@@ -356,8 +357,53 @@
     }
 
     /**
-     * Creates the NullCheck implementation to use for this field.
+     * 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 NONE-PROXY 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 {@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)
     {
@@ -365,10 +411,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