Skip to content

Commit

Permalink
Merge branch 'optimize-persisters'
Browse files Browse the repository at this point in the history
Close #1246
  • Loading branch information
Ocramius committed Jan 13, 2015
2 parents c49b079 + 35dd7f8 commit 9c3cb57
Show file tree
Hide file tree
Showing 8 changed files with 415 additions and 678 deletions.
16 changes: 0 additions & 16 deletions lib/Doctrine/ORM/Cache/Persister/AbstractCollectionPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,6 @@ public function count(PersistentCollection $collection)
return $this->persister->count($collection);
}

/**
* {@inheritdoc}
*/
public function deleteRows(PersistentCollection $collection)
{
$this->persister->deleteRows($collection);
}

/**
* {@inheritdoc}
*/
public function insertRows(PersistentCollection $collection)
{
$this->persister->insertRows($collection);
}

/**
* {@inheritdoc}
*/
Expand Down
189 changes: 0 additions & 189 deletions lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

namespace Doctrine\ORM\Persisters;

use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\PersistentCollection;

/**
* Base class for all collection persisters.
Expand Down Expand Up @@ -73,191 +71,4 @@ public function __construct(EntityManager $em)
$this->platform = $this->conn->getDatabasePlatform();
$this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy();
}

/**
* {@inheritdoc}
*/
public function delete(PersistentCollection $coll)
{
$mapping = $coll->getMapping();

if ( ! $mapping['isOwningSide']) {
return; // ignore inverse side
}

$this->conn->executeUpdate($this->getDeleteSQL($coll), $this->getDeleteSQLParameters($coll));
}

/**
* Gets the SQL statement for deleting the given collection.
*
* @param \Doctrine\ORM\PersistentCollection $coll
*
* @return string
*/
abstract protected function getDeleteSQL(PersistentCollection $coll);

/**
* Gets the SQL parameters for the corresponding SQL statement to delete
* the given collection.
*
* @param \Doctrine\ORM\PersistentCollection $coll
*
* @return array
*/
abstract protected function getDeleteSQLParameters(PersistentCollection $coll);

/**
* {@inheritdoc}
*/
public function update(PersistentCollection $coll)
{
$mapping = $coll->getMapping();

if ( ! $mapping['isOwningSide']) {
return; // ignore inverse side
}

$this->deleteRows($coll);
$this->insertRows($coll);
}

/**
* {@inheritdoc}
*/
public function deleteRows(PersistentCollection $coll)
{
$diff = $coll->getDeleteDiff();
$sql = $this->getDeleteRowSQL($coll);

foreach ($diff as $element) {
$this->conn->executeUpdate($sql, $this->getDeleteRowSQLParameters($coll, $element));
}
}

/**
* {@inheritdoc}
*/
public function insertRows(PersistentCollection $coll)
{
$diff = $coll->getInsertDiff();
$sql = $this->getInsertRowSQL($coll);

foreach ($diff as $element) {
$this->conn->executeUpdate($sql, $this->getInsertRowSQLParameters($coll, $element));
}
}

/**
* {@inheritdoc}
*/
public function count(PersistentCollection $coll)
{
throw new \BadMethodCallException("Counting the size of this persistent collection is not supported by this CollectionPersister.");
}

/**
* {@inheritdoc}
*/
public function slice(PersistentCollection $coll, $offset, $length = null)
{
throw new \BadMethodCallException("Slicing elements is not supported by this CollectionPersister.");
}

/**
* {@inheritdoc}
*/
public function contains(PersistentCollection $coll, $element)
{
throw new \BadMethodCallException("Checking for existence of an element is not supported by this CollectionPersister.");
}

/**
* {@inheritdoc}
*/
public function containsKey(PersistentCollection $coll, $key)
{
throw new \BadMethodCallException("Checking for existence of a key is not supported by this CollectionPersister.");
}

/**
* {@inheritdoc}
*/
public function removeElement(PersistentCollection $coll, $element)
{
throw new \BadMethodCallException("Removing an element is not supported by this CollectionPersister.");
}

/**
* {@inheritdoc}
*/
public function removeKey(PersistentCollection $coll, $key)
{
throw new \BadMethodCallException("Removing a key is not supported by this CollectionPersister.");
}

