Re: Prevayler - update data

Bruno <[email protected]> Thu, 25 Oct 2012 21:05:28 -0200
Newsgroups gmane.comp.java.prevayler
Message-ID <CA+hv7hTkuacMRXaahxqmOkBZz=ckuV_RUpH7JxYRJF5aGqiZ8g@mail.gmail.com>
Hi Karl,

I read the Baptism Problem. I got this part here:

"To avoid the baptism problem, you just need to remove the code that
references business objects directly inside Transactions. This can be done
by, instead of receiving the business objects directly, looking them up
through some sort of identification."

If I understood I should not pass to a transaction class the real object. I
mean this "code":

Object o = prevayler.readObject("1");
o.setName(o.getName() + "name");
prevayler.persist(o);

this is wrong, right?

What should I do is this?

Object o = prevayler.readObject("1");
o.setName(o.getName() + "name");
prevayler.persist(o.getId(), o.getName());

Thanks


On Fri, Oct 19, 2012 at 11:10 PM, Karl Wettin <[email protected]> wrote:

>
> 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
>

------------------------------------------------------------------------------
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