Errai 3.0.1-SNAPSHOT

org.jboss.errai.jpa.client.local
Class ErraiTypedQuery<X>

java.lang.Object
  extended by org.jboss.errai.jpa.client.local.ErraiTypedQuery<X>
Type Parameters:
X - The result type of this query
All Implemented Interfaces:
javax.persistence.Query, javax.persistence.TypedQuery<X>, EntityJsonMatcher

public abstract class ErraiTypedQuery<X>
extends Object
implements javax.persistence.TypedQuery<X>, EntityJsonMatcher

Base implementation of the JPA TypedQuery interface for Errai. This class is expected to be subclassed by generated code that is created during the GWT compiler's rebind phase.

Author:
Jonathan Fuerth

Constructor Summary
protected ErraiTypedQuery(ErraiEntityManager entityManager, Class<X> actualResultType, com.google.common.collect.ImmutableBiMap<String,javax.persistence.Parameter<?>> parameters)
           
 
Method Summary
 int executeUpdate()
          Execute an update or delete statement.
protected abstract  Comparator<X> getComparator()
          Returns a comparator that can be used for sorting a list of result objects based on the ORDER BY clause and the current parameter values of this query.
 int getFirstResult()
          The position of the first result the query object was set to retrieve.
 javax.persistence.FlushModeType getFlushMode()
          Get the flush mode in effect for the query execution.
 Map<String,Object> getHints()
          Get the properties and hints and associated values that are in effect for the query instance.
 javax.persistence.LockModeType getLockMode()
          Get the current lock mode for the query.
 int getMaxResults()
          The maximum number of results the query object was set to retrieve.
 javax.persistence.Parameter<?> getParameter(int position)
          Get the parameter object corresponding to the declared positional parameter with the given position.
<T> javax.persistence.Parameter<T>
getParameter(int position, Class<T> type)
          Get the parameter object corresponding to the declared positional parameter with the given position and type.
 javax.persistence.Parameter<?> getParameter(String name)
          Get the parameter object corresponding to the declared parameter of the given name.
<T> javax.persistence.Parameter<T>
getParameter(String name, Class<T> type)
          Get the parameter object corresponding to the declared parameter of the given name and type.
 Set<javax.persistence.Parameter<?>> getParameters()
          Get the parameter objects corresponding to the declared parameters of the query.
 Object getParameterValue(int position)
          Return the value bound to the positional parameter.
<T> T
getParameterValue(javax.persistence.Parameter<T> param)
          Return the value bound to the parameter.
 Object getParameterValue(String name)
          Return the value bound to the named parameter.
 List<X> getResultList()
          Execute a SELECT query and return the query results as a typed List.
 X getSingleResult()
          Execute a SELECT query that returns a single result.
 boolean isBound(javax.persistence.Parameter<?> param)
          Return a boolean indicating whether a value has been bound to the parameter.
 javax.persistence.TypedQuery<X> setFirstResult(int startPosition)
          Set the position of the first result to retrieve.
 javax.persistence.TypedQuery<X> setFlushMode(javax.persistence.FlushModeType flushMode)
          Set the flush mode type to be used for the query execution.
 javax.persistence.TypedQuery<X> setHint(String hintName, Object value)
          Set a query property or hint.
 javax.persistence.TypedQuery<X> setLockMode(javax.persistence.LockModeType lockMode)
          Set the lock mode type to be used for the query execution.
 javax.persistence.TypedQuery<X> setMaxResults(int maxResult)
          Set the maximum number of results to retrieve.
 javax.persistence.TypedQuery<X> setParameter(int position, Date value, javax.persistence.TemporalType temporalType)
          Bind an instance of java.util.Date to a positional parameter.
 javax.persistence.TypedQuery<X> setParameter(int position, Object value)
          Bind an argument to a positional parameter.
 javax.persistence.TypedQuery<X> setParameter(javax.persistence.Parameter<Date> param, Date value, javax.persistence.TemporalType temporalType)
          Bind an instance of java.util.Date to a Parameter object.
