Package org.hibernate.impl
Class AbstractQueryImpl
java.lang.Object
org.hibernate.impl.AbstractQueryImpl
- All Implemented Interfaces:
Query
- Direct Known Subclasses:
QueryImpl,SQLQueryImpl
Abstract implementation of the Query interface.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ParameterMetadataprotected final SessionImplementor -
Constructor Summary
ConstructorsConstructorDescriptionAbstractQueryImpl(String queryString, FlushMode flushMode, SessionImplementor session, ParameterMetadata parameterMetadata) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafter()protected voidbefore()protected TypedetermineType(int paramPosition, Object paramValue) protected TypedetermineType(int paramPosition, Object paramValue, Type defaultType) protected TypedetermineType(String paramName, Class clazz) protected TypedetermineType(String paramName, Object paramValue) protected TypedetermineType(String paramName, Object paramValue, Type defaultType) protected StringexpandParameterLists(Map namedParamsCopy) Warning: adds new parameters to the argument by side-effect, as well as mutating the query string!abstract LockOptionsprotected MapRetreive the value map for any named parameter lists (i.e., for auto-expansion) bound to this query.String[]Returns an array representing all named parameter names encountered during (intial) parsing of the query.protected MapReturns a shallow copy of the named parameter value map.getQueryParameters(Map namedParams) final StringGet the query string.String[]Return the HQL select clause aliases (if any)Type[]Return the Hibernate types of the query result set.protected RowSelectionprotected ListgetTypes()Retreives the list of parametertypes bound to this query for ordinal parameters.protected ListRetreives the list of parameter values bound to this query for ordinal parameters.booleanDoes this query contain named parameters?booleanShould 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.setBigDecimal(int position, BigDecimal number) setBigDecimal(String name, BigDecimal number) setBigInteger(int position, BigInteger number) setBigInteger(String name, BigInteger number) setBinary(int position, byte[] val) setBoolean(int position, boolean val) setBoolean(String name, boolean val) setByte(int position, byte val) setCacheable(boolean cacheable) Enable caching of this query result set.setCacheMode(CacheMode cacheMode) Override the current session cache mode, just for this query.setCacheRegion(String cacheRegion) Set the name of the cache region.setCalendar(int position, Calendar calendar) setCalendar(String name, Calendar calendar) setCalendarDate(int position, Calendar calendar) setCalendarDate(String name, Calendar calendar) setCharacter(int position, char val) setCharacter(String name, char val) setCollectionKey(Serializable collectionKey) setComment(String comment) Add a comment to the generated SQL.setDouble(int position, double val) Bind an instance of a mapped persistent class to a JDBC-style query parameter.Bind an instance of a mapped persistent class to a named query parameter.setFetchSize(int fetchSize) Set a fetch size for the underlying JDBC query.setFirstResult(int firstResult) Set the first row to retrieve.setFloat(int position, float val) setFlushMode(FlushMode flushMode) Override the current session flush mode, just for this query.setInteger(int position, int val) setInteger(String name, int val) setLong(int position, long val) setMaxResults(int maxResults) Set the maximum number of rows to retrieve.voidsetOptionalEntityName(String optionalEntityName) voidsetOptionalId(Serializable optionalId) voidsetOptionalObject(Object optionalObject) setParameter(int position, Object val) Bind a value to a JDBC-style query parameter.setParameter(int position, Object val, Type type) Bind a value to a JDBC-style query parameter.setParameter(String name, Object val) Bind a value to a named query parameter.setParameter(String name, Object val, Type type) Bind a value to a named query parameter.setParameterList(String name, Object[] vals) Bind multiple values to a named query parameter.setParameterList(String name, Object[] vals, Type type) Bind multiple values to a named query parameter.setParameterList(String name, Collection vals) Bind multiple values to a named query parameter.setParameterList(String name, Collection vals, Type type) Bind multiple values to a named query parameter.setParameters(Object[] values, Type[] types) Bind values and types to positional parameters.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.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.setReadOnly(boolean readOnly) Set the read-only/modifiable mode for entities and proxies loaded by this Query.setResultTransformer(ResultTransformer transformer) Set a strategy for handling the query results.setSerializable(int position, Serializable val) setSerializable(String name, Serializable val) setShort(int position, short val) setTimeout(int timeout) Set a timeout for the underlying JDBC query.setTimestamp(int position, Date date) setTimestamp(String name, Date date) toString()Type[]Convenience method to return a single instance that matches the query, or null if the query returns no results.Object[]protected voidPerform parameter validation.protected voidverifyParameters(boolean reserveFirstParameter) Perform parameter validation.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.hibernate.Query
executeUpdate, iterate, list, scroll, scroll, setLockMode, setLockOptions
-
Field Details
-
session
-
parameterMetadata
-
-
Constructor Details
-
AbstractQueryImpl
public AbstractQueryImpl(String queryString, FlushMode flushMode, SessionImplementor session, ParameterMetadata parameterMetadata)
-
-
Method Details
-
getParameterMetadata
-
toString
-
getQueryString
Description copied from interface:QueryGet the query string.- Specified by:
getQueryStringin interfaceQuery- Returns:
- the query string
-
getSelection
-
setFlushMode
Description copied from interface:QueryOverride the current session flush mode, just for this query.- Specified by:
setFlushModein interfaceQuery- See Also:
-
setCacheMode
Description copied from interface:QueryOverride the current session cache mode, just for this query.- Specified by:
setCacheModein interfaceQuery- See Also:
-
getCacheMode
-
setCacheable
Description copied from interface:QueryEnable caching of this query result set.- Specified by:
setCacheablein interfaceQuery- Parameters:
cacheable- Should the query results be cacheable?
-
setCacheRegion
Description copied from interface:QuerySet the name of the cache region.- Specified by:
setCacheRegionin interfaceQuery- Parameters:
cacheRegion- the name of a query cache region, or null for the default query cache
-
setComment
Description copied from interface:QueryAdd a comment to the generated SQL.- Specified by:
setCommentin interfaceQuery- Parameters:
comment- a human-readable string
-
setFirstResult
Description copied from interface:QuerySet the first row to retrieve. If not set, rows will be retrieved beginnning from row 0.- Specified by:
setFirstResultin interfaceQuery- Parameters:
firstResult- a row number, numbered from 0
-
setMaxResults
Description copied from interface:QuerySet the maximum number of rows to retrieve. If not set, there is no limit to the number of rows retrieved.- Specified by:
setMaxResultsin interfaceQuery- Parameters:
maxResults- the maximum number of rows
-
setTimeout
Description copied from interface:QuerySet a timeout for the underlying JDBC query.- Specified by:
setTimeoutin interfaceQuery- Parameters:
timeout- the timeout in seconds
-
setFetchSize
Description copied from interface:QuerySet a fetch size for the underlying JDBC query.- Specified by:
setFetchSizein interfaceQuery- Parameters:
fetchSize- the fetch size
-
getReturnTypes
Description copied from interface:QueryReturn the Hibernate types of the query result set.- Specified by:
getReturnTypesin interfaceQuery- Returns:
- an array of types
- Throws:
HibernateException
-
getReturnAliases
Description copied from interface:QueryReturn the HQL select clause aliases (if any)- Specified by:
getReturnAliasesin interfaceQuery- Returns:
- an array of aliases as strings
- Throws:
HibernateException
-
setCollectionKey
-
isReadOnly
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.- Specified by:
isReadOnlyin interfaceQuery- 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
- See Also:
-
setReadOnly
Set the read-only/modifiable mode for entities and proxies loaded by this Query. This setting overrides the default setting for the persistence context.- Specified by:
setReadOnlyin interfaceQuery- 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- See Also:
-
setResultTransformer
Description copied from interface:QuerySet a strategy for handling the query results. This can be used to change "shape" of the query result.- Specified by:
setResultTransformerin interfaceQuery- Parameters:
transformer- The transformer to apply- Returns:
- this (for method chaining)
-
setOptionalEntityName
-
setOptionalId
-
setOptionalObject
-
getLockOptions
-
getNamedParams
Returns a shallow copy of the named parameter value map.- Returns:
- Shallow copy of the named parameter value map
-
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.- Specified by:
getNamedParametersin interfaceQuery- Returns:
- Array of named parameter names.
- Throws:
HibernateException
-
hasNamedParameters
public boolean hasNamedParameters()Does this query contain named parameters?- Returns:
- True if the query was found to contain named parameters; false otherwise;
-
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.
-
getValues
Retreives the list of parameter values bound to this query for ordinal parameters.- Returns:
- The ordinal parameter values.
-
getTypes
Retreives the list of parametertypes bound to this query for ordinal parameters.- Returns:
- The ordinal parameter types.
-
verifyParameters
Perform parameter validation. Used prior to executing the encapsulated query.- Throws:
QueryException
-
verifyParameters
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- Throws:
HibernateException
-
setParameter
Description copied from interface:QueryBind a value to a JDBC-style query parameter.- Specified by:
setParameterin interfaceQuery- Parameters:
position- the position of the parameter in the query string, numbered from 0.val- the possibly-null parameter valuetype- the Hibernate type
-
setParameter
Description copied from interface:QueryBind a value to a named query parameter.- Specified by:
setParameterin interfaceQuery- Parameters:
name- the name of the parameterval- the possibly-null parameter valuetype- the Hibernate type
-
setParameter
Description copied from interface:QueryBind 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.- Specified by:
setParameterin interfaceQuery- Parameters:
position- the position of the parameter in the query string, numbered from 0.val- the non-null parameter value- Throws:
HibernateException- if no type could be determined
-
setParameter
Description copied from interface:QueryBind 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.- Specified by:
setParameterin interfaceQuery- Parameters:
name- the name of the parameterval- the non-null parameter value- Throws:
HibernateException- if no type could be determined
-
determineType
-
determineType
- Throws:
HibernateException
-
determineType
-
determineType
- Throws:
HibernateException
-
determineType
- Throws:
HibernateException
-
setString
-
setCharacter
- Specified by:
setCharacterin interfaceQuery
-
setBoolean
- Specified by:
setBooleanin interfaceQuery
-
setByte
-
setShort
-
setInteger
- Specified by:
setIntegerin interfaceQuery
-
setLong
-
setFloat
-
setDouble
-
setBinary
-
setText
-
setSerializable
- Specified by:
setSerializablein interfaceQuery
-
setDate
-
setTime
-
setTimestamp
- Specified by:
setTimestampin interfaceQuery
-
setEntity
Description copied from interface:QueryBind an instance of a mapped persistent class to a JDBC-style query parameter. -
setLocale
-
setCalendar
- Specified by:
setCalendarin interfaceQuery
-
setCalendarDate
- Specified by:
setCalendarDatein interfaceQuery
-
setBinary
-
setText
-
setBoolean
- Specified by:
setBooleanin interfaceQuery
-
setByte
-
setCharacter
- Specified by:
setCharacterin interfaceQuery
-
setDate
-
setDouble
-
setEntity
Description copied from interface:QueryBind an instance of a mapped persistent class to a named query parameter. -
setFloat
-
setInteger
- Specified by:
setIntegerin interfaceQuery
-
setLocale
-
setCalendar
- Specified by:
setCalendarin interfaceQuery
-
setCalendarDate
- Specified by:
setCalendarDatein interfaceQuery
-
setLong
-
setSerializable
- Specified by:
setSerializablein interfaceQuery
-
setShort
-
setString
-
setTime
-
setTimestamp
- Specified by:
setTimestampin interfaceQuery
-
setBigDecimal
- Specified by:
setBigDecimalin interfaceQuery
-
setBigDecimal
- Specified by:
setBigDecimalin interfaceQuery
-
setBigInteger
- Specified by:
setBigIntegerin interfaceQuery
-
setBigInteger
- Specified by:
setBigIntegerin interfaceQuery
-
setParameterList
Description copied from interface:QueryBind 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).- Specified by:
setParameterListin interfaceQuery- Parameters:
name- the name of the parametervals- a collection of values to listtype- the Hibernate type of the values- Throws:
HibernateException
-
expandParameterLists
Warning: adds new parameters to the argument by side-effect, as well as mutating the query string! -
setParameterList
Description copied from interface:QueryBind 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).- Specified by:
setParameterListin interfaceQuery- Parameters:
name- the name of the parametervals- a collection of values to list- Throws:
HibernateException
-
setParameterList
Description copied from interface:QueryBind 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).- Specified by:
setParameterListin interfaceQuery- Parameters:
name- the name of the parametervals- a collection of values to listtype- the Hibernate type of the values- Throws:
HibernateException
-
setParameterList
Description copied from interface:QueryBind 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).- Specified by:
setParameterListin interfaceQuery- Parameters:
name- the name of the parametervals- a collection of values to list- Throws:
HibernateException
-
setProperties
Description copied from interface:QueryBind 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.- Specified by:
setPropertiesin interfaceQuery- Parameters:
map- a java.util.Map- Throws:
HibernateException
-
setProperties
Description copied from interface:QueryBind 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.- Specified by:
setPropertiesin interfaceQuery- Parameters:
bean- any JavaBean or POJO- Throws:
HibernateException
-
setParameters
Description copied from interface:QueryBind values and types to positional parameters.- Specified by:
setParametersin interfaceQuery
-
uniqueResult
Description copied from interface:QueryConvenience method to return a single instance that matches the query, or null if the query returns no results.- Specified by:
uniqueResultin interfaceQuery- Returns:
- the single result or null
- Throws:
HibernateException
-
getRowSelection
-
typeArray
-
valueArray
-
getQueryParameters
-
before
protected void before() -
after
protected void after()
-