/**
  *
  *
  * @param \perf\Db\Connection $connection
  * @param object $entity
  * @return \perf\Db\QueryFilter
  */
 public function getFilter(\perf\Db\Connection $connection, $entity)
 {
     $reflectionObject = new \ReflectionObject($entity);
     $clauses = array();
     $parameters = array();
     foreach ($this->columns as $column) {
         $columnName = $column->getColumnName();
         $propertyName = $column->getPropertyName();
         $reflectionProperty = $reflectionObject->getProperty($propertyName);
         if ($reflectionProperty->isPublic()) {
             $value = $reflectionProperty->getValue($entity);
         } else {
             $reflectionProperty->setAccessible(true);
             $value = $reflectionProperty->getValue($entity);
             $reflectionProperty->setAccessible(false);
         }
         $sqlColumnName = $connection->escapeAndQuoteField($columnName);
         $clauses[] = "({$sqlColumnName} = ?)";
         $parameters[] = $value;
     }
     $clause = join(' AND ', $clauses);
     return new \perf\Db\QueryFilter($clause, $parameters);
 }
예제 #2
0
 /**
  * Updates provided entity within storage.
  *
  * @param object $entity
  * @return void
  * @throws \DomainException
  * @throws \RuntimeException
  */
 public function update($entity)
 {
     $this->entityMetadata = $this->getEntityMetadata($entity);
     $entityStorage = $this->entityMetadata->getStorage();
     $connectionId = $entityStorage->getConnectionId();
     $this->connection = $this->getConnection($connectionId);
     $dbTable = $entityStorage->getTable();
     $sqlTable = $this->connection->escapeAndQuoteTable($dbTable);
     $sqlProperties = array();
     $parameters = array();
     foreach ($this->exportEntity($entity) as $columnName => $value) {
         $sqlField = $this->connection->escapeAndQuoteField($columnName);
         $sqlProperties[] = "{$sqlField} = ?";
         $parameters[] = $value;
     }
     $primaryKeyFilter = $this->getPrimaryKeyFilter($entity);
     $sqlWhere = $primaryKeyFilter->getClause();
     foreach ($primaryKeyFilter->getParameters() as $parameter) {
         $parameters[] = $parameter;
     }
     $sql = "UPDATE {$sqlTable} SET " . join(', ', $sqlProperties) . " WHERE {$sqlWhere}";
     $this->connection->execute($sql, $parameters);
 }
예제 #3
0
 /**
  *
  *
  * @return EntityIterator
  * @throws \RuntimeException
  */
 private function conclude()
 {
     $sql = join(' ', $this->sqlChunks);
     $result = $this->connection->query($sql, $this->parameters);
     return new EntityIterator($this->entityImporter, $this->entityMetadata, $result);
 }
 /**
  *
  *
  * @param \perf\Db\Connection $connection
  * @param object $entity
  * @return void
  */
 public function bind(\perf\Db\Connection $connection, $entity)
 {
     $id = $connection->getInsertId();
     $column = $this->getColumn();
     $reflectionObject = new \ReflectionObject($entity);
     $propertyName = $column->getPropertyName();
     $reflectionProperty = $reflectionObject->getProperty($propertyName);
     if ($reflectionProperty->isPublic()) {
         $reflectionProperty->setValue($entity, $id);
     } else {
         $reflectionProperty->setAccessible(true);
         $reflectionProperty->setValue($entity, $id);
         $reflectionProperty->setAccessible(false);
     }
 }