<T> javax.persistence.TypedQuery<X>
setParameter(javax.persistence.Parameter<T> param, T value)
          Bind the value of a Parameter object.
 javax.persistence.TypedQuery<X> setParameter(String name, Date value, javax.persistence.TemporalType temporalType)
          Bind an instance of java.util.Date to a named parameter.
 javax.persistence.TypedQuery<X> setParameter(String name, Object value)
          Bind an argument to a named parameter.
<T> T
unwrap(Class<T> cls)
          Return an object of the specified type to allow access to the provider-specific API.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.errai.jpa.client.local.EntityJsonMatcher
matches
 

Constructor Detail

ErraiTypedQuery

protected ErraiTypedQuery(ErraiEntityManager entityManager,
                          Class<X> actualResultType,
                          com.google.common.collect.ImmutableBiMap<String,javax.persistence.Parameter<?>> parameters)
Parameters:
entityManager - The EntityManager within whose scope this query will be executed.
actualResultType - The result type of this query. Must be an entity type known to entityManager.
parameters - The parameters of this query. The iteration order of the parameters in the map must be their numeric order in the query (ImmutableMap has a stable iteration order).
Method Detail

getComparator

protected abstract Comparator<X> getComparator()
Returns a comparator that can be used for sorting a list of result objects based on the ORDER BY clause and the current parameter values of this query.

Returns:
A comparator for acheiving the ORDER BY order for this query, or null if this query has no ORDER BY clause.

executeUpdate

public int executeUpdate()
Description copied from interface: javax.persistence.Query
Execute an update or delete statement.

Specified by:
executeUpdate in interface javax.persistence.Query
Returns:
the number of entities updated or deleted

getMaxResults

public int getMaxResults()
Description copied from interface: javax.persistence.Query
The maximum number of results the query object was set to retrieve. Returns Integer.MAX_VALUE if setMaxResults was not applied to the query object.

Specified by:
getMaxResults in interface javax.persistence.Query
Returns:
maximum number of results

getFirstResult

public int getFirstResult()
Description copied from interface: javax.persistence.Query
The position of the first result the query object was set to retrieve. Returns 0 if setFirstResult was not applied to the query object.

Specified by:
getFirstResult in interface javax.persistence.Query
Returns:
position of the first result

getHints

public Map<String,Object> getHints()
Description copied from interface: javax.persistence.Query
Get the properties and hints and associated values that are in effect for the query instance.

Specified by:
getHints in interface javax.persistence.Query
Returns:
query properties and hints

getParameters

public Set<javax.persistence.Parameter<?>> getParameters()
Description copied from interface: javax.persistence.Query
Get the parameter objects corresponding to the declared parameters of the query. Returns empty set if the query has no parameters. This method is not required to be supported for native queries.

Specified by:
getParameters in interface javax.persistence.Query
Returns:
set of the parameter objects

getParameter

public javax.persistence.Parameter<?> getParameter(String name)
Description copied from interface: javax.persistence.Query
Get the parameter object corresponding to the declared parameter of the given name. This method is not required to be supported for native queries.

Specified by:
getParameter in interface javax.persistence.Query
Parameters:
name - parameter name
Returns:
parameter object

getParameter

public <T> javax.persistence.Parameter<T> getParameter(String name,
                                                       Class<T> type)
Description copied from interface: javax.persistence.Query
Get the parameter object corresponding to the declared parameter of the given name and type. This method is required to be supported for criteria queries only.

Specified by:
getParameter in interface javax.persistence.Query
Parameters:
name - parameter name
type - type
Returns:
parameter object

getParameter

public javax.persistence.Parameter<?> getParameter(int position)
Description copied from interface: javax.persistence.Query
Get the parameter object corresponding to the declared positional parameter with the given position. This method is not required to be supported for native queries.

Specified by:
getParameter in interface javax.persistence.Query
Parameters:
position - position
Returns:
parameter object

getParameter

public <T> javax.persistence.Parameter<T> getParameter(int position,
                                                       Class<T> type)
