phpcr-utils/src/PHPCR/Util/QOM/QueryBuilder.php

Show: PublicProtectedPrivateinherited
Table of Contents
This file is part of the PHPCR Utils

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.

License
Apache Software License 2.0  
Link
http://phpcr.github.com/  

\PHPCR\Util\QOM\QueryBuilder

Package: Default
QueryBuilder class is responsible for dynamically create QOM queries.
Author
Nacho Martín  
Author
Guilherme Blanco  
Author
Benjamin Eberlei  

Constants

>VConstant  STATE_DIRTY = 0
The builder states.
>VConstant  STATE_CLEAN = 1

Properties

>VPropertyprivatearray $columns = array()

with the columns to be selected.

Default valuearray()Details
Type
array
>VPropertyprivate\PHPCR\Query\QOM\ConstraintInterface $constraint = null

to apply to the query.

Default valuenullDetails
Type
\PHPCR\Query\QOM\ConstraintInterface
>VPropertyprivateinteger $firstResult = null

The maximum number of results to retrieve.

Default valuenullDetails
Type
integer
>VPropertyprivateinteger $maxResults = null

The maximum number of results to retrieve.

Default valuenullDetails
Type
integer
>VPropertyprivatearray $orderings = array()

with the orderings that determine the order of the result

Default valuearray()Details
Type
array
>VPropertyprivatearray $params = array()

The query parameters.

Default valuearray()Details
Type
array
>VPropertyprivate\PHPCR\Query\QOM\QueryObjectModelFactoryInterface $qomFactory

QOMFactory

>VPropertyprivate\PHPCR\Query\QOM\QueryObjectModelInterface $query = null
QOM tree
Default valuenullDetails
Type
\PHPCR\Query\QOM\QueryObjectModelInterface
>VPropertyprivate\PHPCR\Query\QOM\SourceInterface $source = null

source of the query.

Default valuenullDetails
Type
\PHPCR\Query\QOM\SourceInterface
>VPropertyprivateinteger $state = self::STATE_CLEAN

The state of the query object. Can be dirty or clean.

Default valueself::STATE_CLEANDetails
Type
integer

Methods

methodpublic__construct(\PHPCR\Query\QOM\QueryObjectModelFactoryInterface $qomFactory) : void

Initializes a new QueryBuilder

Parameters
NameTypeDescription
$qomFactory\PHPCR\Query\QOM\QueryObjectModelFactoryInterface
methodpublicaddOrderBy(\PHPCR\Query\QOM\DynamicOperandInterface $sort, string $order = 'ASC') : \PHPCR\Util\QOM\QueryBuilder

Adds an ordering to the query results.

Parameters
NameTypeDescription
$sort\PHPCR\Query\QOM\DynamicOperandInterface

The ordering expression.

$orderstring

