Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function walkSelectStatement(AST\SelectStatement $AST)
 {
     $sql = $this->walkSelectClause($AST->selectClause);
     $sql .= $this->walkFromClause($AST->fromClause);
     $sql .= $this->walkWhereClause($AST->whereClause);
     $sql .= $AST->groupByClause ? $this->walkGroupByClause($AST->groupByClause) : '';
     $sql .= $AST->havingClause ? $this->walkHavingClause($AST->havingClause) : '';
     if (($orderByClause = $AST->orderByClause) !== null) {
         $sql .= $AST->orderByClause ? $this->walkOrderByClause($AST->orderByClause) : '';
     } else {
         if (($orderBySql = $this->_generateOrderedCollectionOrderByItems()) !== '') {
             $sql .= ' ORDER BY ' . $orderBySql;
         }
     }
     $sql = $this->platform->modifyLimitQuery($sql, $this->query->getMaxResults(), $this->query->getFirstResult());
     if (($lockMode = $this->query->getHint(Query::HINT_LOCK_MODE)) !== false) {
         switch ($lockMode) {
             case LockMode::PESSIMISTIC_READ:
                 $sql .= ' ' . $this->platform->getReadLockSQL();
                 break;
             case LockMode::PESSIMISTIC_WRITE:
                 $sql .= ' ' . $this->platform->getWriteLockSQL();
                 break;
             case LockMode::OPTIMISTIC:
                 foreach ($this->selectedClasses as $selectedClass) {
                     if (!$selectedClass['class']->isVersioned) {
                         throw \Doctrine\ORM\OptimisticLockException::lockFailed($selectedClass['class']->name);
                     }
                 }
                 break;
             case LockMode::NONE:
                 break;
             default:
                 throw \Doctrine\ORM\Query\QueryException::invalidLockMode();
         }
     }
     return $sql;
 }
 /**
  * {@inheritdoc}
  */
 public function walkSelectStatement(AST\SelectStatement $AST)
 {
     $limit = $this->query->getMaxResults();
     $offset = $this->query->getFirstResult();
     $lockMode = $this->query->getHint(Query::HINT_LOCK_MODE);
     $sql = $this->walkSelectClause($AST->selectClause) . $this->walkFromClause($AST->fromClause) . $this->walkWhereClause($AST->whereClause);
     if ($AST->groupByClause) {
         $sql .= $this->walkGroupByClause($AST->groupByClause);
     }
     if ($AST->havingClause) {
         $sql .= $this->walkHavingClause($AST->havingClause);
     }
     if ($AST->orderByClause) {
         $sql .= $this->walkOrderByClause($AST->orderByClause);
     }
     if (!$AST->orderByClause && ($orderBySql = $this->_generateOrderedCollectionOrderByItems())) {
         $sql .= ' ORDER BY ' . $orderBySql;
     }
     if ($limit !== null || $offset !== null) {
         $sql = $this->platform->modifyLimitQuery($sql, $limit, $offset);
     }
     if ($lockMode === null || $lockMode === false || $lockMode === LockMode::NONE) {
         return $sql;
     }
     if ($lockMode === LockMode::PESSIMISTIC_READ) {
         return $sql . ' ' . $this->platform->getReadLockSQL();
     }
     if ($lockMode === LockMode::PESSIMISTIC_WRITE) {
         return $sql . ' ' . $this->platform->getWriteLockSQL();
     }
     if ($lockMode !== LockMode::OPTIMISTIC) {
         throw QueryException::invalidLockMode();
     }
     foreach ($this->selectedClasses as $selectedClass) {
         if (!$selectedClass['class']->isVersioned) {
             throw OptimisticLockException::lockFailed($selectedClass['class']->name);
         }
     }
     return $sql;
 }