Query (Java EE 5 SDK)

Java

Java EE 5 SDK

深圳电信培训中心.徐海蛟老师.


javax.persistence Interface Query


public interface Query

Interface used to control query execution.

从以下版本开始:
Java Persistence 1.0

方法摘要
 int executeUpdate()
          Execute an update or delete statement.
 List getResultList()
          Execute a SELECT query and return the query results as a List.
 Object getSingleResult()
          Execute a SELECT query that returns a single result.
 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(String hintName, Object value)
          Set an implementation-specific hint.
 Query setMaxResults(int maxResult)
          Set the maximum number of results to retrieve.
 Query setParameter(int position, Calendar value, TemporalType temporalType)
          Bind an instance of java.util.Calendar to a positional parameter.
 Query setParameter(int position, Date value, TemporalType temporalType)
          Bind an instance of java.util.Date to a positional parameter.
 Query setParameter(int position, Object value)
          Bind an argument to a positional parameter.
 Query setParameter(String name, Calendar value, TemporalType temporalType)
          Bind an instance of java.util.Calendar to a named parameter.
 Query setParameter(String name, Date value, TemporalType temporalType)
          Bind an instance of java.util.Date to a named parameter.
 Query setParameter(String name, Object value)
          Bind an argument to a named parameter.
 

方法详细信息

getResultList

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

返回:
a list of the results
抛出异常:
IllegalStateException - if called for a Java Persistence query language UPDATE or DELETE statement

getSingleResult

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

返回:
the result
抛出异常:
NoResultException - if there is no result
NonUniqueResultException - if more than one result
IllegalStateException - if called for a Java Persistence query language UPDATE or DELETE statement

executeUpdate

int executeUpdate()
Execute an update or delete statement.

返回:
the number of entities updated or deleted
抛出异常:
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.

参数:
maxResult -
返回:
the same query instance
抛出异常:
IllegalArgumentException - if argument is negative

setFirstResult

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

参数:
startPosition - the start position of the first result, numbered from 0
返回:
the same query instance
抛出异常:
IllegalArgumentException - if argument is negative

setHint

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

参数:
hintName -
value -
返回:
the same query instance
抛出异常:
IllegalArgumentException - if the second argument is not valid for the implementation

setParameter

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

参数:
name - the parameter name
value -
返回:
the same query instance
抛出异常:
IllegalArgumentException - if parameter name does not correspond to parameter in query string or argument is of incorrect type

setParameter

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

参数:
name -
value -
temporalType -
返回:
the same query instance
抛出异常:
IllegalArgumentException - if parameter name does not correspond to parameter in query string

setParameter

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

参数:
name -
value -
temporalType -
返回:
the same query instance
抛出异常:
IllegalArgumentException - if parameter name does not correspond to parameter in query string

setParameter

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

参数:
position -
value -
返回:
the same query instance
抛出异常:
IllegalArgumentException - if position does not correspond to positional parameter of query or argument is of incorrect type

setParameter

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

参数:
position -
value -
temporalType -
返回:
the same query instance
抛出异常:
IllegalArgumentException - if position does not correspond to positional parameter of query

setParameter

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

参数:
position -
value -
temporalType -
返回:
the same query instance
抛出异常:
IllegalArgumentException - if position does not correspond to positional parameter of query

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.

参数:
flushMode -

Java EE 5 SDK

深圳电信培训中心.徐海蛟老师.


提交错误或意见

版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。深圳电信培训中心.徐海蛟老师教学参考.