public abstract class

AbstractQueryImpl

extends Object
implements Query
java.lang.Object
   ↳ org.hibernate.impl.AbstractQueryImpl
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Abstract implementation of the Query interface.

Summary

Fields
protected final ParameterMetadata parameterMetadata
protected final SessionImplementor session
Public Constructors
AbstractQueryImpl(String queryString, FlushMode flushMode, SessionImplementor session, ParameterMetadata parameterMetadata)
Public Methods
CacheMode getCacheMode()
abstract LockOptions getLockOptions()
String[] getNamedParameters()
Returns an array representing all named parameter names encountered during (intial) parsing of the query.
ParameterMetadata getParameterMetadata()
QueryParameters getQueryParameters(Map namedParams)
final String getQueryString()
Get the query string.
String[] getReturnAliases()
Return the HQL select clause aliases (if any)
Type[] getReturnTypes()
Return the Hibernate types of the query result set.
RowSelection getSelection()
boolean hasNamedParameters()
Does this query contain named parameters?
boolean isReadOnly()
Should entities and proxies loaded by this Query be put in read-only mode? If the read-only/modifiable setting was not initialized, then the default read-only/modifiable setting for the persistence context is returned instead.
Query setBigDecimal(int position, BigDecimal number)
Query setBigDecimal(String name, BigDecimal number)
Query setBigInteger(String name, BigInteger number)
Query setBigInteger(int position, BigInteger number)
Query setBinary(String name, byte[] val)
Query setBinary(int position, byte[] val)
Query setBoolean(String name, boolean val)
Query setBoolean(int position, boolean val)
Query setByte(int position, byte val)
Query setByte(String name, byte val)
Query setCacheMode(CacheMode cacheMode)
Override the current session cache mode, just for this query.
Query setCacheRegion(String cacheRegion)
Set the name of the cache region.
Query setCacheable(boolean cacheable)
Enable caching of this query result set.
Query setCalendar(String name, Calendar calendar)
Query setCalendar(int position, Calendar calendar)
Query setCalendarDate(int position, Calendar calendar)
Query setCalendarDate(String name, Calendar calendar)
Query setCharacter(int position, char val)
Query setCharacter(String name, char val)
Query setCollectionKey(Serializable collectionKey)
Query setComment(String comment)
Add a comment to the generated SQL.
Query setDate(String name, Date date)
Query setDate(int position, Date date)
Query setDouble(int position, double val)
Query setDouble(String name, double val)
Query setEntity(int position, Object val)
Bind an instance of a mapped persistent class to a JDBC-style query parameter.
Query setEntity(String name, Object val)
Bind an instance of a mapped persistent class to a named query parameter.
Query setFetchSize(int fetchSize)
Set a fetch size for the underlying JDBC query.
Query setFirstResult(int firstResult)
Set the first row to retrieve.
Query setFloat(int position, float val)
Query setFloat(String name, float val)
Query setFlushMode(FlushMode flushMode)
Override the current session flush mode, just for this query.
Query setInteger(String name, int val)
Query setInteger(int position, int val)
Query setLocale(int position, Locale locale)
Query setLocale(String name, Locale locale)
Query setLong(int position, long val)
Query setLong(String name, long val)
Query setMaxResults(int maxResults)
Set the maximum number of rows to retrieve.
void setOptionalEntityName(String optionalEntityName)
void setOptionalId(Serializable optionalId)
void setOptionalObject(Object optionalObject)
Query setParameter(int position, Object val, Type type)
Bind a value to a JDBC-style query parameter.
Query setParameter(int position, Object val)
Bind a value to a JDBC-style query parameter.
Query setParameter(String name, Object val, Type type)
Bind a value to a named query parameter.
Query setParameter(String name, Object val)
Bind a value to a named query parameter.
Query setParameterList(String name, Collection vals)
Bind multiple values to a named query parameter.
Query setParameterList(String name, Object[] vals)
Bind multiple values to a named query parameter.
Query setParameterList(String name, Object[] vals, Type type)
Bind multiple values to a named query parameter.
Query setParameterList(String name, Collection vals, Type type)
Bind multiple values to a named query parameter.
Query setParameters(Object[] values, Type[] types)
Bind values and types to positional parameters.
Query setProperties(Object bean)
Bind the property values of the given bean to named parameters of the query, matching property names with parameter names and mapping property types to Hibernate types using hueristics.
Query setProperties(Map map)
Bind the values of the given Map for each named parameters of the query, matching key names with parameter names and mapping value types to Hibernate types using hueristics.
Query setReadOnly(boolean readOnly)
Set the read-only/modifiable mode for entities and proxies loaded by this Query.
Query setResultTransformer(ResultTransformer transformer)
Set a strategy for handling the query results.
Query setSerializable(String name, Serializable val)
Query setSerializable(int position, Serializable val)
Query setShort(int position, short val)
Query setShort(String name, short val)
Query setString(int position, String val)
Query setString(String name, String val)
Query setText(int position, String val)
Query setText(String name, String val)
Query setTime(int position, Date date)
Query setTime(String name, Date date)
Query setTimeout(int timeout)
Set a timeout for the underlying JDBC query.
Query setTimestamp(int position, Date date)
Query setTimestamp(String name, Date date)
String toString()
Type[] typeArray()
Object uniqueResult()
Convenience method to return a single instance that matches the query, or null if the query returns no results.
Object[] valueArray()
Protected Methods
void after()
void before()
Type determineType(String paramName, Object paramValue, Type defaultType)
Type determineType(int paramPosition, Object paramValue, Type defaultType)
Type determineType(String paramName, Object paramValue)
Type determineType(String paramName, Class clazz)
Type determineType(int paramPosition, Object paramValue)
String expandParameterLists(Map namedParamsCopy)
Warning: adds new parameters to the argument by side-effect, as well as mutating the query string!
Map getNamedParameterLists()
Retreive the value map for any named parameter lists (i.e., for auto-expansion) bound to this query.
Map getNamedParams()
Returns a shallow copy of the named parameter value map.
RowSelection getRowSelection()
List getTypes()
Retreives the list of parameter types bound to this query for ordinal parameters.
List getValues()
Retreives the list of parameter values bound to this query for ordinal parameters.
void verifyParameters(boolean reserveFirstParameter)
Perform parameter validation.
void verifyParameters()
Perform parameter validation.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.hibernate.Query

