You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Bruno René Santos <br...@holos.pt> on 2010/08/09 11:41:41 UTC

Rollbacks and Listeners

Hello all,

 

Im using cayenne on a banking system, where commits and rollbacks are critical.
I was thinking about using cayenne callbacks to include the creation of logs
during database operations. My doubt is what happens when there is a rollback on
the database during a transaction in terms of callbacks? Do all Pre... callbacks
are called but no Post.. callbacks? Is there any way to know on the callbacks
that the objects were rollbacked?

 

Regards

Bruno Santos

 


Re: Rollbacks and Listeners

Posted by Andrey Razumovsky <ra...@gmail.com>.
I meant

callbacks are not called during rollback :)

2010/8/9 Andrey Razumovsky <ra...@gmail.com>

> Hi,
>
> Unless something's changed, callbacks are not called during callback. Also
> note that only "post" callbacks can tell for sure that DB operations had
> happened
>
> 2010/8/9 Bruno René Santos <br...@holos.pt>
>
> Hello all,
>>
>>
>>
>> Im using cayenne on a banking system, where commits and rollbacks are
>> critical.
>> I was thinking about using cayenne callbacks to include the creation of
>> logs
>> during database operations. My doubt is what happens when there is a
>> rollback on
>> the database during a transaction in terms of callbacks? Do all Pre...
>> callbacks
>> are called but no Post.. callbacks? Is there any way to know on the
>> callbacks
>> that the objects were rollbacked?
>>
>>
>>
>> Regards
>>
>> Bruno Santos
>>
>>
>>
>>
>
>
> --
> Andrey
>



-- 
Andrey

Re: Rollbacks and Listeners

Posted by Andrey Razumovsky <ra...@gmail.com>.
Hi,

Unless something's changed, callbacks are not called during callback. Also
note that only "post" callbacks can tell for sure that DB operations had
happened

2010/8/9 Bruno René Santos <br...@holos.pt>

> Hello all,
>
>
>
> Im using cayenne on a banking system, where commits and rollbacks are
> critical.
> I was thinking about using cayenne callbacks to include the creation of
> logs
> during database operations. My doubt is what happens when there is a
> rollback on
> the database during a transaction in terms of callbacks? Do all Pre...
> callbacks
> are called but no Post.. callbacks? Is there any way to know on the
> callbacks
> that the objects were rollbacked?
>
>
>
> Regards
>
> Bruno Santos
>
>
>
>


-- 
Andrey

Re: Rollbacks and Listeners

Posted by Mike Kienenberger <mk...@gmail.com>.
I handle error trapping on the commit statement.   If it throws an
exception, then I do something about it.

Rollbacks in practice over the last few years have almost always been
due to the loss of the ability to change database records (network
issues, database server issues), so logging has to occur via other
methods (inform the end-user if it's interactive, send emails, write
errors to a log file on the local host).  Attempting to write a second
database record at this point normally fails.


On Mon, Aug 9, 2010 at 11:01 AM, Joe Baldwin <jf...@earthlink.net> wrote:
> Wouldn't an important business-concern (or rule) be that if there was indeed a rollback, then one might want to log it (via a Cayenne insert)?
>
> I am doing something like this right now and it is a tad tricky.
>
>
>
>
> On Aug 9, 2010, at 10:37 AM, Mike Kienenberger wrote:
>
>> On Mon, Aug 9, 2010 at 5:41 AM, Bruno René Santos <br...@holos.pt> wrote:
>>> Im using cayenne on a banking system, where commits and rollbacks are critical.
>>> I was thinking about using cayenne callbacks to include the creation of logs
>>> during database operations. My doubt is what happens when there is a rollback on
>>> the database during a transaction in terms of callbacks? Do all Pre... callbacks
>>> are called but no Post.. callbacks? Is there any way to know on the callbacks
>>> that the objects were rollbacked?
>>
>> As long as you create the audit records in the same transaction as the
>> rest of the data, when the transaction is rolled back or committed,
>> then the audit logs will be rolled back or committed.   You should not
>> have to do anything on a Post, only on a Pre.
>>
>> ============
>>
>> An old issue on auditing is here.   Not sure how relevant it is for
>> 3.0 as I haven't used 3.0 yet.
>>
>> https://issues.apache.org/jira/browse/CAY-414
>>
>> Some newer threads on auditing:
>>
>> http://mail-archives.apache.org/mod_mbox/cayenne-dev/200902.mbox/%3CB82E356A-3B9B-4D40-B767-2F7C863AAF77@objectstyle.org%3E
>>
>> Andrey posted one set of code for doing this here -- read through the
>> whole thread.
>>
>> http://mail-archives.apache.org/mod_mbox/cayenne-user/200903.mbox/%3C3219fff70903240316o4644e474ia669ea819510ef9f@mail.gmail.com%3E
>
>

Re: Rollbacks and Listeners

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Aug 9, 2010, at 6:08 PM, Bruno René Santos wrote:

> I have been analyzing the behaviour of the commitChanges lifecycle  
> and inferred
> that only when all database operations that are contained on the  
> current context
> are successfully performed do the post... callbacks are called.

Correct.

> So if you have
> like 4 inserts on the context and one of them raises an exception  
> (because
> violates an unique constraint for example), none post-persist  
> callbacks for the
> other 3 inserts is called. Is that correct?

Correct. None of the post* callbacks will be invoked if transaction  
failed.

Andrus

RE: Rollbacks and Listeners

