1
0
mirror of synced 2024-12-14 23:26:04 +03:00

remove '_' prefix at AbstractCollectionPersister

This commit is contained in:
Fabio B. Silva 2012-07-22 15:26:00 -03:00
parent b998a522b0
commit e6f08f0b92
5 changed files with 205 additions and 141 deletions

View File

@ -33,17 +33,17 @@ abstract class AbstractCollectionPersister
/** /**
* @var EntityManager * @var EntityManager
*/ */
protected $_em; protected $em;
/** /**
* @var \Doctrine\DBAL\Connection * @var \Doctrine\DBAL\Connection
*/ */
protected $_conn; protected $conn;
/** /**
* @var \Doctrine\ORM\UnitOfWork * @var \Doctrine\ORM\UnitOfWork
*/ */
protected $_uow; protected $uow;
/** /**
* The database platform. * The database platform.
@ -66,17 +66,17 @@ abstract class AbstractCollectionPersister
*/ */
public function __construct(EntityManager $em) public function __construct(EntityManager $em)
{ {
$this->_em = $em; $this->em = $em;
$this->_uow = $em->getUnitOfWork(); $this->uow = $em->getUnitOfWork();
$this->_conn = $em->getConnection(); $this->conn = $em->getConnection();
$this->platform = $this->_conn->getDatabasePlatform(); $this->platform = $this->conn->getDatabasePlatform();
$this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy(); $this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy();
} }
/** /**
* Deletes the persistent state represented by the given collection. * Deletes the persistent state represented by the given collection.
* *
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
*/ */
public function delete(PersistentCollection $coll) public function delete(PersistentCollection $coll)
{ {
@ -86,30 +86,30 @@ abstract class AbstractCollectionPersister
return; // ignore inverse side return; // ignore inverse side
} }
$sql = $this->_getDeleteSQL($coll); $sql = $this->getDeleteSQL($coll);
$this->_conn->executeUpdate($sql, $this->_getDeleteSQLParameters($coll)); $this->conn->executeUpdate($sql, $this->getDeleteSQLParameters($coll));
} }
/** /**
* Gets the SQL statement for deleting the given collection. * Gets the SQL statement for deleting the given collection.
* *
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
*/ */
abstract protected function _getDeleteSQL(PersistentCollection $coll); abstract protected function getDeleteSQL(PersistentCollection $coll);
/** /**
* Gets the SQL parameters for the corresponding SQL statement to delete * Gets the SQL parameters for the corresponding SQL statement to delete
* the given collection. * the given collection.
* *
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
*/ */
abstract protected function _getDeleteSQLParameters(PersistentCollection $coll); abstract protected function getDeleteSQLParameters(PersistentCollection $coll);
/** /**
* Updates the given collection, synchronizing it's state with the database * Updates the given collection, synchronizing it's state with the database
* by inserting, updating and deleting individual elements. * by inserting, updating and deleting individual elements.
* *
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
*/ */
public function update(PersistentCollection $coll) public function update(PersistentCollection $coll)
{ {
@ -120,63 +120,117 @@ abstract class AbstractCollectionPersister
} }
$this->deleteRows($coll); $this->deleteRows($coll);
//$this->updateRows($coll);
$this->insertRows($coll); $this->insertRows($coll);
} }
/**
* Delete rows
*
* @param \Doctrine\ORM\PersistentCollection $coll
*/
public function deleteRows(PersistentCollection $coll) public function deleteRows(PersistentCollection $coll)
{ {
$deleteDiff = $coll->getDeleteDiff(); $diff = $coll->getDeleteDiff();
$sql = $this->_getDeleteRowSQL($coll); $sql = $this->getDeleteRowSQL($coll);
foreach ($deleteDiff as $element) { foreach ($diff as $element) {
$this->_conn->executeUpdate($sql, $this->_getDeleteRowSQLParameters($coll, $element)); $this->conn->executeUpdate($sql, $this->getDeleteRowSQLParameters($coll, $element));
} }
} }
//public function updateRows(PersistentCollection $coll) /**
//{} * Insert rows
*
* @param \Doctrine\ORM\PersistentCollection $coll
*/
public function insertRows(PersistentCollection $coll) public function insertRows(PersistentCollection $coll)
{ {
$insertDiff = $coll->getInsertDiff(); $diff = $coll->getInsertDiff();
$sql = $this->_getInsertRowSQL($coll); $sql = $this->getInsertRowSQL($coll);
foreach ($insertDiff as $element) { foreach ($diff as $element) {
$this->_conn->executeUpdate($sql, $this->_getInsertRowSQLParameters($coll, $element)); $this->conn->executeUpdate($sql, $this->getInsertRowSQLParameters($coll, $element));
} }
} }
/**
* Count the size of this persistent collection
*
* @param \Doctrine\ORM\PersistentCollection $coll
* @return integer
*/
public function count(PersistentCollection $coll) public function count(PersistentCollection $coll)
{ {
throw new \BadMethodCallException("Counting the size of this persistent collection is not supported by this CollectionPersister."); throw new \BadMethodCallException("Counting the size of this persistent collection is not supported by this CollectionPersister.");
} }
/**
* Slice elements
*
* @param \Doctrine\ORM\PersistentCollection $coll
* @param integer $offset
* @param integer $length
* @return array
*/
public function slice(PersistentCollection $coll, $offset, $length = null) public function slice(PersistentCollection $coll, $offset, $length = null)
{ {
throw new \BadMethodCallException("Slicing elements is not supported by this CollectionPersister."); throw new \BadMethodCallException("Slicing elements is not supported by this CollectionPersister.");
} }
/**
* Check for existance of an element
*
* @param \Doctrine\ORM\PersistentCollection $coll
* @param mixed \Doctrine\ORM\PersistentCollection
* @return boolean
*/
public function contains(PersistentCollection $coll, $element) public function contains(PersistentCollection $coll, $element)
{ {
throw new \BadMethodCallException("Checking for existance of an element is not supported by this CollectionPersister."); throw new \BadMethodCallException("Checking for existance of an element is not supported by this CollectionPersister.");
} }
/**
* Check for existance of a key
*
* @param \Doctrine\ORM\PersistentCollection $coll
* @param mixed $key
* @return boolean
*/
public function containsKey(PersistentCollection $coll, $key) public function containsKey(PersistentCollection $coll, $key)
{ {
throw new \BadMethodCallException("Checking for existance of a key is not supported by this CollectionPersister."); throw new \BadMethodCallException("Checking for existance of a key is not supported by this CollectionPersister.");
} }
/**
* Remove an element
*
* @param \Doctrine\ORM\PersistentCollection $coll
* @param object $element
* @return mixed
*/
public function removeElement(PersistentCollection $coll, $element) public function removeElement(PersistentCollection $coll, $element)
{ {
throw new \BadMethodCallException("Removing an element is not supported by this CollectionPersister."); throw new \BadMethodCallException("Removing an element is not supported by this CollectionPersister.");
} }
/**
* Remove an element by key
*
* @param \Doctrine\ORM\PersistentCollection $coll
* @param mixed $key
*/
public function removeKey(PersistentCollection $coll, $key) public function removeKey(PersistentCollection $coll, $key)
{ {
throw new \BadMethodCallException("Removing a key is not supported by this CollectionPersister."); throw new \BadMethodCallException("Removing a key is not supported by this CollectionPersister.");
} }
/**
* Get an element by key
*
* @param \Doctrine\ORM\PersistentCollection $coll
* @param mixed $index
* @return object
*/
public function get(PersistentCollection $coll, $index) public function get(PersistentCollection $coll, $index)
{ {
throw new \BadMethodCallException("Selecting a collection by index is not supported by this CollectionPersister."); throw new \BadMethodCallException("Selecting a collection by index is not supported by this CollectionPersister.");
@ -185,39 +239,39 @@ abstract class AbstractCollectionPersister
/** /**
* Gets the SQL statement used for deleting a row from the collection. * Gets the SQL statement used for deleting a row from the collection.
* *
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
*/ */
abstract protected function _getDeleteRowSQL(PersistentCollection $coll); abstract protected function getDeleteRowSQL(PersistentCollection $coll);
/** /**
* Gets the SQL parameters for the corresponding SQL statement to delete the given * Gets the SQL parameters for the corresponding SQL statement to delete the given
* element from the given collection. * element from the given collection.
* *
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
* @param mixed $element * @param mixed $element
*/ */
abstract protected function _getDeleteRowSQLParameters(PersistentCollection $coll, $element); abstract protected function getDeleteRowSQLParameters(PersistentCollection $coll, $element);
/** /**
* Gets the SQL statement used for updating a row in the collection. * Gets the SQL statement used for updating a row in the collection.
* *
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
*/ */
abstract protected function _getUpdateRowSQL(PersistentCollection $coll); abstract protected function getUpdateRowSQL(PersistentCollection $coll);
/** /**
* Gets the SQL statement used for inserting a row in the collection. * Gets the SQL statement used for inserting a row in the collection.
* *
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
*/ */
abstract protected function _getInsertRowSQL(PersistentCollection $coll); abstract protected function getInsertRowSQL(PersistentCollection $coll);
/** /**
* Gets the SQL parameters for the corresponding SQL statement to insert the given * Gets the SQL parameters for the corresponding SQL statement to insert the given
* element of the given collection into the database. * element of the given collection into the database.
* *
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
* @param mixed $element * @param mixed $element
*/ */
abstract protected function _getInsertRowSQLParameters(PersistentCollection $coll, $element); abstract protected function getInsertRowSQLParameters(PersistentCollection $coll, $element);
} }

