QueryInterface.php 11.8 KB
Newer Older
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
1
<?php
Thomas Maroschik's avatar
Thomas Maroschik committed
2
3
namespace TYPO3\CMS\Extbase\Persistence;

4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
8
9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
16

17
18
19
20
21
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface;

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
22
23
24
/**
 * A persistence query interface
 *
25
 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
26
 */
Helmut Hummel's avatar
Helmut Hummel committed
27
interface QueryInterface {
28

29
30
	/**
	 * The '=' comparison operator.
31
	 *
32
	 * @api
33
	 */
34
	const OPERATOR_EQUAL_TO = 1;
35

36
37
38
39
40
41
42
	/**
	 * For NULL we have to use 'IS' instead of '='
	 *
	 * @api
	 */
	const OPERATOR_EQUAL_TO_NULL = 101;

43
44
	/**
	 * The '!=' comparison operator.
45
	 *
46
	 * @api
47
	 */
48
	const OPERATOR_NOT_EQUAL_TO = 2;
49

50
51
52
53
54
55
56
	/**
	 * For NULL we have to use 'IS NOT' instead of '!='
	 *
	 * @api
	 */
	const OPERATOR_NOT_EQUAL_TO_NULL = 202;

57
58
	/**
	 * The '<' comparison operator.
59
	 *
60
	 * @api
61
	 */
62
	const OPERATOR_LESS_THAN = 3;
63

64
65
	/**
	 * The '<=' comparison operator.
66
	 *
67
	 * @api
68
	 */
69
	const OPERATOR_LESS_THAN_OR_EQUAL_TO = 4;
70

71
72
	/**
	 * The '>' comparison operator.
73
	 *
74
	 * @api
75
	 */
76
	const OPERATOR_GREATER_THAN = 5;
77

78
79
	/**
	 * The '>=' comparison operator.
80
	 *
81
	 * @api
82
	 */
83
	const OPERATOR_GREATER_THAN_OR_EQUAL_TO = 6;
84

85
86
	/**
	 * The 'like' comparison operator.
87
	 *
88
	 * @api
89
	 */
90
	const OPERATOR_LIKE = 7;
91

92
	/**
93
	 * The 'contains' comparison operator for collections.
94
	 *
95
	 * @api
96
	 */
97
	const OPERATOR_CONTAINS = 8;
98

99
100
	/**
	 * The 'in' comparison operator.
101
	 *
102
	 * @api
103
	 */
104
	const OPERATOR_IN = 9;
105

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
106
	/**
107
	 * The 'is NULL' comparison operator.
108
	 *
109
	 * @api
110
	 */
111
112
	const OPERATOR_IS_NULL = 10;

113
	/**
114
	 * The 'is empty' comparison operator for collections.
115
	 *
116
	 * @api
117
	 */
118
119
	const OPERATOR_IS_EMPTY = 11;

120
	/**
121
	 * Constants representing the direction when ordering result sets.
122
	 */
123
124
125
	const ORDER_ASCENDING = 'ASC';
	const ORDER_DESCENDING = 'DESC';

126
127
128
	/**
	 * Gets the node-tuple source for this query.
	 *
Thomas Maroschik's avatar
Thomas Maroschik committed
129
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-NULL
130
131
	 * @deprecated since Extbase 6.0, will be removed in Extbase 7.0. It is deprecated only in the interface to be more
	 * in sync with Flow in future and will stay in Generic Persistence.
132
133
134
	 */
	public function getSource();

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
135
	/**
136
	 * Executes the query and returns the result.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
137
	 *
138
	 * @param bool $returnRawQueryResult avoids the object mapping by the persistence
139
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $returnRawQueryResult is TRUE
140
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
141
	 */
142
	public function execute($returnRawQueryResult = FALSE);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
143
144
145
146

