123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
-
-
- namespace Doctrine\ORM\Persisters;
-
- use Doctrine\ORM\EntityManager,
- Doctrine\ORM\PersistentCollection;
-
-
- abstract class AbstractCollectionPersister
- {
-
-
- protected $_em;
-
-
-
- protected $_conn;
-
-
-
- protected $_uow;
-
-
-
- public function __construct(EntityManager $em)
- {
- $this->_em = $em;
- $this->_uow = $em->getUnitOfWork();
- $this->_conn = $em->getConnection();
- }
-
-
-
- public function delete(PersistentCollection $coll)
- {
- $mapping = $coll->getMapping();
-
- if ( ! $mapping['isOwningSide']) {
- return;
- }
-
- $sql = $this->_getDeleteSQL($coll);
- $this->_conn->executeUpdate($sql, $this->_getDeleteSQLParameters($coll));
- }
-
-
-
- abstract protected function _getDeleteSQL(PersistentCollection $coll);
-
-
-
- abstract protected function _getDeleteSQLParameters(PersistentCollection $coll);
-
-
-
- public function update(PersistentCollection $coll)
- {
- $mapping = $coll->getMapping();
-
- if ( ! $mapping['isOwningSide']) {
- return;
- }
-
- $this->deleteRows($coll);
-
- $this->insertRows($coll);
- }
-
- public function deleteRows(PersistentCollection $coll)
- {
- $deleteDiff = $coll->getDeleteDiff();
- $sql = $this->_getDeleteRowSQL($coll);
-
- foreach ($deleteDiff as $element) {
- $this->_conn->executeUpdate($sql, $this->_getDeleteRowSQLParameters($coll, $element));
- }
- }
-
-
-
-
- public function insertRows(PersistentCollection $coll)
- {
- $insertDiff = $coll->getInsertDiff();
- $sql = $this->_getInsertRowSQL($coll);
-
- foreach ($insertDiff as $element) {
- $this->_conn->executeUpdate($sql, $this->_getInsertRowSQLParameters($coll, $element));
- }
- }
-
- public function count(PersistentCollection $coll)
- {
- throw new \BadMethodCallException("Counting the size of this persistent collection is not supported by this CollectionPersister.");
- }
-
- public function slice(PersistentCollection $coll, $offset, $length = null)
- {
- throw new \BadMethodCallException("Slicing elements is not supported by this CollectionPersister.");
- }
-
- public function contains(PersistentCollection $coll, $element)
- {
- throw new \BadMethodCallException("Checking for existance of an element is not supported by this CollectionPersister.");
- }
-
- public function containsKey(PersistentCollection $coll, $key)
- {
- throw new \BadMethodCallException("Checking for existance of a key is not supported by this CollectionPersister.");
- }
-
- public function get(PersistentCollection $coll, $index)
- {
- throw new \BadMethodCallException("Selecting a collection by index is not supported by this CollectionPersister.");
- }
-
-
-
- abstract protected function _getDeleteRowSQL(PersistentCollection $coll);
-
-
-
- abstract protected function _getDeleteRowSQLParameters(PersistentCollection $coll, $element);
-
-
-
- abstract protected function _getUpdateRowSQL(PersistentCollection $coll);
-
-
-
- abstract protected function _getInsertRowSQL(PersistentCollection $coll);
-
-
-
- abstract protected function _getInsertRowSQLParameters(PersistentCollection $coll, $element);
- }
|