Example #1
0
 /**
  * Deleta dados no repositório.
  *
  * @param ValueObjectAbstract $valueObject
  * @return br\gov\sial\core\persist\Persist
  * @throws PersistException
  * */
 public function delete(ValueObjectAbstract $valueObject)
 {
     $annon = $valueObject->annotation()->load();
     $tmpFilter = NULL;
     # tecnica explicada no metodo findByParam
     $tmpOperator = array('WHERE', 'AND');
     foreach ($annon->attrs as $field) {
         if (!isset($field->database) || !isset($field->primaryKey)) {
             // @codeCoverageIgnoreStart
             continue;
             // @codeCoverageIgnoreEnd
         }
         $tmpFilter .= sprintf(' %1$s %2$s = :%2$s', $tmpOperator[(bool) $tmpFilter], $field->database);
         $params[$field->database] = self::_getValue($valueObject, $field->get, $field->type);
     }
     # por padrao nao eh possivel atualizar toda a entidade, se realmente  for necessario realizar
     # esta operacao sobreescreve este metodo
     PersistException::throwsExceptionIfParamIsNull($tmpFilter, sprintf(self::PERSIST_UNAVAILABLE_DELETE_FILTER, $annon->entity));
     $query = sprintf('DELETE FROM %s %s', $annon->entity, $tmpFilter);
     $this->_persist->getConnect()->prepare($query, $params)->update();
 }
Example #2
0
 /**
  * Cria entidade para manipulação no objeto de consulta (Query)
  *
  * <ul>
  *     <li>Entity::__construct(string $namespace, string[] $column)</li>
  *     <li>Entity::__construct(ValueObject $valueObject, string[] $column)</li>
  *     <li>Entity::__construct(array(string $alias => string $namespace), strin[] $column)</li>
  *     <li>Entity::__construct(array(string $alias => ValueObject $valueObject), string[] $column)</li>
  * </ul>
  *
  * @param mixed $entity
  * @param string[] $columns
  * @return Entity
  * */
 public function getEntity($entity, array $columns = array())
 {
     return $this->_leaf->getEntity($entity, $columns);
 }