arminw 2005/04/22 10:21:05
Modified: src/java/org/apache/ojb/broker/util Tag: OJB_1_0_RELEASE
BrokerHelper.java
Log:
update methods to make 'super-table' strategy work
remove duplicated method
Revision Changes Path
No revision
No revision
1.57.2.13 +35 -46
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.57.2.12
retrieving revision 1.57.2.13
diff -u -r1.57.2.12 -r1.57.2.13
--- BrokerHelper.java 17 Apr 2005 13:29:37 -0000 1.57.2.12
+++ BrokerHelper.java 22 Apr 2005 17:21:05 -0000 1.57.2.13
@@ -386,23 +386,35 @@
}
/**
- * returns an Array with an Objects NON-PK VALUES (READ/WRITE only)
- * @throws MetadataException if there is an erros accessing o field
values
+ * Returns an array containing values for all non PK field READ/WRITE
attributes of the object
+ * based on the specified [EMAIL PROTECTED]
org.apache.ojb.broker.metadata.ClassDescriptor}.
+ * <br/>
+ * NOTE: This method doesn't do any checks on the specified [EMAIL
PROTECTED] org.apache.ojb.broker.metadata.ClassDescriptor}
+ * the caller is reponsible to pass a valid descriptor.
+ *
+ * @param cld The [EMAIL PROTECTED]
org.apache.ojb.broker.metadata.ClassDescriptor} to extract the RW-fields
+ * @param obj The object with target fields to extract.
+ * @throws MetadataException if there is an erros accessing obj field
values
*/
public ValueContainer[] getNonKeyRwValues(ClassDescriptor cld, Object
obj) throws PersistenceBrokerException
{
- ClassDescriptor realCld = getRealClassDescriptor(cld, obj);
- return getValuesForObject(realCld.getNonPkRwFields(), obj, true);
+ return getValuesForObject(cld.getNonPkRwFields(), obj, true);
}
/**
- * returns an array containing values for all the Objects attribute
(READ/WRITE only)
+ * Returns an array containing values for all READ/WRITE attributes of
the object
+ * based on the specified [EMAIL PROTECTED]
org.apache.ojb.broker.metadata.ClassDescriptor}.
+ * <br/>
+ * NOTE: This method doesn't do any checks on the specified [EMAIL
PROTECTED] org.apache.ojb.broker.metadata.ClassDescriptor}
+ * the caller is reponsible to pass a valid descriptor.
+ *
+ * @param cld The [EMAIL PROTECTED]
org.apache.ojb.broker.metadata.ClassDescriptor} to extract the RW-fields
+ * @param obj The object with target fields to extract.
* @throws MetadataException if there is an erros accessing obj field
values
*/
public ValueContainer[] getAllRwValues(ClassDescriptor cld, Object obj)
throws PersistenceBrokerException
{
- ClassDescriptor realCld = getRealClassDescriptor(cld, obj);
- return getValuesForObject(realCld.getAllRwFields(), obj, true);
+ return getValuesForObject(cld.getAllRwFields(), obj, true);
}
/**
@@ -434,14 +446,15 @@
int fieldDescriptorSize = fieldDescriptors.length;
for(int i = 0; i < fieldDescriptorSize; i++)
{
+ FieldDescriptor fld = fieldDescriptors[i];
/**
* a pk field is valid if it is either managed by OJB
* (autoincrement or locking) or if it does contain a
* valid non-null value.
*/
- if(!(fieldDescriptors[i].isAutoIncrement()
- || fieldDescriptors[i].isLocking()
- || assertValidPkValue(pkValues[i])))
+ if(!(fld.isAutoIncrement()
+ || fld.isLocking()
+ || !representsNull(fld, pkValues[i])))
{
return false;
}
@@ -458,42 +471,18 @@
*/
public boolean assertValidPkForDelete(ClassDescriptor cld, Object obj)
{
- FieldDescriptor fieldDescriptors[] = cld.getPkFields();
- int fieldDescriptorSize = fieldDescriptors.length;
- for(int i = 0; i < fieldDescriptorSize; i++)
+ if(!ProxyHelper.isProxy(obj))
{
- FieldDescriptor fd = fieldDescriptors[i];
- Object pkValue = fd.getPersistentField().get(obj);
- if (!assertValidPkValue(pkValue))
- {
- return false;
- }
- }
- return true;
- }
-
- /**
- * returns true if a value is non-null, STring instances are also
checked,
- * if they are non-empty.
- * @param pkValue the value to check
- * @return boolean
- */
- private boolean assertValidPkValue(Object pkValue)
- {
- // null as value of a primary key is not acceptable
- if(pkValue == null)
- {
- return false;
- }
- if(pkValue instanceof String)
- {
- // the toString() method on a String-object is maybe faster
- // than the downcast to String. Also use length() to test
- // if a String empty or not, this is faster than the comparing
- // a String-object with an empty string using the
equals()-method.
- if(pkValue.toString().trim().length() == 0)
- {
- return false;
+ FieldDescriptor fieldDescriptors[] = cld.getPkFields();
+ int fieldDescriptorSize = fieldDescriptors.length;
+ for(int i = 0; i < fieldDescriptorSize; i++)
+ {
+ FieldDescriptor fd = fieldDescriptors[i];
+ Object pkValue = fd.getPersistentField().get(obj);
+ if (representsNull(fd, pkValue))
+ {
+ return false;
+ }
}
}
return true;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]