Doctrine\DBAL\Connection::setTransactionIsolation PHP Method

setTransactionIsolation() public method

Sets the transaction isolation level.
public setTransactionIsolation ( integer $level ) : integer
$level integer The level to set.
return integer
    public function setTransactionIsolation($level)
    {
        $this->_transactionIsolationLevel = $level;
        return $this->executeUpdate($this->getDatabasePlatform()->getSetTransactionIsolationSQL($level));
    }

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 public function register(EventDispatcher $dispatcher)
 {
     $dispatcher->addListener(RouteMatchedEvent::class, function (RouteMatchedEvent $event) {
         $annotation = $this->getTransactionalAnnotation($event->getRouteMatch());
         if ($annotation) {
             $this->connection->setTransactionIsolation($annotation->getIsolationLevel());
             $this->connection->beginTransaction();
         }
     });
     $dispatcher->addListener(ControllerInvocatedEvent::class, function (ControllerInvocatedEvent $event) {
         $annotation = $this->getTransactionalAnnotation($event->getRouteMatch());
         if ($annotation) {
             if ($this->connection->isTransactionActive()) {
                 $this->connection->rollback();
             }
         }
     });
 }
All Usage Examples Of Doctrine\DBAL\Connection::setTransactionIsolation