Ejemplo n.º 1
0
 /**
  * Create a Query
  *
  * @param string $statement             the SQL2 statement
  * @param string $language              (see QueryInterface for list of supported types)
  * @param bool   $replaceWithFieldnames if * should be replaced with field names automatically
  *
  * @return Query
  */
 public function createQuery($statement, $language, $options = 0)
 {
     // TODO: refactor this to use the odm query builder
     $qb = $this->dm->createPhpcrQueryBuilder()->setFromQuery($statement, $language);
     if ($options & self::QUERY_REPLACE_WITH_FIELDNAMES) {
         $columns = $qb->getColumns();
         if (1 === count($columns)) {
             $column = reset($columns);
             if ('*' === $column->getColumnName() && null == $column->getPropertyName()) {
                 $qb->setColumns(array());
                 foreach ($this->class->getFieldNames() as $name) {
                     $qb->addSelect('a', $name);
                 }
             }
         }
     }
     $factory = $qb->getQOMFactory();
     $comparison = $factory->comparison($factory->propertyValue('a', 'phpcr:class'), Constants::JCR_OPERATOR_EQUAL_TO, $factory->literal($this->className));
     $qb->andWhere($comparison);
     return new Query($qb->getQuery(), $this->getDocumentManager());
 }