phpcr-utils/src/PHPCR/Util/QOM/QueryBuilder.php
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
\PHPCR\Util\QOM\QueryBuilder
- Author
- Nacho Martín
- Author
- Guilherme Blanco
- Author
- Benjamin Eberlei
Constants
Properties
\PHPCR\Query\QOM\ConstraintInterface $constraint = null
to apply to the query.
null
Detailsinteger $firstResult = null
The maximum number of results to retrieve.
null
Details- Type
- integer
integer $maxResults = null
The maximum number of results to retrieve.
null
Details- Type
- integer
array $orderings = array()
with the orderings that determine the order of the result
array()
Details- Type
- array
Methods
__construct(\PHPCR\Query\QOM\QueryObjectModelFactoryInterface $qomFactory) : void
Initializes a new QueryBuilder
Name | Type | Description |
---|---|---|
$qomFactory | \PHPCR\Query\QOM\QueryObjectModelFactoryInterface |
addOrderBy(\PHPCR\Query\QOM\DynamicOperandInterface $sort, string $order = 'ASC') : \PHPCR\Util\QOM\QueryBuilder
Adds an ordering to the query results.
Name | Type | Description |
---|---|---|
$sort | \PHPCR\Query\QOM\DynamicOperandInterface | The ordering expression. |
$order | string | The ordering direction. |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
addSelect(string $propertyName, string $columnName = null, string $selectorName = null) : \PHPCR\Util\QOM\QueryBuilder
Adds a property in the specified or default selector to include in the tabular view of query results.
Name | Type | Description |
---|---|---|
$propertyName | string | |
$columnName | string | |
$selectorName | string |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
andWhere(\PHPCR\Query\QOM\ConstraintInterface $constraint) : \PHPCR\Util\QOM\QueryBuilder
Creates a new constraint formed by applying a logical AND to the existing constraint and the new one
Order of ands is important:
Given $this->constraint = $constraint1 running andWhere($constraint2) resulting constraint will be $constraint1 AND $constraint2
If there is no previous constraint then it will simply store the provided one
Name | Type | Description |
---|---|---|
$constraint | \PHPCR\Query\QOM\ConstraintInterface |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
execute() : \PHPCR\Query\QueryResultInterface
Executes the query setting firstResult and maxResults.
Type | Description |
---|---|
\PHPCR\Query\QueryResultInterface |
from(\PHPCR\Query\QOM\SourceInterface $source) : \PHPCR\Util\QOM\QueryBuilder
Sets the default Selector or the node-tuple Source.
Can be a selector or a join.
Name | Type | Description |
---|---|---|
$source | \PHPCR\Query\QOM\SourceInterface |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
getColumns() : \PHPCR\Query\QOM\ColumnInterface[]
Returns the columns to be selected
Type | Description |
---|---|
\PHPCR\Query\QOM\ColumnInterface[] | The columns to be selected |
getConstraint() : \PHPCR\Query\QOM\ConstraintInterface
Returns the constraint to apply
Type | Description |
---|---|
\PHPCR\Query\QOM\ConstraintInterface | the constraint to be applied |
getFirstResult() : integer
Gets the position of the first result the query object was set to retrieve (the "offset").
Returns NULL if setFirstResult was not applied to this QueryBuilder.
Type | Description |
---|---|
integer | The position of the first result. |
getMaxResults() : integer
Gets the maximum number of results the query object was set to retrieve (the "limit").
Returns NULL if setMaxResults was not applied to this query builder.
Type | Description |
---|---|
integer | Maximum number of results. |
getOrderings() : \PHPCR\Query\QOM\OrderingInterface[]
Gets the array of orderings.
Type | Description |
---|---|
\PHPCR\Query\QOM\OrderingInterface[] | Orderings to apply. |
getParameter(string $key) : mixed
Gets a (previously set) query parameter of the query being constructed.
Name | Type | Description |
---|---|---|
$key | string | The key (name) of the bound parameter. |
Type | Description |
---|---|
mixed | The value of the bound parameter. |
getParameters() : array
Gets all defined query parameters for the query being constructed.
Type | Description |
---|---|
array | The currently defined query parameters. |
getQOMFactory() : \PHPCR\Query\QOM\QueryObjectModelFactoryInterface
Get the associated QOMFactory for this query builder
Type | Description |
---|---|
\PHPCR\Query\QOM\QueryObjectModelFactoryInterface |
getQuery() : \PHPCR\Query\QOM\QueryObjectModelInterface
Gets the query built
Type | Description |
---|---|
\PHPCR\Query\QOM\QueryObjectModelInterface |
getSource() : \PHPCR\Query\QOM\SourceInterface
Gets the default Selector.
Type | Description |
---|---|
\PHPCR\Query\QOM\SourceInterface | The default selector. |
innerJoin(\PHPCR\Query\QOM\SourceInterface $rightSource, \PHPCR\Query\QOM\JoinConditionInterface $joinCondition) : \PHPCR\Util\QOM\QueryBuilder
Performs an inner join between the stored source and the supplied source.
Name | Type | Description |
---|---|---|
$rightSource | \PHPCR\Query\QOM\SourceInterface | |
$joinCondition | \PHPCR\Query\QOM\JoinConditionInterface |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
Exception | Description |
---|---|
\PHPCR\Util\QOM\RuntimeException | if there is not an existing source. |
join(\PHPCR\Query\QOM\SourceInterface $rightSource, \PHPCR\Query\QOM\JoinConditionInterface $joinCondition) : \PHPCR\Util\QOM\QueryBuilder
Performs an inner join between the stored source and the supplied source.
Name | Type | Description |
---|---|---|
$rightSource | \PHPCR\Query\QOM\SourceInterface | |
$joinCondition | \PHPCR\Query\QOM\JoinConditionInterface |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
Exception | Description |
---|---|
\PHPCR\Util\QOM\RuntimeException | if there is not an existing source. |
joinWithType(\PHPCR\Query\QOM\SourceInterface $rightSource, string $joinType, \PHPCR\Query\QOM\JoinConditionInterface $joinCondition) : \PHPCR\Util\QOM\QueryBuilder
Performs an join between the stored source and the supplied source.
Name | Type | Description |
---|---|---|
$rightSource | \PHPCR\Query\QOM\SourceInterface | |
$joinType | string | as specified in PHPCR\Query\QOM\QueryObjectModelConstantsInterface |
$joinCondition | \PHPCR\Query\QOM\JoinConditionInterface |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
Exception | Description |
---|---|
\PHPCR\Util\QOM\RuntimeException | if there is not an existing source. |
leftJoin(\PHPCR\Query\QOM\SourceInterface $rightSource, \PHPCR\Query\QOM\JoinConditionInterface $joinCondition) : \PHPCR\Util\QOM\QueryBuilder
Performs an left outer join between the stored source and the supplied source.
Name | Type | Description |
---|---|---|
$rightSource | \PHPCR\Query\QOM\SourceInterface | |
$joinCondition | \PHPCR\Query\QOM\JoinConditionInterface |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
Exception | Description |
---|---|
\PHPCR\Util\QOM\RuntimeException | if there is not an existing source. |
orWhere(\PHPCR\Query\QOM\ConstraintInterface $constraint) : \PHPCR\Util\QOM\QueryBuilder
Creates a new constraint formed by applying a logical OR to the existing constraint and the new one
Order of ands is important:
Given $this->constraint = $constraint1 running orWhere($constraint2) resulting constraint will be $constraint1 OR $constraint2
If there is no previous constraint then it will simply store the provided one
Name | Type | Description |
---|---|---|
$constraint | \PHPCR\Query\QOM\ConstraintInterface |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
orderBy(\PHPCR\Query\QOM\DynamicOperandInterface $sort, string $order = 'ASC') : \PHPCR\Util\QOM\QueryBuilder
Specifies an ordering for the query results.
Replaces any previously specified orderings, if any.
Name | Type | Description |
---|---|---|
$sort | \PHPCR\Query\QOM\DynamicOperandInterface | The ordering expression. |
$order | string | The ordering direction. |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
rightJoin(\PHPCR\Query\QOM\SourceInterface $rightSource, \PHPCR\Query\QOM\JoinConditionInterface $joinCondition) : \PHPCR\Util\QOM\QueryBuilder
Performs a right outer join between the stored source and the supplied source.
Name | Type | Description |
---|---|---|
$rightSource | \PHPCR\Query\QOM\SourceInterface | |
$joinCondition | \PHPCR\Query\QOM\JoinConditionInterface |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
Exception | Description |
---|---|
\PHPCR\Util\QOM\RuntimeException | if there is not an existing source. |
select(string $propertyName, string $columnName = null, string $selectorName = null) : \PHPCR\Util\QOM\QueryBuilder
Identifies a property in the specified or default selector to include in the tabular view of query results.
Replaces any previously specified columns to be selected if any.
Name | Type | Description |
---|---|---|
$propertyName | string | |
$columnName | string | |
$selectorName | string |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
setColumns(\PHPCR\Query\QOM\ColumnInterface[] $columns) : \PHPCR\Util\QOM\QueryBuilder
Sets the columns to be selected
Name | Type | Description |
---|---|---|
$columns | \PHPCR\Query\QOM\ColumnInterface[] | The columns to be selected |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
setFirstResult(integer $firstResult) : \PHPCR\Util\QOM\QueryBuilder
sets the position of the first result to retrieve (the "offset").
Name | Type | Description |
---|---|---|
$firstResult | integer | The First result to return. |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
setFromQuery(string $statement, string $language) : \PHPCR\Util\QOM\QueryBuilder
Get a query builder instance from an existing query
Name | Type | Description |
---|---|---|
$statement | string | the statement in the specified language |
$language | string | the query language |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
setMaxResults(integer $maxResults) : \PHPCR\Util\QOM\QueryBuilder
Sets the maximum number of results to retrieve (the "limit").
Name | Type | Description |
---|---|---|
$maxResults | integer | The maximum number of results to retrieve. |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
setParameter(string $key, mixed $value) : \PHPCR\Util\QOM\QueryBuilder
Sets a query parameter for the query being constructed.
Name | Type | Description |
---|---|---|
$key | string | The parameter name. |
$value | mixed | The parameter value. |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
setParameters(array $params) : \PHPCR\Util\QOM\QueryBuilder
Sets a collection of query parameters for the query being constructed.
Name | Type | Description |
---|---|---|
$params | array | The query parameters to set. |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |
where(\PHPCR\Query\QOM\ConstraintInterface $constraint) : \PHPCR\Util\QOM\QueryBuilder
Specifies one restriction (may be simple or composed).
Replaces any previously specified restrictions, if any.
Name | Type | Description |
---|---|---|
$constraint | \PHPCR\Query\QOM\ConstraintInterface |
Type | Description |
---|---|
\PHPCR\Util\QOM\QueryBuilder | This QueryBuilder instance. |