Description copied from interface: javax.persistence.Query
Get the parameter object corresponding to the declared positional parameter with the given position and type. This method is not required to be supported by the provider.

Specified by:
getParameter in interface javax.persistence.Query
Parameters:
position - position
type - type
Returns:
parameter object

isBound

public boolean isBound(javax.persistence.Parameter<?> param)
Description copied from interface: javax.persistence.Query
Return a boolean indicating whether a value has been bound to the parameter.

Specified by:
isBound in interface javax.persistence.Query
Parameters:
param - parameter object
Returns:
boolean indicating whether parameter has been bound

getParameterValue

public <T> T getParameterValue(javax.persistence.Parameter<T> param)
Description copied from interface: javax.persistence.Query
Return the value bound to the parameter.

Specified by:
getParameterValue in interface javax.persistence.Query
Parameters:
param - parameter object
Returns:
parameter value

getParameterValue

public Object getParameterValue(String name)
Description copied from interface: javax.persistence.Query
Return the value bound to the named parameter.

Specified by:
getParameterValue in interface javax.persistence.Query
Parameters:
name - parameter name
Returns:
parameter value

getParameterValue

public Object getParameterValue(int position)
Description copied from interface: javax.persistence.Query
Return the value bound to the positional parameter.

Specified by:
getParameterValue in interface javax.persistence.Query
Parameters:
position - position
Returns:
parameter value

getFlushMode

public javax.persistence.FlushModeType getFlushMode()
Description copied from interface: javax.persistence.Query
Get the flush mode in effect for the query execution. If a flush mode has not been set for the query object, returns the flush mode in effect for the entity manager.

Specified by:
getFlushMode in interface javax.persistence.Query
Returns:
flush mode

getLockMode

public javax.persistence.LockModeType getLockMode()
Description copied from interface: javax.persistence.Query
Get the current lock mode for the query.

Specified by:
getLockMode in interface javax.persistence.Query
Returns:
lock mode

unwrap

public <T> T unwrap(Class<T> cls)
Description copied from interface: javax.persistence.Query
Return an object of the specified type to allow access to the provider-specific API. If the provider's query implementation does not support the specified class, the PersistenceException is thrown.

Specified by:
unwrap in interface javax.persistence.Query
Parameters:
cls - the class of the object to be returned. This is normally either the underlying query implementation class or an interface that it implements.
Returns:
an instance of the specified class

getResultList

public List<X> getResultList()
Description copied from interface: javax.persistence.TypedQuery
Execute a SELECT query and return the query results as a typed List.

Specified by:
getResultList in interface javax.persistence.Query
Specified by:
getResultList in interface javax.persistence.TypedQuery<X>
Returns:
a list of the results

getSingleResult

public X getSingleResult()
Description copied from interface: javax.persistence.TypedQuery
Execute a SELECT query that returns a single result.

Specified by:
getSingleResult in interface javax.persistence.Query
Specified by:
getSingleResult in interface javax.persistence.TypedQuery<X>
Returns:
the result

setMaxResults

public javax.persistence.TypedQuery<X> setMaxResults(int maxResult)
Description copied from interface: javax.persistence.TypedQuery
Set the maximum number of results to retrieve.

Specified by:
setMaxResults in interface javax.persistence.Query
Specified by:
setMaxResults in interface javax.persistence.TypedQuery<X>
Parameters:
maxResult - maximum number of results to retrieve
Returns:
the same query instance

setFirstResult

public javax.persistence.TypedQuery<X> setFirstResult(int startPosition)
Description copied from interface: javax.persistence.TypedQuery
Set the position of the first result to retrieve.

Specified by:
setFirstResult in interface javax.persistence.Query
Specified by:
setFirstResult in interface javax.persistence.TypedQuery<X>
Parameters:
startPosition - position of the first result, numbered from 0
Returns:
the same query instance

setHint

public javax.persistence.TypedQuery<X> setHint(String hintName,
                                               Object value)
Description copied from interface: javax.persistence.TypedQuery
Set a query property or hint. The hints elements may be used to specify query properties and hints. Properties defined by this specification must be observed by the provider. Vendor-specific hints that are not recognized by a provider must be silently ignored. Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, this hint may or may not be observed.

