123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
-
-
- namespace Doctrine\ORM\Persisters;
-
- use Doctrine\ORM\PersistentCollection,
- Doctrine\ORM\UnitOfWork;
-
-
- class OneToManyPersister extends AbstractCollectionPersister
- {
-
-
- protected function _getDeleteRowSQL(PersistentCollection $coll)
- {
- $mapping = $coll->getMapping();
- $targetClass = $this->_em->getClassMetadata($mapping->getTargetEntityName());
- $table = $targetClass->getTableName();
-
- $ownerMapping = $targetClass->getAssociationMapping($mapping['mappedBy']);
-
- $setClause = '';
- foreach ($ownerMapping->sourceToTargetKeyColumns as $sourceCol => $targetCol) {
- if ($setClause != '') $setClause .= ', ';
- $setClause .= "$sourceCol = NULL";
- }
-
- $whereClause = '';
- foreach ($targetClass->getIdentifierColumnNames() as $idColumn) {
- if ($whereClause != '') $whereClause .= ' AND ';
- $whereClause .= "$idColumn = ?";
- }
-
- return array("UPDATE $table SET $setClause WHERE $whereClause", $this->_uow->getEntityIdentifier($element));
- }
-
- protected function _getInsertRowSQL(PersistentCollection $coll)
- {
- return "UPDATE xxx SET foreign_key = yyy WHERE foreign_key = zzz";
- }
-
-
- protected function _getUpdateRowSQL(PersistentCollection $coll)
- {
- return;
- }
-
-
-
- protected function _getDeleteSQL(PersistentCollection $coll)
- {
-
- }
-
-
-
- protected function _getDeleteSQLParameters(PersistentCollection $coll)
- {}
-
-
-
- protected function _getInsertRowSQLParameters(PersistentCollection $coll, $element)
- {}
-
-
-
- protected function _getDeleteRowSQLParameters(PersistentCollection $coll, $element)
- {}
-
-
-
- public function count(PersistentCollection $coll)
- {
- $mapping = $coll->getMapping();
- $targetClass = $this->_em->getClassMetadata($mapping['targetEntity']);
- $sourceClass = $this->_em->getClassMetadata($mapping['sourceEntity']);
-
- $params = array();
- $id = $this->_em->getUnitOfWork()->getEntityIdentifier($coll->getOwner());
-
- $where = '';
- foreach ($targetClass->associationMappings[$mapping['mappedBy']]['joinColumns'] AS $joinColumn) {
- if ($where != '') {
- $where .= ' AND ';
- }
- $where .= $joinColumn['name'] . " = ?";
- if ($targetClass->containsForeignIdentifier) {
- $params[] = $id[$sourceClass->getFieldForColumn($joinColumn['referencedColumnName'])];
- } else {
- $params[] = $id[$sourceClass->fieldNames[$joinColumn['referencedColumnName']]];
- }
- }
-
- $sql = "SELECT count(*) FROM " . $targetClass->getQuotedTableName($this->_conn->getDatabasePlatform()) . " WHERE " . $where;
- return $this->_conn->fetchColumn($sql, $params);
- }
-
-
-
- public function slice(PersistentCollection $coll, $offset, $length = null)
- {
- $mapping = $coll->getMapping();
- return $this->_em->getUnitOfWork()
- ->getEntityPersister($mapping['targetEntity'])
- ->getOneToManyCollection($mapping, $coll->getOwner(), $offset, $length);
- }
-
-
-
- public function contains(PersistentCollection $coll, $element)
- {
- $mapping = $coll->getMapping();
- $uow = $this->_em->getUnitOfWork();
-
-
- if ($uow->getEntityState($element, UnitOfWork::STATE_NEW) == UnitOfWork::STATE_NEW) {
- return false;
- }
-
-
-
- $id = current( $uow->getEntityIdentifier($coll->getOwner()) );
-
- return $uow->getEntityPersister($mapping['targetEntity'])
- ->exists($element, array($mapping['mappedBy'] => $id));
- }
- }
|