org.hibernate.search.jpa.impl
Class FullTextQueryImpl

java.lang.Object
  extended by org.hibernate.search.jpa.impl.FullTextQueryImpl
All Implemented Interfaces:
javax.persistence.Query, FullTextQuery, ProjectionConstants

public class FullTextQueryImpl
extends Object
implements FullTextQuery

Implements JPA 2 query interface and delegate the call to a Hibernate Core FullTextQuery. This has the consequence of "duplicating" the JPA 2 query logic in some areas.

Author:
Emmanuel Bernard

Field Summary
 
Fields inherited from interface org.hibernate.search.ProjectionConstants
DOCUMENT, DOCUMENT_ID, EXPLANATION, ID, OBJECT_CLASS, SCORE, THIS
 
Constructor Summary
FullTextQueryImpl(FullTextQuery query, Session session)
           
 
Method Summary
 void disableFullTextFilter(String name)
          Disable a given filter by its name
 FullTextFilter enableFullTextFilter(String name)
          Enable a given filter by its name.
 int executeUpdate()
           
 org.apache.lucene.search.Explanation explain(int documentId)
          Return the Lucene Explanation object describing the score computation for the matching object/document in the current query
 FacetManager getFacetManager()
           
 int getFirstResult()
           
 javax.persistence.FlushModeType getFlushMode()
           
 Map<String,Object> getHints()
           
 javax.persistence.LockModeType getLockMode()
           
 int getMaxResults()
           
 javax.persistence.Parameter<?> getParameter(int position)
           
<T> javax.persistence.Parameter<T>
getParameter(int position, Class<T> type)
           
 javax.persistence.Parameter<?> getParameter(String name)
           
<T> javax.persistence.Parameter<T>
getParameter(String name, Class<T> type)
           
 Set<javax.persistence.Parameter<?>> getParameters()
           
 Object getParameterValue(int position)
           
