Results 1 to 5 of 5

Thread: Tracking User changing Data in DB

  1. #1
    Join Date
    Jun 2012
    Posts
    3

    Default 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. #2

    Default

    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

  3. #3
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  4. #4
    Join Date
    Jun 2012
    Posts
    3

    Default

    Hi Jeff,

    Quote 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

  5. #5
    Join Date
    Jun 2012
    Posts
    3

    Default

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •