public abstract class AbstractQueryImpl extends Object implements Query
Modifier and Type | Field and Description |
---|---|
protected ParameterMetadata |
parameterMetadata |
protected SessionImplementor |
session |
Constructor and Description |
---|
AbstractQueryImpl(String queryString,
FlushMode flushMode,
SessionImplementor session,
ParameterMetadata parameterMetadata) |
Modifier and Type | Method and Description |
---|---|
Query |
addQueryHint(String queryHint)
Add a DB query hint to the SQL.
|
protected void |
after() |
void |
applyEntityGraphQueryHint(EntityGraphQueryHint hint)
Used from HEM code as a (hopefully temporary) means to apply a custom query plan
in regards to a JPA entity graph.
|
protected void |
before() |
protected Type |
determineType(int paramPosition,
Object paramValue) |
protected Type |
determineType(int paramPosition,
Object paramValue,
Type defaultType) |
protected Type |
determineType(String paramName,
Class clazz) |
protected Type |
determineType(String paramName,
Object paramValue) |
protected Type |
determineType(String paramName,
Object paramValue,
Type defaultType) |
protected String |
expandParameterLists(Map namedParamsCopy)
Warning: adds new parameters to the argument by side-effect, as well as
mutating the query string!
|
CacheMode |
getCacheMode()
Obtain the CacheMode in effect for this query.
|
String |
getCacheRegion()
Obtain the name of the second level query cache region in which query results will be stored (if they are
cached, see the discussion on
BasicQueryContract.isCacheable() for more information). |
String |
getComment()
Obtain the comment currently associated with this query.
|
Integer |
getFetchSize()
Obtain the JDBC fetch size hint in effect for this query.
|
Integer |
getFirstResult()
Obtain the value specified (if any) for the first row to be returned from the query results; zero-based.
|
FlushMode |
getFlushMode()
Obtain the FlushMode in effect for this query.
|
abstract LockOptions |
getLockOptions()
Obtains the LockOptions in effect for this query.
|
Integer |
getMaxResults()
Obtains the limit set on the maximum number of rows to retrieve.
|
protected Map<String,TypedValue> |
getNamedParameterLists()
Retreive the value map for any named parameter lists (i.e., for
auto-expansion) bound to this query.
|
String[] |
getNamedParameters()
Returns an array representing all named parameter names encountered
during (intial) parsing of the query.
|
protected Map<String,TypedValue> |
getNamedParams()
Returns a shallow copy of the named parameter value map.
|
ParameterMetadata |
getParameterMetadata() |
QueryParameters |
getQueryParameters(Map namedParams) |
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 results.
|
protected RowSelection |
getRowSelection() |
Integer |
getTimeout()
Obtain the query timeout in seconds.
|
protected List |
getTypes()
Retreives the list of parameter
type s bound to this query for
ordinal parameters. |
protected List |
getValues()
Retreives the list of parameter values bound to this query for
ordinal parameters.
|
Type |
guessType(Class clazz) |
boolean |
hasNamedParameters()
Does this query contain named parameters?
|
boolean |
isCacheable()
Are the results of this query eligible for second level query caching? This is different that second level
caching of any returned entities and collections.
|
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)
Bind a positional BigDecimal-valued parameter.
|
Query |
setBigDecimal(String name,
BigDecimal number)
Bind a named BigDecimal-valued parameter.
|
Query |
setBigInteger(int position,
BigInteger number)
Bind a positional BigDecimal-valued parameter.
|
Query |
setBigInteger(String name,
BigInteger number)
Bind a named BigInteger-valued parameter.
|
Query |
setBinary(int position,
byte[] val)
Bind a positional binary-valued parameter.
|
Query |
setBinary(String name,
byte[] val)
Bind a named binary-valued parameter.
|
Query |
setBoolean(int position,
boolean val)
Bind a positional boolean-valued parameter.
|
Query |
setBoolean(String name,
boolean val)
Bind a named boolean-valued parameter.
|
Query |
setByte(int position,
byte val)
Bind a positional byte-valued parameter.
|
Query |
setByte(String name,
byte val)
Bind a named byte-valued parameter.
|
Query |
setCacheable(boolean cacheable)
Enable/disable second level query (result) caching for this query.
|
Query |
setCacheMode(CacheMode cacheMode)
(Re)set the current CacheMode in effect for this query.
|
Query |
setCacheRegion(String cacheRegion)
Set the name of the cache region where query results should be cached (if cached at all).
|
Query |
setCalendar(int position,
Calendar calendar)
Bind a positional Calendar-valued parameter using the full Timestamp portion.
|
Query |
setCalendar(String name,
Calendar calendar)
Bind a named Calendar-valued parameter using the full Timestamp.
|
Query |
setCalendarDate(int position,
Calendar calendar)
Bind a positional Calendar-valued parameter using just the Date portion.
|
Query |
setCalendarDate(String name,
Calendar calendar)
Bind a named Calendar-valued parameter using just the Date portion.
|
Query |
setCharacter(int position,
char val)
Bind a positional char-valued parameter.
|
Query |
setCharacter(String name,
char val)
Bind a named char-valued parameter.
|
Query |
setCollectionKey(Serializable collectionKey) |
Query |
setComment(String comment)
Set the comment for this query.
|
Query |
setDate(int position,
Date date)
Bind a positional Date-valued parameter using just the Date portion.
|
Query |
setDate(String name,
Date date)
Bind the date (time is truncated) of a given Date object to a named query parameter.
|
Query |
setDouble(int position,
double val)
Bind a positional double-valued parameter.
|
Query |
setDouble(String name,
double val)
Bind a named double-valued parameter.
|
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)
Sets a JDBC fetch size hint for the query.
|
Query |
setFirstResult(int firstResult)
Set the first row to retrieve.
|
Query |
setFloat(int position,
float val)
Bind a positional float-valued parameter.
|
Query |
setFloat(String name,
float val)
Bind a named float-valued parameter.
|
Query |
setFlushMode(FlushMode flushMode)
(Re)set the current FlushMode in effect for this query.
|
Query |
setInteger(int position,
int val)
Bind a positional int-valued parameter.
|
Query |
setInteger(String name,
int val)
Bind a named int-valued parameter.
|
Query |
setLocale(int position,
Locale locale)
Bind a positional Locale-valued parameter.
|
Query |
setLocale(String name,
Locale locale)
Bind a named Locale-valued parameter.
|
Query |
setLong(int position,
long val)
Bind a positional long-valued parameter.
|
Query |
setLong(String name,
long val)
Bind a named long-valued parameter.
|
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)
Bind a value to a JDBC-style query parameter.
|
Query |
setParameter(int position,
Object val,
Type type)
Bind a value to a JDBC-style query parameter.
|
Query |
setParameter(String name,
Object val)
Bind a value to a named query parameter.
|
Query |
setParameter(String name,
Object val,
Type type)
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,
Collection vals,
Type type)
Bind multiple values to a named query parameter.
|
Query |
setParameterList(String name,
Object[] values)
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 |
setParameters(Object[] values,
Type[] types)
Bind values and types to positional parameters.
|
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 heuristics.
|
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 heuristics.
|
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(int position,
Serializable val)
Bind a positional binary-valued parameter using serialization.
|
Query |
setSerializable(String name,
Serializable val)
Bind a named binary-valued parameter using serialization.
|
Query |
setShort(int position,
short val)
Bind a positional short-valued parameter.
|
Query |
setShort(String name,
short val)
Bind a named short-valued parameter.
|
Query |
setString(int position,
String val)
Bind a positional String-valued parameter.
|
Query |
setString(String name,
String val)
Bind a named String-valued parameter.
|
Query |
setText(int position,
String val)
Bind a positional String-valued parameter using streaming.
|
Query |
setText(String name,
String val)
Bind a named String-valued parameter using streaming.
|
Query |
setTime(int position,
Date date)
Bind a positional Date-valued parameter using just the Time portion.
|
Query |
setTime(String name,
Date date)
Bind the time (date is truncated) of a given Date object to a named query parameter.
|
Query |
setTimeout(int timeout)
Set the query timeout in seconds.
|
Query |
setTimestamp(int position,
Date date)
Bind a positional Date-valued parameter using the full Timestamp.
|
Query |
setTimestamp(String name,
Date date)
Bind the date and the time of a given Date object to a named query parameter.
|
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 void |
verifyParameters()
Perform parameter validation.
|
protected void |
verifyParameters(boolean reserveFirstParameter)
Perform parameter validation.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
executeUpdate, iterate, list, scroll, scroll, setLockMode, setLockOptions
protected final SessionImplementor session
protected final ParameterMetadata parameterMetadata
public AbstractQueryImpl(String queryString, FlushMode flushMode, SessionImplementor session, ParameterMetadata parameterMetadata)
public ParameterMetadata getParameterMetadata()
public final String getQueryString()
Query
getQueryString
in interface Query
public boolean isCacheable()
BasicQueryContract
SessionFactory
for this to happen. Usually that is
controlled by the hibernate.cache.use_query_cache
configuration setting.isCacheable
in interface BasicQueryContract
true
if the query results are eligible for caching, false
otherwise.AvailableSettings.USE_QUERY_CACHE
public Query setCacheable(boolean cacheable)
BasicQueryContract
setCacheable
in interface BasicQueryContract
setCacheable
in interface Query
cacheable
- Should the query results be cacheable?this
, for method chainingBasicQueryContract.isCacheable()
public String getCacheRegion()
BasicQueryContract
BasicQueryContract.isCacheable()
for more information). null
indicates that the
default region should be used.getCacheRegion
in interface BasicQueryContract
null
indicates
the default region.public Query setCacheRegion(String cacheRegion)
BasicQueryContract
setCacheRegion
in interface BasicQueryContract
setCacheRegion
in interface Query
cacheRegion
- the name of a query cache region, or null
to indicate that the default region
should be used.this
, for method chainingBasicQueryContract.getCacheRegion()
public FlushMode getFlushMode()
BasicQueryContract
getFlushMode
in interface BasicQueryContract
Session.getFlushMode()
,
FlushMode
public Query setFlushMode(FlushMode flushMode)
BasicQueryContract
setFlushMode
in interface BasicQueryContract
setFlushMode
in interface Query
flushMode
- The new FlushMode to use.this
, for method chainingBasicQueryContract.getFlushMode()
public CacheMode getCacheMode()
BasicQueryContract
getCacheMode
in interface BasicQueryContract
Session.getCacheMode()
,
CacheMode
public Query setCacheMode(CacheMode cacheMode)
BasicQueryContract
setCacheMode
in interface BasicQueryContract
setCacheMode
in interface Query
cacheMode
- The new CacheMode to use.this
, for method chainingBasicQueryContract.getCacheMode()
public String getComment()
Query
hibernate.use_sql_comments
config setting), this comment will also be added
to the SQL query sent to the database. Often useful for identifying the source of troublesome queries on the
database side.getComment
in interface Query
public Query setComment(String comment)
Query
setComment
in interface Query
comment
- The human-readable commentthis
, for method chainingQuery.getComment()
public Query addQueryHint(String queryHint)
Query
QueryHint
, which is specific
to the JPA implementation and ignores DB vendor-specific hints. Instead, these are intended solely for the
vendor-specific hints, such as Oracle's optimizers. Multiple query hints are supported; the Dialect will
determine concatenation and placement.addQueryHint
in interface Query
queryHint
- The database specific query hint to add.public Integer getFirstResult()
Query
Query.getMaxResults()
in "paginated queries". No value specified means the first result
is returned. Zero and negative numbers are the same as no setting.getFirstResult
in interface Query
public Query setFirstResult(int firstResult)
Query
setFirstResult
in interface Query
firstResult
- a row number, numbered from 0this
, for method chainingQuery.getFirstResult()
public Integer getMaxResults()
Query
null
and any negative values are interpreted as no
limit; however, this method should always return null in such case.getMaxResults
in interface Query
public Query setMaxResults(int maxResults)
Query
setMaxResults
in interface Query
maxResults
- the maximum number of rowsthis
, for method chainingQuery.getMaxResults()
public Integer getTimeout()
BasicQueryContract
Statement.setQueryTimeout(int)
. Zero indicates no timeout.getTimeout
in interface BasicQueryContract
Statement.getQueryTimeout()
,
Statement.setQueryTimeout(int)
public Query setTimeout(int timeout)
BasicQueryContract
setTimeout
in interface BasicQueryContract
setTimeout
in interface Query
timeout
- the timeout in secondsthis
, for method chainingBasicQueryContract.getTimeout()
public Integer getFetchSize()
BasicQueryContract
Statement.setFetchSize(int)
. As defined b y JDBC, this value is a hint to the
driver to indicate how many rows to fetch from the database when more rows are needed.
NOTE : JDBC expressly defines this value as a hint. It may or may not have any effect on the actual
query execution and ResultSet processing depending on the driver.getFetchSize
in interface BasicQueryContract
Statement.getFetchSize()
,
Statement.setFetchSize(int)
public Query setFetchSize(int fetchSize)
BasicQueryContract
setFetchSize
in interface BasicQueryContract
setFetchSize
in interface Query
fetchSize
- the fetch size hintthis
, for method chainingBasicQueryContract.getFetchSize()
public Type[] getReturnTypes() throws HibernateException
BasicQueryContract
getReturnTypes
in interface BasicQueryContract
HibernateException
public String[] getReturnAliases() throws HibernateException
Query
getReturnAliases
in interface Query
HibernateException
public Query setCollectionKey(Serializable collectionKey)
public boolean isReadOnly()
BasicQueryContract
isReadOnly
in interface BasicQueryContract
Query.setReadOnly(boolean)
,
The read-only/modifiable setting has no impact on entities/proxies returned by the
query that existed in the session before the query was executed.
public Query setReadOnly(boolean readOnly)
BasicQueryContract
setReadOnly
in interface BasicQueryContract
setReadOnly
in interface Query
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 modethis
, for method chainingTo set the default read-only/modifiable setting used for
entities and proxies that are loaded into the session:
,
PersistenceContext.setDefaultReadOnly(boolean)
,
Read-only entities are not dirty-checked and snapshots of persistent
state are not maintained. Read-only entities can be modified, but
changes are not persisted.
When a proxy is initialized, the loaded entity will have the same
read-only/modifiable setting as the uninitialized
proxy has, regardless of the session's current setting.
The read-only/modifiable setting has no impact on entities/proxies
returned by the query that existed in the session before the query was executed.
public Query setResultTransformer(ResultTransformer transformer)
Query
setResultTransformer
in interface Query
transformer
- The transformer to applypublic void setOptionalEntityName(String optionalEntityName)
public void setOptionalId(Serializable optionalId)
public void setOptionalObject(Object optionalObject)
public abstract LockOptions getLockOptions()
Query
getLockOptions
in interface Query
LockOptions
protected Map<String,TypedValue> getNamedParams()
public String[] getNamedParameters() throws HibernateException
getNamedParameters
in interface Query
HibernateException
public boolean hasNamedParameters()
protected Map<String,TypedValue> getNamedParameterLists()
protected List getValues()
protected List getTypes()
type
s bound to this query for
ordinal parameters.protected void verifyParameters() throws QueryException
QueryException
protected void verifyParameters(boolean reserveFirstParameter) throws HibernateException
reserveFirstParameter
- if true, the first ? will not be verified since
its needed for e.g. callable statements returning a out parameterHibernateException
public Query setParameter(int position, Object val, Type type)
Query
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 typethis
, for method chainingpublic Query setParameter(String name, Object val, Type type)
Query
setParameter
in interface Query
name
- the name of the parameterval
- the possibly-null parameter valuetype
- the Hibernate typethis
, for method chainingpublic Query setParameter(int position, Object val) throws HibernateException
Query
setParameter
in interface Query
position
- the position of the parameter in the query
string, numbered from 0.val
- the non-null parameter valuethis
, for method chainingHibernateException
public Query setParameter(String name, Object val) throws HibernateException
Query
setParameter
in interface Query
name
- the name of the parameterval
- the non-null parameter valuethis
, for method chainingHibernateException
protected Type determineType(int paramPosition, Object paramValue) throws HibernateException
HibernateException
protected Type determineType(String paramName, Object paramValue) throws HibernateException
HibernateException
protected Type determineType(String paramName, Class clazz) throws HibernateException
HibernateException
public Type guessType(Class clazz) throws HibernateException
HibernateException
public Query setString(int position, String val)
Query
public Query setCharacter(int position, char val)
Query
setCharacter
in interface Query
position
- The parameter positionval
- The bind valuethis
, for method chainingpublic Query setBoolean(int position, boolean val)
Query
setBoolean
in interface Query
position
- The parameter positionval
- The bind valuethis
, for method chainingpublic Query setByte(int position, byte val)
Query
public Query setShort(int position, short val)
Query
public Query setInteger(int position, int val)
Query
setInteger
in interface Query
position
- The parameter positionval
- The bind valuethis
, for method chainingpublic Query setLong(int position, long val)
Query
public Query setFloat(int position, float val)
Query
public Query setDouble(int position, double val)
Query
public Query setBinary(int position, byte[] val)
Query
public Query setText(int position, String val)
Query
public Query setSerializable(int position, Serializable val)
Query
setSerializable
in interface Query
position
- The parameter positionval
- The bind valuethis
, for method chainingpublic Query setDate(int position, Date date)
Query
public Query setTime(int position, Date date)
Query
public Query setTimestamp(int position, Date date)
Query
setTimestamp
in interface Query
position
- The parameter positiondate
- The bind valuethis
, for method chainingpublic Query setEntity(int position, Object val)
Query
Query.setParameter(int, Object)
for null values.public Query setLocale(int position, Locale locale)
Query
public Query setCalendar(int position, Calendar calendar)
Query
setCalendar
in interface Query
position
- The parameter positioncalendar
- The bind valuethis
, for method chainingpublic Query setCalendarDate(int position, Calendar calendar)
Query
setCalendarDate
in interface Query
position
- The parameter positioncalendar
- The bind valuethis
, for method chainingpublic Query setBinary(String name, byte[] val)
Query
public Query setText(String name, String val)
Query
public Query setBoolean(String name, boolean val)
Query
setBoolean
in interface Query
name
- The parameter nameval
- The bind valuethis
, for method chainingpublic Query setByte(String name, byte val)
Query
public Query setCharacter(String name, char val)
Query
setCharacter
in interface Query
name
- The parameter nameval
- The bind valuethis
, for method chainingpublic Query setDate(String name, Date date)
Query
public Query setDouble(String name, double val)
Query
public Query setEntity(String name, Object val)
Query
Query.setParameter(String, Object)
for null values.public Query setFloat(String name, float val)
Query
public Query setInteger(String name, int val)
Query
setInteger
in interface Query
name
- The parameter nameval
- The bind valuethis
, for method chainingpublic Query setLocale(String name, Locale locale)
Query
public Query setCalendar(String name, Calendar calendar)
Query
setCalendar
in interface Query
name
- The parameter namecalendar
- The bind valuethis
, for method chainingpublic Query setCalendarDate(String name, Calendar calendar)
Query
setCalendarDate
in interface Query
name
- The parameter namecalendar
- The bind valuethis
, for method chainingpublic Query setLong(String name, long val)
Query
public Query setSerializable(String name, Serializable val)
Query
setSerializable
in interface Query
name
- The parameter nameval
- The bind valuethis
, for method chainingpublic Query setShort(String name, short val)
Query
public Query setString(String name, String val)
Query
public Query setTime(String name, Date date)
Query
public Query setTimestamp(String name, Date date)
Query
setTimestamp
in interface Query
name
- The name of the parameterdate
- The date objectthis
, for method chainingpublic Query setBigDecimal(int position, BigDecimal number)
Query
setBigDecimal
in interface Query
position
- The parameter positionnumber
- The bind valuethis
, for method chainingpublic Query setBigDecimal(String name, BigDecimal number)
Query
setBigDecimal
in interface Query
name
- The parameter namenumber
- The bind valuethis
, for method chainingpublic Query setBigInteger(int position, BigInteger number)
Query
setBigInteger
in interface Query
position
- The parameter positionnumber
- The bind valuethis
, for method chainingpublic Query setBigInteger(String name, BigInteger number)
Query
setBigInteger
in interface Query
name
- The parameter namenumber
- The bind valuethis
, for method chainingpublic Query setParameterList(String name, Collection vals, Type type) throws HibernateException
Query
setParameterList
in interface Query
name
- the name of the parametervals
- a collection of values to listtype
- the Hibernate type of the valuesthis
, for method chainingHibernateException
protected String expandParameterLists(Map namedParamsCopy)
public Query setParameterList(String name, Collection vals) throws HibernateException
Query
setParameterList
in interface Query
name
- the name of the parametervals
- a collection of values to listthis
, for method chainingHibernateException
public Query setParameterList(String name, Object[] vals, Type type) throws HibernateException
Query
setParameterList
in interface Query
name
- the name of the parametervals
- a collection of values to listtype
- the Hibernate type of the valuesthis
, for method chainingHibernateException
public Query setParameterList(String name, Object[] values) throws HibernateException
Query
setParameterList
in interface Query
name
- the name of the parametervalues
- a collection of values to listthis
, for method chainingHibernateException
public Query setProperties(Map map) throws HibernateException
Query
setProperties
in interface Query
map
- a java.util.Mapthis
, for method chainingHibernateException
public Query setProperties(Object bean) throws HibernateException
Query
setProperties
in interface Query
bean
- any JavaBean or POJOthis
, for method chainingHibernateException
public Query setParameters(Object[] values, Type[] types)
Query
setParameters
in interface Query
values
- The valuestypes
- The typesthis
, for method chainingpublic Object uniqueResult() throws HibernateException
Query
uniqueResult
in interface Query
NonUniqueResultException
- if there is more than one matching resultHibernateException
protected RowSelection getRowSelection()
public Type[] typeArray()
public Object[] valueArray()
public QueryParameters getQueryParameters(Map namedParams)
protected void before()
protected void after()
public void applyEntityGraphQueryHint(EntityGraphQueryHint hint)
hint
- The entity graph hint objectCopyright © 2016 JBoss by Red Hat. All rights reserved.