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 Wed, 23 Apr 2003 16:57:15 GMT
brj         2003/04/23 09:57:15

  Modified:    src/java/org/apache/ojb/broker/util BrokerHelper.java
  Log:
  refactoring
  
  Revision  Changes    Path
  1.21      +12 -40    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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- BrokerHelper.java	23 Apr 2003 16:01:12 -0000	1.20
  +++ BrokerHelper.java	23 Apr 2003 16:57:15 -0000	1.21
  @@ -179,52 +179,19 @@
   		*/
   		if ((objectOrProxy instanceof Proxy) && Proxy.isProxyClass(objectOrProxy.getClass()))
   		{
  -			// return getKeyValuesForProxy((Proxy) objectOrProxy);
   			IndirectionHandler handler;
   			handler = (IndirectionHandler) Proxy.getInvocationHandler((Proxy) objectOrProxy);
   			return handler.getIdentity().getPrimaryKeyValues();
   		}
   		else if (objectOrProxy instanceof VirtualProxy)
   		{
  -			// return getKeyValuesForProxy((VirtualProxy) objectOrProxy);
   			IndirectionHandler handler;
   			handler = (IndirectionHandler) VirtualProxy.getIndirectionHandler((VirtualProxy) objectOrProxy);
   			return handler.getIdentity().getPrimaryKeyValues();
   		}
   		else
   		{
  -			// return getKeyValuesForObject(broker, cld, objectOrProxy, convertToSql);
  -
  -			FieldDescriptor[] pkFields = cld.getPkFields();
  -			Object[] result = new Object[pkFields.length];
  -			for (int i = 0; i < result.length; i++)
  -			{
  -				FieldDescriptor fd = pkFields[i];
  -				PersistentField f = fd.getPersistentField();
  -				Object cv = f.get(objectOrProxy);
  -
  -				// handle autoincrement attributes if not filled
  -				if (fd.isAutoIncrement())
  -				{
  -					// getAutoIncrementValue returns a value that is
  -					// properly typed for the java-world.  This value
  -					// needs to be converted to it's corresponding 
  -					// sql type so that the entire result array contains
  -					// objects that are properly typed for sql.
  -					cv = getAutoIncrementValue(fd, objectOrProxy, cv);
  -					if (convertToSql)
  -					{
  -						cv = fd.getFieldConversion().javaToSql(cv);
  -					}
  -				}
  -				else if (convertToSql)
  -				{
  -					// BRJ : apply type and value mapping
  -					cv = fd.getFieldConversion().javaToSql(cv);
  -				}
  -				result[i] = cv;
  -			}
  -			return result;
  +            return getValuesForObject(cld.getPkFields(), objectOrProxy, convertToSql);
   		}
   	}
   
  @@ -345,7 +312,7 @@
   	 * @param obj
   	 * @throws PersistenceBrokerException
   	 */
  -	protected Object[] getValues(FieldDescriptor[] fields, Object obj) throws PersistenceBrokerException
  +	protected Object[] getValuesForObject(FieldDescriptor[] fields, Object obj, boolean convertToSql)
throws PersistenceBrokerException
   	{
   		Object[] result = new Object[fields.length];
   
  @@ -365,9 +332,14 @@
   				// objects that are properly typed for sql.
   				cv = getAutoIncrementValue(fd, obj, cv);
   			}
  +         
  +            if (convertToSql)
  +            {
  +                // apply type and value conversion
  +                cv = fd.getFieldConversion().javaToSql(cv);
  +            }
   
  -			// apply type and value conversion
  -			result[i] = fd.getFieldConversion().javaToSql(cv);
  +            result[i] = cv;
   		}
   		return result;
   	}
  @@ -378,7 +350,7 @@
   	 */
   	public Object[] getNonKeyRwValues(ClassDescriptor cld, Object obj) throws PersistenceBrokerException
   	{
  -		return getValues(cld.getNonPkRwFields(), obj);
  +		return getValuesForObject(cld.getNonPkRwFields(), obj, true);
   	}
   
   	/**
  @@ -387,7 +359,7 @@
   	 */
   	public Object[] getAllRwValues(ClassDescriptor cld, Object obj) throws PersistenceBrokerException
   	{
  -		return getValues(cld.getAllRwFields(), obj);
  +		return getValuesForObject(cld.getAllRwFields(), obj, true);
   	}
   
   	public static String buildMessageString(Object obj, Object value, Field field)
  
  
  

Mime
View raw message