Skip to content

Package: TypedQuery

TypedQuery

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.model.query;
16:
17: import cz.cvut.kbss.jopa.exceptions.NoResultException;
18: import cz.cvut.kbss.jopa.exceptions.NoUniqueResultException;
19: import cz.cvut.kbss.jopa.exceptions.OWLPersistenceException;
20: import cz.cvut.kbss.jopa.exceptions.TransactionRequiredException;
21:
22: import java.net.URI;
23: import java.util.Collection;
24: import java.util.List;
25:
26: public interface TypedQuery<ResultElement> extends Query {
27: /**
28: * Execute a SELECT query and return the query results as a typed List.
29: *
30: * @return a list of the results
31: * @throws IllegalStateException if called for a Java Persistence query language UPDATE or DELETE statement
32: * @throws TransactionRequiredException if a lock mode has been set and there is no transaction
33: * @throws OWLPersistenceException if the query execution exceeds the query timeout value set and the
34: * transaction is rolled back
35: */
36: @Override
37: List<ResultElement> getResultList();
38:
39: /**
40: * Execute a SELECT query that returns a single result.
41: *
42: * @return Query result
43: * @throws NoResultException There is no result
44: * @throws NoUniqueResultException There are more than one results
45: */
46: ResultElement getSingleResult();
47:
48: /**
49: * Adds URI of context against which this query will be executed. </p>
50: * <p>
51: * If no context was specified, the query is run against the default repository context.
52: *
53: * @param context Context URI
54: * @return This instance
55: */
56: TypedQuery<ResultElement> addContext(URI context);
57:
58: /**
59: * Adds URIs of contexts against which this query will be executed. </p>
60: * <p>
61: * If no context was specified, the query is run against the default repository context.
62: *
63: * @param contexts Context URIs
64: * @return This instance
65: */
66: TypedQuery<ResultElement> addContexts(Collection<URI> contexts);
67:
68: /**
69: * Clears the previously set contexts.
70: *
71: * @return This instance
72: * @see #addContext(URI)
73: * @see #addContexts(Collection)
74: */
75: TypedQuery<ResultElement> clearContexts();
76:
77: /**
78: * Set the maximum number of results to retrieve.
79: *
80: * @param maxResult maximum number of results
81: * @return the same query instance
82: * @throws IllegalArgumentException if the argument is negative
83: */
84: TypedQuery<ResultElement> setMaxResults(int maxResult);
85:
86: /**
87: * Binds an argument value to a positional parameter.
88: *
89: * @param position position
90: * @param value parameter value
91: * @return this query instance
92: * @throws IllegalArgumentException If position does not correspond to a positional parameter of the query or if the
93: * argument is of incorrect type
94: */
95: TypedQuery<ResultElement> setParameter(int position, Object value);
96:
97: /**
98: * Binds a String argument value to a positional parameter.
99: *
100: * @param position position
101: * @param value parameter value
102: * @param language language tag for the parameter value
103: * @return this query instance
104: * @throws IllegalArgumentException If position does not correspond to a positional parameter of the query or if the
105: * argument is of incorrect type
106: */
107: TypedQuery<ResultElement> setParameter(int position, String value, String language);
108:
109: /**
110: * Binds an argument value to a named parameter.
111: *
112: * @param name parameter name
113: * @param value parameter value
114: * @return this query instance
115: * @throws IllegalArgumentException If the parameter name does not correspond to a parameter of the query or if the
116: * argument is of incorrect type
117: */
118: TypedQuery<ResultElement> setParameter(String name, Object value);
119:
120: /**
121: * Binds a String argument value to a named parameter.
122: *
123: * @param name parameter name
124: * @param value parameter value
125: * @param language language tag for the parameter value
126: * @return this query instance
127: * @throws IllegalArgumentException If the parameter name does not correspond to a parameter of the query or if the
128: * argument is of incorrect type
129: */
130: TypedQuery<ResultElement> setParameter(String name, String value, String language);
131:
132: /**
133: * Binds the value of a Parameter object.
134: *
135: * @param parameter parameter object
136: * @param value parameter value
137: * @return this query instance
138: * @throws IllegalArgumentException If the parameter does not correspond to a parameter of the query
139: */
140: <T> TypedQuery<ResultElement> setParameter(Parameter<T> parameter, T value);
141:
142: /**
143: * Binds the value of a String Parameter.
144: *
145: * @param parameter parameter object
146: * @param value parameter value
147: * @param language language tag for the parameter value
148: * @return this query instance
149: * @throws IllegalArgumentException If the parameter does not correspond to a parameter of the query
150: */
151: TypedQuery<ResultElement> setParameter(Parameter<String> parameter, String value, String language);
152: }