protected function onExecute(\UniMapper\Connection $connection) { $adapter = $connection->getAdapter($this->entityReflection->getAdapterName()); $primaryProperty = $this->entityReflection->getPrimaryProperty(); $query = $adapter->createDeleteOne($this->entityReflection->getAdapterResource(), $primaryProperty->getName(true), $connection->getMapper()->unmapValue($primaryProperty, $this->primaryValue)); return (bool) $adapter->execute($query); }
protected function onExecute(\UniMapper\Connection $connection) { $adapter = $connection->getAdapter($this->entityReflection->getAdapterName()); $primaryProperty = $this->entityReflection->getPrimaryProperty(); $query = $adapter->createSelectOne($this->entityReflection->getAdapterResource(), $primaryProperty->getName(true), $connection->getMapper()->unmapValue($primaryProperty, $this->primaryValue)); if ($this->associations["local"]) { $query->setAssociations($this->associations["local"]); } $result = $adapter->execute($query); if (!$result) { return false; } // Get remote associations if ($this->associations["remote"]) { settype($result, "array"); foreach ($this->associations["remote"] as $colName => $association) { $assocValue = $result[$association->getKey()]; $associated = $association->load($connection, [$assocValue]); // Merge returned associations if (isset($associated[$assocValue])) { $result[$colName] = $associated[$assocValue]; } } } return $connection->getMapper()->mapEntity($this->entityReflection->getName(), $result); }
protected function onExecute(\UniMapper\Connection $connection) { $adapter = $connection->getAdapter($this->entityReflection->getAdapterName()); $query = $adapter->createCount($this->entityReflection->getAdapterResource()); if ($this->filter) { $query->setFilter($connection->getMapper()->unmapFilter($this->entityReflection, $this->filter)); } return (int) $adapter->execute($query); }
protected function onExecute(\UniMapper\Connection $connection) { $adapter = $connection->getAdapter($this->entityReflection->getAdapterName()); $mapper = $connection->getMapper(); $query = $adapter->createInsert($this->entityReflection->getAdapterResource(), $mapper->unmapEntity($this->entity), $this->entityReflection->hasPrimary() ? $this->entityReflection->getPrimaryProperty()->getName(true) : null); $primaryValue = $adapter->execute($query); if ($this->entityReflection->hasPrimary()) { $t = $mapper->mapValue($this->entityReflection->getPrimaryProperty(), $primaryValue); return $t; } }
protected function onExecute(\UniMapper\Connection $connection) { $adapter = $connection->getAdapter($this->entityReflection->getAdapterName()); $mapper = $connection->getMapper(); $values = $mapper->unmapEntity($this->entity); // Values can not be empty if (empty($values)) { throw new Exception\QueryException("Nothing to update!"); } $query = $adapter->createUpdateOne($this->entityReflection->getAdapterResource(), $this->entityReflection->getPrimaryProperty()->getName(true), $mapper->unmapValue($this->entityReflection->getPrimaryProperty(), $this->primaryValue), $values); return (bool) $adapter->execute($query); }
protected function onExecute(\UniMapper\Connection $connection) { $mapper = $connection->getMapper(); $values = $mapper->unmapEntity($this->entity); // Values can not be empty if (empty($values)) { throw new Exception\QueryException("Nothing to update!"); } $adapter = $connection->getAdapter($this->entityReflection->getAdapterName()); $query = $adapter->createUpdate($this->entityReflection->getAdapterResource(), $values); if ($this->filter) { $query->setFilter($mapper->unmapFilter($this->entityReflection, $this->filter)); } return (int) $adapter->execute($query); }
protected function onExecute(\UniMapper\Connection $connection) { $adapter = $connection->getAdapter($this->entityReflection->getAdapterName()); $mapper = $connection->getMapper(); $cache = null; if ($this->cached) { $cache = $connection->getCache(); } if ($cache) { $cachedResult = $cache->load($this->_getQueryChecksum()); if ($cachedResult) { return $mapper->mapCollection($this->entityReflection->getName(), $cachedResult); } } $query = $adapter->createSelect($this->entityReflection->getAdapterResource(), $this->createSelection(), $this->orderBy, $this->limit, $this->offset); if ($this->filter) { $query->setFilter($mapper->unmapFilter($this->entityReflection, $this->filter)); } if ($this->associations["local"]) { $query->setAssociations($this->associations["local"]); } // Execute adapter query $result = $adapter->execute($query); // Get remote associations if ($this->associations["remote"] && !empty($result)) { settype($result, "array"); foreach ($this->associations["remote"] as $colName => $association) { $assocKey = $association->getKey(); $assocValues = []; foreach ($result as $item) { if (is_array($item)) { $assocValues[] = $item[$assocKey]; } else { $assocValues[] = $item->{$assocKey}; } } $associated = $association->load($connection, $assocValues); // Merge returned associations if (!empty($associated)) { $result = $this->_mergeAssociated($result, $associated, $assocKey, $colName); } } } if ($cache) { $cachedOptions = $this->cachedOptions; // Add default cache tag if (isset($cachedOptions[ICache::TAGS])) { $cachedOptions[ICache::TAGS][] = ICache::TAG_QUERY; // @todo is it really array? } else { $cachedOptions[ICache::TAGS] = [ICache::TAG_QUERY]; } // Cache invalidation should depend on entity changes if (isset($cachedOptions[ICache::FILES])) { $cachedOptions[ICache::FILES] += $this->entityReflection->getRelatedFiles(); } else { $cachedOptions[ICache::FILES] = $this->entityReflection->getRelatedFiles(); } $cache->save($this->_getQueryChecksum(), $result, $cachedOptions); } return $mapper->mapCollection($this->entityReflection->getName(), empty($result) ? [] : $result); }