Skip to content

Package: Subquery

Subquery

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.criteria;
16:
17: import java.util.List;
18: import java.util.Set;
19:
20: /**
21: * The Subquery interface defines functionality that is specific to subqueries.
22: *
23: * A subquery has an expression as its selection item.
24: *
25: * @param <T>
26: * the type of the selection item.
27: */
28: public interface Subquery<T> extends AbstractQuery<T>, Expression<T> {
29:         /**
30:          * Specify the item that is to be returned as the subquery result. Replaces
31:          * the previously specified selection, if any.
32:          *
33:          * @param expression
34:          * expression specifying the item that
35:          *
36:          * is to be returned as the subquery result
37:          * @return the modified subquery
38:          */
39:         Subquery<T> select(Expression<T> expression);
40:
41:         /**
42:          * Modify the subquery to restrict the result according to the specified
43:          * boolean expression. Replaces the previously added restriction(s), if any.
44:          * This method only overrides the return type of the corresponding
45:          * AbstractQuery method.
46:          *
47:          * @param restriction
48:          * a simple or compound boolean expression
49:          * @return the modified subquery
50:          */
51:         Subquery<T> where(Expression<Boolean> restriction);
52:
53:         /**
54:          * Modify the subquery to restrict the result according to the conjunction
55:          * of the specified restriction predicates. Replaces the previously added
56:          * restriction(s), if any. If no restrictions are specified, any previously
57:          * added restrictions are simply removed. This method only overrides the
58:          * return type of the corresponding AbstractQuery method.
59:          *
60:          * @param restrictions
61:          * zero or more restriction predicates
62:          * @return the modified subquery
63:          */
64:         Subquery<T> where(Predicate... restrictions);
65:
66:         /**
67:          * Specify the expressions that are used to form groups over the subquery
68:          * results. Replaces the previous specified grouping expressions, if any. If
69:          * no grouping expressions are specified, any previously added grouping
70:          * expressions are simply removed. This method only overrides the return
71:          * type of the corresponding AbstractQuery method.
72:          *
73:          * @param grouping
74:          * zero or more grouping expressions
75:          * @return the modified subquery
76:          */
77:         Subquery<T> groupBy(Expression<?>... grouping);
78:
79:         /**
80:          * Specify the expressions that are used to form groups over the subquery
81:          * results. Replaces the previous specified grouping expressions, if any. If
82:          * no grouping expressions are specified, any previously added grouping
83:          * expressions are simply removed. This method only overrides the return
84:          * type of the corresponding AbstractQuery method.
85:          *
86:          * @param grouping
87:          * list of zero or more grouping expressions
88:          * @return the modified subquery
89:          */
90:         Subquery<T> groupBy(List<Expression<?>> grouping);
91:
92:         /**
93:          * Specify a restriction over the groups of the subquery. Replaces the
94:          * previous having restriction(s), if any. This method only overrides the
95:          * return type of the corresponding AbstractQuery method.
96:          *
97:          * @param restriction
98:          * a simple or compound boolean expression
99:          * @return the modified subquery
100:          */
101:         Subquery<T> having(Expression<Boolean> restriction);
102:
103:         /**
104:          * Specify restrictions over the groups of the subquery according the
105:          * conjunction of the specified restriction predicates. Replaces the
106:          * previously added having restriction(s), if any. If no restrictions are
107:          * specified, any previously added restrictions are simply removed. This
108:          * method only overrides the return type of the corresponding AbstractQuery
109:          * method.
110:          *
111:          * @param restrictions
112:          * zero or more restriction predicates
113:          * @return the modified subquery
114:          */
115:         Subquery<T> having(Predicate... restrictions);
116:
117:         /**
118:          * Specify whether duplicate query results will be eliminated. A true value
119:          * will cause duplicates to be eliminated. A false value will cause
120:          * duplicates to be retained. If distinct has not been specified, duplicate
121:          * results must be retained. This method only overrides the return type of
122:          * the corresponding AbstractQuery method.
123:          *
124:          * @param distinct
125:          * boolean value specifying whether duplicate
126:          *
127:          * results must be eliminated from the subquery result or
128:          *
129:          * whether they must be retained
130:          * @return the modified subquery.
131:          */
132:         Subquery<T> distinct(boolean distinct);
133:
134:         /**
135:          * Create a subquery root correlated to a root of the enclosing query.
136:          *
137:          * @param parentRoot
138:          * a root of the containing query
139:          * @return subquery root
140:          */
141:         <Y> Root<Y> correlate(Root<Y> parentRoot);
142:
143:         /**
144:          * Create a subquery join object correlated to a join object of the
145:          * enclosing query.
146:          *
147:          * @param parentJoin
148:          * join object of the containing query
149:          * @return subquery join
150:          */
151:         <X, Y> Join<X, Y> correlate(Join<X, Y> parentJoin);
152:
153:         /**
154:          * Create a subquery collection join object correlated to a collection join
155:          * object of the enclosing query.
156:          *
157:          * @param parentCollection
158:          * join object of the containing query
159:          * @return subquery join
160:          */
161:         <X, Y> CollectionJoin<X, Y> correlate(CollectionJoin<X, Y> parentCollection);
162:
163:         /**
164:          * Create a subquery set join object correlated to a set join object of the
165:          * enclosing query.
166:          *
167:          * @param parentSet
168:          * join object of the containing query
169:          * @return subquery join
170:          */
171:         <X, Y> SetJoin<X, Y> correlate(SetJoin<X, Y> parentSet);
172:
173:         /**
174:          * Create a subquery list join object correlated to a list join object of
175:          * the enclosing query.
176:          *
177:          * @param parentList
178:          * join object of the containing query
179:          * @return subquery join
180:          */
181:         <X, Y> ListJoin<X, Y> correlate(ListJoin<X, Y> parentList);
182:
183:         /**
184:          * Create a subquery map join object correlated to a map join object of the
185:          * enclosing query.
186:          *
187:          * @param parentMap
188:          * join object of the containing query
189:          * @return subquery join
190:          */
191:         <X, K, V> MapJoin<X, K, V> correlate(MapJoin<X, K, V> parentMap);
192:
193:         /**
194:          * Return the query of which this is a subquery.
195:          *
196:          * @return the enclosing query or subquery
197:          */
198:         AbstractQuery<?> getParent();
199:
200:         /**
201:          * Return the selection expression.
202:          *
203:          * @return the item to be returned in the subquery result
204:          */
205:         Expression<T> getSelection();
206:
207:         /**
208:          * Return the correlated joins of the subquery (Join objects obtained as a
209:          * result of the use of the correlate method). Returns empty set if the
210:          * subquery has no correlated joins. Modifications to the set do not affect
211:          * the query.
212:          *
213:          * @return the correlated joins of the subquery
214:          */
215:         Set<Join<?, ?>> getCorrelatedJoins();
216: }