class QueryBuilder extends AbstractNode (View source)

The Query Builder root node.

This is the node which is returned when a query builder is asked for::

$dm = // get document manager $qb = $dm->createQueryBuilder(); $qb->fromDocument('Blog\Post', 'p'); $qb->where()->eq()->field('p.title')->literal('My Post'); $docs = $qb->getQuery()->execute();

A converter is required to be set if the purpose of the query builder is to be fulfilled. The PHPCR converter walks over the query builder node hierarchy and converts the object graph the PHPCR QOM object graph.

Constants

NT_BUILDER

NT_CONSTRAINT

NT_CONSTRAINT_FACTORY

NT_FROM

NT_OPERAND_DYNAMIC

NT_OPERAND_DYNAMIC_FACTORY

NT_OPERAND_STATIC

NT_OPERAND_FACTORY

NT_ORDERING

NT_ORDER_BY

NT_PROPERTY

NT_SELECT

NT_SOURCE

NT_SOURCE_FACTORY

NT_SOURCE_JOIN_CONDITION

NT_SOURCE_JOIN_CONDITION_FACTORY

NT_SOURCE_JOIN_LEFT

NT_SOURCE_JOIN_RIGHT

NT_WHERE

NT_WHERE_AND

NT_WHERE_OR

Properties

protected $children from AbstractNode
protected $parent from AbstractNode
protected $converter
protected $firstResult
protected $maxResults
protected $locale
protected $primaryAlias

Methods

__construct(AbstractNode $parent = null)

No description

string
getNodeType()

Return the type of node.

getParent()

Return the parent of this node.

string
getName()

Return the last part of the this classes FQN (i.e. the basename).

array
getCardinalityMap()

Return the cardinality map for this node.

setChild(AbstractNode $node)

Remove any previous children and add given node via. addChild.

addChild(AbstractNode $node)

Add a child to this node.

getNext()

Return the next object in the fluid interface chain. Leaf nodes always return the parent, deafult behavior is to return /this/ class.

getChildren()

Return all child nodes.

getChildrenOfType(string $type)

Return children of specified type.

removeChildrenOfType($type)

No description

getChild()

Return child of node, there must be exactly one child of any type.

getChildOfType(string $type)

Return child of specified type.

validate()

Validate the current node.

end()

Validates this node and returns its parent.

__call(string $methodName, array $args)

Catch any undefined method calls and tell the developer what methods can be called.

ensureNoArguments($method, $void)

No description

getFactoryMethods()

No description

string
getLocale()

No description

$this
setLocale(string $locale)

Set the locale to use in this query.

getQuery()

No description

setConverter(ConverterInterface $converter)

No description

getConverter()

No description

where($void = null)

Where factory node is used to specify selection criteria::.

andWhere($void = null)

Add additional selection criteria using the AND operator.

orWhere($void = null)

Add additional selection criteria using the OR operator.

from(string $primaryAlias = null)

Set the from source for the query::.

fromDocument(string $documentFqn, string $primaryAlias)

Shortcut for::.

addJoinLeftOuter($void = null)

Replace the existing source with a left outer join source using the existing source as the left operand::.

addJoinRightOuter($void = null)

Replace the existing source with a right outer join source using the existing source as the left operand::.

addJoinInner($void = null)

Replace the existing source with an inner join source using the existing source as the left operand::.

select($void = null)

Method to add properties for selection to builder tree, replaces any existing select.

addSelect($void = null)

Add additional properties to selection::.

orderBy($void = null)

Add orderings to the builder tree.

addOrderBy($void = null)

Add additional orderings to the builder tree.

int
getFirstResult()

Return the offset of the first result in the resultset.

setFirstResult(int $firstResult)

Set the offset of the first result in the resultset.

int
getMaxResults()

Return the maximum number of results to be imposed on the generated query.

setMaxResults(int $maxResults)

Set the maximum number of results to be returned by the generated query.

string
__toString()

Creates an SQL2 representation of the PHPCR query built by this builder.

getPrimaryAlias()

No description

__clone()

Ensure cloned query builder objects have unique instances of the converter.

Details

