/** * @test */ public function getFirstReturnsNullIfResultSetIsEmptyAndQueryIsNotInitialized() { $initializedQueryResult = array(); $queryResult = $this->getAccessibleMock('TYPO3\\Flow\\Persistence\\Generic\\QueryResult', array('dummy'), array($this->query)); $this->query->expects($this->once())->method('setLimit')->with(1); $queryResult->injectPersistenceManager($this->persistenceManager); $mockDataMapper = $this->getMock('TYPO3\\Flow\\Persistence\\Generic\\DataMapper'); $mockDataMapper->expects($this->once())->method('mapToObjects')->with(array('one', 'two'))->will($this->returnValue($initializedQueryResult)); $queryResult->injectDataMapper($mockDataMapper); $this->assertNull($queryResult->getFirst()); }
/** * * @param \TYPO3\Flow\Persistence\QueryInterface $query */ public function __construct(\TYPO3\Flow\Persistence\QueryInterface $query) { $constraint = $query->getConstraint(); $this->type = $query->getType(); if ($constraint !== NULL) { $this->emits = $this->buildEmitsForConstraint($constraint); $constraintName = '_' . $this->buildNameForConstraint($constraint); } else { $constraintName = ''; } $this->queryIdentifier = strtr($this->type, '\\', '_') . $constraintName; $this->viewName = 'entities'; $this->designName = 'query_' . $this->queryIdentifier; }
/** * @param QueryInterface $query * @param $nodeTypeFilter * @return array */ protected function getNodeTypeFilterConstraints(QueryInterface $query, $nodeTypeFilter) { $includeNodeTypeConstraints = array(); $excludeNodeTypeConstraints = array(); $nodeTypeFilterParts = Arrays::trimExplode(',', $nodeTypeFilter); foreach ($nodeTypeFilterParts as $nodeTypeFilterPart) { $nodeTypeFilterPart = trim($nodeTypeFilterPart); if (strpos($nodeTypeFilterPart, '!') === 0) { $negate = true; $nodeTypeFilterPart = substr($nodeTypeFilterPart, 1); } else { $negate = false; } $nodeTypeFilterPartSubTypes = array_merge(array($nodeTypeFilterPart), $this->nodeTypeManager->getSubNodeTypes($nodeTypeFilterPart, false)); foreach ($nodeTypeFilterPartSubTypes as $nodeTypeFilterPartSubType) { if ($negate === true) { $excludeNodeTypeConstraints[] = $query->logicalNot($query->equals('nodeType', $nodeTypeFilterPartSubType)); } else { $includeNodeTypeConstraints[] = $query->equals('nodeType', $nodeTypeFilterPartSubType); } } } $constraints = $excludeNodeTypeConstraints; if (count($includeNodeTypeConstraints) > 0) { $constraints[] = $query->logicalOr($includeNodeTypeConstraints); } return $constraints; }
/** * Sets up this test case * */ public function setUp() { $this->query = $this->getMockBuilder('TYPO3\\Flow\\Persistence\\Doctrine\\Query')->disableOriginalConstructor()->disableOriginalClone()->getMock(); $this->query->expects($this->any())->method('getResult')->will($this->returnValue(array())); $this->queryResult = new \TYPO3\Flow\Persistence\Doctrine\QueryResult($this->query); }
/** * Returns the object data matching the $query. * * @param \TYPO3\Flow\Persistence\QueryInterface $query * @return array * @author Christopher Hlubek <*****@*****.**> */ public function getObjectDataByQuery(\TYPO3\Flow\Persistence\QueryInterface $query) { if ($query instanceof \TYPO3\CouchDB\Persistence\LuceneQuery) { return $this->getObjectDataByIndex($query->getIndex(), array('query' => $query)); } else { $view = new \TYPO3\CouchDB\QueryView($query); return $this->getObjectDataByView($view, array('query' => $query)); } }
/** * Builds a QOM constraint object for one single constraint expression * * @param array $constraintDefinition The constraint expression * @param \TYPO3\Flow\Persistence\QueryInterface $query The query object to build the constraint with * @return \TYPO3\Flow\Persistence\Generic\Qom\Constraint The build constraint object * @throws \TYPO3\Flow\Security\Exception\InvalidQueryRewritingConstraintException */ protected function getQomConstraintForSingleConstraintDefinition(array $constraintDefinition, QueryInterface $query) { if (!is_array($constraintDefinition['leftValue']) && strpos($constraintDefinition['leftValue'], 'this.') === 0) { $propertyName = substr($constraintDefinition['leftValue'], 5); $operand = $this->getValueForOperand($constraintDefinition['rightValue']); } elseif (!is_array($constraintDefinition['rightValue']) && strpos($constraintDefinition['rightValue'], 'this.') === 0) { $propertyName = substr($constraintDefinition['rightValue'], 5); $operand = $this->getValueForOperand($constraintDefinition['leftValue']); } else { throw new InvalidQueryRewritingConstraintException('An entity constraint has to have one operand that references to "this.". Got: "' . $constraintDefinition['leftValue'] . '" and "' . $constraintDefinition['rightValue'] . '"', 1267881842); } switch ($constraintDefinition['operator']) { case '==': return $query->equals($propertyName, $operand); break; case '!=': return $query->logicalNot($query->equals($propertyName, $operand)); break; case '<': return $query->lessThan($propertyName, $operand); break; case '>': return $query->greaterThan($propertyName, $operand); break; case '<=': return $query->lessThanOrEqual($propertyName, $operand); break; case '>=': return $query->greaterThanOrEqual($propertyName, $operand); break; case 'in': return $query->in($propertyName, $operand); break; case 'contains': return $query->contains($propertyName, $operand); break; case 'matches': $compositeConstraint = NULL; foreach ($operand as $operandEntry) { $currentConstraint = $query->contains($propertyName, $operandEntry); if ($compositeConstraint === NULL) { $compositeConstraint = $currentConstraint; continue; } $compositeConstraint = $query->logicalAnd($currentConstraint, $compositeConstraint); } return $compositeConstraint; break; } throw new InvalidQueryRewritingConstraintException('The configured operator of the entity constraint is not valid. Got: ' . $constraintDefinition['operator'], 1270483540); }
public function selectSatisfying(\TYPO3\Flow\Persistence\QueryInterface $query) { $query->logicalAnd($query->greaterThan($this->property, $this->start), $query->lowerThan($this->property, $this->end)); }