The functions as described previously are not really useful on their own: they rather form the groundwork for a higher layer which performs the actual modifications according to the objects' state.
We decided to use the mediator pattern as mentioned in the SDO whitepaper. Each mediator is specific to the used backend, so there could be an EJB mediator if the value objects have entity beans as counterparts, or an HibernateMediator which would transfer the version information in calls to the hibernate persistence layer. The only implemented mediator for now is the DemoMediator, which is used by the Webstart Demo application.
The application only sees the mediator interface, which provides very basic operations to manipulate the graph. Using a prototype VO, you ask the mediator to give you the complete graph:
TestVO prototype = new TestVO(); prototype.setId(new Long(0)); TestVO result = myMediator.getGraph(protoype);
This would look for an object with the primary key '0' and populate a value object with the corresponding data. Once you have obtained the graph , you do your modifications and call updateGraph to let the mediator apply your changes:
// perform a modification result.addObject(new TestVO()); // and update myMediator.updateGraph(result);
As the object is versioned, the mediator can use optimistic locking to detect concurrent access and inform the client accordingly (via a ConcurrencyException).
TestVO test = new TestVO(); test.setId(new Long(0)); TestVO result = myMediator.getGraph(test); result.setName("new"); myMediator.updateGraph(result); result.setName("new2"); // try to do a second update without obtaining the last version first myMediator.updateGraph(result); // will throw ConcurrencyException
To delete objects, simply remove them from the container:
// ... TestVO result = myMediator.getGraph(prototype); result.getCollection().clear(); // or remove(Object o) etc. myMediator.updateGraph(result);
Adding objects works in a similar way, just add objects to the container. Note that this only works if the container has been wrapped in a 'smart' container which does the actual work of flagging the objects.
back | index | next |