/**
* {@inheritdoc}
*/
public function get(PersistentCollection $coll, $index)
{
throw new \BadMethodCallException("Selecting a collection by index is not supported by this CollectionPersister.");
}

/**
* {@inheritdoc}
*/
public function loadCriteria(PersistentCollection $coll, Criteria $criteria)
{
throw new \BadMethodCallException("Filtering a collection by Criteria is not supported by this CollectionPersister.");
}

/**
* Gets the SQL statement used for deleting a row from the collection.
*
* @param \Doctrine\ORM\PersistentCollection $coll
*
* @return string
*/
abstract protected function getDeleteRowSQL(PersistentCollection $coll);

/**
* Gets the SQL parameters for the corresponding SQL statement to delete the given
* element from the given collection.
*
* @param \Doctrine\ORM\PersistentCollection $coll
* @param mixed $element
*
* @return array
*/
abstract protected function getDeleteRowSQLParameters(PersistentCollection $coll, $element);

/**
* Gets the SQL statement used for updating a row in the collection.
*
* @param \Doctrine\ORM\PersistentCollection $coll
*
* @return string
*/
abstract protected function getUpdateRowSQL(PersistentCollection $coll);

/**
* Gets the SQL statement used for inserting a row in the collection.
*
* @param \Doctrine\ORM\PersistentCollection $coll
*
* @return string
*/
abstract protected function getInsertRowSQL(PersistentCollection $coll);

/**
* Gets the SQL parameters for the corresponding SQL statement to insert the given
* element of the given collection into the database.
*
* @param \Doctrine\ORM\PersistentCollection $coll
* @param mixed $element
*
* @return array
*/
abstract protected function getInsertRowSQLParameters(PersistentCollection $coll, $element);
}
25 changes: 7 additions & 18 deletions lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,8 @@ protected function prepareUpdateData($entity)
}
}

$newValId = null;

if ($newVal !== null) {
$newValId = $uow->getEntityIdentifier($newVal);
}
Expand All @@ -667,24 +669,11 @@ protected function prepareUpdateData($entity)
$targetColumn = $joinColumn['referencedColumnName'];
$quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->class, $this->platform);

$this->quotedColumns[$sourceColumn] = $quotedColumn;
$this->columnTypes[$sourceColumn] = $targetClass->getTypeOfColumn($targetColumn);

switch (true) {
case $newVal === null:
$value = null;
break;

case $targetClass->containsForeignIdentifier:
$value = $newValId[$targetClass->getFieldForColumn($targetColumn)];
break;

default:
$value = $newValId[$targetClass->fieldNames[$targetColumn]];
break;
}

$result[$owningTable][$sourceColumn] = $value;
$this->quotedColumns[$sourceColumn] = $quotedColumn;
$this->columnTypes[$sourceColumn] = $targetClass->getTypeOfColumn($targetColumn);
$result[$owningTable][$sourceColumn] = $newValId
? $newValId[$targetClass->getFieldForColumn($targetColumn)]
: null;
}
}

Expand Down
28 changes: 0 additions & 28 deletions lib/Doctrine/ORM/Persisters/CollectionPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,6 @@ public function delete(PersistentCollection $collection);
*/
public function update(PersistentCollection $collection);

/**
* Deletes rows.
*
* @param \Doctrine\ORM\PersistentCollection $collection
*
* @return void
*/
public function deleteRows(PersistentCollection $collection);

/**
* Inserts rows.
*
* @param \Doctrine\ORM\PersistentCollection $collection
*
* @return void
*/
public function insertRows(PersistentCollection $collection);

/**
* Counts the size of this persistent collection.
*
Expand Down Expand Up @@ -118,16 +100,6 @@ public function containsKey(PersistentCollection $collection, $key);
*/
public function removeElement(PersistentCollection $collection, $element);

/**
* Removes an element by key.
*
* @param \Doctrine\ORM\PersistentCollection $collection
* @param mixed $key
*
* @return void
*/
public function removeKey(PersistentCollection $collection, $key);

/**
* Gets an element by key.
*
Expand Down
Loading

0 comments on commit 9c3cb57

Please sign in to comment.