Interceptor

58 views
Skip to first unread message

Fredrik Hultin

unread,
May 30, 2012, 3:31:39 AM5/30/12
to Neo4j
I am using SDN with aspectj. My beans are being backed by the
NodeBacked interface (Neo4jNodeBacking class). This gives me the
possibility to use the object.persist() method that comes with the
interface. I could also use the getTemplate().save(object) method or
simply use the template mapped by spring to save the object (I think
it is all executing the same code in the end).

I would like to execute some code prior to all CRUD`S. In hibernate
you can register an interceptor to do that. Is there anything similar
in Neo4j?

Regards,
Fredrik

Marc de Verdelhan

unread,
May 30, 2012, 3:43:40 AM5/30/12
to ne...@googlegroups.com
I started a thread a few weeks ago (https://groups.google.com/d/topic/neo4j/G5IGZybpqWE/discussion) for a problem of that kind.
Didn't have more time to study the question but I liked the @PrePersist solution.

Cheers,

Marc

Fredrik Hultin

unread,
May 30, 2012, 5:53:27 AM5/30/12
to Neo4j
I like the whole lifecycle of annotations:

@PrePersist
@PostPersist
@PreRemove
@PostRemove
@PreUpdate
@PostUpdate
@PostLoad

But I think they are complements to Interceptors. Sometimes it easier
to just add an interceptor that gets executed for any CRUD for all
entities.

In your case with the last modified date for example. You could easily
use the reflection api to inspect the bean for any field modifyDate
and set that automatically instead of coding that method on all beans.
So I think there is room for both.

By adding multiple interceptors, like filters in web programming, you
could also move validator executions and other pre executions here.

But as I say, I like them both.

Jira request?

Cheers,
Fredrik

On May 30, 9:43 am, Marc de Verdelhan <marc.deverdel...@yahoo.com>
wrote:
> I started a thread a few weeks ago (https://groups.google.com/d/topic/neo4j/G5IGZybpqWE/discussion) for a
> problem of that kind.
> Didn't have more time to study the question but I liked the @PrePersist
> solution.
>
> Cheers,
>
> Marc
>
> On Wed, May 30, 2012 at 9:31 AM, Fredrik Hultin
> <fredrik.hul...@collabra.se>wrote:
Reply all
Reply to author
Forward
0 new messages