Skip to content

Package: Subquery

Subquery

Coverage

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