You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Gary Jarrel <ga...@gmail.com> on 2007/10/17 05:18:41 UTC

More on Callbacks!

Hi Guys

This maybe a silly question, but is there a callback type which would
be fired before a new record is inserted into the database during the
call to commitChanges()? Doesn't seem like PRE_PERSIST or PRE_UPDATE
does the trick?

Maybe I'm just missing something with these whole callbacks business?

Cheers,

Gary

Re: More on Callbacks!

Posted by Mike Kienenberger <mk...@gmail.com>.
What about making it an "optional" JPA-style callback?

Maybe it can make it into the next JPA spec if it becomes popular :-)

On 10/17/07, Andrus Adamchik <an...@objectstyle.org> wrote:
>
> On Oct 17, 2007, at 12:44 PM, Martin Thelian wrote:
>
> > Hi!
> >
> > Andrus Adamchik schrieb:
> >> We followed JPA spec and implemented PRE_PERSIST to be called when a
> >> new object is registered with the context (i.e. prior to
> >> 'commitChanges'). So you you are right - there is no callback for the
> >> new objects right before 'commit'.
> >> [...]
> >> Also as a temporary workaround you can use the old "callback"
> >> CayenneDataObject.validateForInsert()
> > Why do you call this function an "old" callback? Are there any
> > plans to
> > remove it from a new release?
> >
> > Martin
>
> No, no plans to remove that. I think current refactoring of those
> methods into a separate interface called Validating (effectively
> making it optional for POJOs) is as far as we will go in 3.0.
>
> Andrus
>
>

Re: More on Callbacks!

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Oct 17, 2007, at 12:44 PM, Martin Thelian wrote:

> Hi!
>
> Andrus Adamchik schrieb:
>> We followed JPA spec and implemented PRE_PERSIST to be called when a
>> new object is registered with the context (i.e. prior to
>> 'commitChanges'). So you you are right - there is no callback for the
>> new objects right before 'commit'.
>> [...]
>> Also as a temporary workaround you can use the old "callback"
>> CayenneDataObject.validateForInsert()
> Why do you call this function an "old" callback? Are there any  
> plans to
> remove it from a new release?
>
> Martin

No, no plans to remove that. I think current refactoring of those  
methods into a separate interface called Validating (effectively  
making it optional for POJOs) is as far as we will go in 3.0.

Andrus


Re: More on Callbacks!

Posted by Martin Thelian <ma...@lovo.cc>.
Hi!

Andrus Adamchik schrieb:
> We followed JPA spec and implemented PRE_PERSIST to be called when a
> new object is registered with the context (i.e. prior to
> 'commitChanges'). So you you are right - there is no callback for the
> new objects right before 'commit'.
> [...]
> Also as a temporary workaround you can use the old "callback"
> CayenneDataObject.validateForInsert()
Why do you call this function an "old" callback? Are there any plans to
remove it from a new release?

Martin

Re: More on Callbacks!

Posted by Gary Jarrel <ga...@gmail.com>.
Hi Andrus

I figured that validateForInsert was my option, and works quite well.
I was trying to clean up one of my projects for 3.0 and hence trying
to switch all the overrides to callbacks.

The scenario is exactly as you described. I'm working on real estate
software internally it manages a number of properties, some of which
can be advertised on the web site. A property can be in either "on
market" or "not on market" state and the property can be either
"advertised" or "not advertised" state.

And, although the property can be on the market and not advertised on
the site, it can not be advertised on the site without being on the
market.

Hence during commit I need to check that the user has not taken the
property of the market and if he/she has then I need to automatically
set the state to "not advertised".

I hope this makes some sense! But no stress I'll just use the
validateForInsert method.

Thank you!

Gary

On 10/17/07, Andrus Adamchik <an...@objectstyle.org> wrote:
> We followed JPA spec and implemented PRE_PERSIST to be called when a
> new object is registered with the context (i.e. prior to
> 'commitChanges'). So you you are right - there is no callback for the
> new objects right before 'commit'.
>
> I suspect there are cases when this is not sufficient (i.e. when you
> need to change object state based on some other objects state that is
> only available on commit)... BTW, could you describe your scenario
> when you need such callback? Maybe there are other ways around.
>
> Also as a temporary workaround you can use the old "callback"
> CayenneDataObject.validateForInsert()
>
> Andrus
>
>
> On Oct 17, 2007, at 6:18 AM, Gary Jarrel wrote:
>
> > Hi Guys
> >
> > This maybe a silly question, but is there a callback type which would
> > be fired before a new record is inserted into the database during the
> > call to commitChanges()? Doesn't seem like PRE_PERSIST or PRE_UPDATE
> > does the trick?
> >
> > Maybe I'm just missing something with these whole callbacks business?
> >
> > Cheers,
> >
> > Gary
> >
>
>

Re: More on Callbacks!

Posted by Andrus Adamchik <an...@objectstyle.org>.
We followed JPA spec and implemented PRE_PERSIST to be called when a  
new object is registered with the context (i.e. prior to  
'commitChanges'). So you you are right - there is no callback for the  
new objects right before 'commit'.

I suspect there are cases when this is not sufficient (i.e. when you  
need to change object state based on some other objects state that is  
only available on commit)... BTW, could you describe your scenario  
when you need such callback? Maybe there are other ways around.

Also as a temporary workaround you can use the old "callback"  
CayenneDataObject.validateForInsert()

Andrus


On Oct 17, 2007, at 6:18 AM, Gary Jarrel wrote:

> Hi Guys
>
> This maybe a silly question, but is there a callback type which would
> be fired before a new record is inserted into the database during the
> call to commitChanges()? Doesn't seem like PRE_PERSIST or PRE_UPDATE
> does the trick?
>
> Maybe I'm just missing something with these whole callbacks business?
>
> Cheers,
>
> Gary
>