Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [TENEO][EMF] EMFInterceptor + Session in callbacks
[TENEO][EMF] EMFInterceptor + Session in callbacks [message #135356] Mon, 27 April 2009 13:47 Go to next message
Liviu-Marian Negrila is currently offline Liviu-Marian NegrilaFriend
Messages: 53
Registered: July 2009
Member
Hello,

I need to be able to do some database related stuff in any of the
following callbacks described by the Interceptor interface:

- onLoad
- onFlushDirty
- onSave
- onDelete
- beforeTransactionCompletion
- afterTransactionCompletion
- onPrepareStatement

In the Interceptor javadoc it says: "The Session may not be invoked from
a callback (nor may a callback cause a collection or proxy to be lazily
initialized)"

I think this is exactly what I'd like to do; for instance, say a user
saves some modifications to the database then I whant to create a ligne
in another table (create en EObject of some other type than that
currently being modified by the user for that matter) and persist that
within the same session and make sure that should anything "roll back"
than everything is rolled back.

Ideas?



Note: I've read Martin's post dated 06/04/2007 (Re: [Teneo] setting
Hibernate Interceptor) and I've managed to create my own derived
EMFInterceptor.
Re: [TENEO][EMF] EMFInterceptor + Session in callbacks [message #135370 is a reply to message #135356] Mon, 27 April 2009 15:33 Go to previous messageGo to next message
Liviu-Marian Negrila is currently offline Liviu-Marian NegrilaFriend
Messages: 53
Registered: July 2009
Member
Well,

Please discard my previous questions; apparently it's a Hibernate thing
not to allow this behaviour.

I'll hopefully get by using another session (aka datastore.createSession...)

I'll be back if that won't work either.

Cheers and sorry for my spam,
Liviu



Liviu wrote:
> Hello,
>
> I need to be able to do some database related stuff in any of the
> following callbacks described by the Interceptor interface:
>
> - onLoad
> - onFlushDirty
> - onSave
> - onDelete
> - beforeTransactionCompletion
> - afterTransactionCompletion
> - onPrepareStatement
>
> In the Interceptor javadoc it says: "The Session may not be invoked from
> a callback (nor may a callback cause a collection or proxy to be lazily
> initialized)"
>
> I think this is exactly what I'd like to do; for instance, say a user
> saves some modifications to the database then I whant to create a ligne
> in another table (create en EObject of some other type than that
> currently being modified by the user for that matter) and persist that
> within the same session and make sure that should anything "roll back"
> than everything is rolled back.
>
> Ideas?
>
>
>
> Note: I've read Martin's post dated 06/04/2007 (Re: [Teneo] setting
> Hibernate Interceptor) and I've managed to create my own derived
> EMFInterceptor.
Re: [TENEO][EMF] EMFInterceptor + Session in callbacks [message #135382 is a reply to message #135370] Mon, 27 April 2009 15:59 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Liviu,
No problem, I was thinking about your question, but did not have an answer right away. One thing you can also check out
are the Hibernate Event Listeners, internally Hibernate does all its work with event listeners. You can extend/override
them to catch the events you want. Maybe you are allowed to do more actions in an event listener.

Note that Teneo registers one event listener itself: InitializeCollectionEventListener. See the setEventListeners
methods in the data stores. But I don't think you need that one.

btw, support for Teneo is given on the EMF newsgroup which I put on the cc.

gr. Martin

Liviu wrote:
> Well,
>
> Please discard my previous questions; apparently it's a Hibernate thing
> not to allow this behaviour.
>
> I'll hopefully get by using another session (aka datastore.createSession...)
>
> I'll be back if that won't work either.
>
> Cheers and sorry for my spam,
> Liviu
>
>
>
> Liviu wrote:
>> Hello,
>>
>> I need to be able to do some database related stuff in any of the
>> following callbacks described by the Interceptor interface:
>>
>> - onLoad
>> - onFlushDirty
>> - onSave
>> - onDelete
>> - beforeTransactionCompletion
>> - afterTransactionCompletion
>> - onPrepareStatement
>>
>> In the Interceptor javadoc it says: "The Session may not be invoked from
>> a callback (nor may a callback cause a collection or proxy to be lazily
>> initialized)"
>>
>> I think this is exactly what I'd like to do; for instance, say a user
>> saves some modifications to the database then I whant to create a ligne
>> in another table (create en EObject of some other type than that
>> currently being modified by the user for that matter) and persist that
>> within the same session and make sure that should anything "roll back"
>> than everything is rolled back.
>>
>> Ideas?
>>
>>
>>
>> Note: I've read Martin's post dated 06/04/2007 (Re: [Teneo] setting
>> Hibernate Interceptor) and I've managed to create my own derived
>> EMFInterceptor.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [TENEO][EMF] EMFInterceptor + Session in callbacks [message #135408 is a reply to message #135382] Mon, 27 April 2009 20:48 Go to previous message
Liviu-Marian Negrila is currently offline Liviu-Marian NegrilaFriend
Messages: 53
Registered: July 2009
Member
Hi Martin, Hi All,

This is a long one - sorry.

After playing around with my derived EMFInterceptor I found out that:

- onSave is only called for new objects to be persisted
- and update goes by the name of onFlushDirty
- deletes are obvious onDelete
- inside the methods
beforeTransactionCompletion/afterTransactionCompletion I could not get
my hands on the session context of the transaction (tx) that might help
to see all the objects being affected by the transaction.

Why this is important to me?

Well, say you have an editor to edit an object of type Invoice that
contains (aka contained-multi-reference) a list InvoiceLines accesible
from the Invoice by the property: "lines" (you have a getLines() on
every Invoice).

And say I whant to have a flexible system that needs to do some stuff
every time I add, update or delete an Invoice. Or even retrieve/load an
Invoice for that matter (think audit).

1. when I add an InvoiceLine to an existing (already persisted)
Invoice.getLines list, I get a save notification (onSave) for one line
and a call to onFlushDirty for the Invoice itself; this also happens on
delete.
But when I modify a persisted InvoiceLine the Invoice does not get any
notification. Only one onFlushDirty for the InvoiceLine

2. sometimes I may modify something on the Invoice directly, and also
modify something on the InvoiceLine (given both are already persisted),I
will get, in order:
- update of Invoice
- update of InvoiceLine

Finally my questions:
A) how can I set case 1 and case 2 apart? how can I react to the
modification of InvoiceLine in case 1 but only to the modification of
Invoice in case 2?

A1) Moreover, in my previous question I noted that in the onFlushDirty
the "previousState" does not indicate the correct data; for instance
onFlushDirty for the entity Invoice I get in the previousState the new
and update values for the refereced InvoiceLine
Hence, even if I know the answer to question A) I guess I will have a
hard time being able to know how the "old" invoiceLine looked like
before while in "onFlushDirty" for the Invoice.

B) Is it a good approach to try and define an EMFInterceptor (that is
actually closer to Hibernate than EMF) to try and catch these events?
Bare in mind that the fact that I can throw an exception inside the
Interceptor saves me the trouble of rolling back the original
transaction that saves the entities (aka Invoice, InvoiceLine)