	/**
	 * Sets the property names to order the result by. Expected like this:
	 * array(
147
148
	 *  'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
	 *  'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
149
150
151
	 * )
	 *
	 * @param array $orderings The property names to order by
Thomas Maroschik's avatar
Thomas Maroschik committed
152
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
153
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
154
155
156
157
158
	 */
	public function setOrderings(array $orderings);

	/**
	 * Sets the maximum size of the result set to limit. Returns $this to allow
159
	 * for chaining (fluid interface).
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
160
	 *
161
	 * @param int $limit
Thomas Maroschik's avatar
Thomas Maroschik committed
162
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
163
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
164
165
166
167
168
	 */
	public function setLimit($limit);

	/**
	 * Sets the start offset of the result set to offset. Returns $this to
169
	 * allow for chaining (fluid interface).
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
170
	 *
171
	 * @param int $offset
Thomas Maroschik's avatar
Thomas Maroschik committed
172
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
173
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
174
175
176
177
178
	 */
	public function setOffset($offset);

	/**
	 * The constraint used to limit the result set. Returns $this to allow
179
	 * for chaining (fluid interface).
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
180
	 *
181
	 * @param ConstraintInterface $constraint Some constraint, depending on the backend
Thomas Maroschik's avatar
Thomas Maroschik committed
182
	 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
183
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
184
185
186
187
	 */
	public function matching($constraint);

	/**
188
189
190
	 * Performs a logical conjunction of the two given constraints. The method
	 * takes one or more constraints and concatenates them with a boolean AND.
	 * It also accepts a single array of constraints to be concatenated.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
191
	 *
192
	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
193
	 * @return AndInterface
194
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
195
	 */
196
	public function logicalAnd($constraint1);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
197
198

	/**
199
200
201
	 * Performs a logical disjunction of the two given constraints. The method
	 * takes one or more constraints and concatenates them with a boolean OR.
	 * It also accepts a single array of constraints to be concatenated.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
202
	 *
203
	 * @param mixed $constraint1 The first of multiple constraints or an array of constraints.
204
	 * @return OrInterface
205
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
206
	 */
207
	public function logicalOr($constraint1);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
208
209
210
211

	/**
	 * Performs a logical negation of the given constraint
	 *
212
	 * @param ConstraintInterface $constraint Constraint to negate
213
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface
214
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
215
	 */
216
	public function logicalNot(ConstraintInterface $constraint);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
217
218

	/**
219
220
221
222
223
	 * Returns an equals criterion used for matching objects against a query.
	 *
	 * It matches if the $operand equals the value of the property named
	 * $propertyName. If $operand is NULL a strict check for NULL is done. For
	 * strings the comparison can be done with or without case-sensitivity.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
224
225
226
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with
227
	 * @param bool $caseSensitive Whether the equality test should be done case-sensitive for strings
228
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
229
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
230
231
232
233
	 */
	public function equals($propertyName, $operand, $caseSensitive = TRUE);

	/**
234
235
236
	 * Returns a like criterion used for matching objects against a query.
	 * Matches if the property named $propertyName is like the $operand, using
	 * standard SQL wildcards.
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
237
238
	 *
	 * @param string $propertyName The name of the property to compare against
239
	 * @param string $operand The value to compare with
240
	 * @param bool $caseSensitive Whether the matching should be done case-sensitive
241
	 * @return ComparisonInterface
242
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a non-string property
243
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
244
	 */
245
	public function like($propertyName, $operand, $caseSensitive = TRUE);
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
246

247
248
249
250
	/**
	 * Returns a "contains" criterion used for matching objects against a query.
	 * It matches if the multivalued property contains the given operand.
	 *
251
252
253
	 * If NULL is given as $operand, there will never be a match!
	 *
	 * @param string $propertyName The name of the multivalued property to compare against
254
	 * @param mixed $operand The value to compare with
255
	 * @return ComparisonInterface
256
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
257
258
259
260
261
262
263
264
265
266
	 * @api
	 */
	public function contains($propertyName, $operand);

