b6f0a7a6710adf33110872f3d75dd2976ae7a381
[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$
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 array $boundVariables An array of variables to bind to the statement
96 * @param object $language The language of the statement. Must be a supported languanguage defined as Tx_Extbase_Persistence_QOM_QueryObjectModelFactory::TYPO3_*
97 * @return Tx_Extbase_Persistence_QOM_StatementInterface
98 */
99 public function statement($statement, array $boundVariables = array(), $language = Tx_Extbase_Persistence_QOM_Statement::TYPO3_SQL_MYSQL) {
100 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Statement', $statement, $boundVariables, $language);
101 }
102
103 /**
104 * Performs a join between two node-tuple sources.
105 *
106 * @param Tx_Extbase_Persistence_QOM_SourceInterface $left the left node-tuple source; non-null
107 * @param Tx_Extbase_Persistence_QOM_SourceInterface $right the right node-tuple source; non-null
108 * @param string $joinType one of QueryObjectModelConstants.JCR_JOIN_TYPE_*
109 * @param Tx_Extbase_Persistence_QOM_JoinConditionInterface $join Condition the join condition; non-null
110 * @return Tx_Extbase_Persistence_QOM_JoinInterface the join; non-null
111 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
112 */
113 public function join(Tx_Extbase_Persistence_QOM_SourceInterface $left, Tx_Extbase_Persistence_QOM_SourceInterface $right, $joinType, Tx_Extbase_Persistence_QOM_JoinConditionInterface $joinCondition) {
114 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Join', $left, $right, $joinType, $joinCondition);
115 }
116
117 /**
118 * Tests whether the value of a property in a first selector is equal to the value of a property in a second selector.
119 *
120 * @param string $selector1Name the name of the first selector; non-null
121 * @param string $property1Name the property name in the first selector; non-null
122 * @param string $selector2Name the name of the second selector; non-null
123 * @param string $property2Name the property name in the second selector; non-null
124 * @return Tx_Extbase_Persistence_QOM_EquiJoinConditionInterface the constraint; non-null
125 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
126 */
127 public function equiJoinCondition($selector1Name, $property1Name, $selector2Name, $property2Name) {
128 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_EquiJoinCondition', $selector1Name, $property1Name, $selector2Name, $property2Name);
129 }
130
131 /**
132 * Performs a logical conjunction of two other constraints.
133 *
134 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1 the first constraint; non-null
135 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2 the second constraint; non-null
136 * @return Tx_Extbase_Persistence_QOM_AndInterface the And constraint; non-null
137 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
138 */
139 public function _and(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1, Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2) {
140 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_LogicalAnd', $constraint1, $constraint2);
141 }
142
143 /**
144 * Performs a logical disjunction of two other constraints.
145 *
146 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1 the first constraint; non-null
147 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2 the second constraint; non-null
148 * @return Tx_Extbase_Persistence_QOM_OrInterface the Or constraint; non-null
149 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
150 */
151 public function _or(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1, Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2) {
152 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_LogicalOr', $constraint1, $constraint2);
153 }
154
155 /**
156 * Performs a logical negation of another constraint.
157 *
158 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint the constraint to be negated; non-null
159 * @return Tx_Extbase_Persistence_QOM_NotInterface the Not constraint; non-null
160 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
161 */
162 public function not(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint) {
163 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_LogicalNot', $constraint);
164 }
165
166 /**
167 * Filters node-tuples based on the outcome of a binary operation.
168 *
169 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand1 the first operand; non-null
170 * @param string $operator the operator; one of QueryObjectModelConstants.JCR_OPERATOR_*
171 * @param Tx_Extbase_Persistence_QOM_StaticOperandInterface $operand2 the second operand; non-null
172 * @return Tx_Extbase_Persistence_QOM_ComparisonInterface the constraint; non-null
173 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
174 */
175 public function comparison(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand1, $operator, $operand2) {
176 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Comparison', $operand1, $operator, $operand2);
177 }
178
179 /**
180 * Evaluates to the value (or values, if multi-valued) of a property in the specified or default selector.
181 *
182 * @param string $propertyName the property name; non-null
183 * @param string $selectorName the selector name; non-null
184 * @return Tx_Extbase_Persistence_QOM_PropertyValueInterface the operand; non-null
185 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
186 */
187 public function propertyValue($propertyName, $selectorName = '') {
188 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_PropertyValue', $propertyName, $selectorName);
189 }
190
191 /**
192 * Evaluates to the lower-case string value (or values, if multi-valued) of an operand.
193 *
194 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand whose value is converted to a lower-case string; non-null
195 * @return Tx_Extbase_Persistence_QOM_LowerCaseInterface the operand; non-null
196 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
197 */
198 public function lowerCase(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
199 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_LowerCase', $operand);
200 }
201
202 /**
203 * Evaluates to the upper-case string value (or values, if multi-valued) of an operand.
204 *
205 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand whose value is converted to a upper-case string; non-null
206 * @return Tx_Extbase_Persistence_QOM_UpperCaseInterface the operand; non-null
207 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
208 */
209 public function upperCase(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
210 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_UpperCase', $operand);
211 }
212
213 /**
214 * Orders by the value of the specified operand, in ascending order.
215 *
216 * The query is invalid if $operand does not evaluate to a scalar value.
217 *
218 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand by which to order; non-null
219 * @return Tx_Extbase_Persistence_QOM_OrderingInterface the ordering
220 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
221 */
222 public function ascending(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
223 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Ordering', $operand, Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING);
224 }
225
226 /**
227 * Orders by the value of the specified operand, in descending order.
228 *
229 * The query is invalid if $operand does not evaluate to a scalar value.
230 *
231 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand by which to order; non-null
232 * @return Tx_Extbase_Persistence_QOM_OrderingInterface the ordering
233 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
234 */
235 public function descending(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
236 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Ordering', $operand, Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING);
237 }
238
239 /**
240 * Evaluates to the value of a bind variable.
241 *
242 * @param string $bindVariableName the bind variable name; non-null
243 * @return Tx_Extbase_Persistence_QOM_BindVariableValueInterface the operand; non-null
244 * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
245 */
246 public function bindVariable($bindVariableName) {
247 return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_BindVariableValue', $bindVariableName);
248 }
249
250 }
251 ?>