Exemple #1
0
 private string[] GetColumns()
 {
     if (_columns == null)
     {
         // Use the table fromElement and the property name to get the array of column names.
         string tableAlias = GetLhs().FromElement.TableAlias;
         _columns = FromElement.ToColumns(tableAlias, _propertyPath, false);
     }
     return(_columns);
 }
Exemple #2
0
        private void HandleElements(FromReferenceNode collectionNode, String propertyName)
        {
            FromElement          collectionFromElement = collectionNode.FromElement;
            IQueryableCollection queryableCollection   = collectionFromElement.QueryableCollection;

            String path = collectionNode.Path + "[]." + propertyName;

            Log.Debug("Creating elements for {0}", path);

            _fromElement = collectionFromElement;
            if (!collectionFromElement.IsCollectionOfValuesOrComponents)
            {
                Walker.AddQuerySpaces(queryableCollection.ElementPersister);
            }

            DataType       = queryableCollection.ElementType;
            _selectColumns = collectionFromElement.ToColumns(_fromElement.TableAlias, propertyName, _inSelect);
        }
Exemple #3
0
        public override void ResolveIndex(IASTNode parent)
        {
            // An ident node can represent an index expression if the ident
            // represents a naked property ref
            //      *Note: this makes the assumption (which is currently the case
            //      in the hql-sql grammar) that the ident is first resolved
            //      itself (addrExpr -> resolve()).  The other option, if that
            //      changes, is to call resolve from here; but it is
            //      currently un-needed overhead.
            if (!(IsResolved && _nakedPropertyRef))
            {
                throw new InvalidOperationException();
            }

            string propertyName = OriginalText;

            if (!DataType.IsCollectionType)
            {
                throw new SemanticException("Collection expected; [" + propertyName + "] does not refer to a collection property");
            }

            // TODO : most of below was taken verbatim from DotNode; should either delegate this logic or super-type it
            CollectionType       type = (CollectionType)DataType;
            string               role = type.Role;
            IQueryableCollection queryableCollection = SessionFactoryHelper.RequireQueryableCollection(role);

            string columnTableAlias = FromElement.TableAlias;

            FromElementFactory factory = new FromElementFactory(
                Walker.CurrentFromClause,
                FromElement,
                propertyName,
                null,
                FromElement.ToColumns(columnTableAlias, propertyName, false),
                true
                );

            FromElement elem = factory.CreateCollection(queryableCollection, role, JoinType.InnerJoin, false, true);

            FromElement = elem;
            Walker.AddQuerySpaces(queryableCollection.CollectionSpaces);                // Always add the collection's query spaces.
        }
Exemple #4
0
        public void ResolveCollectionProperty(IASTNode expr)
        {
            String propertyName = CollectionProperties.GetNormalizedPropertyName(_methodName);

            if (expr is FromReferenceNode)
            {
                FromReferenceNode collectionNode = ( FromReferenceNode )expr;
                // If this is 'elements' then create a new FROM element.
                if (CollectionPropertyNames.Elements == propertyName)
                {
                    HandleElements(collectionNode, propertyName);
                }
                else
                {
                    // Not elements(x)
                    _fromElement   = collectionNode.FromElement;
                    DataType       = _fromElement.GetPropertyType(propertyName, propertyName);
                    _selectColumns = _fromElement.ToColumns(_fromElement.TableAlias, propertyName, _inSelect);
                }
                if (collectionNode is DotNode)
                {
                    PrepareAnyImplicitJoins(( DotNode )collectionNode);
                }
                if (!_inSelect)
                {
                    _fromElement.Text             = "";
                    _fromElement.UseWhereFragment = false;
                }

                PrepareSelectColumns(_selectColumns);
                Text = _selectColumns[0];
                Type = HqlSqlWalker.SQL_TOKEN;
            }
            else
            {
                throw new SemanticException(
                          "Unexpected expression " + expr +
                          " found for collection function " + propertyName
                          );
            }
        }
Exemple #5
0
        public void ResolveCollectionProperty(IASTNode expr)
        {
            var propertyName = CollectionProperties.GetNormalizedPropertyName(_methodName);

            var collectionNode = expr as FromReferenceNode;

            if (collectionNode == null)
            {
                throw new SemanticException(string.Format("Unexpected expression {0} found for collection function {1}", expr, propertyName));
            }

            // If this is 'elements' then create a new FROM element.
            if (CollectionPropertyNames.Elements == propertyName)
            {
                HandleElements(collectionNode, propertyName);
            }
            else
            {
                // Not elements(x)
                _fromElement   = collectionNode.FromElement;
                DataType       = _fromElement.GetPropertyType(propertyName, propertyName);
                _selectColumns = _fromElement.ToColumns(_fromElement.TableAlias, propertyName, _inSelect);
            }
            var dotNode = collectionNode as DotNode;

            if (dotNode != null)
            {
                PrepareAnyImplicitJoins(dotNode);
            }
            if (!_inSelect)
            {
                _fromElement.Text             = "";
                _fromElement.UseWhereFragment = false;
            }

            PrepareSelectColumns(_selectColumns);
            Text = _selectColumns[0];
            Type = HqlSqlWalker.SQL_TOKEN;
        }
Exemple #6
0
        private void DereferenceCollection(CollectionType collectionType, bool implicitJoin, bool indexed, string classAlias)
        {
            _dereferenceType = DerefCollection;
            string role = collectionType.Role;

            //foo.bars.size (also handles deprecated stuff like foo.bars.maxelement for backwardness)
            IASTNode sibling        = NextSibling;
            bool     isSizeProperty = sibling != null && CollectionProperties.IsAnyCollectionProperty(sibling.Text);

            if (isSizeProperty)
            {
                indexed = true;                 //yuck!}
            }

            IQueryableCollection queryableCollection = SessionFactoryHelper.RequireQueryableCollection(role);
            string     propName          = Path;
            FromClause currentFromClause = Walker.CurrentFromClause;

            if (Walker.StatementType != HqlSqlWalker.SELECT && indexed && classAlias == null)
            {
                // should indicate that we are processing an INSERT/UPDATE/DELETE
                // query with a subquery implied via a collection property
                // function. Here, we need to use the table name itself as the
                // qualification alias.
                // TODO : verify this works for all databases...
                // TODO : is this also the case in non-"indexed" scenarios?
                string alias = GetLhs().FromElement.Queryable.TableName;
                _columns = FromElement.ToColumns(alias, _propertyPath, false, true);
            }

            //We do not look for an existing join on the same path, because
            //it makes sense to join twice on the same collection role
            FromElementFactory factory = new FromElementFactory(
                currentFromClause,
                GetLhs().FromElement,
                propName,
                classAlias,
                GetColumns(),
                implicitJoin
                );
            FromElement elem = factory.CreateCollection(queryableCollection, role, _joinType, _fetch, indexed);

            if (Log.IsDebugEnabled)
            {
                Log.Debug("dereferenceCollection() : Created new FROM element for " + propName + " : " + elem);
            }

            SetImpliedJoin(elem);
            FromElement = elem;                 // This 'dot' expression now refers to the resulting from element.

            if (isSizeProperty)
            {
                elem.Text             = "";
                elem.UseWhereFragment = false;
            }

            if (!implicitJoin)
            {
                IEntityPersister entityPersister = elem.EntityPersister;
                if (entityPersister != null)
                {
                    Walker.AddQuerySpaces(entityPersister.QuerySpaces);
                }
            }
            Walker.AddQuerySpaces(queryableCollection.CollectionSpaces);                // Always add the collection's query spaces.
        }
		public void ResolveCollectionProperty(IASTNode expr)
		{
			String propertyName = CollectionProperties.GetNormalizedPropertyName( _methodName );

			if ( expr is FromReferenceNode ) 
			{
				FromReferenceNode collectionNode = ( FromReferenceNode ) expr;
				// If this is 'elements' then create a new FROM element.
				if ( CollectionPropertyNames.Elements == propertyName ) 
				{
					HandleElements( collectionNode, propertyName );
				}
				else {
					// Not elements(x)
					_fromElement = collectionNode.FromElement;
					DataType = _fromElement.GetPropertyType( propertyName, propertyName );
					_selectColumns = _fromElement.ToColumns( _fromElement.TableAlias, propertyName, _inSelect );
				}
				if ( collectionNode is DotNode ) 
				{
					PrepareAnyImplicitJoins( ( DotNode ) collectionNode );
				}
				if ( !_inSelect ) 
				{
					_fromElement.Text = "";
					_fromElement.UseWhereFragment = false;
				}

				PrepareSelectColumns( _selectColumns );
				Text = _selectColumns[0];
				Type = HqlSqlWalker.SQL_TOKEN;
			}
			else 
			{
				throw new SemanticException( 
						"Unexpected expression " + expr + 
						" found for collection function " + propertyName 
					);
			}
		}
		public void ResolveCollectionProperty(IASTNode expr)
		{
			var propertyName = CollectionProperties.GetNormalizedPropertyName( _methodName );

			var collectionNode = expr as FromReferenceNode;
			if (collectionNode == null)
				throw new SemanticException(string.Format("Unexpected expression {0} found for collection function {1}", expr, propertyName));

			// If this is 'elements' then create a new FROM element.
			if (CollectionPropertyNames.Elements == propertyName)
			{
				HandleElements(collectionNode, propertyName);
			}
			else
			{
				// Not elements(x)
				_fromElement = collectionNode.FromElement;
				DataType = _fromElement.GetPropertyType(propertyName, propertyName);
				_selectColumns = _fromElement.ToColumns(_fromElement.TableAlias, propertyName, _inSelect);
			}
			var dotNode = collectionNode as DotNode;
			if (dotNode != null)
			{
				PrepareAnyImplicitJoins(dotNode);
			}
			if (!_inSelect)
			{
				_fromElement.Text = "";
				_fromElement.UseWhereFragment = false;
			}

			PrepareSelectColumns(_selectColumns);
			Text = _selectColumns[0];
			Type = HqlSqlWalker.SQL_TOKEN;
		}