Raised DBAL version from 1.1.5 to 1.1.6
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / QOM / QueryObjectModelFactory.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * The Query Object Model Factory
30 *
31 * @package Extbase
32 * @subpackage Persistence\QOM
33 * @version $Id: QueryObjectModelFactory.php 1972 2010-03-08 16:59:20Z jocrau $
34 * @scope prototype
35 */
36 class Tx_Extbase_Persistence_QOM_QueryObjectModelFactory implements Tx_Extbase_Persistence_QOM_QueryObjectModelFactoryInterface {
37 // SK: Needs to be cleaned up (methods might need to be removed, and comments fixed)
38 /**
39 * @var Tx_Extbase_Persistence_Storage_BackendInterface
40 */
41 protected $storageBackend;
42
43 /**
44 * Constructs the Component Factory
45 *
46 * @param Tx_Extbase_Persistence_Storage_BackendInterfasce $storageBackend
47 * @param Tx_Extbase_Persistence_Mapper_DataMapper $dataMapper
48 */
49 public function __construct(Tx_Extbase_Persistence_Storage_BackendInterface $storageBackend) {
50 $this->storageBackend = $storageBackend;
51 }
52
53 /**
54 * Creates a query with one or more selectors.
55 * If source is a selector, that selector is the default selector of the
56 * query. Otherwise the query does not have a default selector.
57 *
58 * If the query is invalid, this method throws an InvalidQueryException.
59 * See the individual QOM factory methods for the validity criteria of each
60 * query element.
61 *
62 * @param mixed $source the Selector or the node-tuple Source; non-null
63 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint the constraint, or null if none
64 * @param array $orderings zero or more orderings; null is equivalent to a zero-length array
65 * @param array $columns the columns; null is equivalent to a zero-length array
66 * @return Tx_Extbase_Persistence_QOM_QueryObjectModelInterface the query; non-null
67 * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test and the parameters given fail that test. See the individual QOM factory methods for the validity criteria of each query element.
68 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if another error occurs.
69 */
70 public function createQuery(Tx_Extbase_Persistence_QOM_SourceInterface $selectorOrSource, $constraint, array $orderings, array $columns) {
71 $query = new Tx_Extbase_Persistence_QOM_QueryObjectModel($selectorOrSource, $constraint, $orderings, $columns);
72 $query->injectStorageBackend($this->storageBackend);
73 return $query;
74 }
75
76 /**
77 * Selects a subset of the nodes in the repository based on node type.
78 *
79 * @param string $nodeTypeName the name of the required node type; non-null
80 * @param string $selectorName the selector name; optional
81 * @return Tx_Extbase_Persistence_QOM_SelectorInterface the selector
82 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
83 */
84 public function selector($nodeTypeName, $selectorName = '') {
85 if ($selectorName === '') {
86 $selectorName = $nodeTypeName;
87 }
88 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Selector', $selectorName, $nodeTypeName);
89 }
90
91 /**
92 * Sets a statement as constraint. This is not part of the JCR 2.0 Specification!
93 *
94 * @param string $statement The statement
95 * @param object $language The language of the statement. Must be a supported languanguage defined as Tx_Extbase_Persistence_QOM_QueryObjectModelInterface::JCR_* or Tx_Extbase_Persistence_QOM_QueryObjectModelInterface::TYPO3_* or
96 * @return Tx_Extbase_Persistence_QOM_StatementInterface
97 */
98 public function statement($statement, $boundVariables, $language) {
99 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Statement', $statement, $boundVariables, $language);
100 }
101
102 /**
103 * Performs a join between two node-tuple sources.
104 *
105 * @param Tx_Extbase_Persistence_QOM_SourceInterface $left the left node-tuple source; non-null
106 * @param Tx_Extbase_Persistence_QOM_SourceInterface $right the right node-tuple source; non-null
107 * @param string $joinType one of QueryObjectModelConstants.JCR_JOIN_TYPE_*
108 * @param Tx_Extbase_Persistence_QOM_JoinConditionInterface $join Condition the join condition; non-null
109 * @return Tx_Extbase_Persistence_QOM_JoinInterface the join; non-null
110 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
111 */
112 public function join(Tx_Extbase_Persistence_QOM_SourceInterface $left, Tx_Extbase_Persistence_QOM_SourceInterface $right, $joinType, Tx_Extbase_Persistence_QOM_JoinConditionInterface $joinCondition) {
113 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Join', $left, $right, $joinType, $joinCondition);
114 }
115
116 /**
117 * Tests whether the value of a property in a first selector is equal to the value of a property in a second selector.
118 *
119 * @param string $selector1Name the name of the first selector; non-null
120 * @param string $property1Name the property name in the first selector; non-null
121 * @param string $selector2Name the name of the second selector; non-null
122 * @param string $property2Name the property name in the second selector; non-null
123 * @return Tx_Extbase_Persistence_QOM_EquiJoinConditionInterface the constraint; non-null
124 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
125 */
126 public function equiJoinCondition($selector1Name, $property1Name, $selector2Name, $property2Name) {
127 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_EquiJoinCondition', $selector1Name, $property1Name, $selector2Name, $property2Name);
128 }
129
130 /**
131 * Performs a logical conjunction of two other constraints.
132 *
133 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1 the first constraint; non-null
134 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2 the second constraint; non-null
135 * @return Tx_Extbase_Persistence_QOM_AndInterface the And constraint; non-null
136 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
137 */
138 public function _and(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1, Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2) {
139 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_LogicalAnd', $constraint1, $constraint2);
140 }
141
142 /**
143 * Performs a logical disjunction of two other constraints.
144 *
145 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1 the first constraint; non-null
146 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2 the second constraint; non-null
147 * @return Tx_Extbase_Persistence_QOM_OrInterface the Or constraint; non-null
148 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
149 */
150 public function _or(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1, Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2) {
151 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_LogicalOr', $constraint1, $constraint2);
152 }
153
154 /**
155 * Performs a logical negation of another constraint.
156 *
157 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint the constraint to be negated; non-null
158 * @return Tx_Extbase_Persistence_QOM_NotInterface the Not constraint; non-null
159 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
160 */
161 public function not(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint) {
162 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_LogicalNot', $constraint);
163 }
164
165 /**
166 * Filters node-tuples based on the outcome of a binary operation.
167 *
168 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand1 the first operand; non-null
169 * @param string $operator the operator; one of QueryObjectModelConstants.JCR_OPERATOR_*
170 * @param Tx_Extbase_Persistence_QOM_StaticOperandInterface $operand2 the second operand; non-null
171 * @return Tx_Extbase_Persistence_QOM_ComparisonInterface the constraint; non-null
172 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
173 */
174 public function comparison(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand1, $operator, $operand2) {
175 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Comparison', $operand1, $operator, $operand2);
176 }
177
178 /**
179 * Evaluates to the value (or values, if multi-valued) of a property in the specified or default selector.
180 *
181 * @param string $propertyName the property name; non-null
182 * @param string $selectorName the selector name; non-null
183 * @return Tx_Extbase_Persistence_QOM_PropertyValueInterface the operand; non-null
184 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
185 */
186 public function propertyValue($propertyName, $selectorName = '') {
187 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_PropertyValue', $propertyName, $selectorName);
188 }
189
190 /**
191 * Evaluates to the lower-case string value (or values, if multi-valued) of an operand.
192 *
193 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand whose value is converted to a lower-case string; non-null
194 * @return Tx_Extbase_Persistence_QOM_LowerCaseInterface the operand; non-null
195 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
196 */
197 public function lowerCase(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
198 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_LowerCase', $operand);
199 }
200
201 /**
202 * Evaluates to the upper-case string value (or values, if multi-valued) of an operand.
203 *
204 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand whose value is converted to a upper-case string; non-null
205 * @return Tx_Extbase_Persistence_QOM_UpperCaseInterface the operand; non-null
206 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
207 */
208 public function upperCase(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
209 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_UpperCase', $operand);
210 }
211
212 /**
213 * Orders by the value of the specified operand, in ascending order.
214 *
215 * The query is invalid if $operand does not evaluate to a scalar value.
216 *
217 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand by which to order; non-null
218 * @return Tx_Extbase_Persistence_QOM_OrderingInterface the ordering
219 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
220 */
221 public function ascending(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
222 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Ordering', $operand, Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING);
223 }
224
225 /**
226 * Orders by the value of the specified operand, in descending order.
227 *
228 * The query is invalid if $operand does not evaluate to a scalar value.
229 *
230 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand by which to order; non-null
231 * @return Tx_Extbase_Persistence_QOM_OrderingInterface the ordering
232 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
233 */
234 public function descending(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
235 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Ordering', $operand, Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING);
236 }
237
238 /**
239 * Evaluates to the value of a bind variable.
240 *
241 * @param string $bindVariableName the bind variable name; non-null
242 * @return Tx_Extbase_Persistence_QOM_BindVariableValueInterface the operand; non-null
243 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
244 */
245 public function bindVariable($bindVariableName) {
246 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_BindVariableValue', $bindVariableName);
247 }
248
249 }
250 ?>