Resolves given query.

@param 	$queryBuilder <Kit\Glider\Query\Builder\QueryBuilder>
@param 	$parametersRepository <Kit\Glider\Query\Parameters>
@access 	protected
@return 	<Object> <StdClass>
181057
protected function resolveQuery(QueryBuilder $queryBuilder, Parameters $parametersRepository) : StdClass
	{
		$queryObject = new StdClass;
		$connection = $this->connection;
		$statement = $connection->prepare($queryBuilder->getQuery());
		$transaction = null;

		try {

			$executeParameters = null;
			// bind query parameters.

			$parameters = $parametersRepository->getAll();
			if ($parametersRepository->size() > 0) {

				foreach(array_keys($parameters) as $i => $parameter) {
					$i += 1; // Increase index by 1 to avoid bindParam error.

					$paramValue = $parameters[$parameter];
					$paramType = self::DEFAULT_PARAM_TYPE;

					// The parameter data type is being checked here 
					switch ($parametersRepository->getType($paramValue)) {
						case 'i':
							$paramType = PDO::PARAM_INT;
							break;
						case 'd':
						case 's':
							$paramType = PDO::PARAM_STR;
							break;
						default:
							$paramType = PDO::PARAM_NULL;
							break;
					}
					if ($queryBuilder->getQueryType() !== 3) {
						if ($queryBuilder->getQueryType() == 2) {
							$statement->bindValue($i, $paramValue, $paramType);
						}else{
							$statement->bindParam($i, $paramValue, $paramType);
						}
					}
				}
			}

			if ($queryBuilder->getQueryType() == 3) {
				$executeParameters = $parameters;
			}
			
			if ($queryBuilder->getQueryType() == 1 && $executeParameters == null) {
				$executeParameters = $parameters;
				$parameterValues = array_values($executeParameters);
				if (isset($parameterValues[0])) {
					$parameterValues = $parameterValues[0];
				}

				if (!is_array($parameterValues)) {
					if (preg_match('/\@pdo/', $parameterValues)) {
						$parameterValues  = str_replace('@pdo', '', $parameterValues);
						$executeParameters = [$parameterValues];
					}
				}
			}

			if ($executeParameters == null) {
				$executeParameters = $parameters;
			}

			// This fixes parameter error that occurs when using the insert method.
			if ($queryBuilder->getQueryType() == 2) {
				$executeParameters = array_values($parameters);
			}

			$autocommitDisabled = !$this->platform->isAutoCommitEnabled() && in_array($queryBuilder->getQueryType(), [2, 3]);
				
			if ($autocommitDisabled) {
				$transaction = $this->platform->transaction();
				$transaction->begin($connection);
			}

			$statement->execute($executeParameters);

			if ($autocommitDisabled) {
				$transaction->commit($connection);
			}

		} catch(PdoException $exception) {

			if ($autocommitDisabled) {
				$transaction->rollback($connection);
			}

			throw new QueryException(
				$exception->getMessage(),
				$queryBuilder->generator->convertToSql($queryBuilder->getQuery(), $parametersRepository)
			);

		}

		$queryObject->statement = $statement;
		$queryObject->connection = $connection;
		return $queryObject;
	}
999283
public function getQueryBuilderPartsForCachingHash($queryBuilder)
    {
        return [
            $queryBuilder->getQuery()->getSQL(),
            array_map([$this, 'parameterToArray'], $queryBuilder->getParameters()->toArray()),
        ];
    }
161445
public static function resolveParams(Container $container, $params)
    {
        $resolvedParams = array();
        foreach($params as $key=>$param) {
            $resolvedParam = null;
            if (is_array($param)) {
                $resolvedParam = self::resolveParams($container, $param);
            } else if (is_string($param)){
                $resolvedParam = $container->resolve($param);
            } else {
                $resolvedParam = $param;
            }
            $resolvedParams[$key] = $resolvedParam;
        }
        return $resolvedParams;
    }
1116927
protected function toSql($fields=null) : QueryBuilder
	{
		$queryBuilder = $this->queryBuilder()
		->select($fields)
		->from($this->table);

		$orderBy = [];

		if (isset(Model::$findOptions['asc'])) {
			$orderBy[] = Model::$findOptions['asc'] . ' ASC';
		}

		if (isset(Model::$findOptions['desc'])) {
			$orderBy[] = Model::$findOptions['desc'] . ' DESC';
		}

		if (!empty($orderBy)) {
			$queryBuilder->orderBy($orderBy);
		}

		if (isset(Model::$findOptions['limit'])) {
			$limit = Model::$findOptions['limit'];

			if (is_array($limit) && count($limit) > 1) {
				$queryBuilder->limit($limit[0], $limit[1]);
			}else{
				$queryBuilder->limit($limit);
			}
		}

		return $queryBuilder;
	}
