org.zkoss.zkplus.hibernate
Class OpenSessionInViewListener

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

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

public class OpenSessionInViewListener
extends java.lang.Object
implements ExecutionInit, ExecutionCleanup

Listener to init and cleanup the hibernate session automatically, implement the Hibernate's "Open Session In View" pattern without JTA support. This listener is used with HibernateUtil, or it will not work.

In WEB-INF/zk.xml, add following lines:


        <listener>
                <description>Hibernate "OpenSessionInView" Listener</description>
                <listener-class>org.zkoss.zkplus.hibernate.OpenSessionInViewListener</listener-class>
        </listener>
 

Applicable to Hibernate version 3.2.ga or later

Author:
henrichen

Constructor Summary
OpenSessionInViewListener()
          Deprecated.  
 
Method Summary
 void cleanup(Execution exec, Execution parent, java.util.List errs)
          Deprecated. called when an execution is about to be destroyed.
protected  void handleOtherException(Execution exec, java.lang.Throwable ex)
          Deprecated. Default other exception (other than StaleObjectStateException) handler.
protected  void handleStaleObjectStateException(Execution exec, org.hibernate.StaleObjectStateException ex)
          Deprecated. Default StaleObjectStateException handler.
 void init(Execution exec, Execution parent)
          Deprecated. Called when an exection is created and initialized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OpenSessionInViewListener

public OpenSessionInViewListener()
Deprecated. 
Method Detail

init

public void init(Execution exec,
                 Execution parent)
Deprecated. 
Description copied from interface: ExecutionInit
Called when an exection 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 exection 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 occured before this method is called, or null if no exeption 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.

handleStaleObjectStateException

protected void handleStaleObjectStateException(Execution exec,
                                               org.hibernate.StaleObjectStateException ex)
Deprecated. 

Default StaleObjectStateException handler. This implementation does not implement optimistic concurrency control! It simply rollback the transaction.

Application developer might want to extends this class and override this method to do other things like compensate for any permanent changes during the conversation, and finally restart business conversation. Or maybe give the user of the application a chance to merge some of his work with fresh data... what can be done here depends on the applications design.

Parameters:
exec - the exection to clean up.
ex - the StaleObjectStateException being thrown (and not handled) during the execution

handleOtherException

protected void handleOtherException(Execution exec,
                                    java.lang.Throwable ex)
Deprecated. 

Default other exception (other than StaleObjectStateException) handler. This implementation simply rollback the transaction.

Application developer might want to extends this class and override this method to do other things like compensate for any permanent changes during the conversation, and finally restart business conversation... what can be done here depends on the applications design.

Parameters:
exec - the exection to clean up.
ex - the Throwable other than StaleObjectStateException being thrown (and not handled) during the execution


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