org.mentawai.filter
Class HibernateFilter

java.lang.Object
  extended by org.mentawai.core.InputWrapper
      extended by org.mentawai.filter.HibernateFilter
All Implemented Interfaces:
Map, AfterConsequenceFilter, Filter, Input
Direct Known Subclasses:
HibernateAnnotationFilter

public class HibernateFilter
extends InputWrapper
implements AfterConsequenceFilter

Use this filter to place an opened and connected Hibernate session in the action input. There is no need to close the session. The filter does it automatically when the action ends. The action is injected using the pull.

Author:
Rubem Azenha (rubem.azenha@gmail.com)

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
static String KEY
          The default key name to use when placing the session in the action input.
static String TRANS_KEY
          The default key name to use when placing a hibernate transaction in the action input.
 
Constructor Summary
HibernateFilter()
           
HibernateFilter(boolean transactional)
           
HibernateFilter(boolean transactional, Document document)
           
HibernateFilter(boolean transactional, File file)
           
HibernateFilter(boolean transactional, org.hibernate.SessionFactory sessionFactory)
           
HibernateFilter(boolean transactional, String string)
           
HibernateFilter(boolean transactional, URL url)
           
HibernateFilter(Document document)
           
HibernateFilter(File file)
           
HibernateFilter(org.hibernate.SessionFactory sessionFactory)
           
HibernateFilter(String string)
           
HibernateFilter(URL url)
           
 
Method Summary
 void addResultsForRollback(String... results)
           
 void afterConsequence(Action action, Consequence c, boolean conseqExecuted, boolean actionExecuted, String result)
           
 void destroy()
          Gives a chance to the filter to deallocalte any resources before it is destroyed.
 String filter(InvocationChain chain)
          Sets the action to get an Hibernate Session using the pull model.
 Object getValue(String key)
          Verifies if the requested object is a Hibernate Session, return a Hibernate Session if it is and return the content of the action's input if not.
protected  org.hibernate.Session openSessionHibernate(org.hibernate.SessionFactory sessionFactory)
           
 void setKey(String key)
          Sets the action input key to use.
 void setTransactional(boolean transactional)
           
 void setTransactional(boolean transactional, String transactionKey)
           
 String toString()
           
 
Methods inherited from class org.mentawai.core.InputWrapper
clear, containsKey, containsValue, entries, entrySet, get, getBoolean, getBoolean, getBooleanValue, getBooleanValue, getDate, getDate, getDate, getDouble, getDouble, getDoubleValue, getDoubleValue, getEnum, getEnums, getFloat, getFloat, getFloatValue, getFloatValue, getHeader, getHeaderKeys, getInt, getInt, getInts, getIntValue, getIntValue, getIntValues, getLong, getLong, getLongs, getLongValue, getLongValue, getObject, getObject, getProperty, getRoot, getString, getStrings, getStringValue, getStringValues, has, hasValue, inject, inject, isEmpty, keys, keySet, put, putAll, remove, removeInput, removeValue, setInput, setValue, size, values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

KEY

public static final String KEY
The default key name to use when placing the session in the action input.

See Also:
Constant Field Values

TRANS_KEY

public static final String TRANS_KEY
The default key name to use when placing a hibernate transaction in the action input.

See Also:
Constant Field Values
Constructor Detail

HibernateFilter

public HibernateFilter()

HibernateFilter

public HibernateFilter(boolean transactional)

HibernateFilter

public HibernateFilter(Document document)

HibernateFilter

public HibernateFilter(boolean transactional,
                       Document document)

HibernateFilter

public HibernateFilter(File file)

HibernateFilter

public HibernateFilter(boolean transactional,
                       File file)

HibernateFilter

public HibernateFilter(URL url)

HibernateFilter

public HibernateFilter(boolean transactional,
                       URL url)

HibernateFilter

public HibernateFilter(String string)

HibernateFilter

public HibernateFilter(boolean transactional,
                       String string)

HibernateFilter

public HibernateFilter(org.hibernate.SessionFactory sessionFactory)

HibernateFilter

public HibernateFilter(boolean transactional,
                       org.hibernate.SessionFactory sessionFactory)
Method Detail

setTransactional

public void setTransactional(boolean transactional)

addResultsForRollback

public void addResultsForRollback(String... results)

setTransactional

public void setTransactional(boolean transactional,
                             String transactionKey)

toString

public String toString()
Overrides:
toString in class Object

setKey

public void setKey(String key)
Sets the action input key to use. The Hibernate session will be placed in the action input with this key.

Parameters:
key - The action input key.

filter

public String filter(InvocationChain chain)
              throws Exception
Sets the action to get an Hibernate Session using the pull model.

Specified by:
filter in interface Filter
Parameters:
chain - The InvocationChain for the action this filter is being applied to.
Returns:
The result of the filter or the action the filter is being applied to.
Throws:
Exception

afterConsequence

public void afterConsequence(Action action,
                             Consequence c,
                             boolean conseqExecuted,
                             boolean actionExecuted,
                             String result)
Specified by:
afterConsequence in interface AfterConsequenceFilter

destroy

public void destroy()
Description copied from interface: Filter
Gives a chance to the filter to deallocalte any resources before it is destroyed. This is called when the web application is stopped, in other words, this has nothing to do with garbage collection.

Specified by:
destroy in interface Filter

getValue

public Object getValue(String key)
Verifies if the requested object is a Hibernate Session, return a Hibernate Session if it is and return the content of the action's input if not.

Specified by:
getValue in interface Input
Overrides:
getValue in class InputWrapper
Parameters:
key - the name of the parameter
Returns:
the parameter value (any object) or null if it doesn't exist.

openSessionHibernate

protected org.hibernate.Session openSessionHibernate(org.hibernate.SessionFactory sessionFactory)


Copyright © 2013. All Rights Reserved.