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
Constructor and Description |
---|
HibernateSessionContextListener()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public HibernateSessionContextListener()
public void init(Execution exec, Execution parent)
ExecutionInit
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.
init
in interface ExecutionInit
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.public boolean init(Component comp, Event evt)
EventThreadInit
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<java.lang.Throwable>)
).
init
in interface EventThreadInit
public void cleanup(Execution exec, Execution parent, java.util.List errs)
ExecutionCleanup
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.
cleanup
in interface ExecutionCleanup
exec
- the execution to clean up.parent
- the previous execution, or null if no previous at allerrs
- 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.public void prepare(Component comp, Event evt)
EventThreadInit
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<java.lang.Throwable>)
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.
prepare
in interface EventThreadInit
public void beforeResume(Component comp, Event evt)
EventThreadResume
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<java.lang.Throwable>)
won't be called if an
exception is thrown in this method, since it executes in
the main thread.
beforeResume
in interface EventThreadResume
public void afterResume(Component comp, Event evt)
EventThreadResume
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<java.lang.Throwable>)
).
afterResume
in interface EventThreadResume
public void abortResume(Component comp, Event evt)
EventThreadResume
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<java.lang.Throwable>)
, 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.
abortResume
in interface EventThreadResume
Copyright © 2005-2023 Potix Corporation. All Rights Reserved.