/**
  * Adds a new entity to the storage.
  *
  * @param Identity $value
  *
  * @return mixed
  */
 public function add(Identity $value)
 {
     $id = (string) $value->id();
     $this->data[$id] = clone $value;
     return clone $value;
 }
 /**
  * {@inheritdoc}
  */
 public function exists(Identity $id) : bool
 {
     $key = $this->cacheNamespaceExists . $id->id();
     $cachedItem = $this->cache->getItem($key);
     if ($cachedItem->isHit() && null !== ($result = $cachedItem->get())) {
         return $result;
     }
     $result = $this->repository->exists($id);
     $this->saveToCache($cachedItem, $result);
     return $result;
 }
 /**
  * Retrieves an entity by its id.
  *
  * @param Identity    $id
  * @param Fields|null $fields
  *
  * @return array
  */
 public function find(Identity $id, Fields $fields = null)
 {
     $result = $this->selectOneQuery($id->id(), $fields ? $this->getColumns($fields) : $fields);
     return $result ? $result : [];
 }
 /**
  * Removes the entity with the given id.
  *
  * @param $id
  */
 public function remove(Identity $id)
 {
     $query = $this->queryBuilder();
     $query->delete($this->mapping->name())->where($query->expr()->eq($this->mapping->identity(), ':id'))->setParameter(':id', $id->id())->execute();
 }
 /**
  * Returns whether an entity with the given id exists.
  *
  * @param $id
  *
  * @return bool
  */
 public function exists(Identity $id)
 {
     $model = self::$instance;
     $filter = new DomainFilter();
     $filter->must()->equal($model->getKeyName(), $id->id());
     return $this->count($filter) > 0;
 }