Re: Prevayler - update data
Karl Wettin <[email protected]> Sat, 20 Oct 2012 04:10:39 +0200
| Newsgroups | gmane.comp.java.prevayler |
|---|---|
| Message-ID | <[email protected]> |
19 okt 2012 kl. 18:15 skrev Bruno:
> I'm trying to learn how all prevayler works and I came across one question. I didn't find any examples about in how to update an object.
>
> For my local tests using junit I create a transaction that receive the updated object and inside this I do the getter and setters for all the attributes.
>
> Is this the correct way to work? Do you guys have an example?
Hi Bruno,
I'm not quite sure what you're asking, but first of all you need to be aware of the baptism problem: <http://docs.codehaus.org/display/PREVAYLER/The+Baptism+Problem>, i.e. don't back-reference to an instance persistent in the prevalence layer.
There are several ways of updating an object and it's more or less up to your implementation on how to handle this. The (perhaps not so simple) answer is that it depends on complexity of what you want to do. The simplest solution would be to create a transaction that contains nothing but the one attribute you want to update:
class UpdateAttributeTransaction implements Transaction {
Object key;
Object value;
UpdateAttributeTransaction(key, value){
this.key=key;
this.value=value;
}
executeOn(Object root, Date executionTime) {
((MyRoot)root).getKey(key).setValue(value);
}
}
For a very simple example see <https://github.com/jsampson/prevayler/blob/master/demos/demo1/src/main/java/org/prevayler/demos/demo1/NumberStorageTransaction.java>
Your solution might however be as complex as a transaction including your a complete object graph (again, isolated from the prevalent root) that computes a delta in the transaction and updating that in your root:
Let me know if you have any questions.
karl
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
To unsubscribe go to the end of this page: http://lists.sourceforge.net/lists/listinfo/prevayler-discussion
_______________________________________________
"Databases in Memoriam" -- http://www.prevayler.org