<T> T
getParameterValue(javax.persistence.Parameter<T> param)
           
 Object getParameterValue(String name)
           
 List getResultList()
           
 int getResultSize()
          Returns the number of hits for this search Caution: The number of results might be slightly different from getResultList().size() because getResultList() may be not in sync with the database at the time of query.
 Object getSingleResult()
           
 boolean hasPartialResults()
          *Experimental* API, subject to change or removal When using FullTextQuery.limitExecutionTimeTo(long, java.util.concurrent.TimeUnit) }, returns true if partial results are returned (ie if the time limit has been reached and the result fetching process has been terminated.
 FullTextQuery initializeObjectsWith(ObjectLookupMethod lookupMethod, DatabaseRetrievalMethod retrievalMethod)
          Refine the strategies used to load entities.
 boolean isBound(javax.persistence.Parameter<?> param)
           
 FullTextQuery limitExecutionTimeTo(long timeout, TimeUnit timeUnit)
          *Experimental* API, subject to change or removal Limit the time used by Hibernate Search to execute the query.
 FullTextQuery setCriteriaQuery(Criteria criteria)
          Defines the Database Query used to load the Lucene results.
 FullTextQuery setFilter(org.apache.lucene.search.Filter filter)
          Allows to use lucene filters.
 javax.persistence.Query setFirstResult(int firstResult)
           
 javax.persistence.Query setFlushMode(javax.persistence.FlushModeType flushMode)
           
 javax.persistence.Query setHint(String hintName, Object value)
           
 javax.persistence.Query setLockMode(javax.persistence.LockModeType lockModeType)
           
 javax.persistence.Query setMaxResults(int maxResults)
           
 javax.persistence.Query setParameter(int position, Calendar value, javax.persistence.TemporalType temporalType)
           
 javax.persistence.Query setParameter(int position, Date value, javax.persistence.TemporalType temporalType)
           
 javax.persistence.Query setParameter(int position, Object value)
           
 javax.persistence.Query setParameter(javax.persistence.Parameter<Calendar> calendarParameter, Calendar calendar, javax.persistence.TemporalType temporalType)
           
 javax.persistence.Query setParameter(javax.persistence.Parameter<Date> dateParameter, Date date, javax.persistence.TemporalType temporalType)
           
<T> javax.persistence.Query
setParameter(javax.persistence.Parameter<T> tParameter, T t)
           
 javax.persistence.Query setParameter(String name, Calendar value, javax.persistence.TemporalType temporalType)
           
 javax.persistence.Query setParameter(String name, Date value, javax.persistence.TemporalType temporalType)
           
 javax.persistence.Query setParameter(String name, Object value)
           
 FullTextQuery setProjection(String... fields)
          Defines the Lucene field names projected and returned in a query result Each field is converted back to it's object representation, an Object[] being returned for each "row" (similar to an HQL or a Criteria API projection).
 FullTextQuery setResultTransformer(ResultTransformer transformer)
          defines a result transformer used during projection
 FullTextQuery setSort(org.apache.lucene.search.Sort sort)
          Allows to let lucene sort the results.
<T> T
unwrap(Class<T> type)
           
 javax.persistence.PersistenceException wrapLockException(HibernateException e, LockOptions lockOptions)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FullTextQueryImpl

public FullTextQueryImpl(FullTextQuery query,
                         Session session)
Method Detail

setSort

public FullTextQuery setSort(org.apache.lucene.search.Sort sort)
Description copied from interface: FullTextQuery
Allows to let lucene sort the results. This is useful when you have additional sort requirements on top of the default lucene ranking. Without lucene sorting you would have to retrieve the full result set and order the hibernate objects.

Specified by:
setSort in interface FullTextQuery
Parameters:
sort - The lucene sort object.
Returns:
this for method chaining

setFilter

public FullTextQuery setFilter(org.apache.lucene.search.Filter filter)
Description copied from interface: FullTextQuery
Allows to use lucene filters. Semi-deprecated? a preferred way is to use the @FullTextFilterDef approach

Specified by:
setFilter in interface FullTextQuery
Parameters:
filter - The lucene filter.
Returns:
this for method chaining

getResultSize

public int getResultSize()
Description copied from interface: FullTextQuery
Returns the number of hits for this search Caution: The number of results might be slightly different from getResultList().size() because getResultList() may be not in sync with the database at the time of query.

Specified by:
getResultSize in interface FullTextQuery

setCriteriaQuery

public FullTextQuery setCriteriaQuery(Criteria criteria)
Description copied from interface: FullTextQuery
Defines the Database Query used to load the Lucene results. Useful to load a given object graph by refining the fetch modes No projection (criteria.setProjection() ) allowed, the root entity must be the only returned type No where restriction can be defined either.

Specified by:
setCriteriaQuery in interface FullTextQuery

setProjection

public FullTextQuery setProjection(String... fields)
Description copied from interface: FullTextQuery
Defines the Lucene field names projected and returned in a query result Each field is converted back to it's object representation, an Object[] being returned for each "row" (similar to an HQL or a Criteria API projection). A projectable field must be stored in the Lucene index and use a TwoWayFieldBridge Unless notified in their JavaDoc, all built-in bridges are two-way. All @DocumentId fields are projectable by design. If the projected field is not a projectable field, null is returned in the object[]

Specified by:
setProjection in interface FullTextQuery

enableFullTextFilter

public FullTextFilter enableFullTextFilter(String name)
Description copied from interface: FullTextQuery
Enable a given filter by its name. Returns a FullTextFilter object that allows filter parameter injection

Specified by:
enableFullTextFilter in interface FullTextQuery

disableFullTextFilter

public void disableFullTextFilter(String name)
Description copied from interface: FullTextQuery
Disable a given filter by its name

Specified by:
disableFullTextFilter in interface FullTextQuery

setResultTransformer

public FullTextQuery setResultTransformer(ResultTransformer transformer)
Description copied from interface: FullTextQuery
defines a result transformer used during projection

Specified by:
setResultTransformer in interface FullTextQuery

getResultList

public List getResultList()
Specified by:
getResultList in interface javax.persistence.Query

getFacetManager

public FacetManager getFacetManager()
Specified by:
getFacetManager in interface FullTextQuery
Returns:
return the manager for all faceting related operations

wrapLockException

public javax.persistence.PersistenceException wrapLockException(HibernateException e,
                                                                LockOptions lockOptions)

getSingleResult

public Object getSingleResult()
Specified by:
getSingleResult in interface javax.persistence.Query

setMaxResults

public javax.persistence.Query setMaxResults(int maxResults)
Specified by:
setMaxResults in interface javax.persistence.Query

getMaxResults

public int getMaxResults()
Specified by:
getMaxResults in interface javax.persistence.Query

setFirstResult

public javax.persistence.Query setFirstResult(int firstResult)
Specified by:
setFirstResult in interface javax.persistence.Query

getFirstResult

public int getFirstResult()
Specified by:
getFirstResult in interface javax.persistence.Query

explain

public org.apache.lucene.search.Explanation explain(int documentId)
Description copied from interface: FullTextQuery
Return the Lucene Explanation object describing the score computation for the matching object/document in the current query

Specified by:
explain in interface FullTextQuery
Parameters:
documentId - Lucene Document id to be explain. This is NOT the object id
Returns:
Lucene Explanation

limitExecutionTimeTo

public FullTextQuery limitExecutionTimeTo(long timeout,
                                          TimeUnit timeUnit)
Description copied from interface: FullTextQuery
*Experimental* API, subject to change or removal Limit the time used by Hibernate Search to execute the query. When the limit is reached, results already fetched are returned. This time limit is a best effort. The query will likely run for longer than the provided time. The time limit only applies to the interactions between Hibernate Search and Lucene. In other words, a query to the database will not be limited. If the limit is reached and all results are not yet fetched, FullTextQuery.hasPartialResults() returns true.

Specified by:
limitExecutionTimeTo in interface FullTextQuery
Parameters:
timeout - time out period
timeUnit - time out unit

hasPartialResults

public boolean hasPartialResults()
Description copied from interface: FullTextQuery
*Experimental* API, subject to change or removal When using FullTextQuery.limitExecutionTimeTo(long, java.util.concurrent.TimeUnit) }, returns true if partial results are returned (ie if the time limit has been reached and the result fetching process has been terminated.

Specified by:
hasPartialResults in interface FullTextQuery

initializeObjectsWith

public FullTextQuery initializeObjectsWith(ObjectLookupMethod lookupMethod,
                                           DatabaseRetrievalMethod retrievalMethod)
Description copied from interface: FullTextQuery
Refine the strategies used to load entities. The lookup method defines whether or not to lookup first in the second level cache or the persistence context before trying to initialize objects from the database. Defaults to SKIP. The database retrieval method defines how objects are loaded from the database. Defaults to QUERY. Note that Hibernate Search can deviate from these choices when it makes sense.

Specified by:
initializeObjectsWith in interface FullTextQuery

executeUpdate

public int executeUpdate()
Specified by:
executeUpdate in interface javax.persistence.Query

setHint

public javax.persistence.Query setHint(String hintName,
                                       Object value)
Specified by:
setHint in interface javax.persistence.Query

getHints

public Map<String,Object> getHints()
Specified by:
getHints in interface javax.persistence.Query

setParameter

public <T> javax.persistence.Query setParameter(javax.persistence.Parameter<T> tParameter,
                                                T t)
Specified by:
setParameter in interface javax.persistence.Query

setParameter

public javax.persistence.Query setParameter(javax.persistence.Parameter<Calendar> calendarParameter,
                                            Calendar calendar,
                                            javax.persistence.TemporalType temporalType)
Specified by:
setParameter in interface javax.persistence.Query

setParameter

public javax.persistence.Query setParameter(javax.persistence.Parameter<Date> dateParameter,
                                            Date date,
                                            javax.persistence.TemporalType temporalType)
Specified by:
setParameter in interface javax.persistence.Query

setParameter

public javax.persistence.Query setParameter(String name,
                                            Object value)
Specified by:
setParameter in interface javax.persistence.Query

setParameter

public javax.persistence.Query setParameter(String name,
                                            Date value,
                                            javax.persistence.TemporalType temporalType)
Specified by:
setParameter in interface javax.persistence.Query

setParameter

public javax.persistence.Query setParameter(String name,
                                            Calendar value,
                                            javax.persistence.TemporalType temporalType)
Specified by:
setParameter in interface javax.persistence.Query

setParameter

public javax.persistence.Query setParameter(int position,
                                            Object value)
Specified by:
setParameter in interface javax.persistence.Query

setParameter

public javax.persistence.Query setParameter(int position,
                                            Date value,
                                            javax.persistence.TemporalType temporalType)
Specified by:
setParameter in interface javax.persistence.Query

getParameters

public Set<javax.persistence.Parameter<?>> getParameters()
Specified by:
getParameters in interface javax.persistence.Query

setParameter

public javax.persistence.Query setParameter(int position,
                                            Calendar value,
                                            javax.persistence.TemporalType temporalType)
Specified by:
setParameter in interface javax.persistence.Query

getParameter

public javax.persistence.Parameter<?> getParameter(String name)
Specified by:
getParameter in interface javax.persistence.Query

getParameter

public javax.persistence.Parameter<?> getParameter(int position)
Specified by:
getParameter in interface javax.persistence.Query

getParameter

public <T> javax.persistence.Parameter<T> getParameter(String name,
                                                       Class<T> type)
Specified by:
getParameter in interface javax.persistence.Query

getParameter

public <T> javax.persistence.Parameter<T> getParameter(int position,
                                                       Class<T> type)
Specified by:
getParameter in interface javax.persistence.Query

isBound

public boolean isBound(javax.persistence.Parameter<?> param)
Specified by:
isBound in interface javax.persistence.Query

getParameterValue

public <T> T getParameterValue(javax.persistence.Parameter<T> param)
Specified by:
getParameterValue in interface javax.persistence.Query

getParameterValue

public Object getParameterValue(String name)
Specified by:
getParameterValue in interface javax.persistence.Query

getParameterValue

public Object getParameterValue(int position)
Specified by:
getParameterValue in interface javax.persistence.Query

setFlushMode

public javax.persistence.Query setFlushMode(javax.persistence.FlushModeType flushMode)
Specified by:
setFlushMode in interface javax.persistence.Query

getFlushMode

public javax.persistence.FlushModeType getFlushMode()
Specified by:
getFlushMode in interface javax.persistence.Query

setLockMode

public javax.persistence.Query setLockMode(javax.persistence.LockModeType lockModeType)
Specified by:
setLockMode in interface javax.persistence.Query

getLockMode

public javax.persistence.LockModeType getLockMode()
Specified by:
getLockMode in interface javax.persistence.Query

unwrap

public <T> T unwrap(Class<T> type)
Specified by:
unwrap in interface javax.persistence.Query


Copyright © 2006-2012 Red Hat Middleware, LLC. All Rights Reserved