1
0
mirror of synced 2024-12-14 07:06:04 +03:00
doctrine2/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php

99 lines
2.4 KiB
PHP
Raw Normal View History

2008-08-16 23:40:59 +04:00
<?php
2009-01-29 20:00:44 +03:00
namespace Doctrine\ORM\Persisters;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\PersistentCollection;
2009-01-29 20:00:44 +03:00
abstract class AbstractCollectionPersister
2008-08-16 23:40:59 +04:00
{
protected $_em;
protected $_conn;
public function __construct(EntityManager $em)
{
$this->_em = $em;
$this->_conn = $em->getConnection();
}
public function recreate(PersistentCollection $coll)
2008-08-16 23:40:59 +04:00
{
if ($coll->getRelation()->isInverseSide()) {
return;
}
//...
}
public function delete(PersistentCollection $coll)
2008-08-16 23:40:59 +04:00
{
if ($coll->getRelation()->isInverseSide()) {
return;
}
//...
}
public function update(PersistentCollection $coll)
{
$this->deleteRows($coll);
$this->updateRows($coll);
$this->insertRows($coll);
}
2008-08-16 23:40:59 +04:00
/* collection update actions */
public function deleteRows(PersistentCollection $coll)
2008-08-16 23:40:59 +04:00
{
if ($coll->getMapping()->isInverseSide()) {
return; // ignore inverse side
}
$deleteDiff = $coll->getDeleteDiff();
$sql = $this->_getDeleteRowSql($coll);
$uow = $this->_em->getUnitOfWork();
foreach ($deleteDiff as $element) {
$this->_conn->exec($sql, $uow->getEntityIdentifier($element));
}
2008-08-16 23:40:59 +04:00
}
public function updateRows(PersistentCollection $coll)
2008-08-16 23:40:59 +04:00
{
}
public function insertRows(PersistentCollection $coll)
2009-01-29 20:00:44 +03:00
{
if ($coll->getMapping()->isInverseSide()) {
return; // ignore inverse side
}
2009-01-29 20:00:44 +03:00
$insertDiff = $coll->getInsertDiff();
$sql = $this->_getInsertRowSql($coll);
$uow = $this->_em->getUnitOfWork();
foreach ($insertDiff as $element) {
$this->_conn->exec($sql/*, $uow->getEntityIdentifier($element)*/);
}
2009-01-29 20:00:44 +03:00
}
/**
* Gets the SQL statement used for deleting a row from the collection.
*
* @param PersistentCollection $coll
*/
abstract protected function _getDeleteRowSql(PersistentCollection $coll);
2009-01-29 20:00:44 +03:00
/**
* Gets the SQL statement used for updating a row in the collection.
*
* @param PersistentCollection $coll
*/
abstract protected function _getUpdateRowSql();
/**
* Gets the SQL statement used for inserting a row from to the collection.
*
* @param PersistentCollection $coll
*/
abstract protected function _getInsertRowSql();
2008-08-16 23:40:59 +04:00
}