\ADT\BulkFetcher\Factory
can be used with:
\Kdyby\Doctrine\ResultSet
\Doctrine\ORM\QueryBuilder
\Kdyby\Doctrine\NativeQueryBuilder
via composer:
composer require adt/bulk-fetcher
Whole batch is in transaction.
$qb = $entityManager->createQueryBuilder('user');
try {
$entityManager->beginTransaction();
$data = \ADT\BulkFetcher\Factory::create($qb, 100);
$data->onBeforeFetch[] = function() use ($entityManager) {
$entityManager->commit();
$entityManager->clear();
$entityManager->beginTransaction();
};
foreach ($data as $key => $row) {
// code
}
$entityManager->commit();
} catch (\Exception $e) {
$entityManager->rollback();
throw $e;
}