Announcement Announcement Module
Collapse
No announcement yet.
Tracking User changing Data in DB Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tracking User changing Data in DB

    Hi,

    I am using DAOs to update my DB and I'd like to store the Username every time the user changes data in the DB.
    I'd like to avoid passing the Username to the DAO layer when update-Method is called, as for example:

    update(ContractVo, UserVo)

    Is there a way to use DI to inject the user via a setter method. Normally I inject static values, which are configured in XML-File but in that case I'd have to inject values (objects) that change during runtime.

    Would be great to get any hint...

    Frank

  • #2
    Read up on writing Aspects with Spring AOP. In a nutshell, you can intercept various methods and log some information (or do anything you like) about what's going on (before, during, and/or after the action). I think this may be ideal for you. It keeps the auditing code completely out of your business logic.

    -Jeff

    Comment


    • #3
      You could use AOP but it actually depends on your persistence layer. Do you use plain JDBC, JPA or Hibernate. In the case of JPA you might want to checkout spring-data as this supports that out of the box for hibernate you could write your own EntityListener.

      Comment


      • #4
        Hi Jeff,

        Originally posted by JeffH View Post
        Read up on writing Aspects with Spring AOP. In a nutshell, you can intercept various methods and log some information (or do anything you like) about what's going on (before, during, and/or after the action). I think this may be ideal for you. It keeps the auditing code completely out of your business logic.
        -Jeff
        thanks for that hint. I knew that I could use AOP for that, but in my case, I'd like to store the username together with the business data, for example:

        Customer Birthdate Changed ChangedBy
        Williams 05.02.1980 10.10.2011 Admin

        So I think, I need the User Info in the DAO and not somewhere else.

        Frank

        Comment


        • #5
          I'll check out spring-data. Actually i use plain JDBC.

          I forgot to mention that I only have 1 DB User so I can not use DB mechanisms to achieve it.

          Comment

          Working...
          X