C) Is there any way to inspect the transaction tx and figure out which
object is the "most important" in the transaction? I say an Invoice has
more importance than an InvoiceLine and I prefer reacting to its update
rather than on InvoiceLine update.

Bref, what I'm trying to do is to have some sort of "configurable
document dispachter" that depending on saved parent entity (eg Invoice,
but not InvoiceLine) and on some application specific configuration to
be able to run some specific programs (think "specific invoices generate
movements in specific accounting journals as per client preferences" and
the "movements" generation should not pollute/hardcode/hardwire the
"save" method of the Invoice editor).

If you have gone so far reading I am in great debt.
Thanks
Liviu

Martin Taal wrote:
> Hi Liviu,
> No problem, I was thinking about your question, but did not have an
> answer right away. One thing you can also check out are the Hibernate
> Event Listeners, internally Hibernate does all its work with event
> listeners. You can extend/override them to catch the events you want.
> Maybe you are allowed to do more actions in an event listener.
>
> Note that Teneo registers one event listener itself:
> InitializeCollectionEventListener. See the setEventListeners methods in
> the data stores. But I don't think you need that one.
>
> btw, support for Teneo is given on the EMF newsgroup which I put on the cc.
>
> gr. Martin
>
> Liviu wrote:
>> Well,
>>
>> Please discard my previous questions; apparently it's a Hibernate thing
>> not to allow this behaviour.
>>
>> I'll hopefully get by using another session (aka
>> datastore.createSession...)
>>
>> I'll be back if that won't work either.
>>
>> Cheers and sorry for my spam,
>> Liviu
>>
>>
>>
>> Liviu wrote:
>>> Hello,
>>>
>>> I need to be able to do some database related stuff in any of the
>>> following callbacks described by the Interceptor interface:
>>>
>>> - onLoad
>>> - onFlushDirty
>>> - onSave
>>> - onDelete
>>> - beforeTransactionCompletion
>>> - afterTransactionCompletion
>>> - onPrepareStatement
>>>
>>> In the Interceptor javadoc it says: "The Session may not be invoked from
>>> a callback (nor may a callback cause a collection or proxy to be lazily
>>> initialized)"
>>>
>>> I think this is exactly what I'd like to do; for instance, say a user
>>> saves some modifications to the database then I whant to create a ligne
>>> in another table (create en EObject of some other type than that
>>> currently being modified by the user for that matter) and persist that
>>> within the same session and make sure that should anything "roll back"
>>> than everything is rolled back.
>>>
>>> Ideas?
>>>
>>>
>>>
>>> Note: I've read Martin's post dated 06/04/2007 (Re: [Teneo] setting
>>> Hibernate Interceptor) and I've managed to create my own derived
>>> EMFInterceptor.
>
>
Re: [TENEO][EMF] EMFInterceptor + Session in callbacks [message #620874 is a reply to message #135356] Mon, 27 April 2009 15:33 Go to previous message
Liviu-Marian Negrila is currently offline Liviu-Marian NegrilaFriend
Messages: 53
Registered: July 2009
Member
Well,

Please discard my previous questions; apparently it's a Hibernate thing
not to allow this behaviour.

I'll hopefully get by using another session (aka datastore.createSession...)

I'll be back if that won't work either.

Cheers and sorry for my spam,
Liviu



Liviu wrote:
> Hello,
>
> I need to be able to do some database related stuff in any of the
> following callbacks described by the Interceptor interface:
>
> - onLoad
> - onFlushDirty
> - onSave
> - onDelete
> - beforeTransactionCompletion
> - afterTransactionCompletion
> - onPrepareStatement
>
> In the Interceptor javadoc it says: "The Session may not be invoked from
> a callback (nor may a callback cause a collection or proxy to be lazily
> initialized)"
>
> I think this is exactly what I'd like to do; for instance, say a user
> saves some modifications to the database then I whant to create a ligne
> in another table (create en EObject of some other type than that
> currently being modified by the user for that matter) and persist that
> within the same session and make sure that should anything "roll back"
> than everything is rolled back.
>
> Ideas?
>
>
>
> Note: I've read Martin's post dated 06/04/2007 (Re: [Teneo] setting
> Hibernate Interceptor) and I've managed to create my own derived
> EMFInterceptor.
Re: [TENEO][EMF] EMFInterceptor + Session in callbacks [message #620875 is a reply to message #135370] Mon, 27 April 2009 15:59 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Liviu,
No problem, I was thinking about your question, but did not have an answer right away. One thing you can also check out
are the Hibernate Event Listeners, internally Hibernate does all its work with event listeners. You can extend/override
them to catch the events you want. Maybe you are allowed to do more actions in an event listener.

Note that Teneo registers one event listener itself: InitializeCollectionEventListener. See the setEventListeners
methods in the data stores. But I don't think you need that one.

btw, support for Teneo is given on the EMF newsgroup which I put on the cc.

gr. Martin

Liviu wrote:
> Well,
>
> Please discard my previous questions; apparently it's a Hibernate thing
> not to allow this behaviour.
>
> I'll hopefully get by using another session (aka datastore.createSession...)
>
> I'll be back if that won't work either.
>
> Cheers and sorry for my spam,
> Liviu
>
>
>
> Liviu wrote:
>> Hello,
>>
>> I need to be able to do some database related stuff in any of the
>> following callbacks described by the Interceptor interface:
>>
>> - onLoad
>> - onFlushDirty
>> - onSave
>> - onDelete
>> - beforeTransactionCompletion
>> - afterTransactionCompletion
>> - onPrepareStatement
>>
>> In the Interceptor javadoc it says: "The Session may not be invoked from
>> a callback (nor may a callback cause a collection or proxy to be lazily
>> initialized)"
>>
>> I think this is exactly what I'd like to do; for instance, say a user
>> saves some modifications to the database then I whant to create a ligne
>> in another table (create en EObject of some other type than that
>> currently being modified by the user for that matter) and persist that
>> within the same session and make sure that should anything "roll back"
>> than everything is rolled back.
>>
>> Ideas?
>>
>>
>>
>> Note: I've read Martin's post dated 06/04/2007 (Re: [Teneo] setting
>> Hibernate Interceptor) and I've managed to create my own derived
>> EMFInterceptor.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [TENEO][EMF] EMFInterceptor + Session in callbacks [message #620877 is a reply to message #135382] Mon, 27 April 2009 20:48 Go to previous message
Liviu-Marian Negrila is currently offline Liviu-Marian NegrilaFriend
Messages: 53
Registered: July 2009
Member
Hi Martin, Hi All,

This is a long one - sorry.

After playing around with my derived EMFInterceptor I found out that:

- onSave is only called for new objects to be persisted
- and update goes by the name of onFlushDirty
- deletes are obvious onDelete
- inside the methods
beforeTransactionCompletion/afterTransactionCompletion I could not get
my hands on the session context of the transaction (tx) that might help
to see all the objects being affected by the transaction.

Why this is important to me?

Well, say you have an editor to edit an object of type Invoice that
contains (aka contained-multi-reference) a list InvoiceLines accesible
from the Invoice by the property: "lines" (you have a getLines() on
every Invoice).

And say I whant to have a flexible system that needs to do some stuff
every time I add, update or delete an Invoice. Or even retrieve/load an
Invoice for that matter (think audit).

1. when I add an InvoiceLine to an existing (already persisted)
Invoice.getLines list, I get a save notification (onSave) for one line
and a call to onFlushDirty for the Invoice itself; this also happens on
delete.
But when I modify a persisted InvoiceLine the Invoice does not get any
notification. Only one onFlushDirty for the InvoiceLine

2. sometimes I may modify something on the Invoice directly, and also
modify something on the InvoiceLine (given both are already persisted),I
will get, in order:
- update of Invoice
- update of InvoiceLine

Finally my questions:
A) how can I set case 1 and case 2 apart? how can I react to the
modification of InvoiceLine in case 1 but only to the modification of
Invoice in case 2?

A1) Moreover, in my previous question I noted that in the onFlushDirty
the "previousState" does not indicate the correct data; for instance
onFlushDirty for the entity Invoice I get in the previousState the new
and update values for the refereced InvoiceLine
Hence, even if I know the answer to question A) I guess I will have a
hard time being able to know how the "old" invoiceLine looked like
before while in "onFlushDirty" for the Invoice.

