EclipseLink 2.0.0_ 2.0.0.r3652-M1 API Reference

javax.persistence
Interface Query

All Known Subinterfaces:
JpaQuery

public interface Query

Interface used to control query execution.

Since:
Java Persistence API

Method Summary
 int executeUpdate()
          Execute an update or delete statement.
 int getFirstResult()
          The position of the first result the query object was set to retrieve.
 FlushModeType getFlushMode()
          The flush mode in effect for the query execution.
 java.util.Map<java.lang.String,java.lang.Object> getHints()
          Get the hints and associated values that are in effect for the query instance.
 LockModeType getLockMode()
          Get the current lock mode for the query.
 int getMaxResults()
          The maximum number of results the query object was set to retrieve.
 java.util.Map<java.lang.String,java.lang.Object> getNamedParameters()
          Get the parameters names and associated values of the parameters that are bound for the query instance.
 java.util.List getPositionalParameters()
          Get the values of the positional parameters that are bound for the query instance.
 java.util.List getResultList()
          Execute a SELECT query and return the query results as a List.
 java.lang.Object getSingleResult()
          Execute a SELECT query that returns a single result.
 java.util.Set<java.lang.String> getSupportedHints()
          Get the names of the hints that are supported for query objects.
 Query setFirstResult(int startPosition)
          Set the position of the first result to retrieve.
 Query setFlushMode(FlushModeType flushMode)
          Set the flush mode type to be used for the query execution.
 Query setHint(java.lang.String hintName, java.lang.Object value)
          Set an implementation-specific hint.
 Query setLockMode(LockModeType lockMode)
          Set the lock mode type to be used for the query execution.
 Query setMaxResults(int maxResult)
          Set the maximum number of results to retrieve.
 Query setParameter(int position, java.util.Calendar value, TemporalType temporalType)
          Bind an instance of java.util.Calendar to a positional parameter.
 Query setParameter(int position, java.util.Date value, TemporalType temporalType)
          Bind an instance of java.util.Date to a positional parameter.
 Query setParameter(int position, java.lang.Object value)
          Bind an argument to a positional parameter.
 Query setParameter(java.lang.String name, java.util.Calendar value, TemporalType temporalType)
          Bind an instance of java.util.Calendar to a named parameter.
 Query setParameter(java.lang.String name, java.util.Date value, TemporalType temporalType)
          Bind an instance of java.util.Date to a named parameter.
 Query setParameter(java.lang.String name, java.lang.Object value)
          Bind an argument to a named parameter.
<T> T
unwrap(java.lang.Class<T> cls)
          Return an object of the specified type to allow access to the provider-specific API.
 

Method Detail

getResultList

java.util.List getResultList()
Execute a SELECT query and return the query results as a List.

Returns:
a list of the results
Throws:
java.lang.IllegalStateException - if called for a Java Persistence query language UPDATE or DELETE statement

getSingleResult

java.lang.Object getSingleResult()
Execute a SELECT query that returns a single result.

Returns:
the result
Throws:
NoResultException - if there is no result
NonUniqueResultException - if more than one result
java.lang.IllegalStateException - if called for a Java Persistence query language UPDATE or DELETE statement

executeUpdate

int executeUpdate()
Execute an update or delete statement.

Returns:
the number of entities updated or deleted
Throws:
java.lang.IllegalStateException - if called for a Java Persistence query language SELECT statement
TransactionRequiredException - if there is no transaction

setMaxResults

Query setMaxResults(int maxResult)
Set the maximum number of results to retrieve.

Parameters:
maxResult -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if argument is negative

getMaxResults

int getMaxResults()
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.

Returns:
maximum number of results
Since:
Java Persistence API 2.0

setFirstResult

Query setFirstResult(int startPosition)
Set the position of the first result to retrieve.

Parameters:
startPosition - the start position of the first result, numbered from 0
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if argument is negative

getFirstResult

int getFirstResult()
The position of the first result the query object was set to retrieve. Returns 0 if setFirstResult was not applied to the query object.

