Abstract implementation of the Query interface.
after
protected void after()
before
protected void before()
determineType
protected Type determineType(String paramName,
Object paramValue,
Type defaultType)
determineType
protected Type determineType(int paramPosition,
Object paramValue,
Type defaultType)
expandParameterLists
protected String expandParameterLists(Map namedParamsCopy)
Warning: adds new parameters to the argument by side-effect, as well as
mutating the query string!
getLockModes
protected abstract Map getLockModes()
getNamedParameterLists
protected Map getNamedParameterLists()
Retreive the value map for any named parameter lists (i.e., for
auto-expansion) bound to this query.
- The parameter list value map.
getNamedParameters
public String[] getNamedParameters()
throws HibernateException
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.
- getNamedParameters in interface Query
- Array of named parameter names.
getNamedParams
protected Map getNamedParams()
Returns a shallow copy of the named parameter value map.
- Shallow copy of the named parameter value map
getQueryParameters
public QueryParameters getQueryParameters(Map namedParams)
getQueryString
public final String getQueryString()
Get the query string.
- getQueryString in interface Query
getTypes
protected List getTypes()
Retreives the list of parameter
type
s bound to this query for
ordinal parameters.
- The ordinal parameter types.
getValues
protected List getValues()
Retreives the list of parameter values bound to this query for
ordinal parameters.
- The ordinal parameter values.
hasNamedParameters
public boolean hasNamedParameters()
Does this query contain named parameters?
- True if the query was found to contain named parameters; false
otherwise;
isReadOnly
public boolean isReadOnly()
setCacheRegion
public Query setCacheRegion(String cacheRegion)
Set the name of the cache region.
- setCacheRegion in interface Query
cacheRegion
- the name of a query cache region, or null
for the default query cache
setCacheable
public Query setCacheable(boolean cacheable)
Enable caching of this query result set.
- setCacheable in interface Query
cacheable
- Should the query results be cacheable?
setCollectionKey
public Query setCollectionKey(Serializable collectionKey)
setComment
public Query setComment(String comment)
Add a comment to the generated SQL.
- setComment in interface Query
comment
- a human-readable string
setEntity
public Query setEntity(String name,
Object val)
Bind an instance of a mapped persistent class to a named query parameter.
- setEntity in interface Query
name
- the name of the parameterval
- a non-null instance of a persistent class
setEntity
public Query setEntity(int position,
Object val)
Bind an instance of a mapped persistent class to a JDBC-style query parameter.
- setEntity in interface Query
position
- the position of the parameter in the query
string, numbered from 0.val
- a non-null instance of a persistent class
setFetchSize
public Query setFetchSize(int fetchSize)
Set a fetch size for the underlying JDBC query.
- setFetchSize in interface Query
fetchSize
- the fetch size
setFirstResult
public Query setFirstResult(int firstResult)
Set the first row to retrieve. If not set, rows will be
retrieved beginnning from row 0.
- setFirstResult in interface Query
firstResult
- a row number, numbered from 0
setMaxResults
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.
- setMaxResults in interface Query
maxResults
- the maximum number of rows
setOptionalEntityName
public void setOptionalEntityName(String optionalEntityName)
setOptionalId
public void setOptionalId(Serializable optionalId)
setOptionalObject
public void setOptionalObject(Object optionalObject)
setParameter
public Query setParameter(String name,
Object val)
throws HibernateException
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.
- setParameter in interface Query
name
- the name of the parameterval
- the non-null parameter value
setParameter
public Query setParameter(String name,
Object val,
Type type)
Bind a value to a named query parameter.
- setParameter in interface Query
name
- the name of the parameterval
- the possibly-null parameter valuetype
- the Hibernate type
setParameter
public Query setParameter(int position,
Object val)
throws HibernateException
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.
- setParameter in interface Query
position
- the position of the parameter in the query
string, numbered from 0.val
- the non-null parameter value
setParameter
public Query setParameter(int position,
Object val,
Type type)
Bind a value to a JDBC-style query parameter.
- setParameter in interface Query
position
- the position of the parameter in the query
string, numbered from 0.val
- the possibly-null parameter valuetype
- the Hibernate type
setParameterList
public Query setParameterList(String name,
Collection vals)
throws HibernateException
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).
- setParameterList in interface Query
name
- the name of the parametervals
- a collection of values to list
setParameterList
public Query setParameterList(String name,
Collection vals,
Type type)
throws HibernateException
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).
- setParameterList in interface Query
name
- the name of the parametervals
- a collection of values to listtype
- the Hibernate type of the values
setParameterList
public Query setParameterList(String name,
Object[] vals)
throws HibernateException
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).
- setParameterList in interface Query
name
- the name of the parametervals
- a collection of values to list
setParameterList
public Query setParameterList(String name,
Object[] vals,
Type type)
throws HibernateException
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).
- setParameterList in interface Query
name
- the name of the parametervals
- a collection of values to listtype
- the Hibernate type of the values
setParameters
public Query setParameters(Object[] values,
Type[] types)
Bind values and types to positional parameters.
- setParameters in interface Query
setProperties
public Query setProperties(Map map)
throws HibernateException
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.
- setProperties in interface Query
setProperties
public Query setProperties(Object bean)
throws HibernateException
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.
- setProperties in interface Query
bean
- any JavaBean or POJO
setReadOnly
public Query setReadOnly(boolean readOnly)
Entities retrieved by this query will be loaded in
a read-only mode where Hibernate will never dirty-check
them or make changes persistent.
- setReadOnly in interface Query
setResultTransformer
public Query setResultTransformer(ResultTransformer transformer)
Set a strategy for handling the query results. This can be used to change
"shape" of the query result.
- setResultTransformer in interface Query
transformer
- The transformer to apply
- this (for method chaining)
setTimeout
public Query setTimeout(int timeout)
Set a timeout for the underlying JDBC query.
- setTimeout in interface Query
timeout
- the timeout in seconds
toString
public String toString()
typeArray
public Type[] typeArray()
uniqueResult
public Object uniqueResult()
throws HibernateException
Convenience method to return a single instance that matches
the query, or null if the query returns no results.
- uniqueResult in interface Query
- the single result or null
valueArray
public Object[] valueArray()
verifyParameters
protected void verifyParameters()
throws QueryException
Perform parameter validation. Used prior to executing the encapsulated
query.
verifyParameters
protected void verifyParameters(boolean reserveFirstParameter)
throws HibernateException
Perform parameter validation. Used prior to executing the encapsulated
query.
reserveFirstParameter
- if true, the first ? will not be verified since
its needed for e.g. callable statements returning a out parameter