	/**
	 * Returns an "in" criterion used for matching objects against a query. It
	 * matches if the property's value is contained in the multivalued operand.
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with, multivalued
267
	 * @return ComparisonInterface
268
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property
269
270
271
272
	 * @api
	 */
	public function in($propertyName, $operand);

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
273
274
275
276
277
	/**
	 * Returns a less than criterion used for matching objects against a query
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with
278
	 * @return ComparisonInterface
279
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
280
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
281
282
283
284
285
286
287
288
	 */
	public function lessThan($propertyName, $operand);

	/**
	 * Returns a less or equal than criterion used for matching objects against a query
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with
289
	 * @return ComparisonInterface
290
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
291
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
292
293
294
295
296
297
298
299
	 */
	public function lessThanOrEqual($propertyName, $operand);

	/**
	 * Returns a greater than criterion used for matching objects against a query
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with
300
	 * @return ComparisonInterface
301
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
302
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
303
304
305
306
307
308
309
310
	 */
	public function greaterThan($propertyName, $operand);

	/**
	 * Returns a greater than or equal criterion used for matching objects against a query
	 *
	 * @param string $propertyName The name of the property to compare against
	 * @param mixed $operand The value to compare with
311
	 * @return ComparisonInterface
312
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand
313
	 * @api
Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
314
315
316
	 */
	public function greaterThanOrEqual($propertyName, $operand);

317
318
319
320
321
322
323
324
325
326
327
328
	/**
	 * Returns the type this query cares for.
	 *
	 * @return string
	 * @api
	 */
	public function getType();

	/**
	 * Sets the Query Settings. These Query settings must match the settings expected by
	 * the specific Storage Backend.
	 *
Thomas Maroschik's avatar
Thomas Maroschik committed
329
	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
330
	 * @return void
331
332
	 * @todo decide whether this can be deprecated somewhen
	 * @api This method is not part of TYPO3Flow API
333
	 */
334
	public function setQuerySettings(Generic\QuerySettingsInterface $querySettings);
335
336
337
338

	/**
	 * Returns the Query Settings.
	 *
Thomas Maroschik's avatar
Thomas Maroschik committed
339
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings
340
	 * @todo decide whether this can be deprecated eventually
341
	 * @api This method is not part of  TYPO3Flow API
342
343
	 */
	public function getQuerySettings();
344

345
346
347
	/**
	 * Returns the query result count.
	 *
348
	 * @return int The query result count
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
	 * @api
	 */
	public function count();

	/**
	 * Gets the property names to order the result by, like this:
	 * array(
	 *  'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
	 *  'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
	 * )
	 *
	 * @return array
	 * @api
	 */
	public function getOrderings();

	/**
	 * Returns the maximum size of the result set to limit.
	 *
368
	 * @return int
369
370
371
372
373
374
375
	 * @api
	 */
	public function getLimit();

	/**
	 * Returns the start offset of the result set.
	 *
376
	 * @return int
377
378
379
380
381
382
383
	 * @api
	 */
	public function getOffset();

	/**
	 * Gets the constraint for this query.
	 *
384
	 * @return ConstraintInterface|NULL the constraint, or null if none
385
386
387
388
389
390
391
392
393
	 * @api
	 */
	public function getConstraint();

	/**
	 * Returns an "isEmpty" criterion used for matching objects against a query.
	 * It matches if the multivalued property contains no values or is NULL.
	 *
	 * @param string $propertyName The name of the multivalued property to compare against
394
	 * @return bool
395
396
397
398
	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
	 * @api
	 */
	public function isEmpty($propertyName);
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413

	/**
	 * Sets the source to fetch the result from
	 *
	 * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source
	 */
	public function setSource(Generic\Qom\SourceInterface $source);

	/**
	 * Returns the statement of this query.
	 *
	 * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement
	 */
	public function getStatement();

Sebastian Kurfürst's avatar
Sebastian Kurfürst committed
414
}