B) Is it a good approach to try and define an EMFInterceptor (that is
actually closer to Hibernate than EMF) to try and catch these events?
Bare in mind that the fact that I can throw an exception inside the
Interceptor saves me the trouble of rolling back the original
transaction that saves the entities (aka Invoice, InvoiceLine)

C) Is there any way to inspect the transaction tx and figure out which
object is the "most important" in the transaction? I say an Invoice has
more importance than an InvoiceLine and I prefer reacting to its update
rather than on InvoiceLine update.

Bref, what I'm trying to do is to have some sort of "configurable
document dispachter" that depending on saved parent entity (eg Invoice,
but not InvoiceLine) and on some application specific configuration to
be able to run some specific programs (think "specific invoices generate
movements in specific accounting journals as per client preferences" and
the "movements" generation should not pollute/hardcode/hardwire the
"save" method of the Invoice editor).

If you have gone so far reading I am in great debt.
Thanks
Liviu

Martin Taal wrote:
> Hi Liviu,
> No problem, I was thinking about your question, but did not have an
> answer right away. One thing you can also check out are the Hibernate
> Event Listeners, internally Hibernate does all its work with event
> listeners. You can extend/override them to catch the events you want.
> Maybe you are allowed to do more actions in an event listener.
>
> Note that Teneo registers one event listener itself:
> InitializeCollectionEventListener. See the setEventListeners methods in
> the data stores. But I don't think you need that one.
>
> btw, support for Teneo is given on the EMF newsgroup which I put on the cc.
>
> gr. Martin
>
> Liviu wrote:
>> Well,
>>
>> Please discard my previous questions; apparently it's a Hibernate thing
>> not to allow this behaviour.
>>
>> I'll hopefully get by using another session (aka
>> datastore.createSession...)
>>
>> I'll be back if that won't work either.
>>
>> Cheers and sorry for my spam,
>> Liviu
>>
>>
>>
>> Liviu wrote:
>>> Hello,
>>>
>>> I need to be able to do some database related stuff in any of the
>>> following callbacks described by the Interceptor interface:
>>>
>>> - onLoad
>>> - onFlushDirty
>>> - onSave
>>> - onDelete
>>> - beforeTransactionCompletion
>>> - afterTransactionCompletion
>>> - onPrepareStatement
>>>
>>> In the Interceptor javadoc it says: "The Session may not be invoked from
>>> a callback (nor may a callback cause a collection or proxy to be lazily
>>> initialized)"
>>>
>>> I think this is exactly what I'd like to do; for instance, say a user
>>> saves some modifications to the database then I whant to create a ligne
>>> in another table (create en EObject of some other type than that
>>> currently being modified by the user for that matter) and persist that
>>> within the same session and make sure that should anything "roll back"
>>> than everything is rolled back.
>>>
>>> Ideas?
>>>
>>>
>>>
>>> Note: I've read Martin's post dated 06/04/2007 (Re: [Teneo] setting
>>> Hibernate Interceptor) and I've managed to create my own derived
>>> EMFInterceptor.
>
>
Previous Topic:[TENEO][EMF] EMFInterceptor + Session in callbacks
Next Topic:Exception in [org.eclipse.emf.compare.examples.standalone]
Goto Forum:
  


Current Time: Thu Apr 25 16:18:08 GMT 2024

Powered by FUDForum. Page generated in 0.02700 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top