<commit_before><?php

namespace PHPCR\Util\QOM;

use PHPCR\Query\QOM\QueryObjectModelFactoryInterface,
    PHPCR\Query\QOM\DynamicOperandInterface,
    PHPCR\Query\QOM\ConstraintInterface,
    PHPCR\Query\QOM\SourceInterface,
    PHPCR\Query\QOM\JoinConditionInterface,
    PHPCR\Query\QOM\QueryObjectModelConstantsInterface;

/**
 * QueryBuilder class is responsible for dynamically create QOM queries.
 *
 * @author      <NAME> <<EMAIL>>
 * @author      <NAME> <<EMAIL>>
 * @author      <NAME> <<EMAIL>>
 */
class QueryBuilder
{
    /** The builder states. */
    const STATE_DIRTY = 0;
    const STATE_CLEAN = 1;

    /**
     * @var integer The state of the query object. Can be dirty or clean.
     */
    private $state = self::STATE_CLEAN;

    /**
     * @var \PHPCR\Query\QOM\QueryObjectModelFactoryInterface QOMFactory
     */
    private $qomFactory;

    /**
     * @var integer The maximum number of results to retrieve.
     */
    private $firstResult = null;

    /**
     * @var integer The maximum number of results to retrieve.
     */
    private $maxResults = null;

    /**
     * @var array with the orderings that determine the order of the result
     */
    private $orderings = array();

    /**
     * @var \PHPCR\Query\QOM\ConstraintInterface to apply to the query.
     */
    private $constraint = null;

    /**
     * @var array with the columns to be selected.
     */
    private $columns = array();

    /**
     * @var \PHPCR\Query\QOM\SourceInterface source of the query.
     */
    private $source = null;

    /**
     * @var \PHPCR\Query\QueryObjectModelInterface
     */
    private $query = null;

    /**
     * @var array The query parameters.
     */
    private $params = array();

    /**
     * Initializes a new QueryBuilder
     *
     * @param \PHPCR\Query\QOM\QueryObjectModelFactoryInterface $qomFactory
     */
    public function __construct(QueryObjectModelFactoryInterface $qomFactory)
    {
        $this->qomFactory = $qomFactory;
    }

    /**
     * Get the associated QOMFactory for this query builder
     *
     * @return \PHPCR\Query\QOM\QueryObjectModelFactoryInterface
     */
    public function getQOMFactory()<commit_msg>add support to create a query builder from a query<commit_after><?php

namespace PHPCR\Util\QOM;

use PHPCR\Query\QOM\QueryObjectModelFactoryInterface,
    PHPCR\Query\QOM\DynamicOperandInterface,
    PHPCR\Query\QOM\ConstraintInterface,
    PHPCR\Query\QOM\SourceInterface,
    PHPCR\Query\QOM\JoinConditionInterface,
    PHPCR\Query\QOM\QueryObjectModelConstantsInterface,
    PHPCR\Query\QueryInterface,
    PHPCR\Query\QOM\QueryObjectModelInterface;

/**
 * QueryBuilder class is responsible for dynamically create QOM queries.
 *
 * @author      <NAME> <<EMAIL>>
 * @author      <NAME> <<EMAIL>>
 * @author      <NAME> <<EMAIL>>
 */
class QueryBuilder
{
    /** The builder states. */
    const STATE_DIRTY = 0;
    const STATE_CLEAN = 1;

    /**
     * @var integer The state of the query object. Can be dirty or clean.
     */
    private $state = self::STATE_CLEAN;

    /**
     * @var \PHPCR\Query\QOM\QueryObjectModelFactoryInterface QOMFactory
     */
    private $qomFactory;

    /**
     * @var integer The maximum number of results to retrieve.
     */
    private $firstResult = null;

    /**
     * @var integer The maximum number of results to retrieve.
     */
    private $maxResults = null;

    /**
     * @var array with the orderings that determine the order of the result
     */
    private $orderings = array();

    /**
     * @var \PHPCR\Query\QOM\ConstraintInterface to apply to the query.
     */
    private $constraint = null;

    /**
     * @var array with the columns to be selected.
     */
    private $columns = array();

    /**
     * @var \PHPCR\Query\QOM\SourceInterface source of the query.
     */
    private $source = null;

    /**
     * @var \PHPCR\Query\QueryObjectModelInterface
     */
    private $query = null;

    /**
     * @var array The query parameters.
     */
    private $params = array();

    /**
     * Initializes a new QueryBuilder
     *
     * @param \PHPCR\Query\QOM\QueryObjectModelFactoryInterface $qomFactory
     */
    public function __construct(QueryObjectModelFactoryInterface $qomFactory)
    {
        $this->qomFactory = $qomFactory;
    }

    /**
     * Get a query builder instance from an existing query
     *
     * @param  string $statement the statement in the specified language
     * @param  string $language the query language
     * @return QueryBuilder This QueryBuilder instance.
     */
    public function setFromQuery($statement, $language)
    {
        if (QueryInterface::JCR_SQL2 === $language) {
            $converter = new Sql2ToQomQueryConverter($this->qomFactory);
            $statement = $converter->parse($statement);
        }

        if (!$statement instanceof QueryObjectModelInterface) {
            throw new \InvalidArgumentException("Language '$language' not supported");
        }

        $this->state = self::STATE_DIRTY;
        $this->source = $statement->getSource();
        $this->constraint = $statement->getConstraint();
        $this->orderings = $statement->getOrderings();
        $this->columns = $statement->getColumns();

        return $this;
    }

    /**
     * Get the associated QOMFactory for this query builder
     *
     * @return \PHPCR\Query\QOM\QueryObjectModelFactoryInterface
     */
    public function getQOMFactory()
{'fraction_non_alphanumeric': 0.11174103877103146, 'fraction_numerical': 0.0010972933430870519, 'mean_word_length': 2.5102695763799745, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1194505', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1558, 'n_words': 409}