761992
public function getQuery($queryParams)
    {
        return array_key_exists($queryParams, $this->query) ? $this->query[$queryParams] : null;
    }
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');
    }
862916
public function search(QueryBuilderInterface $Builder) {
        $this->serialyse($Builder);
        $statement = $this->connector->query($this->parsedQuery);
        $result    = $this->statementToArray($statement);
        $resultSetClass = $this->resultSetClassName;
        $resultSet = new $resultSetClass($result);
        $queryCount = $this->getSerialyser()->setCriteriaList($Builder)->count(true)->serialyse();
        $resultSet->setParent($this)->setCountQuery($queryCount);
        return $resultSet;
    }
45397
protected function getPredicates($queryBuilder, $conditions)
    {
        $predicates = [];

        foreach ($conditions as $condition) {
            $predicates[] = $condition->getPredicate($queryBuilder);
        }

        return $predicates;
    }
650877
private function getQueryBuilderForCachingHash($queryBuilder)
    {
        return [
            $queryBuilder->getQuery()->getSQL(),
            array_map([$this, 'parameterToArray'], $queryBuilder->getParameters()->toArray()),
        ];
    }
1163548
protected function resolveQueryFor(Builder $builder, string $filter) : Builder
    {
        $factory = $this->allowed[$filter];

        $input = $this->wantsByPrices($filter)
            ? $this->prices()
            : $this->request[$filter];

    	return (new $factory($input, $builder))->query();
    }
1184454
protected function getFixedQueryBuilder(QueryBuilder $queryBuilder)
    {
        $queryBuilderId = clone $queryBuilder;
        $rootAlias = current($queryBuilderId->getRootAliases());

        // step 1 : retrieve the targeted class
        $from = $queryBuilderId->getDQLPart('from');
        $class = $from[0]->getFrom();
        $metadata = $queryBuilderId->getEntityManager()->getMetadataFactory()->getMetadataFor($class);

        // step 2 : retrieve identifier columns
        $idNames = $metadata->getIdentifierFieldNames();

        // step 3 : retrieve the different subjects ids
        $selects = array();
        $idxSelect = '';
        foreach ($idNames as $idName) {
            $select = sprintf('%s.%s', $rootAlias, $idName);
            // Put the ID select on this array to use it on results QB
            $selects[$idName] = $select;
            // Use IDENTITY if id is a relation too. See: http://doctrine-orm.readthedocs.org/en/latest/reference/dql-doctrine-query-language.html
            // Should work only with doctrine/orm: ~2.2
            $idSelect = $select;
            if ($metadata->hasAssociation($idName)) {
                $idSelect = sprintf('IDENTITY(%s) as %s', $idSelect, $idName);
            }
            $idxSelect .= ($idxSelect !== '' ? ', ' : '') . $idSelect;
        }

        foreach ($queryBuilderId->getDqlParts()['orderBy'] as $sort) {
            $field = chop($sort->getParts()[0], 'ASC');
            $field = chop($field, 'DESC');
            $idxSelect .= ', (' . $field . ')';
        }

        $queryBuilderId->resetDQLPart('select');
        $queryBuilderId->add('select', 'DISTINCT ' . $idxSelect);

        // for SELECT DISTINCT, ORDER BY expressions must appear in idxSelect list
        /* Consider
            SELECT DISTINCT x FROM tab ORDER BY y;
        For any particular x-value in the table there might be many different y
        values.  Which one will you use to sort that x-value in the output?
        */
        // todo : check how doctrine behave, potential SQL injection here ...
        if ($this->getSortBy()) {
            $sortBy = $this->getSortBy();
            if (strpos($sortBy, '.') === false) { // add the current alias
                $sortBy = $rootAlias . '.' . $sortBy;
            }
            $sortBy .= ' AS __order_by';
            $queryBuilderId->addSelect($sortBy);
        }

        // Use ILIKE instead of LIKE for Postgresql
        if ('pdo_pgsql' == $queryBuilderId->getEntityManager()->getConnection()->getDriver()->getName()) {
            $this->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Blast\DoctrinePgsqlBundle\DoctrineExtensions\BlastWalker');
        }

        $query = $queryBuilderId->getQuery();
        foreach ($this->_hints as $name => $value) {
            $query->setHint($name, $value);
        }

        $results = $query->execute(array(), Query::HYDRATE_ARRAY);
        $platform = $queryBuilderId->getEntityManager()->getConnection()->getDatabasePlatform();
        $idxMatrix = array();
        foreach ($results as $id) {
            foreach ($idNames as $idName) {
                // Convert ids to database value in case of custom type, if provided.
                $fieldType = $metadata->getTypeOfField($idName);
                $idxMatrix[$idName][] = $fieldType && Type::hasType($fieldType)
                    ? Type::getType($fieldType)->convertToDatabaseValue($id[$idName], $platform)
                    : $id[$idName];
            }
        }

        // step 4 : alter the query to match the targeted ids
        foreach ($idxMatrix as $idName => $idx) {
            if (count($idx) > 0) {
                $idxParamName = sprintf('%s_idx', $idName);
                $idxParamName = preg_replace('/[^\w]+/', '_', $idxParamName);
                $queryBuilder->andWhere(sprintf('%s IN (:%s)', $selects[$idName], $idxParamName));
                $queryBuilder->setParameter($idxParamName, $idx);
                $queryBuilder->setMaxResults(null);
                $queryBuilder->setFirstResult(null);
            }
        }

        return $queryBuilder;
    }
190207
public function buildQuery(QueryBuilder $qb, array $parameters)
    {

        //Handle single tag
        if (!is_array($parameters['tags'])) {
            $parameters['tags'] = [$parameters['tags']];
        }

        //clean the parameters from the blank value
        foreach ($parameters['tags'] as $index => $parameter) {
            //the blank value is removed
            if ($parameter === '') {
                unset($parameters['tags'][$index]);
            }
        }

        if (count($parameters['tags']) > 0) {
            if (array_key_exists('strict', $parameters)) {
                $repository = $this->getEntityManager()->getRepository('VictoireBlogBundle:Article');
                foreach ($parameters['tags'] as $index => $tag) {
                    $parameter = ':tag'.$index;
                    $subquery = $repository->createQueryBuilder('article_'.$index)
                                ->join('article_'.$index.'.tags', 'tag_'.$index)
                                ->where('tag_'.$index.' = '.$parameter);
                    $qb->andWhere($qb->expr()->in('main_item', $subquery->getDql()))
                                ->setParameter($parameter, $tag);
                }
            } else {
                $qb = $qb
                        ->join('main_item.tags', 't')
                        ->andWhere('t.id IN (:tags)')
                        ->setParameter('tags', $parameters['tags']);
            }
        }

        return $qb;
    }
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();
    }
323625
public function filter(QueryBuilder $queryBuilder, $options = array())
    {
        if ( ! $options instanceof DateTime) {
            throw new InvalidArgumentException(
                '$options is expected to be an instance of DateTime'
            );
        }
        $aliases = $queryBuilder->getRootAliases();
        $queryBuilder->andWhere(sprintf(
            '%s.%s %s :%s',
            $aliases[0],
            $this->getPropertyName(),
            $this->getComparison(),
            $this->getName()
        ));
        $queryBuilder->setParameter(
            $this->getName(),
            $options->format('Y-m-d H:i:s')
        );
    }
1169322
public function executeQuery($dql, $parameters = array(), $entityManager = null)
    {
        return $this->createQuery($dql, $entityManager)->execute($parameters);
    }
1252692
public function evaluate(
        QueryBuilder $queryBuilder,
        CreatePaginator $annotation
    ) {
        foreach ($this->paginatorEvaluators as $paginatorEvaluator) {
            $paginatorEvaluator->evaluate($queryBuilder, $annotation);
        }
    }
866478
public function resolve(
        Parameter $parameter,
        ParameterBag $unresolvedParameters,
        ParameterBag $resolvedParameters,
        ResolvingContext $context = null
    ): ParameterBag {
        $context = ResolvingContext::createFrom($context, $parameter->getKey());

        $self = $this;
        $value = preg_replace_callback(
            self::PATTERN,
            function ($match) use ($self, $context, $unresolvedParameters, &$resolvedParameters, $parameter) {
                $key = $match['parameter'];
                $resolvedParameters = $self->resolveStringKey(
                    $self->resolver,
                    $parameter,
                    $key,
                    $unresolvedParameters,
                    $resolvedParameters,
                    $context
                );

                return $resolvedParameters->get($key);
            },
            $parameter->getValue()
        );

        return $resolvedParameters->with($parameter->withValue($value));
    }