Advertisement
Guest User

homburgs

a guest
Jun 19th, 2008
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. public class HibernateInterceptorConfigurer implements HibernateConfigurer
  2. {
  3.     private Interceptor _interceptor;
  4.  
  5.     public HibernateInterceptorConfigurer(Interceptor interceptor)
  6.     {
  7.         _interceptor = interceptor;
  8.     }
  9.  
  10.     /**
  11.      * Passed the configuration so as to make changes.
  12.      */
  13.     public void configure(Configuration configuration)
  14.     {
  15.         configuration.setInterceptor(_interceptor);
  16.     }
  17. }
  18.  
  19.     /**
  20.      * The session manager manages sessions on a per-thread/per-request basis. A {@link org.hibernate.Transaction} is
  21.      * created initially, and is committed at the end of the request.
  22.      *
  23.      * @param sysLogger               the system logger
  24.      * @param applicationStateManager the application state manager
  25.      *
  26.      * @return the interceptor
  27.      */
  28.     @Scope(PERTHREAD_SCOPE)
  29.     public static Interceptor build(Logger sysLogger, ApplicationStateManager applicationStateManager)
  30.     {
  31.         AuditInterceptor interceptor = new AuditInterceptor(sysLogger);
  32.  
  33.         if (applicationStateManager != null)
  34.         {
  35.             try
  36.             {
  37.                 VisitStateObject visitStateObject = applicationStateManager.getIfExists(VisitStateObject.class);
  38.                 if (visitStateObject != null && visitStateObject.getUserEntity() != null)
  39.                     interceptor.setUser(visitStateObject.getUserEntity().getLoginName());
  40.             }
  41.             catch (NullPointerException e)
  42.             {
  43.                 interceptor.setUser("unknown");
  44.             }
  45.         }
  46.  
  47.         return interceptor;
  48.     }
  49.  
  50.     /**
  51.      * add interceptor to hibernate.
  52.      *
  53.      * @param configuration IOC configuration object
  54.      * @param interceptor   the hibernate interceptor, attacht to hibernate factory
  55.      */
  56.     public static void contributeHibernateSessionSource(OrderedConfiguration<HibernateConfigurer> configuration,
  57.                                                         Interceptor interceptor)
  58.     {
  59.         configuration.add("Interceptor", new HibernateInterceptorConfigurer(interceptor));
  60.     }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement