org.davesag.generica.servlet.plugin
Class HibernatePlugIn

java.lang.Object
  extended byorg.davesag.generica.servlet.plugin.HibernatePlugIn
All Implemented Interfaces:
PlugIn

public class HibernatePlugIn
extends Object
implements PlugIn

Implements the PlugIn interface to configure the Hibernate data persistence library and then go on to intialise your WebApp.

You must have a hibernate.cfg.xml file in the root of your CLASSPATH for this to work.
The configured net.sf.hibernate.SessionFactory is stored in the ServletContext under the key Constants.HSF_KEY.
Place the following into your struts-config file to use it.

          <plugin
                  class="org.davesag.generica.servlet.plugin.HibernatePlugIn">
                  <set-property property="webapp" value="your.webappImpl"/>
          </plugin>
 

Since:
Generica 1.0
Version:
CVS Revision $Id: HibernatePlugIn.java,v 1.8 2004/03/30 10:12:58 norm Exp $
Author:
Dave Sag http://www.davesag.com

Field Summary
protected  SessionFactory theFactory
          The SessionFactory we create must be held on to so we can destroy it later.
protected  String theHibernateConfigFile
          The hibernate config file to use.
protected  WebApp theWebApp
          The WebApp implementation to startup and shutdown.
 
Constructor Summary
HibernatePlugIn()
          Default constuctor used by ActionServlet as per the PlugIn interface guidelines.
 
Method Summary
 void destroy()
          Destroys the SessionFactory instance and then runs the shutdown method of the WebApp
 void init(ActionServlet servlet, ModuleConfig config)
          Initializes the SessionFactory and then if a WebApp has been specified, will start it up.
 void setHibernateConfigFile(String f)
          sets the Hibernate Config File to use based on the value provided in the <set-property name="hibernateConfigFile" value="myHibernate.cfg.xml"/> part of the plugin definition in your struts-config.xml file.
 void setWebapp(String webappimpl)
          sets the Webapp property based on the value provided in the <set-property name="webapp" value="your.webappimpl"/> part of the plugin definition in your struts-config.xml file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theWebApp

protected WebApp theWebApp
The WebApp implementation to startup and shutdown.


theHibernateConfigFile

protected String theHibernateConfigFile
The hibernate config file to use. if not set it will use the default.


theFactory

protected SessionFactory theFactory
The SessionFactory we create must be held on to so we can destroy it later.

Constructor Detail

HibernatePlugIn

public HibernatePlugIn()
Default constuctor used by ActionServlet as per the PlugIn interface guidelines.

Method Detail

setWebapp

public void setWebapp(String webappimpl)
sets the Webapp property based on the value provided in the <set-property name="webapp" value="your.webappimpl"/> part of the plugin definition in your struts-config.xml file.

Parameters:
webappimpl - The fully qualified class name of the WebApp implementation that will be used to startup and shutdown your app.

setHibernateConfigFile

public void setHibernateConfigFile(String f)
sets the Hibernate Config File to use based on the value provided in the <set-property name="hibernateConfigFile" value="myHibernate.cfg.xml"/> part of the plugin definition in your struts-config.xml file.

Parameters:
f - The name of your config file.

init

public void init(ActionServlet servlet,
                 ModuleConfig config)
          throws ServletException
Initializes the SessionFactory and then if a WebApp has been specified, will start it up.

Specified by:
init in interface PlugIn
Parameters:
servlet - the ActionServlet instance under which the plugin will run.
config - the ModuleConfig for the module under which the plugin will run. Unused in this case.
Throws:
ServletException - if something went wrong.

destroy

public void destroy()
Destroys the SessionFactory instance and then runs the shutdown method of the WebApp

Specified by:
destroy in interface PlugIn


Dave Sag Generica API version 0.5.9 - (prerelease) Copyright 2003 - 2004 Dave Sag.