I am porting an application from using JDO as its ORM to using Cayenne.
In the application a Worker has many RosterSlots. Here are some methods
I have put into the Cayenne Worker DO:
public boolean removeRosterSlot( RosterSlotI rosterSlot)
{
removeFromRosterSlots( (RosterSlot)rosterSlot);
return true; //TODO - change signature to returns void to avoid
this hack
}
public void addRosterSlot( RosterSlotI rosterSlot)
{
addToRosterSlots( (RosterSlot)rosterSlot);
}
As you can see I am adapting the original method signatures to call
_Worker methods. All reasonably ok so far. Next I have this method
signature that the existing application calls:
public void addRosterSlot(RosterSlotI rosterSlot, int index)
Because there is no equivalent in the generated _Worker, I wrote this
method in Worker, which is a modified version of the generated
addToRosterSlots() method:
/**
* Copied from super and altered to allow adding at a particular point
*..aram relName
*..aram value
*..aram setReverse
*/
public void addToManyTarget(String relName, DataObject value,
boolean setReverse, int index)
{
if (value == null) {
throw new NullPointerException("Attempt to add null target
DataObject.");
}
willConnect(relName, value);
// Now do the rest of the normal handling (regardless of whether
it was
// flattened or not)
List list = (List) readProperty(relName);
// call 'recordArcCreated' AFTER readProperty as readProperty
ensures that this
// object fault is resolved
getDataContext().getObjectStore().recordArcCreated(
this,
value.getObjectId(),
relName);
list.add(index, value);
if (value != null && setReverse) {
setReverseRelationship(relName, value);
}
}
When I wrote it I did sort of wonder why the generated method didn't
have the ability to insert at a particular index in the list. Anyway
this all works fine - I can use the application to insert a rosterSlot
at a particular position in a worker's list of rosterSlots.
The stage I am up to now is getting this application to work as an ROP
client. The client version of _Worker does not have any of the methods
that addToManyTarget( 'with the extra index arg') calls. So now I have
to re-think my approach...
Any help appreciated.
thanks - Chris
-- Seaweed Software Pty Ltd, http://www.strandz.org
This archive was generated by hypermail 2.0.0 : Thu Sep 25 2008 - 10:50:35 EDT