Detailed Description
ObjectQuery implements a template based object query.
This class provides the user with object templates on which query conditions may be set. Object templates are Node instances whose attribute values are used as conditions on the appropriate attributes. A value maybe a scalar or a Criteria instance. For example $authorTpl->setValue("name", Criteria::forValue("LIKE", "%ingo%") means searching for authors whose name contains 'ingo'. If only a scalar is given LIKE '%...' is assumed.
A value condition of a template is joined with the preceeding conditions using the combine operator (Criteria::OPERATOR_AND, Criteria::OPERATOR_OR) given in the Criteria assigned to the template value. The set of conditions of a template is preceded by the operator (Criteria::OPERATOR_AND, Criteria::OPERATOR_OR) given in the ObjectQuery::PROPERTY_COMBINE_OPERATOR property (default: Criteria::OPERATOR_AND) of the template (see ObjectQuery::getObjectTemplate()).
Multiple conditions for one value are built using different object templates of the same type. Conditions sets of different object templates are grouped with brackets if they are passed to ObjectQuery::makeGroup().
- Note
- : If there are two object templates of the same type as the query type linked in a parent child relation, than the nodes that are selected depend on the attributes of the first object template that is received by ObjectQuery::getObjectTemplate.
- : The query does not search in objects, that are created inside the current transaction.
The following example shows the usage:
- Note
- There are some limitations when using this class:
- This class works only with Nodes as PersistentObjects
- This class only works for Nodes mapped by RDBMapper subclasses.
- All objects have to reside in the same datastore (the connection is taken from the first mapper)
- Since the query values are set together with the operator in a single string, they must be converted to data store format already
Definition at line 106 of file ObjectQuery.php.
Public Member Functions | |
__construct ($type, $queryId=SelectStatement::NO_CACHE) | |
__destruct () | |
getId () | |
getObjectTemplate ($type, $alias=null, $combineOperator=Criteria::OPERATOR_AND) | |
registerObjectTemplate (Node $template, $alias=null, $combineOperator=Criteria::OPERATOR_AND) | |
makeGroup ($templates, $combineOperator=Criteria::OPERATOR_AND) | |
getQueryCondition () | |
getQueryType () | |
valueChanged (ValueChangeEvent $event) | |
Public Member Functions inherited from AbstractQuery | |
execute ($buildDepth, $orderby=null, $pagingInfo=null) | |
getQueryString ($buildDepth=BuildDepth::SINGLE, $orderby=null) | |
getLastQueryString () | |
Public Attributes | |
const | PROPERTY_COMBINE_OPERATOR = "object_query_combine_operator" |
const | PROPERTY_TABLE_NAME = "object_query_table_name" |
const | PROPERTY_INITIAL_OID = "object_query_initial_oid" |
Protected Member Functions | |
getLogger () | |
buildQuery ($buildDepth, $orderby=null, PagingInfo $pagingInfo=null) | |
processObjectTemplate (PersistentObject $tpl, SelectStatement $selectStmt) | |
processOrderBy ($orderby, SelectStatement $selectStmt) | |
getParameters ($criteria, array $parameters) | |
getParameterPosition ($criterion, $criteria) | |
resetInternals () | |
processTableName (Node $tpl) | |
Protected Member Functions inherited from AbstractQuery | |
executeInternal (SelectStatement $selectStmt, $buildDepth, PagingInfo $pagingInfo=null) | |
Additional Inherited Members | |
Static Protected Member Functions inherited from AbstractQuery | |
static | getConnection ($type) |
static | getMapper ($type) |
Constructor & Destructor Documentation
◆ __construct()
__construct | ( | $type, | |
$queryId = SelectStatement::NO_CACHE |
|||
) |
Constructor.
- Parameters
-
$type The type to search for $queryId Identifier for the query cache (maybe null to prevent caching) (default: null)
Definition at line 132 of file ObjectQuery.php.
◆ __destruct()
__destruct | ( | ) |
Destructor.
Definition at line 148 of file ObjectQuery.php.
Member Function Documentation
◆ getId()
getId | ( | ) |
◆ getObjectTemplate()
getObjectTemplate | ( | $type, | |
$alias = null , |
|||
$combineOperator = Criteria::OPERATOR_AND |
|||
) |
Get an object template for a given type.
- Parameters
-
$type The type to query for $alias An alias name to be used in the query. if null, use the default name (default: null) $combineOperator One of the Criteria::OPERATOR constants that precedes the conditions described in the template (default: Criteria::OPERATOR_AND)
- Returns
- Node
Definition at line 169 of file ObjectQuery.php.
◆ registerObjectTemplate()
registerObjectTemplate | ( | Node | $template, |
$alias = null , |
|||
$combineOperator = Criteria::OPERATOR_AND |
|||
) |
Register an object template at the query.
- Parameters
-
$template Node instance to register as template $alias An alias name to be used in the query. if null, use the default name (default: null) $combineOperator One of the Criteria::OPERATOR constants that precedes the conditions described in the template (default: Criteria::OPERATOR_AND)
Definition at line 203 of file ObjectQuery.php.
◆ makeGroup()
makeGroup | ( | $templates, | |
$combineOperator = Criteria::OPERATOR_AND |
|||
) |
Group different templates together to realize brackets in the query.
- Note
- Grouped templates will be ignored, when iterating over the object tree and appended at the end.
- Parameters
-
$templates An array of references to the templates contained in the group $combineOperator One of the Criteria::OPERATOR constants that precedes the group (default: Criteria::OPERATOR_AND)
Definition at line 242 of file ObjectQuery.php.
◆ getQueryCondition()
getQueryCondition | ( | ) |
Get the condition part of the query.
This is especially useful to build a StringQuery from the query objects.
- Returns
- String
Definition at line 260 of file ObjectQuery.php.
◆ getLogger()
|
protected |
- See also
- AbstractQuery::getLogger()
Reimplemented from AbstractQuery.
Definition at line 273 of file ObjectQuery.php.
◆ getQueryType()
getQueryType | ( | ) |
- See also
- AbstractQuery::getQueryType()
Reimplemented from AbstractQuery.
Definition at line 280 of file ObjectQuery.php.
◆ buildQuery()
|
protected |
- See also
- AbstractQuery::buildQuery()
Reimplemented from AbstractQuery.
Reimplemented in StringQuery.
Definition at line 287 of file ObjectQuery.php.
◆ processObjectTemplate()
|
protected |
Process an object template.
- Parameters
-
$tpl The object template $selectStmt A SelectStatement instance
Definition at line 350 of file ObjectQuery.php.
◆ processOrderBy()
|
protected |
Process an object template.
- Parameters
-
$orderby An array holding names of attributes to order by, maybe appended with 'ASC', 'DESC' (maybe null) $selectStmt A SelectStatement instance
Definition at line 479 of file ObjectQuery.php.
◆ getParameters()
|
protected |
Get an array of parameter values for the given criteria.
- Parameters
-
$criteria An array of Criteria instances that define conditions on the object's attributes (maybe null) $parameters Array defining the parameter order
- Returns
- Array
Definition at line 562 of file ObjectQuery.php.
◆ getParameterPosition()
|
protected |
Definition at line 600 of file ObjectQuery.php.
◆ resetInternals()
|
protected |
Reset internal variables.
Must be called after buildQuery
Definition at line 617 of file ObjectQuery.php.
◆ processTableName()
|
protected |
Get the table name for the template and calculate an alias if necessary.
- Parameters
-
$tpl The object template
- Returns
- Associative array with keys 'name', 'alias'
Definition at line 630 of file ObjectQuery.php.
◆ valueChanged()
valueChanged | ( | ValueChangeEvent | $event | ) |
Listen to ValueChangeEvents.
- Parameters
-
$event ValueChangeEvent instance
Definition at line 658 of file ObjectQuery.php.
Member Data Documentation
◆ PROPERTY_COMBINE_OPERATOR
const PROPERTY_COMBINE_OPERATOR = "object_query_combine_operator" |
Definition at line 108 of file ObjectQuery.php.
◆ PROPERTY_TABLE_NAME
const PROPERTY_TABLE_NAME = "object_query_table_name" |
Definition at line 109 of file ObjectQuery.php.
◆ PROPERTY_INITIAL_OID
const PROPERTY_INITIAL_OID = "object_query_initial_oid" |
Definition at line 110 of file ObjectQuery.php.