Fields

protected final ParameterMetadata parameterMetadata

protected final SessionImplementor session

Public Constructors

public AbstractQueryImpl (String queryString, FlushMode flushMode, SessionImplementor session, ParameterMetadata parameterMetadata)

Public Methods

public CacheMode getCacheMode ()

public abstract LockOptions getLockOptions ()

public String[] getNamedParameters ()

Returns an array representing all named parameter names encountered during (intial) parsing of the query.

Note initial here means different things depending on whether this is a native-sql query or an HQL/filter query. For native-sql, a precursory inspection of the query string is performed specifically to locate defined parameters. For HQL/filter queries, this is the information returned from the query-translator. This distinction holds true for all parameter metadata exposed here.

Returns
  • Array of named parameter names.

public ParameterMetadata getParameterMetadata ()

public QueryParameters getQueryParameters (Map namedParams)

public final String getQueryString ()

Get the query string.

Returns
  • the query string

public String[] getReturnAliases ()

Return the HQL select clause aliases (if any)

Returns
  • an array of aliases as strings

public Type[] getReturnTypes ()

Return the Hibernate types of the query result set.

Returns
  • an array of types

public RowSelection getSelection ()

public boolean hasNamedParameters ()

Does this query contain named parameters?

Returns
  • True if the query was found to contain named parameters; false otherwise;

public boolean isReadOnly ()

Should entities and proxies loaded by this Query be put in read-only mode? If the read-only/modifiable setting was not initialized, then the default read-only/modifiable setting for the persistence context is returned instead.

Returns
  • true, entities and proxies loaded by the query will be put in read-only mode false, entities and proxies loaded by the query will be put in modifiable mode

