org.yestech.lib.hibernate.search
Class YesHibernateSearchTemplate

java.lang.Object
  extended by org.springframework.orm.hibernate3.HibernateAccessor
      extended by org.yestech.lib.hibernate.search.YesHibernateSearchTemplate
All Implemented Interfaces:
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean, YesHibernateSearchOperations

public class YesHibernateSearchTemplate
extends org.springframework.orm.hibernate3.HibernateAccessor
implements YesHibernateSearchOperations

A wrapper for Hibernate Search. Modeled after HibernateTemplate.

Version:
$Revision: $
Author:
Artie Copeland

Field Summary
 
Fields inherited from class org.springframework.orm.hibernate3.HibernateAccessor
FLUSH_ALWAYS, FLUSH_AUTO, FLUSH_COMMIT, FLUSH_EAGER, FLUSH_NEVER, logger
 
Constructor Summary
YesHibernateSearchTemplate()
           
YesHibernateSearchTemplate(org.hibernate.SessionFactory sessionFactory)
           
 
Method Summary
protected  org.hibernate.Session createSessionProxy(org.hibernate.Session session)
          Create a close-suppressing proxy for the given Hibernate Session.
 java.lang.Object doExecute(HibernateSearchCallback action, boolean enforceNewSession, boolean enforceNativeSession)
          Execute the action specified by the given action object within a Session.
 org.hibernate.Filter enableFilter(java.lang.String filterName)
           
 java.lang.Object executeWithNativeSession(HibernateSearchCallback action)
          Execute the action specified by the given action object within a native Session.
protected  org.hibernate.Session getSession()
          Return a Session for use by this template.
 void initialize(java.lang.Object proxy)
           
 boolean isAlwaysUseNewSession()
          Return whether to always use a new Hibernate Session for this template.
 boolean isExposeNativeSession()
          Return whether to expose the native Hibernate Session to HibernateCallback code, or rather a Session proxy.
<T> java.util.List<T>
search(org.apache.lucene.search.Query query, java.lang.Class... searchClass)
          Performs a Search.
<T> java.util.List<T>
search(org.apache.lucene.search.Query query, java.lang.Class<T> searchClass)
          Performs a Search.
<T> java.util.List<T>
search(java.lang.String searchText, java.lang.Class[] searchClass, org.apache.lucene.analysis.Analyzer analyzer, java.lang.String... fields)
           
<T> java.util.List<T>
search(java.lang.String searchText, java.lang.Class[] searchClass, java.lang.String... fields)
          Performs a Search with a default analyzer of StandardAnalyzer.
<T> java.util.List<T>
search(java.lang.String searchText, java.lang.Class<T> searchClass, org.apache.lucene.analysis.Analyzer analyzer, java.lang.String... fields)
           
<T> java.util.List<T>
search(java.lang.String searchText, java.lang.Class<T> searchClass, java.lang.String... fields)
          Performs a Search with a default analyzer of StandardAnalyzer.
<T> java.util.List<T>
search(java.lang.String searchText, java.util.List<FilterConfig> filters, java.lang.Class[] classes, java.lang.String... fields)
           
 void setAlwaysUseNewSession(boolean alwaysUseNewSession)
          Set whether to always use a new Hibernate Session for this template.
 void setExposeNativeSession(boolean exposeNativeSession)
          Set whether to expose the native Hibernate Session to HibernateCallback code.
 
Methods inherited from class org.springframework.orm.hibernate3.HibernateAccessor
afterPropertiesSet, applyFlushMode, convertHibernateAccessException, convertJdbcAccessException, convertJdbcAccessException, disableFilters, enableFilters, flushIfNecessary, getDefaultJdbcExceptionTranslator, getEntityInterceptor, getFilterNames, getFlushMode, getJdbcExceptionTranslator, getSessionFactory, setBeanFactory, setEntityInterceptor, setEntityInterceptorBeanName, setFilterName, setFilterNames, setFlushMode, setFlushModeName, setJdbcExceptionTranslator, setSessionFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

YesHibernateSearchTemplate

public YesHibernateSearchTemplate()

YesHibernateSearchTemplate

public YesHibernateSearchTemplate(org.hibernate.SessionFactory sessionFactory)
Method Detail

setAlwaysUseNewSession

public void setAlwaysUseNewSession(boolean alwaysUseNewSession)
Set whether to always use a new Hibernate Session for this template. Default is "false"; if activated, all operations on this template will work on a new Hibernate Session even in case of a pre-bound Session (for example, within a transaction or OpenSessionInViewFilter).

Within a transaction, a new Hibernate Session used by this template will participate in the transaction through using the same JDBC Connection. In such a scenario, multiple Sessions will participate in the same database transaction.

Turn this on for operations that are supposed to always execute independently, without side effects caused by a shared Hibernate Session.


isAlwaysUseNewSession

public boolean isAlwaysUseNewSession()
Return whether to always use a new Hibernate Session for this template.


setExposeNativeSession

public void setExposeNativeSession(boolean exposeNativeSession)
Set whether to expose the native Hibernate Session to HibernateCallback code.

