Interesting AOP question on cross-solution?

Consider a set of DOAs with ways like this

public void addObject(Long sessionId, Long clientId, Dom obj){...}

      

Now every pojo ( Dom

) domain has a property sessionId

and for every insert, update or delete on the domain object, a sessionId

must be passed with setSessionId(Long sessionId)

so that we can find out who is doing what. But it looks like it cuts down on all the data associated with data access, and we believe AOP would be a good tool for inserting sessionId

into tags @Before(JoinPoint)

or @Around(ProceedingJoinPoint)

. Is it really possible? DAOs are mainly Hibernate based on several Spring StoredProcedure

.

+2


source to share


3 answers


Your sessionId parameter seems to be from the auditing aspect . In Hibernate, this aspect of auditing is usually implemented in the org.hibernate.Interceptor implementation .

You can implement many methods that correspond to the lifecycle event for your objects and requests. It is easy for your implementation to access your current sessionId (it can use the ThreadLocal variable). Clear and clean, fast; -)



This is probably easier than doing it yourself with AOP, especially since you get callbacks from Hibernate for lifecycle events.

+1


source


An interceptor around your DAO layer will have problems with transitive persistence, i.e. hibernation (save, delete, ...), cascading for related objects. A Hibernate session interceptor might.



In any case, if your interceptor can somehow detect the current session ID, it can be done anyway.

+1


source


I don't understand why you couldn't do this, I've done something like this (a little more complex) in the past in the past, helped me not to re-qualify every class!

Do you think public void addObject (Long sessionId, Long clientId, Dom obj) {...} in father / top level class? This method can delegate to each implementation.

+1


source







All Articles