org.apache.cayenne.jpa
Class JpaQuery

java.lang.Object
  extended by org.apache.cayenne.jpa.JpaQuery
Direct Known Subclasses:
JpaNativeQuery

public class JpaQuery
extends Object

A JPA Query that wraps a Cayenne Query.


Field Summary
protected  Query cayenneQuery
           
protected  ObjectContext context
           
protected  Map<String,Object> parameters
           
 
Constructor Summary
JpaQuery(ObjectContext ctxt)
           
JpaQuery(ObjectContext context, String name)
          Construct a named query.
 
Method Summary
 int executeUpdate()
          Execute an update or delete statement.
protected  Query getQuery()
           
 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 flushModeType)
           
 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.
protected  void setQuery(Query q)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parameters

protected Map<String,Object> parameters

cayenneQuery

protected Query cayenneQuery

context

protected ObjectContext context
Constructor Detail

JpaQuery

public JpaQuery(ObjectContext ctxt)

JpaQuery

public JpaQuery(ObjectContext context,
                String name)
Construct a named query.

Method Detail

setQuery

protected void setQuery(Query q)

getQuery

protected Query getQuery()

getResultList

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

Returns:
a list of the results
Throws:
IllegalStateException - if called for an EJB QL UPDATE or DELETE statement

executeUpdate

public int executeUpdate()
Execute an update or delete statement.

Returns:
the number of entities updated or deleted
Throws:
IllegalStateException - if called for an EJB QL SELECT statement
TransactionRequiredException - if there is no transaction

getSingleResult

public 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
IllegalStateException - if called for an EJB QL UPDATE or DELETE statement

setMaxResults

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

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

setFlushMode

public Query setFlushMode(FlushModeType flushModeType)

setHint

public Query setHint(String hintName,
                     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:
IllegalArgumentException - if the second argument is not valid for the implementation

setFirstResult

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

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

setParameter

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

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

setParameter

public Query setParameter(String name,
                          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:
IllegalArgumentException - if parameter name does not correspond to parameter in query string

setParameter

public Query setParameter(String name,
                          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:
IllegalArgumentException - if parameter name does not correspond to parameter in query string

setParameter

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

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

setParameter

public Query setParameter(int position,
                          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:
IllegalArgumentException - if position does not correspond to positional parameter of query

setParameter

public Query setParameter(int position,
                          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:
IllegalArgumentException - if position does not correspond to positional parameter of query


Copyright © 2001-2007 Apache Cayenne. All Rights Reserved.