My 2 cents... Expanding on Michaels solution...
I vote for solution #1 suggested by Michael - keep two collections of cars
- one (persistent) managed by Cayenne, another (transient) managed by your
ParkingLot subclass. Your ParkingLot and Car classes become "decorators",
amking the rest of the app unaware of the differences, and still keeping
consistent object graph for Cayenne purposes (as Cayenne uses
"read/writeProperty").
This is a very clean option IMO. If you have problems with it, I suspect
it has something to do with your implementation, and they are likely easy
to fix. I think other suggested solutions may have varios undesired
consequences.
Use Jakarta commons-collections to help with list decorators.. E.g.
1. getCars() - override in subclass to do ListUtils.union(super.getCars(),
transientCars)
2. addCar() - override in subclass to do "if car is transient add to
transient cars and set car's parking lot, else call super)... you may need
to override car.setParkingLot to use the similar logic...
3. removeCar() - override applying the same logic as add...
Andrus
> 1) Use transient variables like I suggested. Just keep the persistent
> cars separate from the random cars. The persistent cars are obviously
> in a data context, the random ones created outside of one (this might
> not be possible, but I'd hope so).
>
> public List allCars()
> {
> List results = new List();
>
> results.addAll(savedCars());
> results.addAll(randomCars());
>
> return results;
> }
>
> (Add all the other plumbing you need to create the random cars, etc.)
This archive was generated by hypermail 2.0.0 : Wed Jun 30 2004 - 13:29:01 EDT