db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/util BrokerHelper.java
Date Fri, 17 Oct 2003 11:39:36 GMT
brj         2003/10/17 04:39:36

  Modified:    src/java/org/apache/ojb/broker/util BrokerHelper.java
  Log:
  treat empty string as null
  patch by andrew clute
  
  Revision  Changes    Path
  1.26      +45 -29    db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java
  
  Index: BrokerHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- BrokerHelper.java	18 Jul 2003 17:23:12 -0000	1.25
  +++ BrokerHelper.java	17 Oct 2003 11:39:36 -0000	1.26
  @@ -280,6 +280,21 @@
   		return getKeyValues(cld, objectOrProxy, true);
   	}
   
  +    /**
  +     * Return true if aValue is regarded as null<br>
  +     * null, Number(0) or empty String 
  +     * @param aValue
  +     * @return
  +     */
  +    private boolean isNull(Object aValue)
  +    {
  +        return (
  +            (aValue == null)
  +                || ((aValue instanceof Number) && (((Number) aValue).intValue()
== 0))
  +                || ((aValue instanceof String) && (((String) aValue).length() ==
0)));
  +    }
  +    
  +    
   	/**
   	 * Get an autoincremented value that has already
   	 * had a field conversion run on it.
  @@ -293,34 +308,35 @@
   	 * @deprecated
   	 */
   	protected Object getAutoIncrementValue(FieldDescriptor fd, Object obj, Object cv)
  -	{
  -		if ((cv == null) || ((cv instanceof Number) && (((Number) cv).intValue() == 0)))
  -		{
  -			PersistentField f = fd.getPersistentField();
  -			try
  -			{
  -				// lookup SeqMan for a value matching db column an fieldconversion
  -				Object result = broker.serviceSequenceManager().getUniqueValue(fd);
  -				// reflect autoincrement value back into object
  -				f.set(obj, result);
  -				return result;
  -			}
  -			catch (MetadataException e)
  -			{
  -				throw new PersistenceBrokerException(
  -					"Error while trying to autoincrement field " + f.getDeclaringClass() + "#" + f.getName(),
  -					e);
  -			}
  -			catch (SequenceManagerException e)
  -			{
  -				throw new PersistenceBrokerException("Could not get key value", e);
  -			}
  -		}
  -		else
  -		{
  -			return cv;
  -		}
  -	}
  +    {
  +        if (isNull(cv))
  +        {
  +            PersistentField f = fd.getPersistentField();
  +            try
  +            {
  +                // lookup SeqMan for a value matching db column an
  +				// fieldconversion
  +                Object result = broker.serviceSequenceManager().getUniqueValue(fd);
  +                // reflect autoincrement value back into object
  +                f.set(obj, result);
  +                return result;
  +            }
  +            catch (MetadataException e)
  +            {
  +                throw new PersistenceBrokerException(
  +                    "Error while trying to autoincrement field " + f.getDeclaringClass()
+ "#" + f.getName(),
  +                    e);
  +            }
  +            catch (SequenceManagerException e)
  +            {
  +                throw new PersistenceBrokerException("Could not get key value", e);
  +            }
  +        }
  +        else
  +        {
  +            return cv;
  +        }
  +    }
   
   	/**
   	 * Get the values of the fields for an obj
  
  
  

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


Mime
View raw message