org.zkoss.zkplus.hibernate
Class HibernateSessionContextListener

java.lang.Object
  extended by org.zkoss.zkplus.hibernate.HibernateSessionContextListener
All Implemented Interfaces:
EventThreadInit, EventThreadResume, ExecutionCleanup, ExecutionInit

Deprecated. As of release 6.0.2, please use the official Hibernate's method instead.

public class HibernateSessionContextListener
extends java.lang.Object
implements ExecutionInit, ExecutionCleanup, EventThreadInit, EventThreadResume

Listener to make sure each ZK thread got the same hibernate session context; used with Hibernate's "thread" session context (org.hibernate.context.ThreadLocalSessionContext).

This listener is used with Hibernate's (version 3.1+) "thread" session context. That is, when you specify


 hibernate.current_session_context_class = thread
 

then you have to add following lines in application's WEB-INF/zk.xml:


        <listener>
                <description>Hibernate thread session context management</description>
                <listener-class>org.zkoss.zkplus.hibernate.HibernateSessionContextListener</listener-class>
        </listener>
 

Applicable to Hibernate version 3.2.ga or later

Author:
henrichen

Constructor Summary
HibernateSessionContextListener()
          Deprecated.  
 
Method Summary
 void abortResume(Component comp, Event evt)
          Deprecated. Called when the suspended event thread is aborted.
 void afterResume(Component comp, Event evt)
          Deprecated. Called after the suspended event thread is resumed.
 void beforeResume(Component comp, Event evt)
          Deprecated. Called just before the suspended event thread is resumed.
 void cleanup(Execution exec, Execution parent, java.util.List errs)
          Deprecated. called when an execution is about to be destroyed.
 boolean init(Component comp, Event evt)
          Deprecated. Initialize the event processing thread before processing the event.
 void init(Execution exec, Execution parent)
          Deprecated. Called when an execution is created and initialized.
 void prepare(Component comp, Event evt)
          Deprecated. Prepares the initialization at the servlet thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HibernateSessionContextListener

public HibernateSessionContextListener()
Deprecated. 
Method Detail

init

public void init(Execution exec,
                 Execution parent)
Deprecated. 
Description copied from interface: ExecutionInit
Called when an execution is created and initialized.

Note: this method is called after exec is activated. In other words, Executions.getCurrent() is the same as the exec argument.

When this method is called, you can retrieve the current page with ExecutionCtrl.getCurrentPage(). However, the page is not initialized yet. In other words, Page.getDesktop(), Page.getId() and Page.getTitle() all return null. To get the current desktop, you have to use Execution.getDesktop() (from Executions.getCurrent()) instead. On the other hand, you can set the page's ID, title or style in this method (to override the declarations in the page definition) by Page.setId(java.lang.String), Page.setTitle(java.lang.String) and Page.setStyle(java.lang.String). In additions, Page.getRequestPath() and Page.getAttribute(java.lang.String, int) are all available.

Specified by:
init in interface ExecutionInit
Parameters:
exec - the execution being created.
parent - the previous execution in the same (Servlet) request, or null if this is the first execution of the request.

cleanup

public void cleanup(Execution exec,
                    Execution parent,
                    java.util.List errs)
Deprecated. 
Description copied from interface: ExecutionCleanup
called when an execution is about to be destroyed.

If this method throws an exception, the stack trace will be logged, and the error message will be displayed at the client.

When this method is invoked, the execution is still activated, so you can create components here.

Specified by:
cleanup in interface ExecutionCleanup
Parameters:
exec - the execution to clean up.
parent - the previous execution, or null if no previous at all
errs - a list of exceptions (java.lang.Throwable) if any exception occurred before this method is called, or null if no exception at all. Note: you can manipulate the list directly to add or clean up exceptions. For example, if exceptions are fixed correctly, you can call errs.clear() such that no error message will be displayed at the client.

prepare

public void prepare(Component comp,
                    Event evt)
Deprecated. 
Description copied from interface: EventThreadInit
Prepares the initialization at the servlet thread.

It is invoked in the servlet thread (and before EventThreadInit.init(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event)). Thus, you can NOT manipulate the desktop in this method.

If this method throws an exception, it will abort the execution and shows an error message to the end user. Note: EventThreadCleanup.cleanup(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event, java.util.List) won't be called if an exception is thrown in this method, since it executes in the main thread.

In addition to throwing an exception, you can prevent an event from processing by returning false in EventThreadInit.init(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event). The event is ignored 'silently' then.

Specified by:
prepare in interface EventThreadInit

init

public boolean init(Component comp,
                    Event evt)
Deprecated. 
Description copied from interface: EventThreadInit
Initialize the event processing thread before processing the event.

The simplest form is void init(Component c, Event e) {return true;}

Unlike EventThreadInit.prepare(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event), it is invoked in the event processing thread (and after EventThreadInit.prepare(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event)). Thus, you can manipulate the desktop in this method such as creating a component.

If you want to prevent an event from processing, you can return false in this method. For example, you might create a highlighted window and return false to prevent the user from accessing, if the system is too busy.

If the use of the event thread is disabled (Configuration.isEventThreadEnabled() returns false), this method is also invoked in the Servlet thread.

If this method throws an exception, it will abort the execution and shows an error message to the end user (unless it is cleaned up by EventThreadCleanup.cleanup(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event, java.util.List)).

Specified by:
init in interface EventThreadInit
Returns:
if it is initialized successfully. If false is returned, the event is ignored, i.e., no event handler/listener will be invoked.

beforeResume

public void beforeResume(Component comp,
                         Event evt)
Deprecated. 
Description copied from interface: EventThreadResume
Called just before the suspended event thread is resumed. Unlike EventThreadResume.afterResume(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event), it executes in the main thread that resumes the suspended event processing thread.

If this method throws an exception, it will abort the execution and shows an error message to the end user. Note: EventThreadCleanup.cleanup(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event, java.util.List) won't be called if an exception is thrown in this method, since it executes in the main thread.

Specified by:
beforeResume in interface EventThreadResume

afterResume

public void afterResume(Component comp,
                        Event evt)
Deprecated. 
Description copied from interface: EventThreadResume
Called after the suspended event thread is resumed. Unlike EventThreadResume.beforeResume(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event), it executes in the event processing thread that is resumed.

If this method throws an exception, it will abort the execution and shows an error message to the end user (unless it is cleaned up by EventThreadCleanup.cleanup(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event, java.util.List)).

Specified by:
afterResume in interface EventThreadResume

abortResume

public void abortResume(Component comp,
                        Event evt)
Deprecated. 
Description copied from interface: EventThreadResume
Called when the suspended event thread is aborted. It is called in the main thread (i.e., the servlet thread).

If a suspended event thread is resumed normally, EventThreadResume.beforeResume(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event) and EventThreadResume.afterResume(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event) are called. On the other hand, if it is aborted (usually caused by destroying the desktop that owns this thread), EventThreadResume.abortResume(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event) is called instead.

Note: if the suspended thread is aborted, none of EventThreadResume.beforeResume(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event), EventThreadResume.afterResume(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event), EventThreadCleanup.cleanup(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event, java.util.List), and EventThreadCleanup.complete(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event) will be called. Thus, you have to do necessary cleanups in this method.

Specified by:
abortResume in interface EventThreadResume


Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo