Commit 4e62d4a9 authored by guilhermeblanco's avatar guilhermeblanco

More refactorings under DQL Parser/AST classes.

Implemented new classes. Fixed a couple of issues around the road.
parent f83f5c3c
......@@ -69,7 +69,7 @@ class Doctrine_ORM_Query_AST_RangeVariableDeclaration extends Doctrine_ORM_Query
$conn = $this->_parserResult->getEntityManager()->getConnection();
// Component alias
$componentAlias = $this->_aliasIdentificationVariable->getComponentAlias();
$componentAlias = $this->_aliasIdentificationVariable;
// Retrieving required information
try {
......
......@@ -86,6 +86,6 @@ class Doctrine_ORM_Query_AST_SelectClause extends Doctrine_ORM_Query_AST
protected function _mapSelectExpression($value)
{
return $value->buildSql();
return is_object($value) ? $value->buildSql() : $value;
}
}
......@@ -31,32 +31,28 @@
*/
class Doctrine_ORM_Query_Parser_AbstractSchemaName extends Doctrine_ORM_Query_ParserRule
{
protected $_AST = null;
protected $_componentName = null;
public function syntax()
{
// AbstractSchemaName ::= identifier
$this->_AST = $this->AST('AbstractSchemaName');
$this->_parser->match(Doctrine_ORM_Query_Token::T_IDENTIFIER);
$this->_AST->setComponentName($this->_parser->token['value']);
$this->_componentName = $this->_parser->token['value'];
}
public function semantical()
{
$componentName = $this->_AST->getComponentName();
// Check if we are dealing with a real Doctrine_Entity or not
if ( ! $this->_isDoctrineEntity($componentName)) {
if ( ! $this->_isDoctrineEntity($this->_componentName)) {
$this->_parser->semanticalError(
"Defined entity '" . $componentName . "' is not a valid entity."
"Defined entity '" . $this->_componentName . "' is not a valid entity."
);
}
// Return AST node
return $this->_AST;
// Return Component Name identifier
return $this->_componentName;
}
......
......@@ -31,16 +31,14 @@
*/
class Doctrine_ORM_Query_Parser_AliasIdentificationVariable extends Doctrine_ORM_Query_ParserRule
{
protected $_AST = null;
protected $_componentAlias = null;
public function syntax()
{
// AliasIdentificationVariable = identifier
$this->_AST = $this->AST('AliasIdentificationVariable');
$this->_parser->match(Doctrine_ORM_Query_Token::T_IDENTIFIER);
$this->_AST->setComponentAlias($this->_parser->token['value']);
$this->_componentAlias = $this->_parser->token['value'];
}
......@@ -48,17 +46,17 @@ class Doctrine_ORM_Query_Parser_AliasIdentificationVariable extends Doctrine_ORM
{
$parserResult = $this->_parser->getParserResult();
if ($parserResult->hasQueryComponent($this->_AST->getComponentAlias())) {
if ($parserResult->hasQueryComponent($this->_componentAlias)) {
// We should throw semantical error if there's already a component for this alias
$queryComponent = $parserResult->getQueryComponent($this->_AST->getComponentAlias());
$queryComponent = $parserResult->getQueryComponent($this->_componentAlias);
$componentName = $queryComponent['metadata']->getClassName();
$message = "Cannot re-declare component alias '" . $this->_AST->getComponentAlias() . "'. "
$message = "Cannot re-declare component alias '" . $this->_componentAlias . "'. "
. "It was already declared for component '" . $componentName . "'.";
$this->_parser->semanticalError($message);
}
return $this->_AST;
return $this->_componentAlias;
}
}
......@@ -20,29 +20,14 @@
*/
/**
* FieldIdentificationVariable ::= identifier
* CollectionValuedAssociationField ::= FieldIdentificationVariable
*
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_ORM_Query_AST_FieldIdentificationVariable extends Doctrine_ORM_Query_AST
{
protected $_fieldName;
/* Setters */
public function setFieldName($fieldName)
{
$this->_fieldName = $fieldName;
}
/* Getters */
public function getFieldName()
{
return $this->_fieldName;
}
}
\ No newline at end of file
class Doctrine_ORM_Query_Parser_CollectionValuedAssociationField extends Doctrine_ORM_Query_Parser_FieldIdentificationVariable
{ }
\ No newline at end of file
......@@ -20,29 +20,14 @@
*/
/**
* AbstractSchemaName ::= identifier
* EmbeddedClassStateField ::= FieldIdentificationVariable
*
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_ORM_Query_AST_AbstractSchemaName extends Doctrine_ORM_Query_AST
{
protected $_componentName;
/* Setters */
public function setComponentName($componentName)
{
$this->_componentName = $componentName;
}
/* Getters */
public function getComponentName()
{
return $this->_componentName;
}
}
\ No newline at end of file
class Doctrine_ORM_Query_Parser_EmbeddedClassStateField extends Doctrine_ORM_Query_Parser_FieldIdentificationVariable
{ }
\ No newline at end of file
......@@ -20,41 +20,39 @@
*/
/**
* IdentificationVariable ::= identifier
* FieldAliasIdentificationVariable ::= identifier
*
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_ORM_Query_AST_IdentificationVariable extends Doctrine_ORM_Query_AST
class Doctrine_ORM_Query_Parser_FieldAliasIdentificationVariable extends Doctrine_ORM_Query_Parser
{
protected $_componentAlias;
protected $_fieldAlias = null;
/* Setters */
public function setComponentAlias($componentAlias)
public function syntax()
{
$this->_componentAlias = $componentAlias;
// AliasIdentificationVariable = identifier
$this->_parser->match(Doctrine_ORM_Query_Token::T_IDENTIFIER);
$this->_fieldAlias = $this->_parser->token['value'];
}
/* Getters */
public function getComponentAlias()
public function semantical()
{
return $this->_componentAlias;
}
$parserResult = $this->_parser->getParserResult();
/* REMOVE ME LATER. COPIED METHODS FROM SPLIT OF PRODUCTION INTO "AST" AND "PARSER" */
public function buildSql()
{
$conn = $this->_parserResult->getEntityManager()->getConnection();
if ($parserResult->hasFieldAlias($this->_fieldAlias)) {
// We should throw semantical error if there's already a field for this alias
$message = "Cannot re-declare field alias '" . $this->_fieldAlias . "'.";
$this->_parser->semanticalError($message);
}
return $conn->quoteIdentifier(
$this->_parserResult->getTableAliasFromComponentAlias($this->_componentAlias)
);
return $this->_fieldAlias;
}
}
\ No newline at end of file
......@@ -31,29 +31,10 @@
*/
class Doctrine_ORM_Query_Parser_FieldIdentificationVariable extends Doctrine_ORM_Query_ParserRule
{
protected $_AST = null;
public function syntax()
{
// FieldIdentificationVariable ::= identifier
$this->_AST = $this->AST('FieldIdentificationVariable');
$this->_parser->match(Doctrine_ORM_Query_Token::T_IDENTIFIER);
$this->_AST->setFieldName($this->_parser->token['value']);
// Return AST node
return $this->_AST;
}
public function semantical()
{
$parserResult = $this->_parser->getParserResult();
// [TODO] Check for field existance somewhere
// Return AST node
return $this->_AST;
return $this->_parser->token['value'];
}
}
......@@ -31,16 +31,14 @@
*/
class Doctrine_ORM_Query_Parser_IdentificationVariable extends Doctrine_ORM_Query_ParserRule
{
protected $_AST = null;
protected $_componentAlias = null;
public function syntax()
{
// IdentificationVariable ::= identifier
$this->_AST = $this->AST('IdentificationVariable');
$this->_parser->match(Doctrine_ORM_Query_Token::T_IDENTIFIER);
$this->_AST->setComponentAlias($this->_parser->token['value']);
$this->_componentAlias = $this->_parser->token['value'];
}
......@@ -48,15 +46,15 @@ class Doctrine_ORM_Query_Parser_IdentificationVariable extends Doctrine_ORM_Quer
{
$parserResult = $this->_parser->getParserResult();
if ( ! $parserResult->hasQueryComponent($this->_AST->getComponentAlias())) {
if ( ! $parserResult->hasQueryComponent($this->_componentAlias)) {
// We should throw semantical error if we cannot find the component alias
$message = "No entity related to declared alias '" . $this->_AST->getComponentAlias()
$message = "No entity related to declared alias '" . $this->_componentAlias
. "' near '" . $this->_parser->getQueryPiece($this->_parser->token) . "'.";
$this->_parser->semanticalError($message);
}
// Return AST node
return $this->_AST;
// Return Component Alias identifier
return $this->_componentAlias;
}
}
......@@ -60,12 +60,11 @@ class Doctrine_ORM_Query_Parser_IdentificationVariableDeclaration extends Doctri
// If we have an INDEX BY RangeVariableDeclaration
if ($this->_AST->getIndexby() !== null) {
// Grab Range component alias
$rangeComponentAlias = $this->_AST->getRangeVariableDeclaration()
->getAliasIdentificationVariable()->getComponentAlias();
$rangeComponentAlias = $this->_AST->getRangeVariableDeclaration()->getAliasIdentificationVariable();
// Grab IndexBy component alias
$indexComponentAlias = $this->_AST->getIndexBy()
->getSimpleStateFieldPathExpression()->getIdentificationVariable()->getComponentAlias();
$indexComponentAlias = $this->_AST->getIndexBy()->getSimpleStateFieldPathExpression()
->getIdentificationVariable();
// Check if we have same component being used in index
if ($rangeComponentAlias !== $indexComponentAlias) {
......
......@@ -52,10 +52,8 @@ class Doctrine_ORM_Query_Parser_IndexBy extends Doctrine_ORM_Query_ParserRule
$parserResult = $this->_parser->getParserResult();
// Grab INDEX BY information
$componentAlias = $this->_AST->getSimpleStateFieldPathExpression()
->getIdentificationVariable()->getComponentAlias();
$componentFieldName = $this->_AST->getSimpleStateFieldPathExpression()
->getSimpleStateField()->getFieldName();
$componentAlias = $this->_AST->getSimpleStateFieldPathExpression()->getIdentificationVariable();
$componentFieldName = $this->_AST->getSimpleStateFieldPathExpression()->getSimpleStateField();
// Trying to retrieve related query component
try {
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
/**
* JoinCollectionValuedPathExpression ::= IdentificationVariable "." CollectionValuedAssociationField
*
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_ORM_Query_Parser_JoinCollectionValuedPathExpression extends Doctrine_ORM_Query_ParserRule
{
protected $_AST = null;
public function syntax()
{
// JoinCollectionValuedPathExpression ::= IdentificationVariable "." CollectionValuedAssociationField
$this->_AST = $this->AST('JoinCollectionValuedPathExpression');
$this->_AST->setIdentificationVariable($this->parse('IdentificationVariable'));
$this->_parser->match(Doctrine_ORM_Query_Token::T_DOT);
$this->_AST->setCollectionValuedAssociationField($this->parse('CollectionValuedAssociationField'));
}
public function semantical()
{
$parserResult = $this->_parser->getParserResult();
$queryComponent = $parserResult->getQueryComponent($this->_AST->setIdentificationVariable());
$fieldName = $this->_AST->setCollectionValuedAssociationField();
if ( ! $queryComponent['metadata']->hasField($fieldName)) {
$componentName = $queryComponent['metadata']->getClassName();
$message = "Field '" . $fieldName . "' does not exist in component '" . $componentName . "'.";
$this->_parser->semanticalError($message);
}
if ( ! $queryComponent['metadata']->hasAssociation($fieldName)) {
$componentName = $queryComponent['metadata']->getClassName();
$message = "Field '" . $fieldName . "' is not an association in component '" . $componentName . "'.";
$this->_parser->semanticalError($message);
}
$mapping = $queryComponent['metadata']->getAssociation($fieldName);
if ($mapping instanceof Doctrine_ORM_Mapping_OneToOneMapping) {
$componentName = $queryComponent['metadata']->getClassName();
$message = "Field '" . $fieldName . "' does not map to a collection valued association in component '"
. $componentName . "'.";
$this->_parser->semanticalError($message);
}
return $this->_AST;
}
}
......@@ -52,8 +52,8 @@ class Doctrine_ORM_Query_Parser_RangeVariableDeclaration extends Doctrine_ORM_Qu
public function semantical()
{
$parserResult = $this->_parser->getParserResult();
$componentName = $this->_AST->getAbstractSchemaName()->getComponentName();
$componentAlias = $this->_AST->getAliasIdentificationVariable()->getComponentAlias();
$componentName = $this->_AST->getAbstractSchemaName();
$componentAlias = $this->_AST->getAliasIdentificationVariable();
// Check if we already have a component defined without an alias
if ($componentAlias === null && $parserResult->hasQueryComponent($componentName)) {
......
......@@ -29,14 +29,5 @@
* @since 2.0
* @version $Revision$
*/
class Doctrine_ORM_Query_Parser_SimpleStateField extends Doctrine_ORM_Query_ParserRule
{
protected $_AST = null;
public function syntax()
{
// SimpleStateField ::= FieldIdentificationVariable
return $this->parse('FieldIdentificationVariable');
}
}
\ No newline at end of file
class Doctrine_ORM_Query_Parser_SimpleStateField extends Doctrine_ORM_Query_Parser_FieldIdentificationVariable
{ }
\ No newline at end of file
......@@ -50,8 +50,8 @@ class Doctrine_ORM_Query_Parser_SimpleStateFieldPathExpression extends Doctrine_
public function semantical()
{
$parserResult = $this->_parser->getParserResult();
$componentAlias = $this->_AST->getIdentificationVariable()->getComponentAlias();
$componentFieldName = $this->_AST->getSimpleStateField()->getFieldName();
$componentAlias = $this->_AST->getIdentificationVariable();
$componentFieldName = $this->_AST->getSimpleStateField();
// We need to make sure field exists
try {
......
......@@ -20,29 +20,14 @@
*/
/**
* AliasIdentificationVariable ::= identifier
* SingleValuedAssociationField ::= FieldIdentificationVariable
*
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_ORM_Query_AST_AliasIdentificationVariable extends Doctrine_ORM_Query_AST
{
protected $_componentAlias;
/* Setters */
public function setComponentAlias($componentAlias)
{
$this->_componentAlias = $componentAlias;
}
/* Getters */
public function getComponentAlias()
{
return $this->_componentAlias;
}
}
\ No newline at end of file
class Doctrine_ORM_Query_Parser_SingleValuedAssociationField extends Doctrine_ORM_Query_Parser_FieldIdentificationVariable
{ }
\ No newline at end of file
......@@ -50,40 +50,41 @@ final class Doctrine_ORM_Query_Token
const T_DELETE = 110;
const T_DESC = 111;
const T_DISTINCT = 112;
const T_ESCAPE = 113;
const T_EXISTS = 114;
const T_FROM = 115;
const T_GROUP = 116;
const T_HAVING = 117;
const T_IN = 118;
const T_INDEX = 119;
const T_INNER = 120;
const T_IS = 121;
const T_JOIN = 122;
const T_LEFT = 123;
const T_LIKE = 124;
const T_LIMIT = 125;
const T_MAX = 126;
const T_MIN = 127;
const T_MOD = 128;
const T_NOT = 129;
const T_NULL = 130;
const T_OFFSET = 131;
const T_ON = 132;
const T_OR = 133;
const T_ORDER = 134;
const T_OUTER = 135;
const T_SELECT = 136;
const T_SET = 137;
const T_SIZE = 138;
const T_SOME = 139;
const T_SUM = 140;
const T_UPDATE = 141;
const T_WHERE = 142;
const T_WITH = 143;
const T_DOT = 113;
const T_ESCAPE = 114;
const T_EXISTS = 115;
const T_FROM = 116;
const T_GROUP = 117;
const T_HAVING = 118;
const T_IN = 119;
const T_INDEX = 120;
const T_INNER = 121;
const T_IS = 122;
const T_JOIN = 123;
const T_LEFT = 124;
const T_LIKE = 125;
const T_LIMIT = 126;
const T_MAX = 127;
const T_MIN = 128;
const T_MOD = 129;
const T_NOT = 130;
const T_NULL = 131;
const T_OFFSET = 132;
const T_ON = 133;
const T_OR = 134;
const T_ORDER = 135;
const T_OUTER = 136;
const T_SELECT = 137;
const T_SET = 138;
const T_SIZE = 139;
const T_SOME = 140;
const T_SUM = 141;
const T_UPDATE = 142;
const T_WHERE = 143;
const T_WITH = 144;
const T_TRUE = 144;
const T_FALSE = 145;
const T_TRUE = 145;
const T_FALSE = 146;
protected $_keywordsTable = array();
......@@ -103,6 +104,7 @@ final class Doctrine_ORM_Query_Token
$this->addKeyword(self::T_DELETE, "DELETE");
$this->addKeyword(self::T_DESC, "DESC");
$this->addKeyword(self::T_DISTINCT, "DISTINCT");
$this->addKeyword(self::T_DOT, ".");
$this->addKeyword(self::T_ESCAPE, "ESPACE");
$this->addKeyword(self::T_EXISTS, "EXISTS");
$this->addKeyword(self::T_FALSE, "FALSE");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment