Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HibernateInterceptorConfigurer implements HibernateConfigurer
- {
- private Interceptor _interceptor;
- public HibernateInterceptorConfigurer(Interceptor interceptor)
- {
- _interceptor = interceptor;
- }
- /**
- * Passed the configuration so as to make changes.
- */
- public void configure(Configuration configuration)
- {
- configuration.setInterceptor(_interceptor);
- }
- }
- /**
- * The session manager manages sessions on a per-thread/per-request basis. A {@link org.hibernate.Transaction} is
- * created initially, and is committed at the end of the request.
- *
- * @param sysLogger the system logger
- * @param applicationStateManager the application state manager
- *
- * @return the interceptor
- */
- @Scope(PERTHREAD_SCOPE)
- public static Interceptor build(Logger sysLogger, ApplicationStateManager applicationStateManager)
- {
- AuditInterceptor interceptor = new AuditInterceptor(sysLogger);
- if (applicationStateManager != null)
- {
- try
- {
- VisitStateObject visitStateObject = applicationStateManager.getIfExists(VisitStateObject.class);
- if (visitStateObject != null && visitStateObject.getUserEntity() != null)
- interceptor.setUser(visitStateObject.getUserEntity().getLoginName());
- }
- catch (NullPointerException e)
- {
- interceptor.setUser("unknown");
- }
- }
- return interceptor;
- }
- /**
- * add interceptor to hibernate.
- *
- * @param configuration IOC configuration object
- * @param interceptor the hibernate interceptor, attacht to hibernate factory
- */
- public static void contributeHibernateSessionSource(OrderedConfiguration<HibernateConfigurer> configuration,
- Interceptor interceptor)
- {
- configuration.add("Interceptor", new HibernateInterceptorConfigurer(interceptor));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement