<commit_before><?php
/**
 * This file is part of the Kappa\Doctrine package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the license.md
 * file that was distributed with this source code.
 */

namespace Kappa\Doctrine\Queries;

use Kappa\Doctrine\InvalidArgumentException;
use Kappa\Doctrine\NotQueryBuilderException;
use Kdyby\Doctrine\EntityManager;
use Kdyby\Doctrine\QueryBuilder;
use Nette\Object;

/**
 * Class QueryExecutor
 *
 * @package Kappa\Doctrine\Queries
 * @author <NAME> <http://zaruba-ondrej.cz>
 */
class QueryExecutor extends Object
{
	/** @var EntityManager */
	private $entityManager;

	/**
	 * @param EntityManager $entityManager
	 */
	public function __construct(EntityManager $entityManager)
	{
		$this->entityManager = $entityManager;
	}

	/**
	 * @param Executable|ExecutableCollectionInterface $query
	 */
	public function execute($query)
	{
		if (!$query instanceof Executable && !$query instanceof ExecutableCollectionInterface) {
			throw new InvalidArgumentException(__METHOD__ . " Query can be only instance of Exectable or ExecutableCollection");
		}
		$builder = $this->entityManager->createQueryBuilder();
		if ($query instanceof Executable) {
			$queries = [$query];
		} else {
			$queries = $query->getQueries();
		}
		foreach ($queries as $query) {
			$qb = $query->build($builder);
			if (!$qb instanceof QueryBuilder) {
				throw new NotQueryBuilderException('Executable object ' . get_class($query) . ' must returns instance of QueryBuilder');
			}
			$qb->getQuery()->execute();
		}
	}
}<commit_msg>Create a new instance of QueryBuilder for each query<commit_after><?php
/**
 * This file is part of the Kappa\Doctrine package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the license.md
 * file that was distributed with this source code.
 */

namespace Kappa\Doctrine\Queries;

use Kappa\Doctrine\InvalidArgumentException;
use Kappa\Doctrine\NotQueryBuilderException;
use Kdyby\Doctrine\EntityManager;
use Kdyby\Doctrine\QueryBuilder;
use Nette\Object;

/**
 * Class QueryExecutor
 *
 * @package Kappa\Doctrine\Queries
 * @author <NAME> <http://zaruba-ondrej.cz>
 */
class QueryExecutor extends Object
{
	/** @var EntityManager */
	private $entityManager;

	/**
	 * @param EntityManager $entityManager
	 */
	public function __construct(EntityManager $entityManager)
	{
		$this->entityManager = $entityManager;
	}

	/**
	 * @param Executable|ExecutableCollectionInterface $query
	 */
	public function execute($query)
	{
		if (!$query instanceof Executable && !$query instanceof ExecutableCollectionInterface) {
			throw new InvalidArgumentException(__METHOD__ . " Query can be only instance of Exectable or ExecutableCollection");
		}
		if ($query instanceof Executable) {
			$queries = [$query];
		} else {
			$queries = $query->getQueries();
		}
		foreach ($queries as $query) {
			$builder = $this->entityManager->createQueryBuilder();
			$qb = $query->build($builder);
			if (!$qb instanceof QueryBuilder) {
				throw new NotQueryBuilderException('Executable object ' . get_class($query) . ' must returns instance of QueryBuilder');
			}
			$qb->getQuery()->execute();
		}
	}
}
{'fraction_non_alphanumeric': 0.1248447204968944, 'fraction_numerical': 0.0, 'mean_word_length': 4.422558922558922, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, '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': '98246', 'n_tokens_mistral': 1017, 'n_tokens_neox': 948, 'n_words': 256}