The ordering direction.

Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
methodpublicaddSelect(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.

Parameters
NameTypeDescription
$propertyNamestring
$columnNamestring
$selectorNamestring
Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
methodpublicandWhere(\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

Parameters
NameTypeDescription
$constraint\PHPCR\Query\QOM\ConstraintInterface
Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
methodpublicexecute() : \PHPCR\Query\QueryResultInterface

Executes the query setting firstResult and maxResults.

Returns
TypeDescription
\PHPCR\Query\QueryResultInterface
methodpublicfrom(\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.

Parameters
NameTypeDescription
$source\PHPCR\Query\QOM\SourceInterface
Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
methodpublicgetColumns() : \PHPCR\Query\QOM\ColumnInterface[]

Returns the columns to be selected

Returns
TypeDescription
\PHPCR\Query\QOM\ColumnInterface[]The columns to be selected
methodpublicgetConstraint() : \PHPCR\Query\QOM\ConstraintInterface

Returns the constraint to apply

Returns
TypeDescription
\PHPCR\Query\QOM\ConstraintInterfacethe constraint to be applied
methodpublicgetFirstResult() : 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.

Returns
TypeDescription
integerThe position of the first result.
methodpublicgetMaxResults() : 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.

Returns
TypeDescription
integerMaximum number of results.
methodpublicgetOrderings() : \PHPCR\Query\QOM\OrderingInterface[]

Gets the array of orderings.

Returns
TypeDescription
\PHPCR\Query\QOM\OrderingInterface[]Orderings to apply.
methodpublicgetParameter(string $key) : mixed

Gets a (previously set) query parameter of the query being constructed.

Parameters
NameTypeDescription
$keystring

The key (name) of the bound parameter.

Returns
TypeDescription
mixedThe value of the bound parameter.
methodpublicgetParameters() : array

Gets all defined query parameters for the query being constructed.

Returns
TypeDescription
arrayThe currently defined query parameters.
methodpublicgetQOMFactory() : \PHPCR\Query\QOM\QueryObjectModelFactoryInterface

Get the associated QOMFactory for this query builder

methodpublicgetSource() : \PHPCR\Query\QOM\SourceInterface

Gets the default Selector.

Returns
TypeDescription
\PHPCR\Query\QOM\SourceInterfaceThe default selector.
methodpublicinnerJoin(\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.

Parameters
NameTypeDescription
$rightSource\PHPCR\Query\QOM\SourceInterface
$joinCondition\PHPCR\Query\QOM\JoinConditionInterface
Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
Throws
ExceptionDescription
\PHPCR\Util\QOM\RuntimeExceptionif there is not an existing source.
methodpublicjoin(\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.

Parameters
NameTypeDescription
$rightSource\PHPCR\Query\QOM\SourceInterface
$joinCondition\PHPCR\Query\QOM\JoinConditionInterface
Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
Throws
ExceptionDescription
\PHPCR\Util\QOM\RuntimeExceptionif there is not an existing source.
methodpublicjoinWithType(\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.

Parameters
NameTypeDescription
$rightSource\PHPCR\Query\QOM\SourceInterface
$joinTypestring

as specified in PHPCR\Query\QOM\QueryObjectModelConstantsInterface

$joinCondition\PHPCR\Query\QOM\JoinConditionInterface
Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
Throws
ExceptionDescription
\PHPCR\Util\QOM\RuntimeExceptionif there is not an existing source.
methodpublicleftJoin(\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.

Parameters
NameTypeDescription
$rightSource\PHPCR\Query\QOM\SourceInterface
$joinCondition\PHPCR\Query\QOM\JoinConditionInterface
Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
Throws
ExceptionDescription
\PHPCR\Util\QOM\RuntimeExceptionif there is not an existing source.
methodpublicorWhere(\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

Parameters
NameTypeDescription
$constraint\PHPCR\Query\QOM\ConstraintInterface
Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
methodpublicorderBy(\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.

Parameters
NameTypeDescription
$sort\PHPCR\Query\QOM\DynamicOperandInterface

The ordering expression.

$orderstring

The ordering direction.

Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
methodpublicqomf() : void

Shortcut for getQOMFactory()

methodpublicrightJoin(\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.

Parameters
NameTypeDescription
$rightSource\PHPCR\Query\QOM\SourceInterface
$joinCondition\PHPCR\Query\QOM\JoinConditionInterface
Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
Throws
ExceptionDescription
\PHPCR\Util\QOM\RuntimeExceptionif there is not an existing source.
methodpublicselect(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.

Parameters
NameTypeDescription
$propertyNamestring
$columnNamestring
$selectorNamestring
Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
methodpublicsetColumns(\PHPCR\Query\QOM\ColumnInterface[] $columns) : \PHPCR\Util\QOM\QueryBuilder

Sets the columns to be selected

Parameters
NameTypeDescription
$columns\PHPCR\Query\QOM\ColumnInterface[]

The columns to be selected

Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
methodpublicsetFirstResult(integer $firstResult) : \PHPCR\Util\QOM\QueryBuilder

sets the position of the first result to retrieve (the "offset").

Parameters
NameTypeDescription
$firstResultinteger

The First result to return.

Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
methodpublicsetFromQuery(string $statement, string $language) : \PHPCR\Util\QOM\QueryBuilder

Get a query builder instance from an existing query

Parameters
NameTypeDescription
$statementstring

the statement in the specified language

$languagestring

the query language

Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
methodpublicsetMaxResults(integer $maxResults) : \PHPCR\Util\QOM\QueryBuilder

Sets the maximum number of results to retrieve (the "limit").

Parameters
NameTypeDescription
$maxResultsinteger

The maximum number of results to retrieve.

Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
methodpublicsetParameter(string $key, mixed $value) : \PHPCR\Util\QOM\QueryBuilder

Sets a query parameter for the query being constructed.

Parameters
NameTypeDescription
$keystring

The parameter name.

$valuemixed

The parameter value.

Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
methodpublicsetParameters(array $params) : \PHPCR\Util\QOM\QueryBuilder

Sets a collection of query parameters for the query being constructed.

Parameters
NameTypeDescription
$paramsarray

The query parameters to set.

Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
methodpublicwhere(\PHPCR\Query\QOM\ConstraintInterface $constraint) : \PHPCR\Util\QOM\QueryBuilder

Specifies one restriction (may be simple or composed).

Replaces any previously specified restrictions, if any.

Parameters
NameTypeDescription
$constraint\PHPCR\Query\QOM\ConstraintInterface
Returns
TypeDescription
\PHPCR\Util\QOM\QueryBuilderThis QueryBuilder instance.
Documentation was generated by phpDocumentor 2.0.0a12.