Returns:
position of first result
Since:
Java Persistence API 2.0

setHint

Query setHint(java.lang.String hintName,
              java.lang.Object value)
Set an implementation-specific hint. If the hint name is not recognized, it is silently ignored.

Parameters:
hintName -
value -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if the second argument is not valid for the implementation

getHints

java.util.Map<java.lang.String,java.lang.Object> getHints()
Get the hints and associated values that are in effect for the query instance.

Returns:
query hints
Since:
Java Persistence API 2.0

getSupportedHints

java.util.Set<java.lang.String> getSupportedHints()
Get the names of the hints that are supported for query objects. These hints correspond to hints that may be passed to the methods of the Query interface that take hints as arguments or used with the NamedQuery and NamedNativeQuery annotations. These include all standard query hints as well as vendor-specific hints supported by the provider. These hints may or may not currently be in effect.

Returns:
hints
Since:
Java Persistence API 2.0

setParameter

Query setParameter(java.lang.String name,
                   java.lang.Object value)
Bind an argument to a named parameter.

Parameters:
name - the parameter name
value -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if parameter name does not correspond to parameter in query string or argument is of incorrect type

setParameter

Query setParameter(java.lang.String name,
                   java.util.Date value,
                   TemporalType temporalType)
Bind an instance of java.util.Date to a named parameter.

Parameters:
name -
value -
temporalType -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if parameter name does not correspond to parameter in query string

setParameter

Query setParameter(java.lang.String name,
                   java.util.Calendar value,
                   TemporalType temporalType)
Bind an instance of java.util.Calendar to a named parameter.

Parameters:
name -
value -
temporalType -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if parameter name does not correspond to parameter in query string

setParameter

Query setParameter(int position,
                   java.lang.Object value)
Bind an argument to a positional parameter.

Parameters:
position -
value -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if position does not correspond to positional parameter of query or argument is of incorrect type

setParameter

Query setParameter(int position,
                   java.util.Date value,
                   TemporalType temporalType)
Bind an instance of java.util.Date to a positional parameter.

Parameters:
position -
value -
temporalType -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if position does not correspond to positional parameter of query

setParameter

Query setParameter(int position,
                   java.util.Calendar value,
                   TemporalType temporalType)
Bind an instance of java.util.Calendar to a positional parameter.

Parameters:
position -
value -
temporalType -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if position does not correspond to positional parameter of query

getNamedParameters

java.util.Map<java.lang.String,java.lang.Object> getNamedParameters()
Get the parameters names and associated values of the parameters that are bound for the query instance. Returns empty map if no parameters have been bound or if the query does not use named parameters.

Returns:
named parameters
Since:
Java Persistence API 2.0

getPositionalParameters

java.util.List getPositionalParameters()
Get the values of the positional parameters that are bound for the query instance. Positional positions are listed in order of position. Returns empty list if no parameters have been bound or if the query does not use positional parameters.

Returns:
positional parameters
Since:
Java Persistence API 2.0

setFlushMode

Query setFlushMode(FlushModeType flushMode)
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.

Parameters:
flushMode -

getFlushMode

FlushModeType getFlushMode()
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.

Returns:
flush mode
Since:
Java Persistence API 2.0

setLockMode

Query setLockMode(LockModeType lockMode)
Set the lock mode type to be used for the query execution.

Parameters:
lockMode -
Throws:
java.lang.IllegalStateException - if not a Java Persistence query language SELECT query
Since:
Java Persistence API 2.0

getLockMode

LockModeType getLockMode()
Get the current lock mode for the query.

Returns:
lock mode
Throws:
java.lang.IllegalStateException - if not a Java Persistence query language SELECT query
Since:
Java Persistence API 2.0

unwrap

<T> T unwrap(java.lang.Class<T> cls)
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.

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
Throws:
PersistenceException - if the provider does not support the call.
Since:
Java Persistence API 2.0

EclipseLink 2.0.0_ 2.0.0.r3652-M1 API Reference