Re: Prevayler - update data

Bruno <[email protected]> Thu, 25 Oct 2012 22:53:04 -0200
Newsgroups gmane.comp.java.prevayler
Message-ID <CA+hv7hSjTKtG8q9JrTAOO359t64d=xiiMwELxNAehTZG5XEGRw@mail.gmail.com>
Thanks Karl,

I think we are looking to the same point.

I already saw all demos and I always see AddSomething.java and
RemoveSomething.java. I never saw an example of ChangeSomething.java. But
now I think I`m good!


I`m looking to the example that you said and I came across one question. Is
it a good option, for example in the GetEntity class to return a clone from
the object? I don`t think so, but I`m asking hehe!

Thanks!

On Thu, Oct 25, 2012 at 10:14 PM, Karl Wettin <[email protected]> wrote:

> 26 okt 2012 kl. 01:05 skrev Bruno:
>
> 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());
>
>
> I take it this is a bit of pseudo code where persist() really
> represents prevayler.execute(new UpdateObjectNameTransaction(o.getId(),
> o.getName()));
>
> If so, then you've got the concept! However, it should rather be:
>
> Object o = prevayler.readObject("1");
> prevayler.persist(o.getId(), o.getName() + "name");
>
>
> I.e. you should probably not be changing your business objects outside of
> a transaction.
>
> That is, unless you really know what you are doing. In some cases it might
> be possible to execute a transaction where you update the object outside of
> the transaction and pass down the complete object that you updated. In some
> of those cases I might also say that it's correct to do so (others here
> might not agree with this), it will however cause a whole bunch of caveats
> you'll need to be aware of. So simply avoid that for now.
>
>
> I'm in the process of writing a bunch of example applications using
> Prevayler with escalating complexity, but so far I've only committed a
> single one. You are welcome to take a look at it, perhaps it can be of
> help. I've commented all classes as much as I can in order to show common
> problems.
>
> <
> https://github.com/karlwettin/prevayler-examples/tree/master/e101/src/test/java/org/prevayler/examples/e101
> >
>
> Be aware, it use Prevayler 2.6-SNAPSHOT so you'll need to clone Prevayler
> from github and then run "mvn install -Dtest=false -DfailIfNoTests=false "
> to install it to your local Maven repository before running the examples.
>
>
> 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