public function useWithLock($id, $lockMode, $callback)
{
$entityName = $this->getEntityName();
return $this->transaction(function ($em, $self) use($id, $lockMode, $callback, $entityName) {
$entity = $self->find($id, $lockMode);
if (empty($entity)) {
$message = \sprintf("Could not lock %s entity by id %d: entity not found", $entityName, $id);
throw new LockException($message);
}
$result = $callback($entity, $em, $self);
return $result;
});
}