__construct(AbstractNode $parent = null)

Parameters

AbstractNode $parent

string getNodeType()

Return the type of node.

Must be one of self::NT_*

Return Value

string

AbstractNode getParent()

Return the parent of this node.

Return Value

AbstractNode

final string getName()

Return the last part of the this classes FQN (i.e. the basename).

This should only be used when generating exceptions This is also used to determine the dispatching method -- should it be?

Return Value

string

array getCardinalityMap()

Return the cardinality map for this node.

e.g. array( self::NT_JOIN_CONDITION => array(1, 1), // require exactly 1 join condition self::NT_SOURCE => array(2, 2), // exactly 2 sources );

or: array( self::NT_PROPERTY => array(1, null), // require one to many Columns );

or: array( self::NT_PROPERTY => array(null, 1), // require none to 1 properties );

Return Value

array

AbstractNode setChild(AbstractNode $node)

Remove any previous children and add given node via. addChild.

Parameters

AbstractNode $node

Return Value

AbstractNode

See also

removeChildrenOfType
addChild

AbstractNode addChild(AbstractNode $node)

Add a child to this node.

Exception will be thrown if child node type is not described in the cardinality map, or if the maxiumum permitted number of nodes would be exceeded by adding the given child node.

The given node will be returned EXCEPT when the current node is a leaf node, in which case we return the parent.

Parameters

AbstractNode $node

Return Value

AbstractNode

Exceptions

OutOfBoundsException

AbstractNode getNext()

Return the next object in the fluid interface chain. Leaf nodes always return the parent, deafult behavior is to return /this/ class.

Return Value

AbstractNode

AbstractNode[] getChildren()

Return all child nodes.

Note that this will returned a flattened version of the classes type => children map.

Return Value

AbstractNode[]

AbstractNode[] getChildrenOfType(string $type)

Return children of specified type.

Parameters

string $type The type name.

Return Value

AbstractNode[]

removeChildrenOfType($type)

Parameters

$type

AbstractNode getChild()

Return child of node, there must be exactly one child of any type.

Return Value

AbstractNode

Exceptions

OutOfBoundsException if there are more than one or none

AbstractNode getChildOfType(string $type)

Return child of specified type.

Note: This does not take inheritance into account.

Parameters

string $type The name of the type.

Return Value

AbstractNode

Exceptions

OutOfBoundsException if there are more than one or none

validate()

Validate the current node.

Validation is performed both when the query is being built and when the dev explicitly calls "end()".

This method simply checks the minimum boundries are satisfied, the addChild() method already validates maximum boundries and types.

AbstractNode end()

Validates this node and returns its parent.

This should be used if the developer wants to define the entire Query in a fluid manner.

Return Value

AbstractNode

__call(string $methodName, array $args)

Catch any undefined method calls and tell the developer what methods can be called.

Parameters

string $methodName The requested nonexistent method.
array $args The arguments that where used.

Exceptions

BadMethodCallException if an unknown method is called.

ensureNoArguments($method, $void)

Parameters

$method
$void

getFactoryMethods()

string getLocale()

Return Value

string the locale for this query.

$this setLocale(string $locale)

Set the locale to use in this query.

Parameters

string $locale

Return Value

$this

Query getQuery()

Return Value

Query

setConverter(ConverterInterface $converter)

Parameters

ConverterInterface $converter

protected ConverterInterface getConverter()

Return Value

ConverterInterface

Where where($void = null)

Where factory node is used to specify selection criteria::.

$qb->where() ->eq() ->field('a.foobar')->literal('bar')->end() ->end() ->end();

Parameters

$void

Return Value

Where

WhereAnd andWhere($void = null)

Add additional selection criteria using the AND operator.

Parameters

$void

Return Value

WhereAnd

WhereOr orWhere($void = null)

Add additional selection criteria using the OR operator.

Parameters

$void

Return Value

WhereOr

From from(string $primaryAlias = null)

Set the from source for the query::.

$qb->from()->document('Foobar', 'a');

// or with a join ...

$qb->from('a')->joinInner() ->left()->document('Foobar', 'a')->end() ->right()->document('Barfoo', 'b')->end() ->condition()->equi('a.prop_1', 'b.prop_1')->end() ->end();

Parameters

string $primaryAlias
  • Alias to use as primary source (optional for single sources)

Return Value

From

QueryBuilder fromDocument(string $documentFqn, string $primaryAlias)

Shortcut for::.

$qb->from() ->document('Foobar', 'a')->end() ->end();

Which becomes::

$qb->fromDocument('Foobar', 'a')->end();

Replaces any existing from source.

Parameters

string $documentFqn
  • Fully qualified class name for document.
string $primaryAlias
  • Alias for document source and primary alias when using multiple sources.

Return Value

QueryBuilder

SourceJoin addJoinLeftOuter($void = null)

Replace the existing source with a left outer join source using the existing source as the left operand::.

$qb->fromDocument('Foobar', 'a') ->addJoinLeftOuter() ->right()->document('Barfoo', 'b')->end() ->condition()->equi('a.prop_1', 'b.prop_2')->end() ->end() ->end();

Note that for outer joins to work correctly, documents being joined to must be mapped with a node type that is unique to the repository workspace, and the uniqueNodeType property must be set to true for the document (see :ref:<_annref_document>). Otherwise, the join will behave as an inner join.

Parameters

$void

Return Value

SourceJoin

SourceJoin addJoinRightOuter($void = null)

Replace the existing source with a right outer join source using the existing source as the left operand::.

$qb->fromDocument('Foobar', 'a') ->addJoinRightOuter() ->right()->document('Barfoo', 'b')->end()->end() ->condition()->equi('a.prop_1', 'b.prop_2')->end() ->end() ->end();

Note that for outer joins to work correctly, documents being joined to must be mapped with a node type that is unique to the repository workspace, and the uniqueNodeType property must be set to true for the document (see :ref:<_annref_document>). Otherwise, the join will behave as an inner join.

Parameters

$void

Return Value

SourceJoin

SourceJoin addJoinInner($void = null)

Replace the existing source with an inner join source using the existing source as the left operand::.

$qb->fromDocument('Foobar', 'a') ->addJoinInner() ->right()->document('Barfoo', 'b')->end() ->condition()->equi('a.prop_1', 'b.prop_2')->end() ->end() ->end();

Note that for outer joins to work correctly, documents being joined to must be mapped with a node type that is unique to the repository workspace, and the uniqueNodeType property must be set to true for the document (see :ref:<_annref_document>). Otherwise, the join will behave as an inner join.

Parameters

$void

Return Value

SourceJoin

Select select($void = null)

Method to add properties for selection to builder tree, replaces any existing select.

Number of property nodes is unbounded::

$qb->select() ->field('a.prop_1') ->field('a.prop_2') ->field('a.prop_3') ->end();

Parameters

$void

Return Value

Select

SelectAdd addSelect($void = null)

Add additional properties to selection::.

$qb->select() ->field('a.prop_1') ->end() ->addSelect() ->field('a.prop_2') ->field('a.prop_3') ->field('a.prop_4') ->end();

Parameters

$void

Return Value

SelectAdd

OrderBy orderBy($void = null)

Add orderings to the builder tree.

Number of orderings is unbounded::

$qb->orderBy() ->asc()->field('a.prop_1')->end() ->desc()->field('a.prop_2')->end() ->end();

Parameters

$void

Return Value

OrderBy

OrderByAdd addOrderBy($void = null)

Add additional orderings to the builder tree.

Parameters

$void

Return Value

OrderByAdd

int getFirstResult()

Return the offset of the first result in the resultset.

Return Value

int

setFirstResult(int $firstResult)

Set the offset of the first result in the resultset.

Parameters

int $firstResult

int getMaxResults()

Return the maximum number of results to be imposed on the generated query.

Return Value

int

setMaxResults(int $maxResults)

Set the maximum number of results to be returned by the generated query.

Parameters

int $maxResults

string __toString()

Creates an SQL2 representation of the PHPCR query built by this builder.

Return Value

string

getPrimaryAlias()

__clone()

Ensure cloned query builder objects have unique instances of the converter.