T5: using SessionManager in a dispatcher

View: New views
1 Messages — Rating Filter:   Alert me  

T5: using SessionManager in a dispatcher

by Angelo Chen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I use a dispatcher to log page access, I need to use sessionManager to commit otherwise the log will not be saved to the mysql, however, the commit sometimes produce undesirable effects to the page, is there a way to maintain a separate sessionManager in addition to the default SessionManager? or any easier way to maintain a log in the mysql? thanks.

Angelo

public class LoggingDispatcher implements Dispatcher {

    private final HibernateSessionManager sessionManager;
 
  public LoggingDispatcher(HibernateSessionManager sessionManager) {
        this.sessionManager = sessionManager;
    }

    public boolean dispatch(Request request, Response response) throws IOException {

        PageLog log = new PageLog();
        log.setPath(request.getPath());
        sessionManager.getSession().save(log);
        sessionManager.commit();
        return false;
    }
}
LightInTheBox - Buy quality products at wholesale price