public function merge(array $query, array $result)
 {
     $query = ObjectManager::splitFromRow($query, $this->queryKeys);
     if ($query === null) {
         // the queryKeys are either unset or null, and not indexable
         // TODO: what should happen here?
         return;
     }
     $this->result[$query] = $result;
 }
 public function fromStorageRow(array $row, $object = null)
 {
     $pk = ObjectManager::splitFromRow($row, $this->primaryKey);
     if ($pk === null) {
         throw new \InvalidArgumentException('Storage row has no pk');
     } elseif (!isset($this->loaded[$pk])) {
         // unserialize the object
         return $this->loaded[$pk] = call_user_func($this->fromStorageRow, $row, $object);
     } elseif ($object === null) {
         // provide previously loaded object
         return $this->loaded[$pk];
     } elseif ($object !== $this->loaded[$pk]) {
         // loaded object of this id is not same object
         $class = get_class($object);
         $id = json_encode($pk);
         throw new \InvalidArgumentException("Duplicate '{$class}' objects for id {$id}");
     } else {
         // object was provided, load $row into $object
         // we already know $this->loaded[$pk] === $object
         return call_user_func($this->fromStorageRow, $row, $object);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function onAfterRemove($object, array $old, array $metadata)
 {
     $indexed = ObjectManager::splitFromRow($old, $this->indexed);
     if (!$indexed) {
         throw new DataModelException('Unindexable row: ' . FormatJson::encode($old), 'process-data');
     }
     $this->removeFromIndex($indexed, $old);
 }
 public function findMulti(array $queries, array $options = array())
 {
     $keys = array_keys(reset($queries));
     $pks = $this->getPrimaryKeyColumns();
     if (count($keys) !== count($pks) || array_diff($keys, $pks)) {
         return $this->fallbackFindMulti($queries, $options);
     }
     $conds = array();
     $dbr = $this->dbFactory->getDB(DB_SLAVE);
     foreach ($queries as $query) {
         $conds[] = $dbr->makeList($this->preprocessSqlArray($query), LIST_AND);
     }
     unset($query);
     $conds = $dbr->makeList($conds, LIST_OR);
     $result = array();
     // options can be ignored for primary key search
     $res = $this->find(array(new RawSql($conds)));
     if (!$res) {
         return $result;
     }
     // create temp array with pk value (usually uuid) as key and full db row
     // as value
     $temp = new MultiDimArray();
     foreach ($res as $val) {
         $val = UUID::convertUUIDs($val, 'alphadecimal');
         $temp[ObjectManager::splitFromRow($val, $this->primaryKey)] = $val;
     }
     // build return value by mapping the database rows to the matching array
     // index in $queries
     foreach ($queries as $i => $val) {
         $val = UUID::convertUUIDs($val, 'alphadecimal');
         $pk = ObjectManager::splitFromRow($val, $this->primaryKey);
         $result[$i][] = isset($temp[$pk]) ? $temp[$pk] : null;
     }
     return $result;
 }