tomdz 2005/04/17 13:25:21
Modified: src/java/org/apache/ojb/broker/core
QueryReferenceBroker.java
Log:
Small change to support the unification of collection creation
Revision Changes Path
1.34 +20 -27
db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java
Index: QueryReferenceBroker.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- QueryReferenceBroker.java 14 Apr 2005 19:56:54 -0000 1.33
+++ QueryReferenceBroker.java 17 Apr 2005 20:25:21 -0000 1.34
@@ -255,12 +255,12 @@
/**
* retrieve a collection of itemClass Objects matching the Query query
*/
- private Collection getCollectionByQuery(Query query,
CollectionDescriptor cds) throws PersistenceBrokerException
+ private ManageableCollection getCollectionByQuery(Query query,
CollectionDescriptor cds) throws PersistenceBrokerException
{
// the class is guaranteed to be a subtype of Collection
Class collType =
pb.getConfiguration().getCollectionFactory().getCollectionClass(cds);
- return (Collection)getCollectionByQuery(collType, query,
cds.isLazy());
+ return (ManageableCollection)getCollectionByQuery(collType, query,
cds.isLazy());
}
/**
@@ -589,46 +589,39 @@
else
{
// this collection type will be used:
- Class collectionClass = cds.getCollectionClass();
PersistentField collectionField = cds.getPersistentField();
- Query fkQuery = getFKQuery(obj, cds);
- Object value;
+ Query fkQuery = getFKQuery(obj, cds);
+ Object value;
pb.ojbLocalCache().enableMaterializationCache();
try
{
- if (collectionClass == null)
+ ManageableCollection result =
getCollectionByQuery(fkQuery, cds);
+
+ // assign collection to objects attribute
+ // if attribute has an array type build an array, else
assign collection directly
+ if (collectionField.getType().isArray() && (result
instanceof Collection))
{
- Collection result = getCollectionByQuery(fkQuery,
cds);
+ Collection coll = (Collection)result;
+ int length = coll.size();
+ Class itemtype =
collectionField.getType().getComponentType();
+ int j = 0;
- // assign collection to objects attribute
- // if attribute has an array type build an array,
else assign collection directly
- if (collectionField.getType().isArray())
- {
- int length = result.size();
- Class itemtype =
collectionField.getType().getComponentType();
- Object resultArray = Array.newInstance(itemtype,
length);
- int j = 0;
- for (Iterator iter = result.iterator();
iter.hasNext();j++)
- {
- Array.set(resultArray, j, iter.next());
- }
- collectionField.set(obj, resultArray);
- }
- else
+ value = Array.newInstance(itemtype, length);
+ for (Iterator iter = coll.iterator();
iter.hasNext();j++)
{
- collectionField.set(obj, result);
+ Array.set(value, j, iter.next());
}
- value = result;
+ collectionField.set(obj, value);
}
else
{
- ManageableCollection result =
getCollectionByQuery(collectionClass, fkQuery, cds.isLazy());
- collectionField.set(obj, result);
value = result;
}
+ collectionField.set(obj, value);
+
if (prefetchProxies && (m_retrievalTasks != null)
&& (cds.getProxyPrefetchingLimit() > 0)
&& (cds.getQueryCustomizer() == null)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]