/** * Returns the object with the (internal) identifier, if it is known to the * backend. Otherwise NULL is returned. * * @param string $identifier * @param string $className * @return object The object for the identifier if it is known, or NULL */ public function getObjectByIdentifier($identifier, $className) { if ($this->identityMap->hasIdentifier($identifier, $className)) { return $this->identityMap->getObjectByIdentifier($identifier, $className); } else { $query = $this->queryFactory->create($className); return $query->matching($query->withUid($identifier))->execute()->getFirst(); } }
/** * Maps a single row on an object of the given class * * @param string $className The name of the target class * @param array $row A single array with field_name => value pairs * @return object An object of the given class */ protected function mapSingleRow($className, array $row) { if ($this->identityMap->hasIdentifier($row['uid'], $className)) { $object = $this->identityMap->getObjectByIdentifier($row['uid'], $className); } else { $object = $this->createEmptyObject($className); $this->identityMap->registerObject($object, $row['uid']); $this->thawProperties($object, $row); $object->_memorizeCleanState(); $this->persistenceSession->registerReconstitutedObject($object); } return $object; }
/** * Returns the object with the (internal) identifier, if it is known to the * backend. Otherwise NULL is returned. * * @param string $identifier * @param string $className * @return object The object for the identifier if it is known, or NULL */ public function getObjectByIdentifier($identifier, $className) { if ($this->identityMap->hasIdentifier($identifier, $className)) { return $this->identityMap->getObjectByIdentifier($identifier, $className); } else { $query = $this->queryFactory->create($className); $result = $query->matching($query->withUid($identifier))->execute(); $object = NULL; if (count($result) > 0) { $object = current($result); } return $object; } }
/** * Finds an object matching the given identifier. * * @param int $uid The identifier of the object to find * @return object The matching object if found, otherwise NULL * @api */ public function findByUid($uid) { if ($this->identityMap->hasIdentifier($uid, $this->objectType)) { $object = $this->identityMap->getObjectByIdentifier($uid, $this->objectType); } else { $query = $this->createQuery(); $query->getQuerySettings()->setRespectSysLanguage(FALSE); $query->getQuerySettings()->setRespectStoragePage(FALSE); $object = $query->matching($query->equals('uid', $uid))->execute()->getFirst(); if ($object !== NULL) { $this->identityMap->registerObject($object, $uid); } } return $object; }