[~TASK] Extbase (Persistence): Refactored persistence layer (part I). Dropped QueryObjectModel. The Query-Object is now passed directly to the StorageBackend.
[+API] Extbase (Persistence): Implemented methods in() and contains() in the Query-Object. Resolves #6707.
[+FEATURE] Extbase (Persistence): It is now possible to ask contains() for mm-relations, e.g. $query->contains('categories', $category). Resolves #4679.
$dataMapper->injectIdentityMap($identityMap);
$dataMapper->injectSession($persistenceSession);
$dataMapper->injectReflectionService(self::$reflectionService);
-
+
$storageBackend = t3lib_div::makeInstance('Tx_Extbase_Persistence_Storage_Typo3DbBackend', $GLOBALS['TYPO3_DB']); // singleton
$storageBackend->injectDataMapper($dataMapper);
-
+
$qomFactory = t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_QueryObjectModelFactory', $storageBackend);
$dataMapper->setQomFactory($qomFactory);
*/
interface Tx_Extbase_DomainObject_DomainObjectInterface {
+ /**
+ * Getter for uid.
+ *
+ * @return int the uid or NULL if none set yet.
+ */
+ public function getUid();
+
/**
* Register an object's clean state, e.g. after it has been reconstituted
* from the database
return $this->reflectionService;
}
+ /**
+ * Returns the number of records matching the query.
+ *
+ * @param Tx_Extbase_Persistence_QueryInterface $query
+ * @return integer
+ * @api
+ */
+ public function getObjectCountByQuery(Tx_Extbase_Persistence_QueryInterface $query) {
+ return $this->storageBackend->getObjectCountByQuery($query);
+ }
+
+ /**
+ * Returns the object data matching the $query.
+ *
+ * @param Tx_Extbase_Persistence_QueryInterface $query
+ * @return array
+ * @api
+ */
+ public function getObjectDataByQuery(Tx_Extbase_Persistence_QueryInterface $query) {
+ return $this->storageBackend->getObjectDataByQuery($query);
+ }
+
/**
* Returns the (internal) identifier for the object, if it is known to the
* backend. Otherwise NULL is returned.
$columnMap = $this->dataMapper->getDataMap($className)->getColumnMap($propertyName);
$query = $this->queryFactory->create($className);
$query->getQuerySettings()->setReturnRawQueryResult(TRUE);
- $result = $query->matching($query->withUid($object->getUid()))->execute();
- $rows = $result->getRows();
- $currentRow = current(current($rows));
- $fieldValue = $currentRow->getValue($columnMap->getColumnName());
+ $rows = $query->matching($query->withUid($object->getUid()))->execute();
+ $currentRow = current($rows);
+ $fieldValue = $currentRow[$columnMap->getColumnName()];
return $fieldValue;
}
public function getRepositoryClassNames() {
return $this->repositoryClassNames;
}
+
+ /**
+ * Returns the number of records matching the query.
+ *
+ * @param Tx_Extbase_Persistence_QueryInterface $query
+ * @return integer
+ * @api
+ */
+ public function getObjectCountByQuery(Tx_Extbase_Persistence_QueryInterface $query) {
+ return $this->backend->getObjectCountByQuery($query);
+ }
+
+ /**
+ * Returns the object data matching the $query.
+ *
+ * @param Tx_Extbase_Persistence_QueryInterface $query
+ * @return array
+ * @api
+ */
+ public function getObjectDataByQuery(Tx_Extbase_Persistence_QueryInterface $query) {
+ return $this->backend->getObjectDataByQuery($query);
+ }
/**
* Commits new objects and changes to objects in the current persistence
* @param Tx_Extbase_Persistence_RowIteratorInterface $rows
* @return array
*/
- public function map($className, Tx_Extbase_Persistence_RowIteratorInterface $rows) {
+ public function map($className, ARRAY $rows) {
$objects = array();
foreach ($rows as $row) {
$objects[] = $this->mapSingleRow($className, $row);
* @param Tx_Extbase_Persistence_RowInterface $node
* @return object
*/
- protected function mapSingleRow($className, Tx_Extbase_Persistence_RowInterface $row) {
- if ($this->identityMap->hasIdentifier($row->getValue('uid'), $className)) {
- $object = $this->identityMap->getObjectByIdentifier($row->getValue('uid'), $className);
+ protected function mapSingleRow($className, array $row) {
+ if ($this->identityMap->hasIdentifier($row['uid'], $className)) {
+ $object = $this->identityMap->getObjectByIdentifier($row['uid'], $className);
} else {
$object = $this->createEmptyObject($className);
- $this->identityMap->registerObject($object, $row->getValue('uid'));
+ $this->identityMap->registerObject($object, $row['uid']);
$this->thawProperties($object, $row);
$object->_memorizeCleanState();
$this->persistenceSession->registerReconstitutedObject($object);
* @param Tx_Extbase_Persistence_RowInterface $row
* @return void
*/
- protected function thawProperties(Tx_Extbase_DomainObject_DomainObjectInterface $object, Tx_Extbase_Persistence_RowInterface $row) {
+ protected function thawProperties(Tx_Extbase_DomainObject_DomainObjectInterface $object, array $row) {
$className = get_class($object);
$dataMap = $this->getDataMap($className);
$properties = $object->_getProperties();
- $localizedUid = $row->getValue('_LOCALIZED_UID');
+ $localizedUid = $row['_LOCALIZED_UID'];
if ($localizedUid !== NULL) {
$object->_setProperty('uid', $localizedUid);
- $object->_setProperty('_localizationParentUid', $row->getValue('uid'));
+ $object->_setProperty('_localizationParentUid', $row['uid']);
} else {
- $object->_setProperty('uid', $row->getValue('uid'));
+ $object->_setProperty('uid', $row['uid']);
}
unset($properties['uid']);
foreach ($properties as $propertyName => $propertyValue) {
case Tx_Extbase_Persistence_PropertyType::LONG;
case Tx_Extbase_Persistence_PropertyType::DOUBLE;
case Tx_Extbase_Persistence_PropertyType::BOOLEAN;
- if ($row->hasValue($columnName)) {
- $rawPropertyValue = $row->getValue($columnName);
+ if (isset($row[$columnName])) {
+ $rawPropertyValue = $row[$columnName];
$propertyValue = $dataMap->convertFieldValueToPropertyValue($propertyType, $rawPropertyValue);
}
break;
case (Tx_Extbase_Persistence_PropertyType::REFERENCE):
- $propertyValue = $row->getValue($columnName);
+ $propertyValue = $row[$columnName];
if (!is_null($propertyValue)) {
- $fieldValue = $row->getValue($columnName);
+ $fieldValue = $row[$columnName];
$result = $this->fetchRelated($object, $propertyName, $fieldValue);
$propertyValue = $this->mapResultToPropertyValue($object, $propertyName, $result);
}
if (isset($parentKeyFieldName)) {
$query->matching($query->equals($parentKeyFieldName, $parentObject->getUid()));
} else {
- $query->matching($query->equals('uid', t3lib_div::intExplode(',', $fieldValue)));
+ $query->matching($query->in('uid', t3lib_div::intExplode(',', $fieldValue)));
}
} elseif ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
$query = $queryFactory->create($this->getElementType($parentObject, $propertyName));
$source = $this->qomFactory->join(
$left,
$right,
- Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_JOIN_TYPE_INNER,
+ Tx_Extbase_Persistence_QueryInterface::JCR_JOIN_TYPE_INNER,
$joinCondition
);
protected $operator;
/**
- * @var Tx_Extbase_Persistence_QOM_StaticOperandInterface
+ * @var mixed
*/
protected $operand2;
* Constructs this Comparison instance
*
* @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand1
- * @param unknown_type $operator
- * @param Tx_Extbase_Persistence_QOM_StaticOperandInterface $operand2
+ * @param int $operator one of Tx_Extbase_Persistence_QueryInterface.OPERATOR_*
+ * @param mixed $operand2
*/
- public function __construct(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand1, $operator, Tx_Extbase_Persistence_QOM_StaticOperandInterface $operand2) {
+ public function __construct(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand1, $operator, $operand2) {
$this->operand1 = $operand1;
$this->operator = $operator;
$this->operand2 = $operand2;
}
- /**
- * Fills an array with the names of all bound variables in the operand
- *
- * @param array &$boundVariables
- * @return void
- */
- public function collectBoundVariableNames(&$boundVariables) {
- $this->operand2->collectBoundVariablenames($boundVariables);
- }
-
/**
*
* Gets the first operand.
/**
* Gets the second operand.
*
- * @return Tx_Extbase_Persistence_QOM_StaticOperandInterface the operand; non-null
+ * @return mixed the operand; non-null
*/
public function getOperand2() {
return $this->operand2;
--- /dev/null
+<?php
+/***************************************************************
+* Copyright notice
+*
+* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+* All rights reserved
+*
+* This class is a backport of the corresponding class of FLOW3.
+* All credits go to the v5 team.
+*
+* This script is part of the TYPO3 project. The TYPO3 project is
+* free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* The GNU General Public License can be found at
+* http://www.gnu.org/copyleft/gpl.html.
+*
+* This script is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Base class for constraints in the QOM.
+ *
+ * @version $Id: Constraint.php 3616 2010-01-13 16:30:32Z k-fish $
+ * @api
+ * @scope prototype
+ */
+class Constraint {}
+
+?>
\ No newline at end of file
return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_EquiJoinCondition', $selector1Name, $property1Name, $selector2Name, $property2Name);
}
- /**
- * Tests whether a first selector's node is the same as a node identified by relative path from a second selector's node.
- *
- * @param string $selector1Name the name of the first selector; non-null
- * @param string $selector2Name the name of the second selector; non-null
- * @param string $selector2Path the path relative to the second selector; non-null
- * @return Tx_Extbase_Persistence_QOM_SameNodeJoinConditionInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function sameNodeJoinCondition($selector1Name, $selector2Name, $selector2Path = NULL) {
- throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058190);
- }
-
- /**
- * Tests whether a first selector's node is a child of a second selector's node.
- *
- * @param string $childSelectorName the name of the child selector; non-null
- * @param string $parentSelectorName the name of the parent selector; non-null
- * @return Tx_Extbase_Persistence_QOM_ChildNodeJoinConditionInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function childNodeJoinCondition($childSelectorName, $parentSelectorName) {
- throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058190);
- }
-
- /**
- * Tests whether a first selector's node is a descendant of a second selector's node.
- *
- * @param string $descendantSelectorName the name of the descendant selector; non-null
- * @param string $ancestorSelectorName the name of the ancestor selector; non-null
- * @return Tx_Extbase_Persistence_QOM_DescendantNodeJoinConditionInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function descendantNodeJoinCondition($descendantSelectorName, $ancestorSelectorName) {
- throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058192);
- }
-
/**
* Performs a logical conjunction of two other constraints.
*
public function not(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint) {
return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_LogicalNot', $constraint);
}
-
- /**
- * Filters related node-tuples based on an object property.
- *
- * @param Tx_Extbase_DomainObject_AbstractEntity $object The object
- * @param string $propertyName The name of the property of the related object
- * @return Tx_Extbase_Persistence_QOM_RelatedInterface the constraint; non-null
- */
- public function related(Tx_Extbase_DomainObject_AbstractEntity $object, $propertyName) {
- return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Related', $object, $propertyName);
- }
-
+
/**
* Filters node-tuples based on the outcome of a binary operation.
*
* @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
* @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
*/
- public function comparison(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand1, $operator, Tx_Extbase_Persistence_QOM_StaticOperandInterface $operand2) {
+ public function comparison(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand1, $operator, $operand2) {
return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Comparison', $operand1, $operator, $operand2);
}
-
- /**
- * Tests the existence of a property in the specified or default selector.
- *
- * @param string $propertyName the property name; non-null
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_PropertyExistenceInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function propertyExistence($propertyName, $selectorName = NULL) {
- throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058196);
- }
-
- /**
- * Performs a full-text search against the specified or default selector.
- *
- * @param string $propertyName the property name, or null to search all full-text indexed properties of the node (or node subgraph, in some implementations);
- * @param string $fullTextSearchExpression the full-text search expression; non-null
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_FullTextSearchInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function fullTextSearch($propertyName, $fullTextSearchExpression, $selectorName = NULL) {
- throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058197);
- }
-
- /**
- * Tests whether a node in the specified or default selector is reachable by a specified absolute path.
- *
- * @param string $selectorName the selector name; non-null
- * @param string $path an absolute path; non-null
- * @return Tx_Extbase_Persistence_QOM_SameNodeInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function sameNode($path, $selectorName = NULL) {
- throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058198);
- }
-
- /**
- * Tests whether a node in the specified or default selector is a child of a node reachable by a specified absolute path.
- *
- * @param string $path an absolute path; non-null
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_ChildNodeInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function childNode($path, $selectorName = NULL) {
- throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058199);
- }
-
- /**
- * Tests whether a node in the specified or default selector is a descendant of a node reachable by a specified absolute path.
- *
- * @param string $path an absolute path; non-null
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_DescendantNodeInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function descendantNode($path, $selectorName = NULL) {
- throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058200);
- }
-
+
/**
* Evaluates to the value (or values, if multi-valued) of a property in the specified or default selector.
*
public function propertyValue($propertyName, $selectorName = '') {
return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_PropertyValue', $propertyName, $selectorName);
}
-
- /**
- * Evaluates to the length (or lengths, if multi-valued) of a property.
- *
- * @param Tx_Extbase_Persistence_QOM_PropertyValueInterface $propertyValue the property value for which to compute the length; non-null
- * @return Tx_Extbase_Persistence_QOM_LengthInterface the operand; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function length(Tx_Extbase_Persistence_QOM_PropertyValueInterface $propertyValue) {
- throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058202);
- }
-
- /**
- * Evaluates to a NAME value equal to the prefix-qualified name of a node in the specified or default selector.
- *
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_NodeNameInterface the operand; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function nodeName($selectorName = NULL) {
- throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058203);
- }
-
- /**
- * Evaluates to a NAME value equal to the local (unprefixed) name of a node in the specified or default selector.
- *
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_NodeLocalNameInterface the operand; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function nodeLocalName($selectorName = NULL) {
- throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058204);
- }
-
- /**
- * Evaluates to a DOUBLE value equal to the full-text search score of a node in the specified or default selector.
- *
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_FullTextSearchScoreInterface the operand; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function fullTextSearchScore($selectorName = NULL) {
- throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058205);
- }
-
+
/**
* Evaluates to the lower-case string value (or values, if multi-valued) of an operand.
*
public function upperCase(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_UpperCase', $operand);
}
-
- /**
- * Evaluates to the value of a bind variable.
- *
- * @param string $bindVariableName the bind variable name; non-null
- * @return Tx_Extbase_Persistence_QOM_BindVariableValueInterface the operand; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function bindVariable($bindVariableName) {
- return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_BindVariableValue', $bindVariableName);
- }
-
- /**
- * Evaluates to a literal value.
- *
- * The query is invalid if no value is bound to $literalValue.
- *
- * @param \F3\PHPCR\ValueInterface $literalValue the value
- * @return \F3\PHPCR\ValueInterface the operand; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function literal(Tx_Extbase_Persistence_ValueInterface $literalValue) {
- throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058209);
- }
-
+
/**
* Orders by the value of the specified operand, in ascending order.
*
public function descending(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Ordering', $operand, Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING);
}
-
+
/**
- * Identifies a property in the specified or default selector to include in
- * the tabular view of query results.
- * The column name is the property name if not given.
- *
- * The query is invalid if:
- * $selectorName is not the name of a selector in the query, or
- * $propertyName is specified but it is not a syntactically valid JCR name, or
- * $propertyName is specified but does not evaluate to a scalar value, or
- * $propertyName is specified but $columnName is omitted, or
- * $propertyName is omitted but $columnName is specified, or
- * the columns in the tabular view are not uniquely named, whether those
- * column names are specified by $columnName (if $propertyName is specified)
- * or generated as described above (if $propertyName is omitted).
- *
- * If $propertyName is specified but, for a node-tuple, the selector node
- * does not have a property named $propertyName, the query is valid and the
- * column has null value.
+ * Evaluates to the value of a bind variable.
*
- * @param string $propertyName the property name, or null to include a column for each single-value non-residual property of the selector's node type
- * @param string $columnName the column name; must be null if propertyName is null
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_ColumnInterface the column; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query has no default selector or is otherwise invalid
+ * @param string $bindVariableName the bind variable name; non-null
+ * @return Tx_Extbase_Persistence_QOM_BindVariableValueInterface the operand; non-null
+ * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
* @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
*/
- public function column($propertyName, $columnName = NULL, $selectorName = NULL) {
- throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058211);
+ public function bindVariable($bindVariableName) {
+ return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_BindVariableValue', $bindVariableName);
}
-
+
}
?>
*/
interface Tx_Extbase_Persistence_QOM_QueryObjectModelFactoryInterface extends Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface {
- /**
- * Creates a query with one or more selectors.
- * If source is a selector, that selector is the default selector of the
- * query. Otherwise the query does not have a default selector.
- *
- * If the query is invalid, this method throws an InvalidQueryException.
- * See the individual QOM factory methods for the validity criteria of each
- * query element.
- *
- * @param mixed $source the Selector or the node-tuple Source; non-null
- * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint the constraint, or null if none
- * @param array $orderings zero or more orderings; null is equivalent to a zero-length array
- * @param array $columns the columns; null is equivalent to a zero-length array
- * @return Tx_Extbase_Persistence_QOM_QueryObjectModelInterface the query; non-null
- */
- public function createQuery(Tx_Extbase_Persistence_QOM_SourceInterface $selectorOrSource, $constraint, array $orderings, array $columns);
-
- /**
- * Selects a subset of the nodes in the repository based on node type.
- *
- * The query is invalid if $nodeTypeName or $selectorName is not a
- * syntactically valid JCR name.
- *
- * The query is invalid if $selectorName is identical to the name of another
- * selector in the query.
- *
- * If $nodeTypeName is a valid JCR name but not the name of a node type
- * available in the repository, the query is valid but the selector selects
- * no nodes.
- *
- * @param string $nodeTypeName the name of the required node type; non-null
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_SelectorInterface the selector; non-null
- */
- public function selector($nodeTypeName, $selectorName = NULL);
-
- /**
- * Performs a join between two node-tuple sources.
- *
- * The query is invalid if $left is the same source as $right.
- *
- * @param Tx_Extbase_Persistence_QOM_SourceInterface $left the left node-tuple source; non-null
- * @param Tx_Extbase_Persistence_QOM_SourceInterface $right the right node-tuple source; non-null
- * @param string $joinType one of QueryObjectModelConstants.JCR_JOIN_TYPE_*
- * @param Tx_Extbase_Persistence_QOM_JoinConditionInterface $join Condition the join condition; non-null
- * @return Tx_Extbase_Persistence_QOM_JoinInterface the join; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function join(Tx_Extbase_Persistence_QOM_SourceInterface $left, Tx_Extbase_Persistence_QOM_SourceInterface $right, $joinType, Tx_Extbase_Persistence_QOM_JoinConditionInterface $joinCondition);
-
- /**
- * Tests whether the value of a property in a first selector is equal to the
- * value of a property in a second selector.
- *
- * The query is invalid if:
- * * $selector1 is not the name of a selector in the query, or
- * * $selector2 is not the name of a selector in the query, or
- * * $selector1 is the same as $selector2, or
- * * $property1 is not a syntactically valid JCR name, or
- * * $property2 is not a syntactically valid JCR name, or
- * * the value of $property1 is not the same property type as the value of
- * $property2, or
- * * $property1 is a multi-valued property, or
- * * $property2 is a multi-valued property, or
- * * $property1 is a BINARY property, or
- * * $property2 is a BINARY property.
- *
- * @param string $selector1Name the name of the first selector; non-null
- * @param string $property1Name the property name in the first selector; non-null
- * @param string $selector2Name the name of the second selector; non-null
- * @param string $property2Name the property name in the second selector; non-null
- * @return Tx_Extbase_Persistence_QOM_EquiJoinConditionInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function equiJoinCondition($selector1Name, $property1Name, $selector2Name, $property2Name);
-
- /**
- * Tests whether a first selector's node is the same as a node identified by
- * relative path from a second selector's node.
- *
- * The query is invalid if:
- * * $selector1 is not the name of a selector in the query, or
- * * $selector2 is not the name of a selector in the query, or
- * * $selector1 is the same as $selector2, or
- * * $selector2Path is not a syntactically valid relative path. Note, however,
- * that if the path is syntactically valid but does not identify a node
- * visible to the current session, the query is valid but the constraint
- * is not satisfied.
- *
- * @param string $selector1Name the name of the first selector; non-null
- * @param string $selector2Name the name of the second selector; non-null
- * @param string $selector2Path the path relative to the second selector; non-null
- * @return Tx_Extbase_Persistence_QOM_SameNodeJoinConditionInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function sameNodeJoinCondition($selector1Name, $selector2Name, $selector2Path = NULL);
-
- /**
- * Tests whether a first selector's node is a child of a second selector's node.
- *
- * The query is invalid if:
- * $childSelector is not the name of a selector in the query, or
- * $parentSelector is not the name of a selector in the query, or
- * $childSelector is the same as $parentSelector.
- *
- * @param string $childSelectorName the name of the child selector; non-null
- * @param string $parentSelectorName the name of the parent selector; non-null
- * @return Tx_Extbase_Persistence_QOM_ChildNodeJoinConditionInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function childNodeJoinCondition($childSelectorName, $parentSelectorName);
-
- /**
- * Tests whether a first selector's node is a descendant of a second selector's node.
- *
- * The query is invalid if:
- * $descendantSelector is not the name of a selector in the query, or
- * $ancestorSelector is not the name of a selector in the query, or
- * $descendantSelector is the same as $ancestorSelector.
- *
- * @param string $descendantSelectorName the name of the descendant selector; non-null
- * @param string $ancestorSelectorName the name of the ancestor selector; non-null
- * @return Tx_Extbase_Persistence_QOM_DescendantNodeJoinConditionInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function descendantNodeJoinCondition($descendantSelectorName, $ancestorSelectorName);
-
- /**
- * Performs a logical conjunction of two other constraints.
- *
- * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1 the first constraint; non-null
- * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2 the second constraint; non-null
- * @return Tx_Extbase_Persistence_QOM_AndInterface the And constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function _and(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1, Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2);
-
- /**
- * Performs a logical disjunction of two other constraints.
- *
- * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1 the first constraint; non-null
- * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2 the second constraint; non-null
- * @return Tx_Extbase_Persistence_QOM_OrInterface the Or constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function _or(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint1, Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint2);
-
- /**
- * Performs a logical negation of another constraint.
- *
- * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint the constraint to be negated; non-null
- * @return Tx_Extbase_Persistence_QOM_NotInterface the Not constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function not(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint);
-
- /**
- * Filters node-tuples based on the outcome of a binary operation.
- *
- * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand1 the first operand; non-null
- * @param string $operator the operator; one of QueryObjectModelConstants.JCR_OPERATOR_*
- * @param Tx_Extbase_Persistence_QOM_StaticOperandInterface $operand2 the second operand; non-null
- * @return Tx_Extbase_Persistence_QOM_ComparisonInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function comparison(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand1, $operator, Tx_Extbase_Persistence_QOM_StaticOperandInterface $operand2);
-
- /**
- * Tests the existence of a property in the specified or default selector.
- *
- * The query is invalid if:
- *
- * $propertyName is not a syntactically valid JCR name, or
- * $selectorName is not the name of a selector in the query.
- *
- * @param string $propertyName the property name; non-null
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_PropertyExistenceInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function propertyExistence($propertyName, $selectorName = NULL);
-
- /**
- * Performs a full-text search against the specified or default selector.
- *
- * The query is invalid if:
- * $selectorName is not the name of a selector in the query, or
- * $propertyName is specified but is not a syntactically valid JCR name, or
- * $fullTextSearchExpression does not conform to the full text search grammar.
- *
- * If $propertyName is specified but, for a node-tuple, the selector node
- * does not have a property named $propertyName, the query is valid but the
- * constraint is not satisfied.
- *
- * @param string $propertyName the property name, or null to search all full-text indexed properties of the node (or node subgraph, in some implementations);
- * @param string $fullTextSearchExpression the full-text search expression; non-null
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_FullTextSearchInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function fullTextSearch($propertyName, $fullTextSearchExpression, $selectorName = NULL);
-
- /**
- * Tests whether a node in the specified or default selector is reachable by
- * a specified absolute path.
- *
- * The query is invalid if:
- * $selectorName is not the name of a selector in the query, or
- * $path is not a syntactically valid absolute path. Note,
- * however, that if the path is syntactically valid but does not identify a
- * node in the repository (or the node is not visible to this session,
- * because of access control constraints), the query is valid but the
- * constraint is not satisfied.
- *
- * @param string $selectorName the selector name; non-null
- * @param string $path an absolute path; non-null
- * @return Tx_Extbase_Persistence_QOM_SameNodeInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function sameNode($path, $selectorName = NULL);
-
- /**
- * Tests whether a node in the specified or default selector is a child of a
- * node reachable by a specified absolute path.
- *
- * The query is invalid if:
- * $selectorName is not the name of a selector in the query, or
- * $path is not a syntactically valid absolute path. Note,
- * however, that if the path is syntactically valid but does not identify a
- * node in the repository (or the node is not visible to this session,
- * because of access control constraints), the query is valid but the
- * constraint is not satisfied.
- *
- * @param string $path an absolute path; non-null
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_ChildNodeInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function childNode($path, $selectorName = NULL);
-
- /**
- * Tests whether a node in the specified or default selector is a descendant
- * of a node reachable by a specified absolute path.
- *
- * The query is invalid if:
- * $selectorName is not the name of a selector in the query, or
- * $path is not a syntactically valid absolute path. Note,
- * however, that if the path is syntactically valid but does not identify a
- * node in the repository (or the node is not visible to this session,
- * because of access control constraints), the query is valid but the
- * constraint is not satisfied.
- *
- * @param string $path an absolute path; non-null
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_DescendantNodeInterface the constraint; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function descendantNode($path, $selectorName = NULL);
-
- /**
- * Evaluates to the value (or values, if multi-valued) of a property in the
- * specified or default selector.
- *
- * The query is invalid if:
- * $selectorName is not the name of a selector in the query, or
- * $propertyName is not a syntactically valid JCR name.
- *
- * @param string $propertyName the property name; non-null
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_PropertyValueInterface the operand; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function propertyValue($propertyName, $selectorName = NULL);
-
- /**
- * Evaluates to the length (or lengths, if multi-valued) of a property.
- *
- * @param Tx_Extbase_Persistence_QOM_PropertyValueInterface $propertyValue the property value for which to compute the length; non-null
- * @return Tx_Extbase_Persistence_QOM_LengthInterface the operand; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function length(Tx_Extbase_Persistence_QOM_PropertyValueInterface $propertyValue);
-
- /**
- * Evaluates to a NAME value equal to the prefix-qualified name of a node in
- * the specified or default selector.
- *
- * The query is invalid if $selectorName is not the name of a selector in
- * the query.
- *
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_NodeNameInterface the operand; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function nodeName($selectorName = NULL);
-
- /**
- * Evaluates to a NAME value equal to the local (unprefixed) name of a node in the specified or default selector.
- *
- * The query is invalid if $selectorName is not the name of a selector in
- * the query.
- *
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_NodeLocalNameInterface the operand; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function nodeLocalName($selectorName = NULL);
-
- /**
- * Evaluates to a DOUBLE value equal to the full-text search score of a node in the specified or default selector.
- *
- * The query is invalid if $selectorName is not the name of a selector in
- * the query.
- *
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_FullTextSearchScoreInterface the operand; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function fullTextSearchScore($selectorName = NULL);
-
- /**
- * Evaluates to the lower-case string value (or values, if multi-valued) of an operand.
- *
- * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand whose value is converted to a lower-case string; non-null
- * @return Tx_Extbase_Persistence_QOM_LowerCaseInterface the operand; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function lowerCase(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand);
-
- /**
- * Evaluates to the upper-case string value (or values, if multi-valued) of an operand.
- *
- * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand whose value is converted to a upper-case string; non-null
- * @return Tx_Extbase_Persistence_QOM_UpperCaseInterface the operand; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function upperCase(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand);
-
- /**
- * Evaluates to the value of a bind variable.
- *
- * The query is invalid if $bindVariableName is not a valid JCR prefix.
- *
- * @param string $bindVariableName the bind variable name; non-null
- * @return Tx_Extbase_Persistence_QOM_BindVariableValueInterface the operand; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function bindVariable($bindVariableName);
-
- /**
- * Evaluates to a literal value.
- *
- * The query is invalid if no value is bound to $literalValue.
- *
- * @param \F3\PHPCR\ValueInterface $literalValue the value
- * @return \F3\PHPCR\ValueInterface the operand; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test (and not leave it until later) on createQuery, and the parameters given fail that test
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function literal(Tx_Extbase_Persistence_ValueInterface $literalValue);
-
- /**
- * Orders by the value of the specified operand, in ascending order.
- *
- * The query is invalid if $operand does not evaluate to a scalar value.
- *
- * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand by which to order; non-null
- * @return Tx_Extbase_Persistence_QOM_OrderingInterface the ordering
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function ascending(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand);
-
- /**
- * Orders by the value of the specified operand, in descending order.
- *
- * The query is invalid if $operand does not evaluate to a scalar value.
- *
- * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand the operand by which to order; non-null
- * @return Tx_Extbase_Persistence_QOM_OrderingInterface the ordering
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query is invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function descending(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand);
-
- /**
- * Identifies a property in the specified or default selector to include in
- * the tabular view of query results.
- * The column name is the property name if not given.
- *
- * The query is invalid if:
- * $selectorName is not the name of a selector in the query, or
- * $propertyName is specified but it is not a syntactically valid JCR name, or
- * $propertyName is specified but does not evaluate to a scalar value, or
- * $propertyName is specified but $columnName is omitted, or
- * $propertyName is omitted but $columnName is specified, or
- * the columns in the tabular view are not uniquely named, whether those
- * column names are specified by $columnName (if $propertyName is specified)
- * or generated as described above (if $propertyName is omitted).
- *
- * If $propertyName is specified but, for a node-tuple, the selector node
- * does not have a property named $propertyName, the query is valid and the
- * column has null value.
- *
- * @param string $propertyName the property name, or null to include a column for each single-value non-residual property of the selector's node type
- * @param string $columnName the column name; must be null if propertyName is null
- * @param string $selectorName the selector name; non-null
- * @return Tx_Extbase_Persistence_QOM_ColumnInterface the column; non-null
- * @throws \F3\PHPCR\Query\InvalidQueryException if the query has no default selector or is otherwise invalid
- * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
- */
- public function column($propertyName, $columnName = NULL, $selectorName = NULL);
}
protected $dataMapper;
/**
- * @var Tx_Extbase_Persistence_QOM_QueryObjectModelFactoryInterface
+ * @var Tx_Extbase_Persistence_Manager
*/
- protected $QOMFactory;
+ protected $persistenceManager;
/**
- * @var Tx_Extbase_Persistence_ValueFactoryInterface
+ * @var Tx_Extbase_Persistence_QOM_QueryObjectModelFactoryInterface
*/
- protected $valueFactory;
+ protected $qomFactory;
/**
- * @var Tx_Extbase_Persistence_ManagerInterface
+ * @var Tx_Extbase_Persistence_ValueFactoryInterface
*/
- protected $persistenceManager;
+ protected $valueFactory;
/**
* @var Tx_Extbase_Persistence_QOM_SourceInterface
*/
public function injectPersistenceManager(Tx_Extbase_Persistence_ManagerInterface $persistenceManager) {
$this->persistenceManager = $persistenceManager;
- $this->QOMFactory = $this->persistenceManager->getBackend()->getQOMFactory();
+ $this->qomFactory = $this->persistenceManager->getBackend()->getQomFactory();
$this->valueFactory = $this->persistenceManager->getBackend()->getValueFactory();
}
/**
* Returns the Query Settings.
- *
+ *
* @return Tx_Extbase_Persistence_QuerySettingsInterface $querySettings The Query Settings
- * @api
*/
public function getQuerySettings() {
+ if (!($this->querySettings instanceof Tx_Extbase_Persistence_QuerySettingsInterface)) throw new Tx_Extbase_Persistence_Exception('Tried to get the query settings without seting them before.', 1248689115);
return $this->querySettings;
}
public function setSource(Tx_Extbase_Persistence_QOM_SourceInterface $source) {
$this->source = $source;
}
+
+ /**
+ * Returns the selectorn name or an empty string, if the source is not a selector
+ * // TODO This has to be checked at another place
+ * @return string The selector name
+ */
+ protected function getSelectorName() {
+ if ($this->getSource() instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
+ return $this->source->getSelectorName();
+ } else {
+ return '';
+ }
+ }
+
+ /**
+ * Gets the node-tuple source for this query.
+ *
+ * @return Tx_Extbase_Persistence_QOM_SourceInterface the node-tuple source; non-null
+ */
+ public function getSource() {
+ if ($this->source === NULL) {
+ $this->source = $this->qomFactory->selector($this->className, $this->dataMapper->convertClassNameToTableName($this->className));
+ }
+ return $this->source;
+ }
/**
* Executes the query against the database and returns the result
* @api
*/
public function execute() {
- $result = $this->getPreparedQueryObjectModel()->execute();
+ $rows = $this->persistenceManager->getObjectDataByQuery($this);
if ($this->getQuerySettings()->getReturnRawQueryResult() === TRUE) {
- return $result;
+ return $rows;
} else {
- return $this->dataMapper->map($this->className, $result->getRows());
+ return $this->dataMapper->map($this->className, $rows);
}
}
/**
- * Executes the query against the database and returns the number of matching objects
+ * Executes the number of matching objects for the query
*
* @return integer The number of matching objects
* @api
*/
public function count() {
- return $this->getPreparedQueryObjectModel()->count();
+ return $this->persistenceManager->getObjectCountByQuery($this);
}
/**
*/
protected function getPreparedQueryObjectModel() {
if ($this->source === NULL) {
- $this->source = $this->QOMFactory->selector($this->className, $this->dataMapper->convertClassNameToTableName($this->className));
+ $this->source = $this->qomFactory->selector($this->className, $this->dataMapper->convertClassNameToTableName($this->className));
}
if ($this->constraint instanceof Tx_Extbase_Persistence_QOM_StatementInterface) {
- $query = $this->QOMFactory->createQuery(
+ $query = $this->qomFactory->createQuery(
$this->source,
$this->constraint,
array(),
array()
);
} else {
- $query = $this->QOMFactory->createQuery(
+ $query = $this->qomFactory->createQuery(
$this->source,
$this->constraint,
$this->orderings,
$parsedOrderings = array();
foreach ($orderings as $propertyName => $order) {
if ($order === Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING) {
- $parsedOrderings[] = $this->QOMFactory->descending($this->QOMFactory->propertyValue($propertyName));
+ $parsedOrderings[] = $this->qomFactory->descending($this->qomFactory->propertyValue($propertyName));
} elseif ($order === Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING) {
- $parsedOrderings[] = $this->QOMFactory->ascending($this->QOMFactory->propertyValue($propertyName));
+ $parsedOrderings[] = $this->qomFactory->ascending($this->qomFactory->propertyValue($propertyName));
} else {
throw new Tx_Extbase_Persistence_Exception_UnsupportedOrder('The order you specified for your query is not supported.', 1253785630);
}
$this->orderings = $parsedOrderings;
return $this;
}
+
+ /**
+ * Returns the property names to order the result by. Like this:
+ * array(
+ * 'foo' => \F3\FLOW3\Persistence\QueryInterface::ORDER_ASCENDING,
+ * 'bar' => \F3\FLOW3\Persistence\QueryInterface::ORDER_DESCENDING
+ * )
+ *
+ * @return array
+ * @api
+ */
+ public function getOrderings() {
+ return $this->orderings;
+ }
/**
* Sets the maximum size of the result set to limit. Returns $this to allow
return $this;
}
+ /**
+ * Returns the maximum size of the result set to limit.
+ *
+ * @param integer
+ * @api
+ */
+ public function getLimit() {
+ return $this->limit;
+ }
+
/**
* Sets the start offset of the result set to offset. Returns $this to
* allow for chaining (fluid interface)
return $this;
}
+ /**
+ * Returns the start offset of the result set.
+ *
+ * @return integer
+ * @api
+ */
+ public function getOffset() {
+ return $this->offset;
+ }
+
/**
* The constraint used to limit the result set. Returns $this to allow
* for chaining (fluid interface)
* @return Tx_Extbase_Persistence_QOM_StatementInterface
*/
public function statement($statement, array $parameters = array(), $language = Tx_Extbase_Persistence_QOM_QueryObjectModelInterface::TYPO3_SQL_MYSQL) {
- $boundVariables = array();
- foreach ($parameters as $parameter) {
- $uniqueVariableName = uniqid();
- $this->operands[$uniqueVariableName] = $parameter;
- $boundVariables[$uniqueVariableName] = $this->QOMFactory->bindVariable($uniqueVariableName);
- }
- $this->constraint = $this->QOMFactory->statement($statement, $boundVariables, $language);
+ $this->constraint = $this->qomFactory->statement($statement, $parameters, $language);
return $this;
}
+
+ /**
+ * Gets the constraint for this query.
+ *
+ * @return Tx_Extbase_Persistence_QOM_Constraint the constraint, or null if none
+ * @author Karsten Dambekalns <karsten@typo3.org>
+ * @api
+ */
+ public function getConstraint() {
+ return $this->constraint;
+ }
/**
* Performs a logical conjunction of the two given constraints.
* @api
*/
public function logicalAnd($constraint1, $constraint2) {
- return $this->QOMFactory->_and(
+ return $this->qomFactory->_and(
$constraint1,
$constraint2
);
* @api
*/
public function logicalOr($constraint1, $constraint2) {
- return $this->QOMFactory->_or(
+ return $this->qomFactory->_or(
$constraint1,
$constraint2
);
* @api
*/
public function logicalNot($constraint) {
- return $this->QOMFactory->not($constraint);
+ return $this->qomFactory->not($constraint);
}
/**
* @return Tx_Extbase_Persistence_QOM_ComparisonInterface
* @api
*/
- public function withUid($uid) {
- $uniqueVariableName = $this->getUniqueVariableName('uid');
- $this->operands[$uniqueVariableName] = $uid;
- return $this->QOMFactory->comparison(
- $this->QOMFactory->propertyValue('uid', $this->getSelectorName()),
- Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO,
- $this->QOMFactory->bindVariable($uniqueVariableName)
+ public function withUid($operand) {
+ return $this->qomFactory->comparison(
+ $this->qomFactory->propertyValue('uid', $this->getSelectorName()),
+ Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO,
+ $operand
);
}
* @return Tx_Extbase_Persistence_QOM_ComparisonInterface
*/
public function equals($propertyName, $operand, $caseSensitive = TRUE) {
- $uniqueVariableName = uniqid($propertyName);
- if (is_object($operand) && !($operand instanceof DateTime)) {
- $operand = $this->persistenceManager->getBackend()->getIdentifierByObject($operand);
- }
- if ($caseSensitive) {
- $comparison = $this->QOMFactory->comparison(
- $this->QOMFactory->propertyValue($propertyName, $this->getSelectorName()),
- Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO,
- $this->QOMFactory->bindVariable($uniqueVariableName)
- );
+ if (is_object($operand) || $caseSensitive) {
+ $comparison = $this->qomFactory->comparison(
+ $this->qomFactory->propertyValue($propertyName, $this->getSelectorName()),
+ Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO,
+ $operand
+ );
} else {
- $comparison = $this->QOMFactory->comparison(
- $this->QOMFactory->lowerCase(
- $this->QOMFactory->propertyValue($propertyName, $this->getSelectorName())
+ $comparison = $this->qomFactory->comparison(
+ $this->qomFactory->lowerCase(
+ $this->qomFactory->propertyValue($propertyName, $this->getSelectorName())
),
- Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO,
- $this->QOMFactory->bindVariable($uniqueVariableName)
- );
- }
-
- // TODO Implement case sensitivity for arrays (callback)
- if ($caseSensitive || !is_string($operand)) {
- $this->operands[$uniqueVariableName] = $operand;
- } else {
- $this->operands[$uniqueVariableName] = strtolower($operand);
+ Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO,
+ strtolower($operand)
+ );
}
return $comparison;
* @return Tx_Extbase_Persistence_QOM_ComparisonInterface
*/
public function like($propertyName, $operand) {
- $uniqueVariableName = uniqid($propertyName);
- $this->operands[$uniqueVariableName] = $operand;
- return $this->QOMFactory->comparison(
- $this->QOMFactory->propertyValue($propertyName, $this->getSelectorName()),
- Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_LIKE,
- $this->QOMFactory->bindVariable($uniqueVariableName)
+ return $this->qomFactory->comparison(
+ $this->qomFactory->propertyValue($propertyName, $this->getSelectorName()),
+ Tx_Extbase_Persistence_QueryInterface::OPERATOR_LIKE,
+ $operand
);
}
+
+ /**
+ * Returns a "contains" criterion used for matching objects against a query.
+ * It matches if the multivalued property contains the given operand.
+ *
+ * @param string $propertyName The name of the (multivalued) property to compare against
+ * @param mixed $operand The value to compare with
+ * @return Tx_Extbase_Persistence_QOM_ComparisonInterface
+ * @api
+ */
+ public function contains($propertyName, $operand){
+ return $this->qomFactory->comparison(
+ $this->qomFactory->propertyValue($propertyName, $this->getSelectorName()),
+ Tx_Extbase_Persistence_QueryInterface::OPERATOR_CONTAINS,
+ $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
+ * @return Tx_Extbase_Persistence_QOM_ComparisonInterface
+ * @api
+ */
+ public function in($propertyName, $operand) {
+ if (!is_array($operand) && (!$operand instanceof ArrayAccess) && (!$operand instanceof Traversable)) {
+ throw new Tx_Extbase_Persistence_Exception_UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095);
+ }
+
+ return $this->qomFactory->comparison(
+ $this->qomFactory->propertyValue($propertyName, $this->getSelectorName()),
+ Tx_Extbase_Persistence_QueryInterface::OPERATOR_IN,
+ $operand
+ );
+ }
/**
* Returns a less than criterion used for matching objects against a query
* @return Tx_Extbase_Persistence_QOM_ComparisonInterface
*/
public function lessThan($propertyName, $operand) {
- $uniqueVariableName = uniqid($propertyName);
- $this->operands[$uniqueVariableName] = $operand;
- return $this->QOMFactory->comparison(
- $this->QOMFactory->propertyValue($propertyName, $this->getSelectorName()),
- Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_LESS_THAN,
- $this->QOMFactory->bindVariable($uniqueVariableName)
+ return $this->qomFactory->comparison(
+ $this->qomFactory->propertyValue($propertyName, $this->getSelectorName()),
+ Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN,
+ $operand
);
}
* @return Tx_Extbase_Persistence_QOM_ComparisonInterface
*/
public function lessThanOrEqual($propertyName, $operand) {
- $uniqueVariableName = uniqid($propertyName);
- $this->operands[$uniqueVariableName] = $operand;
- return $this->QOMFactory->comparison(
- $this->QOMFactory->propertyValue($propertyName, $this->getSelectorName()),
- Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO,
- $this->QOMFactory->bindVariable($uniqueVariableName)
+ return $this->qomFactory->comparison(
+ $this->qomFactory->propertyValue($propertyName, $this->getSelectorName()),
+ Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO,
+ $operand
);
}
* @return Tx_Extbase_Persistence_QOM_ComparisonInterface
*/
public function greaterThan($propertyName, $operand) {
- $uniqueVariableName = uniqid($propertyName);
- $this->operands[$uniqueVariableName] = $operand;
- return $this->QOMFactory->comparison(
- $this->QOMFactory->propertyValue($propertyName, $this->getSelectorName()),
- Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_GREATER_THAN,
- $this->QOMFactory->bindVariable($uniqueVariableName)
+ return $this->qomFactory->comparison(
+ $this->qomFactory->propertyValue($propertyName, $this->getSelectorName()),
+ Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN,
+ $operand
);
}
* @return Tx_Extbase_Persistence_QOM_ComparisonInterface
*/
public function greaterThanOrEqual($propertyName, $operand) {
- $uniqueVariableName = uniqid($propertyName);
- $this->operands[$uniqueVariableName] = $operand;
- return $this->QOMFactory->comparison(
- $this->QOMFactory->propertyValue($propertyName, $this->getSelectorName()),
- Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO,
- $this->QOMFactory->bindVariable($uniqueVariableName)
+ return $this->qomFactory->comparison(
+ $this->qomFactory->propertyValue($propertyName, $this->getSelectorName()),
+ Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO,
+ $operand
);
}
-
- /**
- * Returns a unique variable name for a given property name. This is necessary for storing
- * the variable values in an associative array without overwriting existing variables.
- *
- * @param string $propertyName The name of the property
- * @return string The postfixed property name
- */
- protected function getUniqueVariableName($propertyName) {
- return uniqid($propertyName);
- }
-
- /**
- * Returns the selectorn name or an empty string, if the source is not a selector
- * // TODO This has to be checked at another place
- * @return string The selector name
- */
- protected function getSelectorName() {
- if ($this->source === NULL) {
- $this->source = $this->QOMFactory->selector($this->className, $this->dataMapper->convertClassNameToTableName($this->className));
- }
- if ($this->source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
- return $this->source->getSelectorName();
- } else {
- return '';
- }
- }
-
+
}
?>
\ No newline at end of file
*/
interface Tx_Extbase_Persistence_QueryInterface {
+ /**
+ * The '=' comparison operator.
+ * @api
+ */
+ const OPERATOR_EQUAL_TO = 1;
+
+ /**
+ * The '!=' comparison operator.
+ * @api
+ */
+ const OPERATOR_NOT_EQUAL_TO = 2;
+
+ /**
+ * The '<' comparison operator.
+ * @api
+ */
+ const OPERATOR_LESS_THAN = 3;
+
+ /**
+ * The '<=' comparison operator.
+ * @api
+ */
+ const OPERATOR_LESS_THAN_OR_EQUAL_TO = 4;
+
+ /**
+ * The '>' comparison operator.
+ * @api
+ */
+ const OPERATOR_GREATER_THAN = 5;
+
+ /**
+ * The '>=' comparison operator.
+ * @api
+ */
+ const OPERATOR_GREATER_THAN_OR_EQUAL_TO = 6;
+
+ /**
+ * The 'like' comparison operator.
+ * @api
+ */
+ const OPERATOR_LIKE = 7;
+
+ /**
+ * The 'contains' comparison operator.
+ * @api
+ */
+ const OPERATOR_CONTAINS = 8;
+
+ /**
+ * The 'in' comparison operator.
+ * @api
+ */
+ const OPERATOR_IN = 9;
+
/**
* Constants representing the direction when ordering result sets.
*/
const ORDER_ASCENDING = 'ASC';
const ORDER_DESCENDING = 'DESC';
+ /**
+ * An inner join.
+ */
+ const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner';
+
+ /**
+ * A left-outer join.
+ */
+ const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter';
+
+ /**
+ * A right-outer join.
+ */
+ const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter';
+
/**
* Executes the query against the backend and returns the result
*
*/
public function like($propertyName, $operand);
+ /**
+ * Returns a "contains" criterion used for matching objects against a query.
+ * It matches if the multivalued property contains the given operand.
+ *
+ * @param string $propertyName The name of the (multivalued) property to compare against
+ * @param mixed $operand The value to compare with
+ * @return object
+ * @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
+ * @return object
+ * @api
+ */
+ public function in($propertyName, $operand);
+
/**
* Returns a less than criterion used for matching objects against a query
*
public function removeRow($tableName, array $identifier, $isRelation = FALSE);
/**
- * Returns an array with rows matching the query.
+ * Returns the number of items matching the query.
*
- * @param Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query
- * @return array
+ * @param Tx_Extbase_Persistence_QueryInterface $query
+ * @return integer
+ * @api
*/
- public function getRows(Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query);
+ public function getObjectCountByQuery(Tx_Extbase_Persistence_QueryInterface $query);
/**
- * Returns the number of tuples matching the query.
+ * Returns the object data matching the $query.
*
- * @param Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query
- * @return int The number of matching tuples
+ * @param Tx_Extbase_Persistence_QueryInterface $query
+ * @return array
+ * @api
*/
- public function countRows(Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query);
-
+ public function getObjectDataByQuery(Tx_Extbase_Persistence_QueryInterface $query);
+
}
?>
\ No newline at end of file
}
return implode(' AND ', $suffixedFieldNames);
}
-
+
/**
- * Returns an array with tuples matching the query.
+ * Returns the object data matching the $query.
*
- * @param Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query
- * @return array The matching tuples
+ * @param Tx_Extbase_Persistence_QueryInterface $query
+ * @return array
+ * @author Karsten Dambekalns <karsten@typo3.org>
*/
- public function getRows(Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query) {
+ public function getObjectDataByQuery(Tx_Extbase_Persistence_QueryInterface $query) {
+ $parameters = array();
+ // $this->knownRecords = array();
+
$constraint = $query->getConstraint();
if($constraint instanceof Tx_Extbase_Persistence_QOM_StatementInterface) {
if ($constraint->getLanguage() === Tx_Extbase_Persistence_QOM_QueryObjectModelInterface::TYPO3_SQL_MYSQL) {
- $statement = $constraint->getStatement();
+ $sql = $constraint->getStatement();
$parameters = $query->getBoundVariableValues();
} else {
throw new Tx_Extbase_Persistence_Exception('Unsupported query language.', 1248701951);
}
} else {
$parameters = array();
- $statement = $this->getStatement($query, $parameters);
+ $statementParts = $this->parseQuery($query, $parameters);
+ $sql = $this->buildQuery($statementParts, $parameters);
}
- $this->replacePlaceholders($statement, $parameters);
- // debug($statement,-2);
- $result = $this->databaseHandle->sql_query($statement);
+ $this->replacePlaceholders($sql, $parameters);
+ // debug($sql,-2);
+ $result = $this->databaseHandle->sql_query($sql);
$this->checkSqlErrors();
$rows = $this->getRowsFromResult($query->getSource(), $result);
$rows = $this->doLanguageAndWorkspaceOverlay($query->getSource(), $rows);
+
+ // $objectData = $this->processObjectRecords($statementHandle);
return $rows;
}
* @param Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query
* @return int The number of matching tuples
*/
- public function countRows(Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query) {
+ public function getObjectCountByQuery(Tx_Extbase_Persistence_QueryInterface $query) {
$constraint = $query->getConstraint();
if($constraint instanceof Tx_Extbase_Persistence_QOM_StatementInterface) throw new Tx_Extbase_Persistence_Storage_Exception_BadConstraint('Could not execute count on queries with a constraint of type Tx_Extbase_Persistence_QOM_StatementInterface', 1256661045);
$parameters = array();
$statementParts = $this->parseQuery($query, $parameters);
$statementParts['fields'] = array('COUNT(*)');
- $statement = $this->buildStatement($statementParts, $parameters);
+ $statement = $this->buildQuery($statementParts, $parameters);
$this->replacePlaceholders($statement, $parameters);
+ // debug($sql,-2);
$result = $this->databaseHandle->sql_query($statement);
$this->checkSqlErrors();
$rows = $this->getRowsFromResult($query->getSource(), $result);
return current(current($rows));
}
-
- /**
- * Returns the statement, ready to be executed.
- *
- * @param Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query
- * @return string The SQL statement
- */
- public function getStatement(Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query, array &$parameters) {
- $statementParts = $this->parseQuery($query, $parameters);
- $statement = $this->buildStatement($statementParts);
- return $statement;
- }
-
+
/**
* Parses the query and returns the SQL statement parts.
*
* @param Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query
* @return array The SQL statement parts
*/
- public function parseQuery(Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query, array &$parameters) {
+ public function parseQuery(Tx_Extbase_Persistence_Query $query, array &$parameters) {
$sql = array();
$sql['tables'] = array();
$sql['fields'] = array();
$source = $query->getSource();
$this->parseSource($query, $source, $sql, $parameters);
- $this->parseConstraint($query->getConstraint(), $source, $sql, $parameters, $query->getBoundVariableValues());
+ $this->parseConstraint($query->getConstraint(), $source, $sql, $parameters);
$this->parseOrderings($query->getOrderings(), $source, $sql);
$this->parseLimitAndOffset($query->getLimit(), $query->getOffset(), $sql);
* @param array $sql The SQL statement parts
* @return string The SQL statement
*/
- public function buildStatement(array $sql) {
+ public function buildQuery(array $sql) {
$statement = 'SELECT ' . implode(',', $sql['fields']) . ' FROM ' . implode(' ', $sql['tables']);
if (!empty($sql['where'])) {
$statement .= ' WHERE ' . implode('', $sql['where']);
* @param array &$parameters
* @return void
*/
- protected function parseSource(Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters) {
+ protected function parseSource(Tx_Extbase_Persistence_Query $query, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql) {
if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
$tableName = $source->getSelectorName();
$sql['fields'][] = $tableName . '.*';
* @param array &$sql The query parts
* @return void
*/
- protected function parseJoin(Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query, Tx_Extbase_Persistence_QOM_JoinInterface $join, array &$sql) {
+ protected function parseJoin(Tx_Extbase_Persistence_QueryInterface $query, Tx_Extbase_Persistence_QOM_JoinInterface $join, array &$sql) {
$leftSource = $join->getLeft();
$leftTableName = $leftSource->getSelectorName();
$rightSource = $join->getRight();
* @param array $boundVariableValues The bound variables in the query (key) and their values (value)
* @return void
*/
- protected function parseConstraint(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint = NULL, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters, array $boundVariableValues) {
+ protected function parseConstraint(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint = NULL, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters) {
if ($constraint === NULL) return;
if ($constraint instanceof Tx_Extbase_Persistence_QOM_AndInterface) {
$sql['where'][] = '(';
- $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters, $boundVariableValues);
- $sql['where'][] = ' AND ';
- $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters, $boundVariableValues);
- $sql['where'][] = ')';
- } elseif ($constraint instanceof Tx_Extbase_Persistence_QOM_OrInterface) {
- $sql['where'][] = '(';
- $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters, $boundVariableValues);
- $sql['where'][] = ' OR ';
- $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters, $boundVariableValues);
+ $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters);
+ $sql['where'][] = ' AND ';
+ $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters);
+ $sql['where'][] = ')';
+ } elseif ($constraint instanceof Tx_Extbase_Persistence_QOM_OrInterface) {
+ $sql['where'][] = '(';
+ $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters);
+ $sql['where'][] = ' OR ';
+ $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters);
$sql['where'][] = ')';
} elseif ($constraint instanceof Tx_Extbase_Persistence_QOM_NotInterface) {
$sql['where'][] = 'NOT (';
- $this->parseConstraint($constraint->getConstraint(), $source, $sql, $parameters, $boundVariableValues);
+ $this->parseConstraint($constraint->getConstraint(), $source, $sql, $parameters);
$sql['where'][] = ')';
} elseif ($constraint instanceof Tx_Extbase_Persistence_QOM_ComparisonInterface) {
- $this->parseComparison($constraint, $source, $sql, $parameters, $boundVariableValues);
+ $this->parseComparison($constraint, $source, $sql, $parameters);
} elseif ($constraint instanceof Tx_Extbase_Persistence_QOM_RelatedInterface) {
- $this->parseRelated($constraint, $sql, $parameters, $boundVariableValues);
+ $this->parseRelated($constraint, $sql, $parameters);
}
}
* @param array $boundVariableValues The bound variables in the query and their values
* @return void
*/
- protected function parseComparison(Tx_Extbase_Persistence_QOM_ComparisonInterface $comparison, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters, array $boundVariableValues) {
- if (!($comparison->getOperand2() instanceof Tx_Extbase_Persistence_QOM_BindVariableValueInterface)) throw new Tx_Extbase_Persistence_Exception('Type of operand is not supported', 1247581135);
-
- $value = $boundVariableValues[$comparison->getOperand2()->getBindVariableName()];
+ protected function parseComparison(Tx_Extbase_Persistence_QOM_ComparisonInterface $comparison, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters) {
+ $operand1 = $comparison->getOperand1();
$operator = $comparison->getOperator();
- if ($value === NULL) {
- if ($operator === Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO) {
+ $operand2 = $comparison->getOperand2();
+ if (($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO) && (is_array($operand2) || ($operand2 instanceof ArrayAccess) || ($operand2 instanceof Traversable))) {
+ // FIXME this else branch enables equals() to behave like in(). This behavior is deprecated and will be removed in future. Use in() instead.
+ $operator = Tx_Extbase_Persistence_QueryInterface::OPERATOR_IN;
+ }
+
+ if ($operand2 === NULL) {
+ if ($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO) {
$operator = self::OPERATOR_EQUAL_TO_NULL;
- } elseif ($operator === Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_NOT_EQUAL_TO) {
+ } elseif ($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_NOT_EQUAL_TO) {
$operator = self::OPERATOR_NOT_EQUAL_TO_NULL;
}
- } elseif (is_array($value)) {
- if ($operator === Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO) {
- $operator = self::OPERATOR_IN;
- } elseif ($operator === Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_NOT_EQUAL_TO) {
- $operator = self::OPERATOR_NOT_IN;
- }
}
- $parameters[] = $value;
- $this->parseDynamicOperand($comparison->getOperand1(), $operator, $source, $sql, $parameters);
+ if ($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_IN) {
+ $this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters, NULL, $operand2);
+ $items = array();
+ foreach ($operand2 as $value) {
+ $items[] = $this->getPlainValue($value);
+ }
+ $parameters[] = $items;
+ } elseif ($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_CONTAINS) {
+ $dataMap = $this->dataMapper->getDataMap($source->getNodeTypeName());
+ $columnMap = $dataMap->getColumnMap($operand1->getPropertyName());
+ $typeOfRelation = $columnMap->getTypeOfRelation();
+ if ($typeOfRelation === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
+ $relationTableName = $columnMap->getRelationTableName();
+ $sql['where'][] = 'uid IN (SELECT uid_local FROM ' . $relationTableName . ' WHERE uid_foreign=' . $this->getPlainValue($operand2) . ')';
+ } elseif ($typeOfRelation === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) {
+ $parentKeyFieldName = $columnMap->getParentKeyFieldName();
+ if (isset($parentKeyFieldName)) {
+ $columnName = $this->dataMapper->convertPropertyNameToColumnName($operand1->getPropertyName(), $source->getNodeTypeName());
+ $childTableName = $columnMap->getChildTableName();
+ $sql['where'][] = 'uid=(SELECT ' . $childTableName . '.' . $parentKeyFieldName . ' FROM ' . $childTableName . ' WHERE ' . $childTableName . '.uid=' . $this->getPlainValue($operand2) . ')';
+ } else {
+ $tableName = $operand1->getSelectorName();
+ $statement = '(' . $tableName . '.' . $operand1->getPropertyName() . ' LIKE \'%,' . $this->getPlainValue($operand2) . ',%\'';
+ $statement .= ' OR ' . $tableName . '.' . $operand1->getPropertyName() . ' LIKE \'%,' . $this->getPlainValue($operand2) . '\'';
+ $statement .= ' OR ' . $tableName . '.' . $operand1->getPropertyName() . ' LIKE \'' . $this->getPlainValue($operand2) . ',%\')';
+ $sql['where'][] = $statement;
+ }
+ } else {
+ throw new Tx_Extbase_Persistence_Exception_RepositoryException('Unsupported relation for contains().', 1267832524);
+ }
+ } else {
+ $this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters);
+ $parameters[] = $this->getPlainValue($operand2);
+ }
+ }
+
+ /**
+ * Returns a plain value, i.e. objects are flattened out if possible.
+ *
+ * @param mixed $input
+ * @return mixed
+ */
+ protected function getPlainValue($input) {
+ if ($input instanceof DateTime) {
+ return $input->getTimestamp();
+ } elseif ($input instanceof Tx_Extbase_DomainObject_DomainObjectinterface) {
+ return $input->getUid();
+ } else {
+ return $input;
+ }
}
/**
* @param string $valueFunction an optional SQL function to apply to the operand value
* @return void
*/
- protected function parseDynamicOperand(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand, $operator, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters, $valueFunction = NULL) {
+ protected function parseDynamicOperand(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand, $operator, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters, $valueFunction = NULL, $operand2 = NULL) {
if ($operand instanceof Tx_Extbase_Persistence_QOM_LowerCaseInterface) {
$this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'LOWER');
} elseif ($operand instanceof Tx_Extbase_Persistence_QOM_UpperCaseInterface) {
}
$columnName = $this->dataMapper->convertPropertyNameToColumnName($operand->getPropertyName(), $className);
$operator = $this->resolveOperator($operator);
-
if ($valueFunction === NULL) {
$constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $operator . ' ?';
} else {
case self::OPERATOR_NOT_EQUAL_TO_NULL:
$operator = 'IS NOT';
break;
- case self::OPERATOR_IN:
+ case Tx_Extbase_Persistence_QueryInterface::OPERATOR_IN:
$operator = 'IN';
break;
- case self::OPERATOR_NOT_IN:
- $operator = 'NOT IN';
- break;
- case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO:
+ case Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO:
$operator = '=';
break;
- case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_NOT_EQUAL_TO:
+ case Tx_Extbase_Persistence_QueryInterface::OPERATOR_NOT_EQUAL_TO:
$operator = '!=';
break;
- case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_LESS_THAN:
+ case Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN:
$operator = '<';
break;
- case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO:
+ case Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO:
$operator = '<=';
break;
- case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_GREATER_THAN:
+ case Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN:
$operator = '>';
break;
- case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO:
+ case Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO:
$operator = '>=';
break;
- case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_LIKE:
+ case Tx_Extbase_Persistence_QueryInterface::OPERATOR_LIKE:
$operator = 'LIKE';
break;
default:
if ($markPosition !== FALSE) {
if ($parameter === NULL) {
$parameter = 'NULL';
- } elseif (is_array($parameter)) {
+ } elseif (is_array($parameter) || ($parameter instanceof ArrayAccess) || ($parameter instanceof Traversable)) {
$items = array();
foreach ($parameter as $item) {
$items[] = $this->databaseHandle->fullQuoteStr($item, 'foo');
public function getString() {
if ($this->value === NULL) return NULL;
if (is_array($this->value)) return $this->value;
+ if ($this->value instanceof Tx_Extbase_DomainObject_AbstractDomainObject) {
+ return (string)$this->value->getUid();
+ }
switch ($this->type) {
case Tx_Extbase_Persistence_PropertyType::DATE:
public function providerForBasicComparison() {
return array(
'equal' => array(
- Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO,
+ Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO,
"SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo = 'baz'"
),
'less' => array(
- Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_LESS_THAN,
+ Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN,
"SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo < 'baz'"
),
'less or equal' => array(
- Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO,
+ Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO,
"SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo <= 'baz'"
),
'greater' => array(
- Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_GREATER_THAN,
+ Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN,
"SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo > 'baz'"
),
'greater or equal' => array(
- Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO,
+ Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO,
"SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo >= 'baz'"
),