Package cz.cvut.kbss.jopa.query
Interface QueryHolder
- All Known Implementing Classes:
TokenStreamSparqlQueryHolder
public interface QueryHolder
Represents a caretaker of a query, enabling parameter setting and final assembly of the query.
-
Method Summary
Modifier and TypeMethodDescriptionAssembles the query, using any parameter values specified, and returns it as a string.voidclearParameter(Parameter<?> parameter) Clears any previously set value of the specified parameter.voidClears any previously set parameter values in this query.intGets the currently set first result position.intGets the currently set maximum number of results to retrieveParameter<?>getParameter(int position) Gets a parameter with the specified position.Parameter<?>getParameter(String name) Gets a parameter with the specified name.Gets a collection of parameters in the query.getParameterValue(Parameter<?> parameter) Gets value bound to the specified parameter.default List<? extends QueryParameter<?>>Gets the list of query parameters that appear in the SELECT projection clause (in the order in which they are declared).getQuery()Gets the original query string.Set<? extends QueryParameter<?>>Gets a collection of parameters in the query.Gets the type of this query.booleanhasParameter(int position) Checks whether the query has a parameter at the specified position.booleanhasParameter(String name) Checks whether the query has a parameter with the specified name.voidsetFirstResult(int startPosition) Sets the position of the first result to retrieve.voidsetMaxResults(int maxResults) Sets the maximum number of results the query should retrieve.<T> voidsetParameter(Parameter<T> parameter, Object value) Sets value of the specified parameter in the query.<T> voidsetParameter(Parameter<T> parameter, String value, String language) Sets value of the specified parameter in the query.<T> voidsetUntypedParameter(Parameter<T> parameter, Object value) Sets value of the specified parameter in the query.
-
Method Details
-
getQuery
String getQuery()Gets the original query string.- Returns:
- Gets the original unparsed query
-
getParameters
Gets a collection of parameters in the query.- Returns:
- Parameter objects
-
getQueryParameters
Set<? extends QueryParameter<?>> getQueryParameters()Gets a collection of parameters in the query.This returns the same set as
getParameters(), but it returns more specific typeQueryParameter.- Returns:
- Parameter objects
-
getProjectedQueryParameters
Gets the list of query parameters that appear in the SELECT projection clause (in the order in which they are declared).- Returns:
- Projected query parameters
-
hasParameter
Checks whether the query has a parameter with the specified name.- Parameters:
name- Parameter name- Returns:
trueif the query has a matching parameter,falseotherwise
-
hasParameter
boolean hasParameter(int position) Checks whether the query has a parameter at the specified position.- Parameters:
position- Parameter position- Returns:
trueif the query has a matching parameter,falseotherwise
-
getParameter
Gets a parameter with the specified name.- Parameters:
name- Parameter name- Returns:
- Parameter object
- Throws:
IllegalArgumentException- If the parameter of the specified name does not exist
-
getParameter
Gets a parameter with the specified position.- Parameters:
position- Parameter position- Returns:
- Parameter object
- Throws:
IllegalArgumentException- If the parameter at the specified position does not exist
-
getParameterValue
Gets value bound to the specified parameter.- Parameters:
parameter- Parameter- Returns:
- parameter value
- Throws:
IllegalArgumentException- If there is no parameter with the specified name
-
setParameter
Sets value of the specified parameter in the query.If a value was already specified for the parameter, it is overwritten by the new one. This version expresses the value type information using XSD datatype in the query string.
- Type Parameters:
T- Type of the parameter- Parameters:
parameter- Parameter objectvalue- Value to use- Throws:
IllegalArgumentException- If there is no such parameter in the query- See Also:
-
setParameter
Sets value of the specified parameter in the query.If a value was already specified for the parameter, it is overwritten by the new one.
- Type Parameters:
T- Type of the parameter- Parameters:
parameter- Parameter objectvalue- String value to uselanguage- Parameter language- Throws:
IllegalArgumentException- If there is no such parameter in the query
-
setUntypedParameter
Sets value of the specified parameter in the query.If a value was already specified for the parameter, it is overwritten by the new one. This version inserts the string representation of the value directly into the query, without any type information.
- Parameters:
parameter- Parameter objectvalue- Value to use- Throws:
IllegalArgumentException- If there is no such parameter in the query- See Also:
-
setFirstResult
void setFirstResult(int startPosition) Sets the position of the first result to retrieve.- Parameters:
startPosition- The position to set, starting at 0
-
getFirstResult
int getFirstResult()Gets the currently set first result position.- Returns:
- the first result position, 0 if none was set
-
setMaxResults
void setMaxResults(int maxResults) Sets the maximum number of results the query should retrieve.- Parameters:
maxResults- The maximum number of results
-
getMaxResults
int getMaxResults()Gets the currently set maximum number of results to retrieve- Returns:
- Maximum results value,
Integer.MAX_VALUEwhen none was set
-
clearParameter
Clears any previously set value of the specified parameter.- Parameters:
parameter- Parameter object- Throws:
IllegalArgumentException- If there is no such parameter in the query
-
clearParameters
void clearParameters()Clears any previously set parameter values in this query. -
assembleQuery
String assembleQuery()Assembles the query, using any parameter values specified, and returns it as a string.- Returns:
- Assembled query
-
getQueryType
QueryType getQueryType()Gets the type of this query.- Returns:
- Query type
-