@param ORMBuilder|DBALBuilder $queryBuilder

@return QueryBuilderInterface

@throws QueryBuilderException
559534
public static function createQueryBuilder($queryBuilder)
    {
        if ($queryBuilder instanceof ORMBuilder) {
            return new ORMQueryBuilder($queryBuilder);
        }
        if ($queryBuilder instanceof DBALBuilder) {
            return new DBALQueryBuilder($queryBuilder);
        }

        throw new QueryBuilderException(
            sprintf('Invalid parameter "queryBuilder". Use %s or %s', ORMBuilder::class, DBALBuilder::class)
        );
    }
1233825
public function setQueryBuilder($queryBuilder)
    {
        if (!is_object($queryBuilder)) {
            throw new InvalidQueryBuilderObject('Parameter must be an object of "\Doctrine\ORM\QueryBuilder" or "Doctrine\ODM\MongoDB\Query\Builder"');
        }

        if (!$queryBuilder instanceof QueryBuilder && !$queryBuilder instanceof Builder) {
            throw new InvalidQueryBuilderObject(sprintf('%s is not valid query builder object', get_class($queryBuilder)));
        }

        $this->queryBuilder = $queryBuilder;
    }
445259
public function alterBaseQueryBuilder($queryBuilder, $options = array(), $action = 'list')
    {
        if ($this->getHasContextProperty()) {

            $queryBuilder = $this->getResourceContextManager()->addContextFilterToQueryBuilder(
                $queryBuilder,
                $this->getContextPropertyRelationName(),
                $this->getContextPropertyValueNamePrefix()
            );

        }
        return $queryBuilder;
    }
828491
private function getPreparedFlushErrorQuery(QueryBuilder $queryBuilder)
    {
        return $queryBuilder
            ->update($this->table)
            ->set('errors', '')
            ->where(
                $queryBuilder->expr()->notLike('errors', $queryBuilder->createNamedParameter(''))
            );
    }
317290
public function getScalarPaginator(\Doctrine\ORM\QueryBuilder $queryBuilder)
    {
        $request = $this->container->get('request_stack')->getCurrentRequest();
        
        $pagerfanta = new Paginator(new ArrayAdapter($queryBuilder->getQuery()->getScalarResult()));
        $pagerfanta->setDefaultFormat($this->getFormatPaginator());
        $pagerfanta->setContainer($this->container);
        if($request){
            $pagerfanta->setRequest($request);
        }
        return $pagerfanta;
    }
650877
private function getQueryBuilderForCachingHash($queryBuilder)
    {
        return [
            $queryBuilder->getQuery()->getSQL(),
            array_map([$this, 'parameterToArray'], $queryBuilder->getParameters()->toArray()),
        ];
    }