Default is "false": a Session proxy will be returned, suppressing close calls and automatically applying query cache settings and transaction timeouts.

See Also:
HibernateCallback, Session

isExposeNativeSession

public boolean isExposeNativeSession()
Return whether to expose the native Hibernate Session to HibernateCallback code, or rather a Session proxy.


executeWithNativeSession

public java.lang.Object executeWithNativeSession(HibernateSearchCallback action)
Execute the action specified by the given action object within a native Session.

This execute variant overrides the template-wide "exposeNativeSession" setting.

Parameters:
action - callback object that specifies the Hibernate action
Returns:
a result object returned by the action, or null
Throws:
org.springframework.dao.DataAccessException - in case of Hibernate errors

doExecute

public java.lang.Object doExecute(HibernateSearchCallback action,
                                  boolean enforceNewSession,
                                  boolean enforceNativeSession)
                           throws org.springframework.dao.DataAccessException
Execute the action specified by the given action object within a Session.

Specified by:
doExecute in interface YesHibernateSearchOperations
Parameters:
action - callback object that specifies the Hibernate action
enforceNewSession - whether to enforce a new Session for this template even if there is a pre-bound transactional Session
enforceNativeSession - whether to enforce exposure of the native Hibernate Session to callback code
Returns:
a result object returned by the action, or null
Throws:
org.springframework.dao.DataAccessException - in case of Hibernate errors

createSessionProxy

protected org.hibernate.Session createSessionProxy(org.hibernate.Session session)
Create a close-suppressing proxy for the given Hibernate Session. The proxy also prepares returned Query and Criteria objects.

Parameters:
session - the Hibernate Session to create a proxy for
Returns:
the Session proxy
See Also:
Session.close()

getSession

protected org.hibernate.Session getSession()
Return a Session for use by this template.

Returns a new Session in case of "alwaysUseNewSession" (using the same JDBC Connection as a transactional Session, if applicable), a pre-bound Session in case of "allowCreate" turned off, and a pre-bound or new Session otherwise (new only if no transactional or otherwise pre-bound Session exists).

Returns:
the Session to use (never null)
See Also:
SessionFactoryUtils.getSession(org.hibernate.SessionFactory, boolean), SessionFactoryUtils.getNewSession(org.hibernate.SessionFactory), setAlwaysUseNewSession(boolean)

initialize

public void initialize(java.lang.Object proxy)
                throws org.springframework.dao.DataAccessException
Throws:
org.springframework.dao.DataAccessException

enableFilter

public org.hibernate.Filter enableFilter(java.lang.String filterName)
                                  throws java.lang.IllegalStateException
Throws:
java.lang.IllegalStateException

search

public <T> java.util.List<T> search(org.apache.lucene.search.Query query,
                                    java.lang.Class<T> searchClass)
Performs a Search.

Specified by:
search in interface YesHibernateSearchOperations
Type Parameters:
T -
Parameters:
query -
searchClass -
Returns:

search

public <T> java.util.List<T> search(org.apache.lucene.search.Query query,
                                    java.lang.Class... searchClass)
Performs a Search.

Specified by:
search in interface YesHibernateSearchOperations
Type Parameters:
T -
Parameters:
query -
searchClass -
Returns:

search

public <T> java.util.List<T> search(java.lang.String searchText,
                                    java.util.List<FilterConfig> filters,
                                    java.lang.Class[] classes,
                                    java.lang.String... fields)
Specified by:
search in interface YesHibernateSearchOperations

search

public <T> java.util.List<T> search(java.lang.String searchText,
                                    java.lang.Class<T> searchClass,
                                    java.lang.String... fields)
Performs a Search with a default analyzer of StandardAnalyzer.

Specified by:
search in interface YesHibernateSearchOperations
Type Parameters:
T -
Parameters:
searchText -
searchClass -
fields -
Returns:

search

public <T> java.util.List<T> search(java.lang.String searchText,
                                    java.lang.Class[] searchClass,
                                    java.lang.String... fields)
Performs a Search with a default analyzer of StandardAnalyzer.

Specified by:
search in interface YesHibernateSearchOperations
Type Parameters:
T -
Parameters:
searchText -
searchClass -
fields -
Returns:

search

public <T> java.util.List<T> search(java.lang.String searchText,
                                    java.lang.Class<T> searchClass,
                                    org.apache.lucene.analysis.Analyzer analyzer,
                                    java.lang.String... fields)
Specified by:
search in interface YesHibernateSearchOperations
Type Parameters:
T -
Parameters:
searchText -
searchClass -
analyzer -
fields -
Returns:

search

public <T> java.util.List<T> search(java.lang.String searchText,
                                    java.lang.Class[] searchClass,
                                    org.apache.lucene.analysis.Analyzer analyzer,
                                    java.lang.String... fields)
Specified by:
search in interface YesHibernateSearchOperations
Type Parameters:
T -
Parameters:
searchText -
searchClass -
analyzer -
fields -
Returns:


Copyright © 2009 YES Technology Association. All Rights Reserved.