public Query setBigDecimal (int position, BigDecimal number)

public Query setBigDecimal (String name, BigDecimal number)

public Query setBigInteger (String name, BigInteger number)

public Query setBigInteger (int position, BigInteger number)

public Query setBinary (String name, byte[] val)

public Query setBinary (int position, byte[] val)

public Query setBoolean (String name, boolean val)

public Query setBoolean (int position, boolean val)

public Query setByte (int position, byte val)

public Query setByte (String name, byte val)

public Query setCacheMode (CacheMode cacheMode)

Override the current session cache mode, just for this query.

public Query setCacheRegion (String cacheRegion)

Set the name of the cache region.

Parameters
cacheRegion the name of a query cache region, or null for the default query cache

public Query setCacheable (boolean cacheable)

Enable caching of this query result set.

Parameters
cacheable Should the query results be cacheable?

public Query setCalendar (String name, Calendar calendar)

public Query setCalendar (int position, Calendar calendar)

public Query setCalendarDate (int position, Calendar calendar)

public Query setCalendarDate (String name, Calendar calendar)

public Query setCharacter (int position, char val)

public Query setCharacter (String name, char val)

public Query setCollectionKey (Serializable collectionKey)

public Query setComment (String comment)

Add a comment to the generated SQL.

Parameters
comment a human-readable string

public Query setDate (String name, Date date)

public Query setDate (int position, Date date)

public Query setDouble (int position, double val)

public Query setDouble (String name, double val)

public Query setEntity (int position, Object val)

Bind an instance of a mapped persistent class to a JDBC-style query parameter.

Parameters
position the position of the parameter in the query string, numbered from 0.
val a non-null instance of a persistent class

public Query setEntity (String name, Object val)

Bind an instance of a mapped persistent class to a named query parameter.

Parameters
name the name of the parameter
val a non-null instance of a persistent class

public Query setFetchSize (int fetchSize)

Set a fetch size for the underlying JDBC query.

Parameters
fetchSize the fetch size

public Query setFirstResult (int firstResult)

Set the first row to retrieve. If not set, rows will be retrieved beginnning from row 0.

Parameters
firstResult a row number, numbered from 0

public Query setFloat (int position, float val)

public Query setFloat (String name, float val)

public Query setFlushMode (FlushMode flushMode)

Override the current session flush mode, just for this query.

public Query setInteger (String name, int val)

public Query setInteger (int position, int val)

public Query setLocale (int position, Locale locale)

public Query setLocale (String name, Locale locale)

public Query setLong (int position, long val)

public Query setLong (String name, long val)

public Query setMaxResults (int maxResults)

Set the maximum number of rows to retrieve. If not set, there is no limit to the number of rows retrieved.

Parameters
maxResults the maximum number of rows

public void setOptionalEntityName (String optionalEntityName)

public void setOptionalId (Serializable optionalId)

public void setOptionalObject (Object optionalObject)

public Query setParameter (int position, Object val, Type type)

Bind a value to a JDBC-style query parameter.

Parameters
position the position of the parameter in the query string, numbered from 0.
val the possibly-null parameter value
type the Hibernate type

public Query setParameter (int position, Object val)

Bind a value to a JDBC-style query parameter. The Hibernate type of the parameter is first detected via the usage/position in the query and if not sufficient secondly guessed from the class of the given object.

Parameters
position the position of the parameter in the query string, numbered from 0.
val the non-null parameter value

public Query setParameter (String name, Object val, Type type)

Bind a value to a named query parameter.

Parameters
name the name of the parameter
val the possibly-null parameter value
type the Hibernate type

public Query setParameter (String name, Object val)

Bind a value to a named query parameter. The Hibernate type of the parameter is first detected via the usage/position in the query and if not sufficient secondly guessed from the class of the given object.

Parameters
name the name of the parameter
val the non-null parameter value

public Query setParameterList (String name, Collection vals)

Bind multiple values to a named query parameter. The Hibernate type of the parameter is first detected via the usage/position in the query and if not sufficient secondly guessed from the class of the first object in the collection. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).