Posted by Bruno René Santos <br...@holos.pt>.
I have been analyzing the behaviour of the commitChanges lifecycle and inferred
that only when all database operations that are contained on the current context
are successfully performed do the post... callbacks are called. So if you have
like 4 inserts on the context and one of them raises an exception (because
violates an unique constraint for example), none post-persist callbacks for the
other 3 inserts is called. Is that correct?

Thank you

-----Mensagem original-----
De: Joe Baldwin [mailto:jfbaldwin@earthlink.net] 
Enviada: segunda-feira, 9 de Agosto de 2010 16:02
Para: user@cayenne.apache.org
Assunto: Re: Rollbacks and Listeners

Wouldn't an important business-concern (or rule) be that if there was indeed a
rollback, then one might want to log it (via a Cayenne insert)?

I am doing something like this right now and it is a tad tricky.



 
On Aug 9, 2010, at 10:37 AM, Mike Kienenberger wrote:

> On Mon, Aug 9, 2010 at 5:41 AM, Bruno René Santos <br...@holos.pt> wrote:
>> Im using cayenne on a banking system, where commits and rollbacks are
critical.
>> I was thinking about using cayenne callbacks to include the creation of logs
>> during database operations. My doubt is what happens when there is a rollback
on
>> the database during a transaction in terms of callbacks? Do all Pre...
callbacks
>> are called but no Post.. callbacks? Is there any way to know on the callbacks
>> that the objects were rollbacked?
> 
> As long as you create the audit records in the same transaction as the
> rest of the data, when the transaction is rolled back or committed,
> then the audit logs will be rolled back or committed.   You should not
> have to do anything on a Post, only on a Pre.
> 
> ============
> 
> An old issue on auditing is here.   Not sure how relevant it is for
> 3.0 as I haven't used 3.0 yet.
> 
> https://issues.apache.org/jira/browse/CAY-414
> 
> Some newer threads on auditing:
> 
>
http://mail-archives.apache.org/mod_mbox/cayenne-dev/200902.mbox/%3CB82E356A-3B9
B-4D40-B767-2F7C863AAF77@objectstyle.org%3E
> 
> Andrey posted one set of code for doing this here -- read through the
> whole thread.
> 
>
http://mail-archives.apache.org/mod_mbox/cayenne-user/200903.mbox/%3C3219fff7090
3240316o4644e474ia669ea819510ef9f@mail.gmail.com%3E



Re: Rollbacks and Listeners

Posted by Joe Baldwin <jf...@earthlink.net>.
Wouldn't an important business-concern (or rule) be that if there was indeed a rollback, then one might want to log it (via a Cayenne insert)?

I am doing something like this right now and it is a tad tricky.



 
On Aug 9, 2010, at 10:37 AM, Mike Kienenberger wrote:

> On Mon, Aug 9, 2010 at 5:41 AM, Bruno René Santos <br...@holos.pt> wrote:
>> Im using cayenne on a banking system, where commits and rollbacks are critical.
>> I was thinking about using cayenne callbacks to include the creation of logs
>> during database operations. My doubt is what happens when there is a rollback on
>> the database during a transaction in terms of callbacks? Do all Pre... callbacks
>> are called but no Post.. callbacks? Is there any way to know on the callbacks
>> that the objects were rollbacked?
> 
> As long as you create the audit records in the same transaction as the
> rest of the data, when the transaction is rolled back or committed,
> then the audit logs will be rolled back or committed.   You should not
> have to do anything on a Post, only on a Pre.
> 
> ============
> 
> An old issue on auditing is here.   Not sure how relevant it is for
> 3.0 as I haven't used 3.0 yet.
> 
> https://issues.apache.org/jira/browse/CAY-414
> 
> Some newer threads on auditing:
> 
> http://mail-archives.apache.org/mod_mbox/cayenne-dev/200902.mbox/%3CB82E356A-3B9B-4D40-B767-2F7C863AAF77@objectstyle.org%3E
> 
> Andrey posted one set of code for doing this here -- read through the
> whole thread.
> 
> http://mail-archives.apache.org/mod_mbox/cayenne-user/200903.mbox/%3C3219fff70903240316o4644e474ia669ea819510ef9f@mail.gmail.com%3E


Re: Rollbacks and Listeners

Posted by Mike Kienenberger <mk...@gmail.com>.
On Mon, Aug 9, 2010 at 5:41 AM, Bruno René Santos <br...@holos.pt> wrote:
> Im using cayenne on a banking system, where commits and rollbacks are critical.
> I was thinking about using cayenne callbacks to include the creation of logs
> during database operations. My doubt is what happens when there is a rollback on
> the database during a transaction in terms of callbacks? Do all Pre... callbacks
> are called but no Post.. callbacks? Is there any way to know on the callbacks
> that the objects were rollbacked?

As long as you create the audit records in the same transaction as the
rest of the data, when the transaction is rolled back or committed,
then the audit logs will be rolled back or committed.   You should not
have to do anything on a Post, only on a Pre.

============

An old issue on auditing is here.   Not sure how relevant it is for
3.0 as I haven't used 3.0 yet.

https://issues.apache.org/jira/browse/CAY-414

Some newer threads on auditing:

http://mail-archives.apache.org/mod_mbox/cayenne-dev/200902.mbox/%3CB82E356A-3B9B-4D40-B767-2F7C863AAF77@objectstyle.org%3E

Andrey posted one set of code for doing this here -- read through the
whole thread.

http://mail-archives.apache.org/mod_mbox/cayenne-user/200903.mbox/%3C3219fff70903240316o4644e474ia669ea819510ef9f@mail.gmail.com%3E