Hi,
Thimo K�nig wrote:
> Hi Thomas,
>
>
>>achieved with little pain with the existing PB API. All you
>>have to to is to add the criteria for the foreign keys to the
>>selection criteria and perform a PB.getCollectionByQuery(...).
>
>
> Could you explain how to get the foreign keys criteria?
For an Object obj of a class c described by ClassDescriptor cld you want
to retrieve a collection attribute described by cod.
The following method will produce the query:
private Query getForeignKeyQuery(Object obj, ClassDescriptor cld,
CollectionDescriptor cod)
{
Object[] values = cld.getKeyValues(obj);
ClassDescriptor refCld = getClassDescriptor(cod.getItemClass());
FieldDescriptor[] fields =
cod.getForeignKeyFieldDescriptors(refCld);
Criteria criteria = new Criteria();
for (int i = 0; i < fields.length; i++)
{
FieldDescriptor fld = (FieldDescriptor) fields[i];
criteria.addEqualTo(fld.getAttributeName(), values[i]);
}
Query result =
QueryFactory.newQuery(refCld.getClassOfObject(), criteria);
return result;
}
It's easy to add further filtering criteria to this query and to perform
a PB.getCollectionByQuery(...)
> Shouldn't all the FK stuff be hidden?
As you can see from my code snippet: It's not a hack, but a clear
utilization of the OJB metadata facility.
cheers,
Thomas
>
> Thimo
>
> --
> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
>
>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>