Parameters
name the name of the parameter
vals a collection of values to list

public Query setParameterList (String name, Object[] vals)

Bind multiple values to a named query parameter. The Hibernate type of the parameter is first detected via the usage/position in the query and if not sufficient secondly guessed from the class of the first object in the array. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).

Parameters
name the name of the parameter
vals a collection of values to list

public Query setParameterList (String name, Object[] vals, Type type)

Bind multiple values to a named query parameter. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).

Parameters
name the name of the parameter
vals a collection of values to list
type the Hibernate type of the values

public Query setParameterList (String name, Collection vals, Type type)

Bind multiple values to a named query parameter. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).

Parameters
name the name of the parameter
vals a collection of values to list
type the Hibernate type of the values

public Query setParameters (Object[] values, Type[] types)

Bind values and types to positional parameters.

public Query setProperties (Object bean)

Bind the property values of the given bean to named parameters of the query, matching property names with parameter names and mapping property types to Hibernate types using hueristics.

Parameters
bean any JavaBean or POJO

public Query setProperties (Map map)

Bind the values of the given Map for each named parameters of the query, matching key names with parameter names and mapping value types to Hibernate types using hueristics.

Parameters
map a java.util.Map

public Query setReadOnly (boolean readOnly)

Set the read-only/modifiable mode for entities and proxies loaded by this Query. This setting overrides the default setting for the persistence context.

Parameters
readOnly true, entities and proxies loaded by the query will be put in read-only mode false, entities and proxies loaded by the query will be put in modifiable mode

public Query setResultTransformer (ResultTransformer transformer)

Set a strategy for handling the query results. This can be used to change "shape" of the query result.

Parameters
transformer The transformer to apply
Returns
  • this (for method chaining)

public Query setSerializable (String name, Serializable val)

public Query setSerializable (int position, Serializable val)

public Query setShort (int position, short val)

public Query setShort (String name, short val)

public Query setString (int position, String val)

public Query setString (String name, String val)

public Query setText (int position, String val)

public Query setText (String name, String val)

public Query setTime (int position, Date date)

public Query setTime (String name, Date date)

public Query setTimeout (int timeout)

Set a timeout for the underlying JDBC query.

Parameters
timeout the timeout in seconds

public Query setTimestamp (int position, Date date)

public Query setTimestamp (String name, Date date)

public String toString ()

public Type[] typeArray ()

public Object uniqueResult ()

Convenience method to return a single instance that matches the query, or null if the query returns no results.

Returns
  • the single result or null

public Object[] valueArray ()

Protected Methods

protected void after ()

protected void before ()

protected Type determineType (String paramName, Object paramValue, Type defaultType)

protected Type determineType (int paramPosition, Object paramValue, Type defaultType)

protected Type determineType (String paramName, Object paramValue)

protected Type determineType (String paramName, Class clazz)

protected Type determineType (int paramPosition, Object paramValue)

protected String expandParameterLists (Map namedParamsCopy)

Warning: adds new parameters to the argument by side-effect, as well as mutating the query string!

protected Map getNamedParameterLists ()

Retreive the value map for any named parameter lists (i.e., for auto-expansion) bound to this query.

Returns
  • The parameter list value map.

protected Map getNamedParams ()

Returns a shallow copy of the named parameter value map.

Returns
  • Shallow copy of the named parameter value map

protected RowSelection getRowSelection ()

protected List getTypes ()

Retreives the list of parameter types bound to this query for ordinal parameters.

Returns
  • The ordinal parameter types.

protected List getValues ()

Retreives the list of parameter values bound to this query for ordinal parameters.

Returns
  • The ordinal parameter values.

protected void verifyParameters (boolean reserveFirstParameter)

Perform parameter validation. Used prior to executing the encapsulated query.

Parameters
reserveFirstParameter if true, the first ? will not be verified since its needed for e.g. callable statements returning a out parameter

protected void verifyParameters ()

Perform parameter validation. Used prior to executing the encapsulated query.