Inheritance: implements Doctrine\Common\Persistence\ObjectManager
Exemplo n.º 1
0
 /**
  * @param \Doctrine\OXM\XmlEntityManager $xem
  * @param \Doctrine\OXM\Mapping\ClassMetadataInfo
  */
 public function __construct(XmlEntityManager $xem, ClassMetadata $metadata)
 {
     $this->metadata = $metadata;
     $this->xem = $xem;
     $this->marshaller = $xem->getMarshaller();
     $this->storage = $xem->getStorage();
 }
Exemplo n.º 2
0
 /**
  * Finds an entity by its identifier.
  *
  * @param $id The identifier.
  * @param int $lockMode
  * @param int $lockVersion
  * @return object The entity.
  */
 public function find($id, $lockMode = LockMode::NONE, $lockVersion = null)
 {
     // Check identity map first
     if ($entity = $this->xem->getUnitOfWork()->tryGetById($id, $this->class->rootXmlEntityName)) {
         if ($lockMode != LockMode::NONE) {
             $this->xem->lock($entity, $lockMode, $lockVersion);
         }
         return $entity;
         // Hit!
     }
     if ($lockMode == LockMode::NONE) {
         return $this->xem->getUnitOfWork()->getXmlEntityPersister($this->entityName)->load($id);
     } else {
         if ($lockMode == LockMode::OPTIMISTIC) {
             if (!$this->class->isVersioned) {
                 throw OptimisticLockException::notVersioned($this->entityName);
             }
             $entity = $this->xem->getUnitOfWork()->getEntityPersister($this->entityName)->load($id);
             $this->xem->getUnitOfWork()->lock($entity, $lockMode, $lockVersion);
             return $entity;
         } else {
             if (!$this->xem->getConnection()->isTransactionActive()) {
                 throw TransactionRequiredException::transactionRequired();
             }
             return $this->xem->getUnitOfWork()->getXmlEntityPersister($this->entityName)->load($id, null, null, array(), $lockMode);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Returns the identifier assigned to the given entity.
  *
  * @param object $xmlEntity
  * @return mixed
  * @override
  */
 public function generate(XmlEntityManager $xem, $xmlEntity)
 {
     $class = $xem->getClassMetadata(get_class($xmlEntity));
     $idField = $class->identifier;
     $value = $class->reflFields[$idField]->getValue($xmlEntity);
     if (isset($value)) {
         if (is_object($value)) {
             // NOTE: Single Columns as associated identifiers only allowed - this constraint it is enforced.
             $identifier = current($xem->getUnitOfWork()->getEntityIdentifier($value));
         } else {
             $identifier = $value;
         }
     } else {
         throw OXMException::entityMissingAssignedId($xmlEntity);
     }
     return $identifier;
 }
Exemplo n.º 4
0
 public function testObjectFlushPerPersist()
 {
     for ($i = 1; $i <= 10; $i++) {
         $simple = new SimpleWithField();
         $simple->id = $i;
         $this->xem->persist($simple);
         $this->xem->flush();
         $filepath = __DIR__ . "/../Workspace/Doctrine/Tests/OXM/Entities/SimpleWithField/{$i}.xml";
         $this->assertFileExists($filepath);
         $this->assertXmlStringEqualsXmlFile($filepath, '<?xml version="1.0" encoding="UTF-8"?><simple-with-field id="' . $i . '"/>');
         unlink($filepath);
     }
 }
Exemplo n.º 5
0
 /**
  * @override
  */
 public function getUnitOfWork()
 {
     return isset($this->_uowMock) ? $this->_uowMock : parent::getUnitOfWork();
 }
Exemplo n.º 6
0
 /**
  * Initializes a new UnitOfWork instance, bound to the given EntityManager.
  *
  * @param Doctrine\OXM\XmlEntityManager $em
  */
 public function __construct(XmlEntityManager $xem)
 {
     $this->xem = $xem;
     $this->evm = $xem->getEventManager();
 }