Interface Query
- All Known Subinterfaces:
TypedQuery<X>
- All Known Implementing Classes:
QueryImpl
,ResultSetMappingQuery
,TypedQueryImpl
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Execute an update or delete statement.int
The position of the first result the query object was set to retrieve.getHints()
Gets the hints and associated values that are in effect for this query instance.int
The maximum number of results the query object was set to retrieve.Parameter<?>
getParameter
(int position) Gets the parameter object corresponding to the declared positional parameter with the given position.Parameter<?>
getParameter
(String name) Gets the parameter object corresponding to the declared parameter of the given name.Gets the parameter objects corresponding to the declared parameters of the query.getParameterValue
(int position) Returns the input value bound to the positional parameter.<T> T
getParameterValue
(Parameter<T> parameter) Returns the input value bound to the parameter.getParameterValue
(String name) Returns the input value bound to the named parameter.Execute a SELECT query and return the query results as an untyped List.default Stream
Execute a SELECT query and return the query results as an untyped java.util.stream.Stream.Execute a SELECT query that returns a single result.boolean
Returns a boolean indicating whether a value has been bound to the parameter.setFirstResult
(int startPosition) Set the position of the first result to retrieve.Sets a query hint.setMaxResults
(int maxResult) Set the maximum number of results to retrieve.setParameter
(int position, Object value) Binds an argument value to a positional parameter.setParameter
(int position, String value, String language) Binds a String argument value to a positional parameter.setParameter
(Parameter<String> parameter, String value, String language) Binds the value of a String Parameter.<T> Query
setParameter
(Parameter<T> parameter, T value) Binds the value of a Parameter object.setParameter
(String name, Object value) Binds an argument value to a named parameter.setParameter
(String name, String value, String language) Binds a String argument value to a named parameter.setUntypedParameter
(int position, Object value) Binds an argument value to a positional parameter.<T> Query
setUntypedParameter
(Parameter<T> parameter, T value) Binds the value of a Parameter object.setUntypedParameter
(String name, Object value) Binds an argument value to a named parameter.
-
Method Details
-
executeUpdate
void executeUpdate()Execute an update or delete statement.- Throws:
IllegalStateException
- if called for a SELECT statement or for a criteria queryTransactionRequiredException
- if there is no transaction or the persistence context has not been joined to the transactionOWLPersistenceException
- if the query execution exceeds the query timeout value set and the transaction is rolled back
-
getResultList
List getResultList()Execute a SELECT query and return the query results as an untyped List.- Returns:
- a list of the results
- Throws:
IllegalStateException
- if called for a Java Persistence query language UPDATE or DELETE statementTransactionRequiredException
- if a lock mode has been set and there is no transactionOWLPersistenceException
- if the query execution exceeds the query timeout value set and the transaction is rolled back
-
getResultStream
Execute a SELECT query and return the query results as an untyped java.util.stream.Stream.By default this method delegates to getResultList().stream(), however persistence provider may choose to override this method to provide additional capabilities.
- Returns:
- a stream of the results
- Throws:
IllegalStateException
- if called for a SELECT statement or for a criteria queryTransactionRequiredException
- if there is no transaction or the persistence context has not been joined to the transactionOWLPersistenceException
- if the query execution exceeds the query timeout value set and the transaction is rolled back
-
getSingleResult
Object getSingleResult()Execute a SELECT query that returns a single result.- Returns:
- Query result
- Throws:
NoResultException
- There is no resultNoUniqueResultException
- There are more than one results
-
setMaxResults
Set the maximum number of results to retrieve.- Parameters:
maxResult
- maximum number of results- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if the argument is negative
-
getMaxResults
int getMaxResults()The maximum number of results the query object was set to retrieve.Returns Integer.MAX_VALUE if
setMaxResults(int)
was not applied to the query object.- Returns:
- maximum number of results
-
setFirstResult
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 the 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 the first result
-
getParameter
Gets the parameter object corresponding to the declared positional parameter with the given position. This method is not required to be supported for native queries.- Parameters:
position
- position- Returns:
- parameter object
- Throws:
IllegalArgumentException
- If the parameter with the specified position does not exist
-
getParameter
Gets the parameter object corresponding to the declared parameter of the given name. This method is not required to be supported for native queries.- Parameters:
name
- Parameter name- Returns:
- parameter object
- Throws:
IllegalArgumentException
- If the parameter of the specified name does not exist
-
getParameters
Gets 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.- Returns:
- set of parameter objects
-
isBound
Returns a boolean indicating whether a value has been bound to the parameter.- Parameters:
parameter
- parameter object- Returns:
- boolean indicating whether parameter has been bound
-
getParameterValue
Returns the input value bound to the positional parameter.- Parameters:
position
- position- Returns:
- parameter value
- Throws:
IllegalStateException
- If the parameter has not been boundIllegalArgumentException
- If the parameter with the specified position does not exist
-
getParameterValue
Returns the input value bound to the named parameter.- Parameters:
name
- parameter name- Returns:
- parameter value
- Throws:
IllegalStateException
- If the parameter has not been boundIllegalArgumentException
- If the parameter with the specified name does not exist
-
getParameterValue
Returns the input value bound to the parameter.- Parameters:
parameter
- parameter object- Returns:
- parameter value
- Throws:
IllegalStateException
- If the parameter has not been boundIllegalArgumentException
- If the parameter is not a parameter of the query
-
setParameter
Binds an argument value to a positional parameter.This version exploits the type of the parameter value and maps it to the corresponding XSD datatype (if it exists).
- Parameters:
position
- positionvalue
- parameter value- Returns:
- this query instance
- Throws:
IllegalArgumentException
- If position does not correspond to a positional parameter of the query or if the argument is of incorrect type- See Also:
-
setParameter
Binds a String argument value to a positional parameter.- Parameters:
position
- positionvalue
- parameter valuelanguage
- language tag for the parameter value- Returns:
- this query instance
- Throws:
IllegalArgumentException
- If position does not correspond to a positional parameter of the query or if the argument is of incorrect type
-
setParameter
Binds an argument value to a named parameter.This version exploits the type of the parameter value and maps it to the corresponding XSD datatype (if it exists).
- Parameters:
name
- parameter namevalue
- parameter value- Returns:
- this query instance
- Throws:
IllegalArgumentException
- If the parameter name does not correspond to a parameter of the query or if the argument is of incorrect type- See Also:
-
setParameter
Binds a String argument value to a named parameter.- Parameters:
name
- parameter namevalue
- parameter valuelanguage
- language tag for the parameter value- Returns:
- this query instance
- Throws:
IllegalArgumentException
- If the parameter name does not correspond to a parameter of the query or if the argument is of incorrect type
-
setParameter
Binds the value of a Parameter object.This version exploits the type of the parameter value and maps it to the corresponding XSD datatype (if it exists).
- Parameters:
parameter
- parameter objectvalue
- parameter value- Returns:
- this query instance
- Throws:
IllegalArgumentException
- If the parameter does not correspond to a parameter of the query- See Also:
-
setParameter
Binds the value of a String Parameter.- Parameters:
parameter
- parameter objectvalue
- parameter valuelanguage
- language tag for the parameter value- Returns:
- this query instance
- Throws:
IllegalArgumentException
- If the parameter does not correspond to a parameter of the query
-
setUntypedParameter
Binds an argument value to a positional parameter.This version does not express the type of the value in the query. Instead, it inserts the value directly into the query string. Can be useful e.g. for specifying OFFSET or LIMIT values.
- Parameters:
position
- positionvalue
- parameter value- Returns:
- this query instance
- Throws:
IllegalArgumentException
- If position does not correspond to a positional parameter of the query or if the argument is of incorrect type
-
setUntypedParameter
Binds an argument value to a named parameter.This version does not express the type of the value in the query. Instead, it inserts the value directly into the query string. Can be useful e.g. for specifying OFFSET or LIMIT values.
- Parameters:
name
- parameter namevalue
- parameter value- Returns:
- this query instance
- Throws:
IllegalArgumentException
- If parameter name does not correspond to a parameter of the query or if the argument is of incorrect type
-
setUntypedParameter
Binds the value of a Parameter object.This version does not express the type of the value in the query. Instead, it inserts the value directly into the query string. Can be useful e.g. for specifying OFFSET or LIMIT values.
- Parameters:
parameter
- parameter objectvalue
- parameter value- Returns:
- this query instance
- Throws:
IllegalArgumentException
- If the parameter does not correspond to a parameter of the query
-
setHint
Sets a query hint.The hints elements may be used to specify query properties and hints. Vendor-specific hints that are not recognized by a provider are silently ignored.
- Parameters:
hintName
- Name of the query hintvalue
- Value of the query hint- Returns:
- this query instance
- Throws:
IllegalArgumentException
- If the value is not valid for the hint implementation
-
getHints
Gets the hints and associated values that are in effect for this query instance.- Returns:
- Map of query hints with values
-