示例#1
0
 /**
  * 
  * @param object $entity
  * @param array $visited
  * @return void
  * @throws OHMRuntimeException
  */
 private function doPersist($entity, array &$visited)
 {
     $oid = spl_object_hash($entity);
     // Prevent infinite recursion
     if (isset($visited[$oid])) {
         return;
     }
     // Mark visited
     $visited[$oid] = $entity;
     $cm = $this->em->getClassMetadata(get_class($entity));
     $state = $this->cs->getState($entity, $oid, $cm);
     switch ($state) {
         case self::STATE_NEW:
             $this->cs->states[$oid] = self::STATE_MANAGED;
             $this->cs->insertions[$oid] = $entity;
             break;
         case self::STATE_REMOVED:
             // Entity becomes managed again
             unset($this->cs->deletions[$oid]);
             $this->cs->addToIdentityMap($entity, $cm);
             $this->cs->states[$oid] = self::STATE_MANAGED;
             $this->cs->updates[$oid] = $entity;
             break;
         case self::STATE_DETACHED:
             throw OHMRuntimeException::cannotPersistDetachedEntity($entity);
         case self::STATE_MANAGED:
             $this->cs->updates[$oid] = $entity;
     }
 }
示例#2
0
 /**
  * 
  * @param object $entity
  * @param string $oid
  * @param ClassMetadata $cm
  * @return boolean
  * @throws OHMRuntimeException
  */
 public function removeFromIdentityMap($entity, $oid, ClassMetadata $cm)
 {
     $idHash = implode(' ', $this->identifiers[$oid]);
     if ($idHash === '') {
         throw OHMRuntimeException::entityHasNoIdentity($entity, "remove from identity map");
     }
     $className = $cm->rootName;
     if (isset($this->identityMap[$className][$idHash])) {
         unset($this->identityMap[$className][$idHash]);
         return true;
     }
     return false;
 }