Commit 276fca1c authored by Alexander Schnitzler's avatar Alexander Schnitzler Committed by Anja Leichsenring
Browse files

[TASK] Resync TYPO3Flow- and Extbase-Persistence

Releases: 6.0
Fixes: #42505
Change-Id: I1d3160013b248afcf0451fbc49bdb68b6bf9c92e
Reviewed-on: http://review.typo3.org/16037
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
parent 34cc2230
<?php
namespace TYPO3\CMS\Extbase\Persistence\Exception;
/* *
* This script belongs to the Extbase framework. *
* *
* This class is a backport of the corresponding class of FLOW3. *
* All credits go to the v5 team. *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */
/**
* An "Invalid Query" Exception
*
* @api
*/
class InvalidQueryException extends \TYPO3\CMS\Extbase\Exception {
}
?>
\ No newline at end of file
<?php
namespace TYPO3\CMS\Extbase\Persistence\Generic\Exception;
/* *
* This script belongs to the Extbase framework. *
* *
* This class is a backport of the corresponding class of FLOW3. *
* All credits go to the v5 team. *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */
/**
* An "NotImplementedException" exception
*/
class NotImplementedException extends \TYPO3\CMS\Extbase\Persistence\Exception {
/**
* @param string $method
*/
public function __construct($method) {
parent::__construct(sprintf('Method %s is not supported by generic persistence"', $method), 1350213237);
}
}
?>
\ No newline at end of file
......@@ -436,7 +436,7 @@ class DataMapper implements \TYPO3\CMS\Core\SingletonInterface {
$childClassName = $this->getType(get_class($parentObject), $propertyName);
$right = $this->qomFactory->selector($childClassName, $columnMap->getChildTableName());
$joinCondition = $this->qomFactory->equiJoinCondition($columnMap->getRelationTableName(), $columnMap->getChildKeyFieldName(), $columnMap->getChildTableName(), 'uid');
$source = $this->qomFactory->join($left, $right, \TYPO3\CMS\Extbase\Persistence\QueryInterface::JCR_JOIN_TYPE_INNER, $joinCondition);
$source = $this->qomFactory->join($left, $right, \TYPO3\CMS\Extbase\Persistence\Generic\Query::JCR_JOIN_TYPE_INNER, $joinCondition);
return $source;
}
......
......@@ -139,10 +139,11 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
*
* @param mixed $identifier
* @param string $objectType
* @param boolean $useLazyLoading Set to TRUE if you want to use lazy loading for this object
* @return object The object for the identifier if it is known, or NULL
* @api
*/
public function getObjectByIdentifier($identifier, $objectType) {
public function getObjectByIdentifier($identifier, $objectType = NULL, $useLazyLoading = FALSE) {
return $this->backend->getObjectByIdentifier($identifier, $objectType);
}
......@@ -181,6 +182,129 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
}
}
/**
* Adds an object to the persistence.
*
* @param object $object The object to add
* @return void
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
* @api
*/
public function add($object) {
throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
}
/**
* Removes an object to the persistence.
*
* @param object $object The object to remove
* @return void
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
* @api
*/
public function remove($object) {
throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
}
/**
* Update an object in the persistence.
*
* @param object $object The modified object
* @return void
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
* @api
*/
public function update($object) {
throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
}
/**
* Injects the Extbase settings, called by Extbase.
*
* @param array $settings
* @return void
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
* @api
*/
public function injectSettings(array $settings) {
throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
}
/**
* Initializes the persistence manager, called by Extbase.
*
* @return void
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
* @api
*/
public function initialize() {
throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
}
/**
* Clears the in-memory state of the persistence.
*
* Managed instances become detached, any fetches will
* return data directly from the persistence "backend".
*
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
* @return void
*/
public function clearState() {
throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
}
/**
* Checks if the given object has ever been persisted.
*
* @param object $object The object to check
* @return boolean TRUE if the object is new, FALSE if the object exists in the repository
* @api
*/
public function isNewObject($object) {
return $this->backend->isNewObject($object);
}
/**
* Converts the given object into an array containing the identity of the domain object.
*
* @param object $object The object to be converted
* @return array The identity array in the format array('__identity' => '...')
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException if the given object is not known to the Persistence Manager
* @api
*/
public function convertObjectToIdentityArray($object) {
throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
}
/**
* Recursively iterates through the given array and turns objects
* into arrays containing the identity of the domain object.
*
* @param array $array The array to be iterated over
* @return array The modified array without objects
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException if array contains objects that are not known to the Persistence Manager
* @api
* @see convertObjectToIdentityArray()
*/
public function convertObjectsToIdentityArrays(array $array) {
throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
}
/**
* Return a query object for the given type.
*
* @param string $type
* @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
* @api
*/
public function createQueryForType($type) {
throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
}
}
......
......@@ -34,6 +34,26 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic;
*/
class Query implements \TYPO3\CMS\Extbase\Persistence\QueryInterface {
/**
* 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';
/**
* Charset of strings in QOM
*/
const CHARSET = 'utf-8';
/**
* @var string
*/
......@@ -445,7 +465,7 @@ class Query implements \TYPO3\CMS\Extbase\Persistence\QueryInterface {
if (is_object($operand) || $caseSensitive) {
$comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_EQUAL_TO, $operand);
} else {
$comparison = $this->qomFactory->comparison($this->qomFactory->lowerCase($this->qomFactory->propertyValue($propertyName, $this->getSelectorName())), \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_EQUAL_TO, \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter')->conv_case(\TYPO3\CMS\Extbase\Persistence\QueryInterface::CHARSET, $operand, 'toLower'));
$comparison = $this->qomFactory->comparison($this->qomFactory->lowerCase($this->qomFactory->propertyValue($propertyName, $this->getSelectorName())), \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_EQUAL_TO, \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter')->conv_case(\TYPO3\CMS\Extbase\Persistence\Generic\Query::CHARSET, $operand, 'toLower'));
}
return $comparison;
}
......@@ -455,10 +475,11 @@ class Query implements \TYPO3\CMS\Extbase\Persistence\QueryInterface {
*
* @param string $propertyName The name of the property to compare against
* @param mixed $operand The value to compare with
* @param boolean $caseSensitive Whether the matching should be done case-sensitive
* @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
* @api
*/
public function like($propertyName, $operand) {
public function like($propertyName, $operand, $caseSensitive = TRUE) {
return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_LIKE, $operand);
}
......@@ -557,6 +578,29 @@ class Query implements \TYPO3\CMS\Extbase\Persistence\QueryInterface {
return array('type', 'source', 'constraint', 'statement', 'orderings', 'limit', 'offset', 'querySettings');
}
/**
* Returns the query result count.
*
* @return integer The query result count
* @api
*/
public function count() {
return $this->execute()->count();
}
/**
* Returns an "isEmpty" criterion used for matching objects against a query.
* It matches if the multivalued property contains no values or is NULL.
*
* @param string $propertyName The name of the multivalued property to compare against
* @return boolean
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
* @api
*/
public function isEmpty($propertyName) {
throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
}
}
......
......@@ -16,8 +16,8 @@ namespace TYPO3\CMS\Extbase\Persistence;
/**
* The Extbase Persistence Manager interface
*/
interface PersistenceManagerInterface
{
interface PersistenceManagerInterface {
/**
* Commits new objects and changes to objects in the current persistence
* session into the backend
......@@ -47,16 +47,18 @@ interface PersistenceManagerInterface
*
* @param mixed $identifier
* @param string $objectType
* @param boolean $useLazyLoading Set to TRUE if you want to use lazy loading for this object
* @return object The object for the identifier if it is known, or NULL
* @api
*/
public function getObjectByIdentifier($identifier, $objectType);
public function getObjectByIdentifier($identifier, $objectType = NULL, $useLazyLoading = FALSE);
/**
* Returns the number of records matching the query.
*
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
* @return integer
* @deprecated since Extbase 6.0, will be removed in Extbase 7.0
* @api
*/
public function getObjectCountByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query);
......@@ -66,6 +68,7 @@ interface PersistenceManagerInterface
*
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
* @return array
* @deprecated since Extbase 6.0, will be removed in Extbase 7.0
* @api
*/
public function getObjectDataByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query);
......@@ -74,10 +77,105 @@ interface PersistenceManagerInterface
* Registers a repository
*
* @param string $className The class name of the repository to be reigistered
* @deprecated since Extbase 6.0, will be removed in Extbase 7.0
* @return void
*/
public function registerRepositoryClassName($className);
/**
* Adds an object to the persistence.
*
* @param object $object The object to add
* @return void
* @api
*/
public function add($object);
/**
* Removes an object to the persistence.
*
* @param object $object The object to remove
* @return void
* @api
*/
public function remove($object);
/**
* Update an object in the persistence.
*
* @param object $object The modified object
* @return void
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
* @api
*/
public function update($object);
/**
* Injects the Extbase settings, called by Extbase.
*
* @param array $settings
* @return void
* @api
*/
public function injectSettings(array $settings);
/**
* Initializes the persistence manager, called by Extbase.
*
* @return void
* @api
*/
public function initialize();
/**
* Clears the in-memory state of the persistence.
*
* Managed instances become detached, any fetches will
* return data directly from the persistence "backend".
*
* @return void
*/
public function clearState();
/**
* Checks if the given object has ever been persisted.
*
* @param object $object The object to check
* @return boolean TRUE if the object is new, FALSE if the object exists in the repository
* @api
*/
public function isNewObject($object);
/**
* Converts the given object into an array containing the identity of the domain object.
*
* @param object $object The object to be converted
* @return array The identity array in the format array('__identity' => '...')
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException if the given object is not known to the Persistence Manager
* @api
*/
public function convertObjectToIdentityArray($object);
/**
* Recursively iterates through the given array and turns objects
* into arrays containing the identity of the domain object.
*
* @param array $array The array to be iterated over
* @return array The modified array without objects
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException if array contains objects that are not known to the Persistence Manager
* @api
* @see convertObjectToIdentityArray()
*/
public function convertObjectsToIdentityArrays(array $array);
/**
* Return a query object for the given type.
*
* @param string $type
* @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
* @api
*/
public function createQueryForType($type);
}
?>
\ No newline at end of file
......@@ -19,90 +19,89 @@ namespace TYPO3\CMS\Extbase\Persistence;
* @api
*/
interface 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.
*
* The 'contains' comparison operator for collections.
* @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.
* The 'is NULL' comparison operator.
* @api
*/
const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter';
const OPERATOR_IS_NULL = 10;
/**
* A right-outer join.
* The 'is empty' comparison operator for collections.
* @api
*/
const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter';
const OPERATOR_IS_EMPTY = 11;
/**
* Charset of strings in QOM
* Constants representing the direction when ordering result sets.
*/
const CHARSET = 'utf-8';
const ORDER_ASCENDING = 'ASC';
const ORDER_DESCENDING = 'DESC';
/**
* Gets the node-tuple source for this query.
*
* @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-NULL
* @deprecated since Extbase 6.0, will be removed in Extbase 7.0
*/
public function getSource();
/**
* Executes the query against the backend and returns the result
* Executes the query and returns the result.
*
* @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is TRUE
* @api
......@@ -112,8 +111,8 @@ interface QueryInterface {
/**
* Sets the property names to order the result by. Expected like this:
* array(
* 'foo' => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING,
* 'bar' => Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING
* 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
* 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
* )
*
* @param array $orderings The property names to order by
......@@ -124,7 +123,7 @@ interface QueryInterface {
/**
* Sets the maximum size of the result set to limit. Returns $this to allow
* for chaining (fluid interface)
* for chaining (fluid interface).
*
* @param integer $limit
* @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
......@@ -134,7 +133,7 @@ interface QueryInterface {
/**
* Sets the start offset of the result set to offset. Returns $this to
* allow for chaining (fluid interface)
* allow for chaining (fluid interface).
*
* @param integer $offset
* @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
......@@ -144,7 +143,7 @@ interface QueryInterface {
/**
* The constraint used to limit the result set. Returns $this to allow
* for chaining (fluid interface)
* for chaining (fluid interface).
*
* @param object $constraint Some constraint, depending on the backend
* @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
......@@ -153,7 +152,9 @@ interface QueryInterface {
public function matching($constraint);
/**
* Performs a logical conjunction of the two given constraints.
* Performs a logical conjunction of the two given constraints. The method
* takes one or more constraints and concatenates them with a boolean AND.
* It also accepts a single array of constraints to be concatenated.
*
* @param mixed $constraint1 The first of multiple constraints or an array of constraints.
* @return object
......@@ -162,7 +163,9 @@ interface QueryInterface {
public function logicalAnd($constraint1);
/**
* Performs a logical disjunction of the two given constraints
* Performs a logical disjunction of the two given constraints. The method
* takes one or more constraints and concatenates them with a boolean OR.
* It also accepts a single array of constraints to be concatenated.
*
* @param mixed $constraint1 The first of multiple constraints or an array of constraints.
* @return object
......@@ -180,33 +183,44 @@ interface QueryInterface {