Announcement Announcement Module
Collapse
No announcement yet.
Replacement for the SET field pointcut designator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Replacement for the SET field pointcut designator

    I need to create an aspect that would intercept change of value of several attributes in 3-4 java classes (within same package) annotated with @Indexed.
    In plain AspectJ it is possible to do:
    Code:
        @Pointcut("set(@Indexed * com.rnd.ams.domain.entities..*) && args(newValue)")
        public void indexEffectingFieldSet(Object newValue) {        
        }
    However, I need to use Spring 3.1 and according to its documentation it is not supporting field pointcut types.
    I am thinking about creating a pointcut on setter execution and then from the name of the setter get the name of the field and using reflection find if it is annotated as needed.
    I do not like this solution, it doesn't look elegant.
    All AOP I have done before was quite basic, i.e. I am not very knowledgeable in advanced Spring AOP.
    If anyone knows how to do it better, I would greatly appreciate an advice.
    Thanks a lot.

    P.S. There is one more thing that I can use a help with. When entities are read from the database, there is a user session ID that is available within the DAO. I can't change the entity object, period. However my aspect advice suppose to use that session ID for the instance of entity object.
    Let's say my advice shall print a log message:
    Indexed field ABC in the entity com...myentity with ID 123 changed to a new value XYZ by user session 765
    I do need to do much more then that but that's beyond the point. I know how to do the rest.

  • #2
    However, I need to use Spring 3.1 and according to its documentation it is not supporting field pointcut types.
    Read again... It depends on which type of AOP you use (runtime, loadtime, compiletime)..

    Runtime does, indeed, not support anything besides the execution pointcut due to the fact that it uses proxies to add aspects. However if you use loadtime weaving (which is quite easy to enable with spring) you can do whatever you like so even the set pointcut should work.

    Comment


    • #3
      Can you please refer me to any example of set pointcut usage? As I said, I am not very astute in Spring AOP and reviewing of ch.8-9 of Spring reference guide did not give me any useful clues on how to do that.
      Thank you.

      P.S. Can I use @target(com...annotations.Indexed) along with the execution pointcut for the set methods instead? I did not quite understood how this @target thing works.
      Last edited by gary002g; Jun 3rd, 2013, 04:40 PM.

      Comment

      Working...
      X