Exemplo n.º 1
0
 /**
  * When entity have columns for required associations, this will fail.
  * Calls $em->flush().
  *
  * @todo fix error codes! PDO is returning database-specific codes
  *
  * @param object $entity
  * @throws \Doctrine\DBAL\DBALException
  * @throws \Exception
  * @return bool|object
  */
 public function persist($entity)
 {
     $this->db->beginTransaction();
     try {
         $persisted = $this->doInsert($entity);
         $this->db->commit();
         return $persisted;
     } catch (Doctrine\DBAL\Exception\UniqueConstraintViolationException $e) {
         $this->db->rollback();
         return FALSE;
     } catch (Kdyby\Doctrine\DuplicateEntryException $e) {
         $this->db->rollback();
         return FALSE;
     } catch (DBALException $e) {
         $this->db->rollback();
         if ($this->isUniqueConstraintViolation($e)) {
             return FALSE;
         }
         throw $this->db->resolveException($e);
     } catch (\Exception $e) {
         $this->db->rollback();
         throw $e;
     } catch (\Throwable $e) {
         $this->db->rollback();
         throw $e;
     }
 }
 public function wrap()
 {
     if ($this->isWrapped) {
         throw new LogicException('The connection has been already wrapped');
     }
     $this->isWrapped = TRUE;
     $this->oldIsolationLevel = parent::getTransactionIsolation();
     parent::setTransactionIsolation(DBALConnection::TRANSACTION_SERIALIZABLE);
     parent::beginTransaction();
 }