getUnitOfWork() 공개 메소드

Gets the UnitOfWork used by the EntityManager to coordinate operations.
public getUnitOfWork ( ) : UnitOfWork
리턴 UnitOfWork
예제 #1
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);
         }
     }
 }
예제 #2
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;
 }
예제 #3
0
 /**
  * @override
  */
 public function getUnitOfWork()
 {
     return isset($this->_uowMock) ? $this->_uowMock : parent::getUnitOfWork();
 }