Пример #1
0
 /**
  * Applies the query options to the resource(s) retrieved from the data source.
  * 
  * @param SegmentDescriptor $segment The descriptor which holds resource(s) on which query options to be applied.
  *
  */
 private function applyQueryOptions(SegmentDescriptor $segment)
 {
     //TODO: I'm not really happy with this..i think i'd rather keep the result the QueryResult
     //not even bother with the setCountValue stuff (shouldn't counts be on segments?)
     //and just work with the QueryResult in the object model serializer
     $result = $segment->getResult();
     if (!$result instanceof QueryResult) {
         //If the segment isn't a query result, then there's no paging or counting to be done
         return;
     }
     // Note $inlinecount=allpages means include the total count regardless of paging..so we set the counts first
     // regardless if POData does the paging or not.
     if ($this->request->queryType == QueryType::ENTITIES_WITH_COUNT()) {
         if ($this->providers->handlesOrderedPaging()) {
             $this->request->setCountValue($result->count);
         } else {
             $this->request->setCountValue(count($result->results));
         }
     }
     //Have POData perform paging if necessary
     if (!$this->providers->handlesOrderedPaging() && !empty($result->results)) {
         $result->results = $this->performPaging($result->results);
     }
     //a bit surprising, but $skip and $top affects $count so update it here, not above
     //IE  data.svc/Collection/$count?$top=10 returns 10 even if Collection has 11+ entries
     if ($this->request->queryType == QueryType::COUNT()) {
         if ($this->providers->handlesOrderedPaging()) {
             $this->request->setCountValue($result->count);
         } else {
             $this->request->setCountValue(count($result->results));
         }
     }
     $segment->setResult($result->results);
 }
Пример #2
0
 /**
  * Checks whether etag headers are allowed for this request.
  * 
  * @return boolean True if ETag header (If-Match or If-NoneMatch)
  *                 is allowed for the request, False otherwise.
  */
 public function isETagHeaderAllowed()
 {
     return $this->lastSegment->isSingleResult() && $this->queryType != QueryType::COUNT() && !$this->isLinkUri() && (is_null($this->_rootProjectionNode) || !$this->_rootProjectionNode->isExpansionSpecified());
 }
Пример #3
0
 /**
  * Create SegmentDescriptor for the first segment
  * 
  * @param string $segmentIdentifier The identifier part of the first segment
  * @param string $keyPredicate The predicate part of the first segment if any else NULL
  * @param boolean $checkRights Whether to check the rights on this segment
  *
  * @return SegmentDescriptor Descriptor for the first segment
  * 
  * @throws ODataException Exception if any validation fails
  */
 private function _createFirstSegmentDescriptor($segmentIdentifier, $keyPredicate, $checkRights)
 {
     $descriptor = new SegmentDescriptor();
     $descriptor->setIdentifier($segmentIdentifier);
     if ($segmentIdentifier === ODataConstants::URI_METADATA_SEGMENT) {
         $this->_assertion(is_null($keyPredicate));
         $descriptor->setTargetKind(TargetKind::METADATA());
         return $descriptor;
     }
     if ($segmentIdentifier === ODataConstants::URI_BATCH_SEGMENT) {
         $this->_assertion(is_null($keyPredicate));
         $descriptor->setTargetKind(TargetKind::BATCH());
         return $descriptor;
     }
     if ($segmentIdentifier === ODataConstants::URI_COUNT_SEGMENT) {
         throw ODataException::createBadRequestError(Messages::segmentParserSegmentNotAllowedOnRoot(ODataConstants::URI_COUNT_SEGMENT));
     }
     if ($segmentIdentifier === ODataConstants::URI_LINK_SEGMENT) {
         throw ODataException::createBadRequestError(Messages::segmentParserSegmentNotAllowedOnRoot(ODataConstants::URI_LINK_SEGMENT));
     }
     $resourceSetWrapper = $this->providerWrapper->resolveResourceSet($segmentIdentifier);
     if ($resourceSetWrapper === null) {
         throw ODataException::createResourceNotFoundError($segmentIdentifier);
     }
     $descriptor->setTargetResourceSetWrapper($resourceSetWrapper);
     $descriptor->setTargetResourceType($resourceSetWrapper->getResourceType());
     $descriptor->setTargetSource(TargetSource::ENTITY_SET);
     $descriptor->setTargetKind(TargetKind::RESOURCE());
     if ($keyPredicate !== null) {
         $keyDescriptor = $this->_createKeyDescriptor($segmentIdentifier . '(' . $keyPredicate . ')', $resourceSetWrapper->getResourceType(), $keyPredicate);
         $descriptor->setKeyDescriptor($keyDescriptor);
         if (!$keyDescriptor->isEmpty()) {
             $descriptor->setSingleResult(true);
         }
     }
     if ($checkRights) {
         $resourceSetWrapper->checkResourceSetRightsForRead($descriptor->isSingleResult());
     }
     return $descriptor;
 }