1174889
protected function getUseI18nQueryMethod(\QueryBuilder $builder)
    {

        $currentTable = $this->getTable();
        $db = $currentTable->getDatabase();

        $i18nTableName = $currentTable->getName() . '_i18n';
        $i18nTable = $db->getTable($i18nTableName);
        if (!$i18nTable) {
            $this->exceptionError('Table '.$i18nTableName.' not found');
        }
        foreach ($i18nTable->getForeignKeys() as $fk) {
            if ($fk->getForeignTableName() == $currentTable->getName()) {
                $foreignKey = $fk;
            }
        }

        $script = '

    /**
     * Use the I18n relation query object
     *
     * @see       useQuery()
     *
     * @param     string $locale Locale to use for the join condition, e.g. \'fr_FR\'
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, \'left join\', \'right join\', \'inner join\'. Defaults to left join.
     *
     * @return    \\' . $builder->getNewStubQueryBuilder($i18nTable)->getFullyQualifiedClassname() . ' A secondary query class using the current class as primary query
     */
    public function useI18nQuery($locale = \'ru\', $relationAlias = null, $joinType = Criteria::LEFT_JOIN)
    {
        return $this
            ->joinI18n($locale, $relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : \''. $builder->getRefFKPhpNameAffix($foreignKey) .'\', \'\\'. $builder->getNewStubQueryBuilder($i18nTable)->getFullyQualifiedClassname() .'\');
    }';
        return $script;
    }
209762
public function newQuery() : QueryBuilder
    {
        $model = $this->container->make($this->getModelName());

        if (!$model instanceof Model) {
            throw new RepositoryException("Class {$this->model()} must be an instance of " . Model::class);
        }

        return $model->newQuery();
    }
178225
public function getQuery(QueryBuilder $queryBuilder)
    {
        $action = $this->getRule()->getAction();
        $foundType = preg_match('/\[\[(.*)\]\]/', $action, $matches);

        if ($foundType) {
            $type = $matches[1];
            $parts = explode(']]', $action);
            $action = ($foundType) ? $parts[1] : $action;

            return $queryBuilder
                ->join('l.resourceType', 'rt')
                ->andWhere('l.action = :action')
                ->andWhere('rt.name = :type')
                ->setParameter('action', $action)
                ->setParameter('type', $type);
        } else {
            return $queryBuilder
                ->andWhere('l.action = :action')
                ->setParameter('action', $action);
        }
    }
1312191
protected function filterQueryBuilder(QueryBuilder $queryBuilder, string $field, ListFilter $listFilter)
    {
        $value = $this->filterEasyadminAutocompleteValue($listFilter->getValue());
        // Empty string and numeric keys is considered as "not applied filter"
        if (null === $value || '' === $value || \is_int($field)) {
            return;
        }

        // Add root entity alias if none provided
        $queryField = $listFilter->getProperty();
        if (false === \strpos($queryField, '.')) {
            $queryField = $queryBuilder->getRootAlias().'.'.$queryField;
        }

        // Checks if filter is directly appliable on queryBuilder
        if (!$this->isFilterAppliable($queryBuilder, $queryField)) {
            return;
        }

        $operator = $listFilter->getOperator();
        // Sanitize parameter name
        $parameter = 'form_filter_'.\str_replace('.', '_', $field);

        switch ($operator) {
            case ListFilter::OPERATOR_EQUALS:
                if ('_NULL' === $value) {
                    $queryBuilder->andWhere(\sprintf('%s IS NULL', $queryField));
                } elseif ('_NOT_NULL' === $value) {
                    $queryBuilder->andWhere(\sprintf('%s IS NOT NULL', $queryField));
                } else {
                    $queryBuilder
                        ->andWhere(\sprintf('%s %s :%s', $queryField, '=', $parameter))
                        ->setParameter($parameter, $value)
                    ;
                }
                break;
            case ListFilter::OPERATOR_NOT:
                $queryBuilder
                    ->andWhere(\sprintf('%s %s :%s', $queryField, '!=', $parameter))
                    ->setParameter($parameter, $value)
                ;
                break;
            case ListFilter::OPERATOR_IN:
                // Checks that $value is not an empty Traversable
                if (0 < \count($value)) {
                    $queryBuilder
                        ->andWhere(\sprintf('%s %s (:%s)', $queryField, 'IN', $parameter))
                        ->setParameter($parameter, $value)
                    ;
                }
                break;
            case ListFilter::OPERATOR_NOTIN:
                // Checks that $value is not an empty Traversable
                if (0 < \count($value)) {
                    $queryBuilder
                        ->andWhere(\sprintf('%s %s (:%s)', $queryField, 'NOT IN', $parameter))
                        ->setParameter($parameter, $value)
                    ;
                }
                break;
            case ListFilter::OPERATOR_GT:
                $queryBuilder
                    ->andWhere(\sprintf('%s %s :%s', $queryField, '>', $parameter))
                    ->setParameter($parameter, $value)
                ;
                break;
            case ListFilter::OPERATOR_GTE:
                $queryBuilder
                    ->andWhere(\sprintf('%s %s :%s', $queryField, '>=', $parameter))
                    ->setParameter($parameter, $value)
                ;
                break;
            case ListFilter::OPERATOR_LT:
                $queryBuilder
                    ->andWhere(\sprintf('%s %s :%s', $queryField, '<', $parameter))
                    ->setParameter($parameter, $value)
                ;
                break;
            case ListFilter::OPERATOR_LTE:
                $queryBuilder
                    ->andWhere(\sprintf('%s %s :%s', $queryField, '<=', $parameter))
                    ->setParameter($parameter, $value)
                ;
                break;
            case ListFilter::OPERATOR_LIKE:
                $queryBuilder
                    ->andWhere(\sprintf('%s %s :%s', $queryField, 'LIKE', $parameter))
                    ->setParameter($parameter, '%'.$value.'%')
                ;
                break;
            default:
                throw new \RuntimeException(\sprintf('Operator "%s" is not supported !', $operator));
        }
    }
361025
protected function newBaseQueryBuilder()
    {
        $conn = $this->getConnection();

        $grammar = $conn->getQueryGrammar();

        return new QueryCacheBuilder($this->queryCache(), $conn, $grammar, $conn->getPostProcessor());
    }
646152
public function adaptQueryBuilder(QueryBuilder $queryBuilder, array $params = array())
    {
        parent::adaptQueryBuilder($queryBuilder);
        $queryBuilder
                ->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id')
                ->andWhere('n.id = :node')
                ->andWhere('b.lang = :lang')
                ->setParameter('node', $this->nodeTranslation->getNode()->getId())
                ->setParameter('lang', $this->nodeTranslation->getLang())
                ->addOrderBy('b.created', 'DESC');
    }
921789
protected function isFilterAppliable(QueryBuilder $queryBuilder, string $field): bool
    {
        $qbClone = clone $queryBuilder;

        try {
            $qbClone->andWhere($field.' IS NULL');

            // Generating SQL throws a QueryException if using wrong field/association
            $qbClone->getQuery()->getSQL();
        } catch (QueryException $e) {
            return false;
        }

        return true;
    }
335165
private function createBelongingToOtherEntitiesQueryBuilder(
        Connection $connection,
        QueryBuilder $parentQueryBuilder
    ) {
        $revisionFieldName = $this->configuration->getRevisionFieldName();
        $identifierColumnNames = $this->metadata->getIdentifierColumnNames();

        $queryBuilder = $connection->createQueryBuilder()
            ->select('1')
            ->from($this->configuration->getTableName($this->metadata), 'st')
            ->andWhere(sprintf('st.%1$s > t.%1$s', $revisionFieldName));

        $queryBuilder->andWhere(sprintf(
            'st.%s <= %s',
            $revisionFieldName,
            $parentQueryBuilder->createPositionalParameter($this->revision)
        ));

        //ids
        foreach ($identifierColumnNames as $name) {
            $queryBuilder->andWhere(sprintf('st.%1$s = t.%1$s', $name));
        }

        //master entity query, not equals
        $notEqualParts = $nullParts = array();
        foreach ($this->foreignKeys as $column => $value) {
            $notEqualParts[] = $column . ' <> ' . $parentQueryBuilder->createPositionalParameter($value);
            $nullParts[] = $column . ' IS NULL';
        }

        $expr = $queryBuilder->expr();
        $queryBuilder->andWhere(
            $expr->orX(
                $expr->andX(...$notEqualParts),
                $expr->andX(...$nullParts)
            )
        );

        return $queryBuilder;
    }
66708
public function apply(QueryBuilder $builder)
    {
        $builder->where($this->name, $this->operation, $this->value);
    }
273963
private function addConfigurationFilterToQueryBuilder(QueryBuilder $queryBuilder, $configs)
    {
        foreach ($configs as $config) {
            $workspaceId = $config->getWidgetInstance()->getWorkspace()->getId();
            $queryBuilder
                ->where('workspace.id = :workspaceId')
                ->setParameter('workspaceId', $workspaceId);

            if ($config->hasRestriction()) {
                $queryBuilder
                    ->andWhere('log.action IN (:actions)')
                    ->setParameter('actions', $config->getRestrictions());
            }
        }

        return $queryBuilder;
    }
1308659
public function getStatement(QueryBuilder $queryBuilder)
    {
        $paramName1 = $this->getFieldName() . $this->getUniqueId();
        $paramName2 = $this->getFieldName() . $this->getUniqueId();
        $queryBuilder->setParameter($paramName1, $this->getStart());
        $queryBuilder->setParameter($paramName2, $this->getEnd());

        return $this->field->getSelect() . ' BETWEEN :' . $paramName1 . ' AND :' . $paramName2;
    }