Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General optimizations around Persisters for simplicity and sanity of us all. #1246

Merged
merged 5 commits into from
Jan 13, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
117 changes: 1 addition & 116 deletions lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,73 +79,7 @@ public function __construct(EntityManager $em)
*/
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));
}
throw new \BadMethodCallException("Deleting elements is not supported by this CollectionPersister.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the method abstract instead?

}

/**
Expand Down Expand Up @@ -211,53 +145,4 @@ 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);
}
18 changes: 0 additions & 18 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
Loading