Specified by:
setHint in interface javax.persistence.Query
Specified by:
setHint in interface javax.persistence.TypedQuery<X>
Parameters:
hintName - name of property or hint
value - value for the property or hint
Returns:
the same query instance

setParameter

public <T> javax.persistence.TypedQuery<X> setParameter(javax.persistence.Parameter<T> param,
                                                        T value)
Description copied from interface: javax.persistence.TypedQuery
Bind the value of a Parameter object.

Specified by:
setParameter in interface javax.persistence.Query
Specified by:
setParameter in interface javax.persistence.TypedQuery<X>
Parameters:
param - parameter object
value - parameter value
Returns:
the same query instance

setParameter

public javax.persistence.TypedQuery<X> setParameter(javax.persistence.Parameter<Date> param,
                                                    Date value,
                                                    javax.persistence.TemporalType temporalType)
Description copied from interface: javax.persistence.TypedQuery
Bind an instance of java.util.Date to a Parameter object.

Specified by:
setParameter in interface javax.persistence.Query
Specified by:
setParameter in interface javax.persistence.TypedQuery<X>
Parameters:
param - parameter object
value - parameter value
temporalType - temporal type
Returns:
the same query instance

setParameter

public javax.persistence.TypedQuery<X> setParameter(String name,
                                                    Object value)
Description copied from interface: javax.persistence.TypedQuery
Bind an argument to a named parameter.

Specified by:
setParameter in interface javax.persistence.Query
Specified by:
setParameter in interface javax.persistence.TypedQuery<X>
Parameters:
name - parameter name
value - parameter value
Returns:
the same query instance

setParameter

public javax.persistence.TypedQuery<X> setParameter(String name,
                                                    Date value,
                                                    javax.persistence.TemporalType temporalType)
Description copied from interface: javax.persistence.TypedQuery
Bind an instance of java.util.Date to a named parameter.

Specified by:
setParameter in interface javax.persistence.Query
Specified by:
setParameter in interface javax.persistence.TypedQuery<X>
Parameters:
name - parameter name
value - parameter value
temporalType - temporal type
Returns:
the same query instance

setParameter

public javax.persistence.TypedQuery<X> setParameter(int position,
                                                    Object value)
Description copied from interface: javax.persistence.TypedQuery
Bind an argument to a positional parameter.

Specified by:
setParameter in interface javax.persistence.Query
Specified by:
setParameter in interface javax.persistence.TypedQuery<X>
Parameters:
position - position
value - parameter value
Returns:
the same query instance

setParameter

public javax.persistence.TypedQuery<X> setParameter(int position,
                                                    Date value,
                                                    javax.persistence.TemporalType temporalType)
Description copied from interface: javax.persistence.TypedQuery
Bind an instance of java.util.Date to a positional parameter.

Specified by:
setParameter in interface javax.persistence.Query
Specified by:
setParameter in interface javax.persistence.TypedQuery<X>
Parameters:
position - position
value - parameter value
temporalType - temporal type
Returns:
the same query instance

setFlushMode

public javax.persistence.TypedQuery<X> setFlushMode(javax.persistence.FlushModeType flushMode)
Description copied from interface: javax.persistence.TypedQuery
Set the flush mode type to be used for the query execution. The flush mode type applies to the query regardless of the flush mode type in use for the entity manager.

Specified by:
setFlushMode in interface javax.persistence.Query
Specified by:
setFlushMode in interface javax.persistence.TypedQuery<X>
Parameters:
flushMode - flush mode
Returns:
the same query instance

setLockMode

public javax.persistence.TypedQuery<X> setLockMode(javax.persistence.LockModeType lockMode)
Description copied from interface: javax.persistence.TypedQuery
Set the lock mode type to be used for the query execution.

Specified by:
setLockMode in interface javax.persistence.Query
Specified by:
setLockMode in interface javax.persistence.TypedQuery<X>
Parameters:
lockMode - lock mode
Returns:
the same query instance

Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.