Esempio n. 1
0
 /**
  * Find a model for a scheme and id combo, false on fail
  *
  * @param string $schemeName Scheme name
  * @param mixed $identity Identity
  * @return One_Model
  */
 public static function find($schemeName, $identity)
 {
     $key = "model.{$schemeName}.{$identity}";
     if (!self::$registry) {
         self::$registry = new One_Registry();
         return false;
     }
     return self::$registry->get($key);
 }
Esempio n. 2
0
 /**
  * Select a single instance.
  *
  * @param mixed $scheme Can be the name of a One_Scheme or the One_Scheme object itself
  * @param mixed $identityValue
  * @return One_Model
  */
 public function selectOne(One_Scheme_Interface $scheme, $identityValue)
 {
     $cached = One_Model_IdentityMap::find($scheme->getName(), $identityValue);
     if ($cached) {
         return $cached;
     }
     $db = $this->db($scheme);
     $renderer = $this->getRenderer();
     $query = One_Repository::selectQuery($scheme->getName());
     $idAttr = $scheme->getIdentityAttribute();
     $column = $idAttr->getName();
     $value = $idAttr->toString($identityValue);
     $query->where($column, 'eq', $value);
     $result = $this->executeSchemeQuery($query);
     return count($result) > 0 ? $result[0] : NULL;
 }
Esempio n. 3
0
 /**
  * Select a single instance.
  *
  * @param mixed $scheme Can be the name of a One_Scheme or the One_Scheme object itself
  * @param mixed $identityValue
  * @return One_Model
  */
 public function selectOne(One_Scheme $scheme, $identityValue)
 {
     $cached = One_Model_IdentityMap::find($scheme->getName(), $identityValue);
     if ($cached) {
         return $cached;
     }
     $db = $this->db($scheme);
     $connectionMeta = $scheme->getResources();
     $collection = $db->selectCollection($connectionMeta['collection']);
     try {
         $result = $collection->findOne(array('_id' => new MongoId($identityValue)));
     } catch (Exception $e) {
         throw new One_Exception('Query failed: ' . $e->getMessage());
     }
     if (null !== $result) {
         $result = $this->arrayToInstance($scheme, $result);
     }
     return $result;
 }