org.datanucleus.jpa
Class JPAQuery

java.lang.Object
  extended by org.datanucleus.jpa.JPAQuery
All Implemented Interfaces:
javax.persistence.Query

public class JPAQuery
extends java.lang.Object
implements javax.persistence.Query

Basic implementation of a JPA Query. Wraps an internal query.


Field Summary
protected static org.datanucleus.util.Localiser LOCALISER
          Localisation utility for output messages
 
Constructor Summary
JPAQuery(javax.persistence.EntityManager em, org.datanucleus.store.query.Query query, java.lang.String language)
          Constructor for a query used by JPA.
 
Method Summary
 int executeUpdate()
          Method to execute a (UPDATE/DELETE) query returning the number of changed records.
 int getFirstResult()
          The position of the first result the query object was set to retrieve.
 javax.persistence.FlushModeType getFlushMode()
          The flush mode in effect for the query execution.
 java.util.Map getHints()
          Get the hints and associated values that are in effect for the query instance.
 org.datanucleus.store.query.Query getInternalQuery()
          Accessor for the internal query.
 java.lang.String getLanguage()
          Accessor for the query language.
 int getMaxResults()
          The maximum number of results the query object was set to retrieve.
 java.util.Map 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()
          Method to execute a (SELECT) query statement returning multiple results.
 java.lang.Object getSingleResult()
          Method to execute a SELECT statement returning a single result.
 java.util.Set<java.lang.String> getSupportedHints()
          Get the names of the hints that are supported for query objects.
 javax.persistence.Query setFirstResult(int startPosition)
          Method to set the results to start from a particular position.
 javax.persistence.Query setFlushMode(javax.persistence.FlushModeType mode)
          Mutator for the flush mode.
 javax.persistence.Query setHint(java.lang.String hintName, java.lang.Object value)
          Method to add a vendor extension to the query.
 javax.persistence.Query setMaxResults(int max)
          Method to set the max number of results to return.
 javax.persistence.Query setParameter(int position, java.util.Calendar value, javax.persistence.TemporalType temporalType)
          Bind an instance of java.util.Calendar to a positional parameter.
 javax.persistence.Query setParameter(int position, java.util.Date value, javax.persistence.TemporalType temporalType)
          Bind an instance of java.util.Date to a positional parameter.
 javax.persistence.Query setParameter(int position, java.lang.Object value)
          Bind an argument to a positional parameter.
 javax.persistence.Query setParameter(java.lang.String name, java.util.Calendar value, javax.persistence.TemporalType temporalType)
          Bind an instance of java.util.Calendar to a named parameter.
 javax.persistence.Query setParameter(java.lang.String name, java.util.Date value, javax.persistence.TemporalType temporalType)
          Bind an instance of java.util.Date to a named parameter.
 javax.persistence.Query setParameter(java.lang.String name, java.lang.Object value)
          Bind an argument to a named parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static final org.datanucleus.util.Localiser LOCALISER
Localisation utility for output messages

Constructor Detail

JPAQuery

public JPAQuery(javax.persistence.EntityManager em,
                org.datanucleus.store.query.Query query,
                java.lang.String language)
Constructor for a query used by JPA.

Parameters:
em - Entity Manager
query - Underlying query
language - Query language
Method Detail

executeUpdate

public int executeUpdate()
Method to execute a (UPDATE/DELETE) query returning the number of changed records.

Specified by:
executeUpdate in interface javax.persistence.Query
Returns:
Number of records updated/deleted with the query.

getResultList

public java.util.List getResultList()
Method to execute a (SELECT) query statement returning multiple results.

Specified by:
getResultList in interface javax.persistence.Query
Returns:
The results

getSingleResult

public java.lang.Object getSingleResult()
Method to execute a SELECT statement returning a single result.

Specified by:
getSingleResult in interface javax.persistence.Query
Returns:
the result

setFirstResult

public javax.persistence.Query setFirstResult(int startPosition)
Method to set the results to start from a particular position.

Specified by:
setFirstResult in interface javax.persistence.Query
Parameters:
startPosition - position of first result numbered from 0
Returns:
The query

setMaxResults

public javax.persistence.Query setMaxResults(int max)
Method to set the max number of results to return.

Specified by:
setMaxResults in interface javax.persistence.Query
Parameters:
max - Number of results max
Returns:
The query

getMaxResults

public 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

getFirstResult

public 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

setFlushMode

public javax.persistence.Query setFlushMode(javax.persistence.FlushModeType mode)
Mutator for the flush mode.

Specified by:
setFlushMode in interface javax.persistence.Query
Parameters:
mode - Flush mode
Returns:
The query

getFlushMode

public javax.persistence.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

setHint

public javax.persistence.Query setHint(java.lang.String hintName,
                                       java.lang.Object value)
Method to add a vendor extension to the query. If the hint name is not recognized, it is silently ignored.

Specified by:
setHint in interface javax.persistence.Query
Parameters:
hintName - Name of the "hint"
value - Value for the "hint"
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if the second argument is not valid for the implementation

getHints

public java.util.Map getHints()
Get the hints and associated values that are in effect for the query instance.

Returns:
query hints

getSupportedHints

public 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

setParameter

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

Specified by:
setParameter in interface javax.persistence.Query
Parameters:
name - the parameter name
value - The value for the param
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

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

Specified by:
setParameter in interface javax.persistence.Query
Parameters:
position - Parameter position
value - The 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

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

Specified by:
setParameter in interface javax.persistence.Query
Parameters:
name - Name of the param
value - Value for the param
temporalType - The temporal type
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if parameter name does not correspond to parameter in query string

setParameter

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

Specified by:
setParameter in interface javax.persistence.Query
Parameters:
name - name of the param
value - Value for the param
temporalType - The temporal type
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if parameter name does not correspond to parameter in query string

setParameter

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

Specified by:
setParameter in interface javax.persistence.Query
Parameters:
position - Parameter position
value - Value for the param
temporalType - Temporal Type
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if position does not correspond to positional parameter of query

setParameter

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

Specified by:
setParameter in interface javax.persistence.Query
Parameters:
position - Parameter position
value - Value for the param
temporalType - Temporal type
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if position does not correspond to positional parameter of query

getNamedParameters

public java.util.Map 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

getPositionalParameters

public 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

getInternalQuery

public org.datanucleus.store.query.Query getInternalQuery()
Accessor for the internal query.

Returns:
Internal query

getLanguage

public java.lang.String getLanguage()
Accessor for the query language.

Returns:
Query language


Copyright © 2009. All Rights Reserved.