View File

@ -338,7 +338,7 @@ class BasicEntityPersister
* *
* Subclasses are also supposed to take care of versioning when overriding this method, * Subclasses are also supposed to take care of versioning when overriding this method,
* if necessary. The {@link updateTable} method can be used to apply the data retrieved * if necessary. The {@link updateTable} method can be used to apply the data retrieved
* from {@_prepareUpdateData} on the target tables, thereby optionally applying versioning. * from {@prepareUpdateData} on the target tables, thereby optionally applying versioning.
* *
* @param object $entity The entity to update. * @param object $entity The entity to update.
*/ */

View File

@ -439,13 +439,17 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
return 'FROM ' .$this->quoteStrategy->getTableName($this->class, $this->platform) . ' ' . $baseTableAlias . $joinSql; return 'FROM ' .$this->quoteStrategy->getTableName($this->class, $this->platform) . ' ' . $baseTableAlias . $joinSql;
} }
/* Ensure this method is never called. This persister overrides _getSelectEntitiesSQL directly. */ /*
* Ensure this method is never called. This persister overrides getSelectEntitiesSQL directly.
*/
protected function getSelectColumnListSQL() protected function getSelectColumnListSQL()
{ {
throw new \BadMethodCallException("Illegal invocation of ".__METHOD__."."); throw new \BadMethodCallException("Illegal invocation of ".__METHOD__.".");
} }
/** {@inheritdoc} */ /**
* {@inheritdoc}
*/
protected function getInsertColumnList() protected function getInsertColumnList()
{ {
// Identifier columns must always come first in the column list of subclasses. // Identifier columns must always come first in the column list of subclasses.

View File

@ -38,11 +38,11 @@ class ManyToManyPersister extends AbstractCollectionPersister
* *
* @override * @override
*/ */
protected function _getDeleteRowSQL(PersistentCollection $coll) protected function getDeleteRowSQL(PersistentCollection $coll)
{ {
$columns = array(); $columns = array();
$mapping = $coll->getMapping(); $mapping = $coll->getMapping();
$class = $this->_em->getClassMetadata(get_class($coll->getOwner())); $class = $this->em->getClassMetadata(get_class($coll->getOwner()));
foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) { foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) {
$columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform);
@ -60,34 +60,34 @@ class ManyToManyPersister extends AbstractCollectionPersister
* {@inheritdoc} * {@inheritdoc}
* *
* @override * @override
* @internal Order of the parameters must be the same as the order of the columns in * @internal Order of the parameters must be the same as the order of the columns in getDeleteRowSql.
* _getDeleteRowSql.
*/ */
protected function _getDeleteRowSQLParameters(PersistentCollection $coll, $element) protected function getDeleteRowSQLParameters(PersistentCollection $coll, $element)
{ {
return $this->_collectJoinTableColumnParameters($coll, $element); return $this->collectJoinTableColumnParameters($coll, $element);
}
/**
* {@inheritdoc}
*
* @throws \BadMethodCallException Not used for OneToManyPersister
*/
protected function getUpdateRowSQL(PersistentCollection $coll)
{
throw new \BadMethodCallException("Insert Row SQL is not used for ManyToManyPersister");
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
* @override * @override
* @internal Order of the parameters must be the same as the order of the columns in getInsertRowSql.
*/ */
protected function _getUpdateRowSQL(PersistentCollection $coll) protected function getInsertRowSQL(PersistentCollection $coll)
{}
/**
* {@inheritdoc}
*
* @override
* @internal Order of the parameters must be the same as the order of the columns in
* _getInsertRowSql.
*/
protected function _getInsertRowSQL(PersistentCollection $coll)
{ {
$columns = array(); $columns = array();
$mapping = $coll->getMapping(); $mapping = $coll->getMapping();
$class = $this->_em->getClassMetadata(get_class($coll->getOwner())); $class = $this->em->getClassMetadata(get_class($coll->getOwner()));
$joinTable = $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform); $joinTable = $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform);
foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) { foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) {
@ -106,33 +106,32 @@ class ManyToManyPersister extends AbstractCollectionPersister
* {@inheritdoc} * {@inheritdoc}
* *
* @override * @override
* @internal Order of the parameters must be the same as the order of the columns in * @internal Order of the parameters must be the same as the order of the columns in getInsertRowSql.
* _getInsertRowSql.
*/ */
protected function _getInsertRowSQLParameters(PersistentCollection $coll, $element) protected function getInsertRowSQLParameters(PersistentCollection $coll, $element)
{ {
return $this->_collectJoinTableColumnParameters($coll, $element); return $this->collectJoinTableColumnParameters($coll, $element);
} }
/** /**
* Collects the parameters for inserting/deleting on the join table in the order * Collects the parameters for inserting/deleting on the join table in the order
* of the join table columns as specified in ManyToManyMapping#joinTableColumns. * of the join table columns as specified in ManyToManyMapping#joinTableColumns.
* *
* @param $coll * @param \Doctrine\ORM\PersistentCollection $coll
* @param $element * @param object $element
* @return array * @return array
*/ */
private function _collectJoinTableColumnParameters(PersistentCollection $coll, $element) private function collectJoinTableColumnParameters(PersistentCollection $coll, $element)
{ {
$params = array(); $params = array();
$mapping = $coll->getMapping(); $mapping = $coll->getMapping();
$isComposite = count($mapping['joinTableColumns']) > 2; $isComposite = count($mapping['joinTableColumns']) > 2;
$identifier1 = $this->_uow->getEntityIdentifier($coll->getOwner()); $identifier1 = $this->uow->getEntityIdentifier($coll->getOwner());
$identifier2 = $this->_uow->getEntityIdentifier($element); $identifier2 = $this->uow->getEntityIdentifier($element);
if ($isComposite) { if ($isComposite) {
$class1 = $this->_em->getClassMetadata(get_class($coll->getOwner())); $class1 = $this->em->getClassMetadata(get_class($coll->getOwner()));
$class2 = $coll->getTypeClass(); $class2 = $coll->getTypeClass();
} }
@ -162,11 +161,11 @@ class ManyToManyPersister extends AbstractCollectionPersister
* *
* @override * @override
*/ */
protected function _getDeleteSQL(PersistentCollection $coll) protected function getDeleteSQL(PersistentCollection $coll)
{ {
$columns = array(); $columns = array();
$mapping = $coll->getMapping(); $mapping = $coll->getMapping();
$class = $this->_em->getClassMetadata(get_class($coll->getOwner())); $class = $this->em->getClassMetadata(get_class($coll->getOwner()));
$joinTable = $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform); $joinTable = $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform);
foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) { foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) {
@ -181,12 +180,11 @@ class ManyToManyPersister extends AbstractCollectionPersister
* {@inheritdoc} * {@inheritdoc}
* *
* @override * @override
* @internal Order of the parameters must be the same as the order of the columns in * @internal Order of the parameters must be the same as the order of the columns in getDeleteSql.
* _getDeleteSql.
*/ */
protected function _getDeleteSQLParameters(PersistentCollection $coll) protected function getDeleteSQLParameters(PersistentCollection $coll)
{ {
$identifier = $this->_uow->getEntityIdentifier($coll->getOwner()); $identifier = $this->uow->getEntityIdentifier($coll->getOwner());
$mapping = $coll->getMapping(); $mapping = $coll->getMapping();
$params = array(); $params = array();
@ -198,7 +196,7 @@ class ManyToManyPersister extends AbstractCollectionPersister
} }
// Composite identifier // Composite identifier
$sourceClass = $this->_em->getClassMetadata(get_class($coll->getOwner())); $sourceClass = $this->em->getClassMetadata(get_class($coll->getOwner()));
foreach ($mapping['relationToSourceKeyColumns'] as $srcColumn) { foreach ($mapping['relationToSourceKeyColumns'] as $srcColumn) {
$params[] = $identifier[$sourceClass->fieldNames[$srcColumn]]; $params[] = $identifier[$sourceClass->fieldNames[$srcColumn]];
@ -216,11 +214,11 @@ class ManyToManyPersister extends AbstractCollectionPersister
$params = array(); $params = array();
$mapping = $coll->getMapping(); $mapping = $coll->getMapping();
$association = $mapping; $association = $mapping;
$class = $this->_em->getClassMetadata($mapping['sourceEntity']); $class = $this->em->getClassMetadata($mapping['sourceEntity']);
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($coll->getOwner()); $id = $this->em->getUnitOfWork()->getEntityIdentifier($coll->getOwner());
if ( ! $mapping['isOwningSide']) { if ( ! $mapping['isOwningSide']) {
$targetEntity = $this->_em->getClassMetadata($mapping['targetEntity']); $targetEntity = $this->em->getClassMetadata($mapping['targetEntity']);
$association = $targetEntity->associationMappings[$mapping['mappedBy']]; $association = $targetEntity->associationMappings[$mapping['mappedBy']];
} }
@ -249,11 +247,11 @@ class ManyToManyPersister extends AbstractCollectionPersister
. $joinTargetEntitySQL . $joinTargetEntitySQL
. ' WHERE ' . implode(' AND ', $conditions); . ' WHERE ' . implode(' AND ', $conditions);
return $this->_conn->fetchColumn($sql, $params); return $this->conn->fetchColumn($sql, $params);
} }
/** /**
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
* @param int $offset * @param int $offset
* @param int $length * @param int $length
* @return array * @return array
@ -262,17 +260,17 @@ class ManyToManyPersister extends AbstractCollectionPersister
{ {
$mapping = $coll->getMapping(); $mapping = $coll->getMapping();
return $this->_em->getUnitOfWork()->getEntityPersister($mapping['targetEntity'])->getManyToManyCollection($mapping, $coll->getOwner(), $offset, $length); return $this->em->getUnitOfWork()->getEntityPersister($mapping['targetEntity'])->getManyToManyCollection($mapping, $coll->getOwner(), $offset, $length);
} }
/** /**
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
* @param object $element * @param object $element
* @return boolean * @return boolean
*/ */
public function contains(PersistentCollection $coll, $element) public function contains(PersistentCollection $coll, $element)
{ {
$uow = $this->_em->getUnitOfWork(); $uow = $this->em->getUnitOfWork();
// Shortcut for new entities // Shortcut for new entities
$entityState = $uow->getEntityState($element, UnitOfWork::STATE_NEW); $entityState = $uow->getEntityState($element, UnitOfWork::STATE_NEW);
@ -290,17 +288,17 @@ class ManyToManyPersister extends AbstractCollectionPersister
$sql = 'SELECT 1 FROM ' . $quotedJoinTable . ' WHERE ' . implode(' AND ', $whereClauses); $sql = 'SELECT 1 FROM ' . $quotedJoinTable . ' WHERE ' . implode(' AND ', $whereClauses);
return (bool) $this->_conn->fetchColumn($sql, $params); return (bool) $this->conn->fetchColumn($sql, $params);
} }
/** /**
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
* @param object $element * @param object $element
* @return boolean * @return boolean
*/ */
public function removeElement(PersistentCollection $coll, $element) public function removeElement(PersistentCollection $coll, $element)
{ {
$uow = $this->_em->getUnitOfWork(); $uow = $this->em->getUnitOfWork();
// shortcut for new entities // shortcut for new entities
$entityState = $uow->getEntityState($element, UnitOfWork::STATE_NEW); $entityState = $uow->getEntityState($element, UnitOfWork::STATE_NEW);
@ -319,7 +317,7 @@ class ManyToManyPersister extends AbstractCollectionPersister
$sql = 'DELETE FROM ' . $quotedJoinTable . ' WHERE ' . implode(' AND ', $whereClauses); $sql = 'DELETE FROM ' . $quotedJoinTable . ' WHERE ' . implode(' AND ', $whereClauses);
return (bool) $this->_conn->executeUpdate($sql, $params); return (bool) $this->conn->executeUpdate($sql, $params);
} }
/** /**
@ -330,19 +328,19 @@ class ManyToManyPersister extends AbstractCollectionPersister
*/ */
private function getJoinTableRestrictions(PersistentCollection $coll, $element, $addFilters) private function getJoinTableRestrictions(PersistentCollection $coll, $element, $addFilters)
{ {
$uow = $this->_em->getUnitOfWork(); $uow = $this->em->getUnitOfWork();
$mapping = $filterMapping = $coll->getMapping(); $mapping = $filterMapping = $coll->getMapping();
if ( ! $mapping['isOwningSide']) { if ( ! $mapping['isOwningSide']) {
$sourceClass = $this->_em->getClassMetadata($mapping['targetEntity']); $sourceClass = $this->em->getClassMetadata($mapping['targetEntity']);
$targetClass = $this->_em->getClassMetadata($mapping['sourceEntity']); $targetClass = $this->em->getClassMetadata($mapping['sourceEntity']);
$sourceId = $uow->getEntityIdentifier($element); $sourceId = $uow->getEntityIdentifier($element);
$targetId = $uow->getEntityIdentifier($coll->getOwner()); $targetId = $uow->getEntityIdentifier($coll->getOwner());
$mapping = $sourceClass->associationMappings[$mapping['mappedBy']]; $mapping = $sourceClass->associationMappings[$mapping['mappedBy']];
} else { } else {
$sourceClass = $this->_em->getClassMetadata($mapping['sourceEntity']); $sourceClass = $this->em->getClassMetadata($mapping['sourceEntity']);
$targetClass = $this->_em->getClassMetadata($mapping['targetEntity']); $targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
$sourceId = $uow->getEntityIdentifier($coll->getOwner()); $sourceId = $uow->getEntityIdentifier($coll->getOwner());
$targetId = $uow->getEntityIdentifier($element); $targetId = $uow->getEntityIdentifier($element);
} }
@ -393,7 +391,7 @@ class ManyToManyPersister extends AbstractCollectionPersister
*/ */
public function getFilterSql($mapping) public function getFilterSql($mapping)
{ {
$targetClass = $this->_em->getClassMetadata($mapping['targetEntity']); $targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
if ($mapping['isOwningSide']) { if ($mapping['isOwningSide']) {
$joinColumns = $mapping['relationToTargetKeyColumns']; $joinColumns = $mapping['relationToTargetKeyColumns'];
@ -402,7 +400,7 @@ class ManyToManyPersister extends AbstractCollectionPersister
$joinColumns = $mapping['relationToSourceKeyColumns']; $joinColumns = $mapping['relationToSourceKeyColumns'];
} }
$targetClass = $this->_em->getClassMetadata($targetClass->rootEntityName); $targetClass = $this->em->getClassMetadata($targetClass->rootEntityName);
// A join is needed if there is filtering on the target entity // A join is needed if there is filtering on the target entity
$joinTargetEntitySQL = ''; $joinTargetEntitySQL = '';
@ -434,7 +432,7 @@ class ManyToManyPersister extends AbstractCollectionPersister
{ {
$filterClauses = array(); $filterClauses = array();
foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) { foreach ($this->em->getFilters()->getEnabledFilters() as $filter) {
if ($filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { if ($filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) {
$filterClauses[] = '(' . $filterExpr . ')'; $filterClauses[] = '(' . $filterExpr . ')';
} }

View File

@ -36,14 +36,14 @@ class OneToManyPersister extends AbstractCollectionPersister
* Generates the SQL UPDATE that updates a particular row's foreign * Generates the SQL UPDATE that updates a particular row's foreign
* key to null. * key to null.
* *
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
* @return string * @return string
* @override * @override
*/ */
protected function _getDeleteRowSQL(PersistentCollection $coll) protected function getDeleteRowSQL(PersistentCollection $coll)
{ {
$mapping = $coll->getMapping(); $mapping = $coll->getMapping();
$class = $this->_em->getClassMetadata($mapping['targetEntity']); $class = $this->em->getClassMetadata($mapping['targetEntity']);
return 'DELETE FROM ' . $this->quoteStrategy->getTableName($class, $this->platform) return 'DELETE FROM ' . $this->quoteStrategy->getTableName($class, $this->platform)
. ' WHERE ' . implode('= ? AND ', $class->getIdentifierColumnNames()) . ' = ?'; . ' WHERE ' . implode('= ? AND ', $class->getIdentifierColumnNames()) . ' = ?';
@ -51,52 +51,60 @@ class OneToManyPersister extends AbstractCollectionPersister
/** /**
* {@inheritdoc} * {@inheritdoc}
*
*/ */
protected function _getDeleteRowSQLParameters(PersistentCollection $coll, $element) protected function getDeleteRowSQLParameters(PersistentCollection $coll, $element)
{ {
return array_values($this->_uow->getEntityIdentifier($element)); return array_values($this->uow->getEntityIdentifier($element));
}
protected function _getInsertRowSQL(PersistentCollection $coll)
{
return "UPDATE xxx SET foreign_key = yyy WHERE foreign_key = zzz";
} }
/** /**
* Gets the SQL parameters for the corresponding SQL statement to insert the given * {@inheritdoc}
* element of the given collection into the database. * @throws \BadMethodCallException Not used for OneToManyPersister
*
* @param PersistentCollection $coll
* @param mixed $element
*/ */
protected function _getInsertRowSQLParameters(PersistentCollection $coll, $element) protected function getInsertRowSQL(PersistentCollection $coll)
{}
/* Not used for OneToManyPersister */
protected function _getUpdateRowSQL(PersistentCollection $coll)
{ {
return; throw new \BadMethodCallException("Insert Row SQL is not used for OneToManyPersister");
} }
/** /**
* Generates the SQL UPDATE that updates all the foreign keys to null. * {@inheritdoc}
* *
* @param PersistentCollection $coll * @throws \BadMethodCallException Not used for OneToManyPersister
*/ */
protected function _getDeleteSQL(PersistentCollection $coll) protected function getInsertRowSQLParameters(PersistentCollection $coll, $element)
{ {
throw new \BadMethodCallException("Insert Row SQL is not used for OneToManyPersister");
} }
/** /**
* Gets the SQL parameters for the corresponding SQL statement to delete * {@inheritdoc}
* the given collection.
* *
* @param PersistentCollection $coll * @throws \BadMethodCallException Not used for OneToManyPersister
*/ */
protected function _getDeleteSQLParameters(PersistentCollection $coll) protected function getUpdateRowSQL(PersistentCollection $coll)
{} {
throw new \BadMethodCallException("Update Row SQL is not used for OneToManyPersister");
}
/**
* {@inheritdoc}
*
* @throws \BadMethodCallException Not used for OneToManyPersister
*/
protected function getDeleteSQL(PersistentCollection $coll)
{
throw new \BadMethodCallException("Update Row SQL is not used for OneToManyPersister");
}
/**
* {@inheritdoc}
*
* @throws \BadMethodCallException Not used for OneToManyPersister
*/
protected function getDeleteSQLParameters(PersistentCollection $coll)
{
throw new \BadMethodCallException("Update Row SQL is not used for OneToManyPersister");
}
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -104,9 +112,9 @@ class OneToManyPersister extends AbstractCollectionPersister
public function count(PersistentCollection $coll) public function count(PersistentCollection $coll)
{ {
$mapping = $coll->getMapping(); $mapping = $coll->getMapping();
$targetClass = $this->_em->getClassMetadata($mapping['targetEntity']); $targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
$sourceClass = $this->_em->getClassMetadata($mapping['sourceEntity']); $sourceClass = $this->em->getClassMetadata($mapping['sourceEntity']);
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($coll->getOwner()); $id = $this->em->getUnitOfWork()->getEntityIdentifier($coll->getOwner());
$whereClauses = array(); $whereClauses = array();
$params = array(); $params = array();
@ -119,8 +127,8 @@ class OneToManyPersister extends AbstractCollectionPersister
: $id[$sourceClass->fieldNames[$joinColumn['referencedColumnName']]]; : $id[$sourceClass->fieldNames[$joinColumn['referencedColumnName']]];
} }
$filterTargetClass = $this->_em->getClassMetadata($targetClass->rootEntityName); $filterTargetClass = $this->em->getClassMetadata($targetClass->rootEntityName);
foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) { foreach ($this->em->getFilters()->getEnabledFilters() as $filter) {
if ($filterExpr = $filter->addFilterConstraint($filterTargetClass, 't')) { if ($filterExpr = $filter->addFilterConstraint($filterTargetClass, 't')) {
$whereClauses[] = '(' . $filterExpr . ')'; $whereClauses[] = '(' . $filterExpr . ')';
} }
@ -130,11 +138,11 @@ class OneToManyPersister extends AbstractCollectionPersister
. ' FROM ' . $this->quoteStrategy->getTableName($targetClass, $this->platform) . ' t' . ' FROM ' . $this->quoteStrategy->getTableName($targetClass, $this->platform) . ' t'
. ' WHERE ' . implode(' AND ', $whereClauses); . ' WHERE ' . implode(' AND ', $whereClauses);
return $this->_conn->fetchColumn($sql, $params); return $this->conn->fetchColumn($sql, $params);
} }
/** /**
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
* @param int $offset * @param int $offset
* @param int $length * @param int $length
* @return \Doctrine\Common\Collections\ArrayCollection * @return \Doctrine\Common\Collections\ArrayCollection
@ -142,21 +150,21 @@ class OneToManyPersister extends AbstractCollectionPersister
public function slice(PersistentCollection $coll, $offset, $length = null) public function slice(PersistentCollection $coll, $offset, $length = null)
{ {
$mapping = $coll->getMapping(); $mapping = $coll->getMapping();
$uow = $this->_em->getUnitOfWork(); $uow = $this->em->getUnitOfWork();
$persister = $uow->getEntityPersister($mapping['targetEntity']); $persister = $uow->getEntityPersister($mapping['targetEntity']);
return $persister->getOneToManyCollection($mapping, $coll->getOwner(), $offset, $length); return $persister->getOneToManyCollection($mapping, $coll->getOwner(), $offset, $length);
} }
/** /**
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
* @param object $element * @param object $element
* @return boolean * @return boolean
*/ */
public function contains(PersistentCollection $coll, $element) public function contains(PersistentCollection $coll, $element)
{ {
$mapping = $coll->getMapping(); $mapping = $coll->getMapping();
$uow = $this->_em->getUnitOfWork(); $uow = $this->em->getUnitOfWork();
// shortcut for new entities // shortcut for new entities
$entityState = $uow->getEntityState($element, UnitOfWork::STATE_NEW); $entityState = $uow->getEntityState($element, UnitOfWork::STATE_NEW);
@ -181,13 +189,13 @@ class OneToManyPersister extends AbstractCollectionPersister
} }
/** /**
* @param PersistentCollection $coll * @param \Doctrine\ORM\PersistentCollection $coll
* @param object $element * @param object $element
* @return boolean * @return boolean
*/ */
public function removeElement(PersistentCollection $coll, $element) public function removeElement(PersistentCollection $coll, $element)
{ {
$uow = $this->_em->getUnitOfWork(); $uow = $this->em->getUnitOfWork();
// shortcut for new entities // shortcut for new entities
$entityState = $uow->getEntityState($element, UnitOfWork::STATE_NEW); $entityState = $uow->getEntityState($element, UnitOfWork::STATE_NEW);
@ -203,10 +211,10 @@ class OneToManyPersister extends AbstractCollectionPersister
} }
$mapping = $coll->getMapping(); $mapping = $coll->getMapping();
$class = $this->_em->getClassMetadata($mapping['targetEntity']); $class = $this->em->getClassMetadata($mapping['targetEntity']);
$sql = 'DELETE FROM ' . $this->quoteStrategy->getTableName($class, $this->platform) $sql = 'DELETE FROM ' . $this->quoteStrategy->getTableName($class, $this->platform)
. ' WHERE ' . implode('= ? AND ', $class->getIdentifierColumnNames()) . ' = ?'; . ' WHERE ' . implode('= ? AND ', $class->getIdentifierColumnNames()) . ' = ?';
return (bool) $this->_conn->executeUpdate($sql, $this->_getDeleteRowSQLParameters($coll, $element)); return (bool) $this->conn->executeUpdate($sql, $this->getDeleteRowSQLParameters($coll, $element));
} }
} }