Exemplo n.º 1
0
		/// <summary>
		/// Generates the scalar column AST nodes for a given array of SQL columns
		/// </summary>
		public static void GenerateScalarColumns(IASTFactory factory, IASTNode node, string[] sqlColumns, int i)
		{
			if (sqlColumns.Length == 1)
			{
				GenerateSingleScalarColumn(factory, node, i);
			}
			else
			{
				node.Text = sqlColumns[0]; // Use the DOT node to emit the first column name.

				// Create the column names, folled by the column aliases.
				for (int j = 0; j < sqlColumns.Length; j++)
				{
					if (j > 0)
					{
						node = node.AddSibling(factory.CreateNode(HqlSqlWalker.SQL_TOKEN, sqlColumns[j]));
					}

					node = node.AddSibling(factory.CreateNode(HqlSqlWalker.SELECT_COLUMNS, " as " + NameGenerator.ScalarName(i, j)));
				}
			}
		}
Exemplo n.º 2
0
        /// <summary>
        /// Generates the scalar column AST nodes for a given array of SQL columns
        /// </summary>
        public static void GenerateScalarColumns(IASTFactory factory, IASTNode node, string[] sqlColumns, int i)
        {
            if (sqlColumns.Length == 1)
            {
                GenerateSingleScalarColumn(factory, node, i);
            }
            else
            {
                node.Text = sqlColumns[0];                 // Use the DOT node to emit the first column name.

                // Create the column names, folled by the column aliases.
                for (int j = 0; j < sqlColumns.Length; j++)
                {
                    if (j > 0)
                    {
                        node = node.AddSibling(factory.CreateNode(HqlSqlWalker.SQL_TOKEN, sqlColumns[j]));
                    }

                    node = node.AddSibling(factory.CreateNode(HqlSqlWalker.SELECT_COLUMNS, " as " + NameGenerator.ScalarName(i, j)));
                }
            }
        }
        private void TransformUnshardedAverageNode(IASTNode average)
        {
            var star = average.DupNode();

            star.Type = HqlSqlWalker.ROW_STAR;
            star.Text = "*";

            var count = average.DupNode();

            count.Type = HqlSqlWalker.COUNT;
            count.Text = "count";
            count.AddChild(star);

            while (average.Parent.Type != HqlSqlWalker.SELECT)
            {
                average = average.Parent;
            }
            average.AddSibling(count);
        }
Exemplo n.º 4
0
        public OrderByClause GetOrderByClause()
        {
            if (_orderByClause == null)
            {
                _orderByClause = LocateOrderByClause();

                // if there is no order by, make one
                if (_orderByClause == null)
                {
                    Log.Debug("getOrderByClause() : Creating a new ORDER BY clause");
                    _orderByClause = (OrderByClause)Walker.ASTFactory.CreateNode(HqlSqlWalker.ORDER, "ORDER");

                    // Find the WHERE; if there is no WHERE, find the FROM...
                    IASTNode prevSibling = ASTUtil.FindTypeInChildren(this, HqlSqlWalker.WHERE) ??
                                           ASTUtil.FindTypeInChildren(this, HqlSqlWalker.FROM);

                    // Now, inject the newly built ORDER BY into the tree
                    prevSibling.AddSibling(_orderByClause);
                }
            }
            return(_orderByClause);
        }
Exemplo n.º 5
0
 public static void MakeSiblingOfParent(IASTNode parent, IASTNode child)
 {
     parent.RemoveChild(child);
     parent.AddSibling(child);
 }
Exemplo n.º 6
0
        public void AddWhereFragment(
            JoinFragment joinFragment,
            SqlString whereFragment,
            QueryNode query,
            FromElement fromElement,
            HqlSqlWalker hqlSqlWalker)
        {
            if (whereFragment == null)
            {
                return;
            }

            if (!fromElement.UseWhereFragment && !joinFragment.HasThetaJoins)
            {
                return;
            }

            whereFragment = whereFragment.Trim();
            if (StringHelper.IsEmpty(whereFragment.ToString()))
            {
                return;
            }

            // Forcefully remove leading ands from where fragments; the grammar will
            // handle adding them
            if (whereFragment.StartsWithCaseInsensitive("and"))
            {
                whereFragment = whereFragment.Substring(4);
            }

            log.Debug("Using unprocessed WHERE-fragment [" + whereFragment + "]");

            SqlFragment fragment = (SqlFragment)Create(HqlSqlWalker.SQL_TOKEN, whereFragment.ToString());

            fragment.SetJoinFragment(joinFragment);
            fragment.FromElement = fromElement;

            if (fromElement.IndexCollectionSelectorParamSpec != null)
            {
                fragment.AddEmbeddedParameter(fromElement.IndexCollectionSelectorParamSpec);
                fromElement.IndexCollectionSelectorParamSpec = null;
            }

            if (hqlSqlWalker.IsFilter())
            {
                //if (whereFragment.IndexOfCaseInsensitive("?") >= 0)
                if (whereFragment.ToString().IndexOf("?") >= 0)
                {
                    IType collectionFilterKeyType = hqlSqlWalker.SessionFactoryHelper
                                                    .RequireQueryableCollection(hqlSqlWalker.CollectionFilterRole)
                                                    .KeyType;
                    CollectionFilterKeyParameterSpecification paramSpec = new CollectionFilterKeyParameterSpecification(
                        hqlSqlWalker.CollectionFilterRole,
                        collectionFilterKeyType,
                        0
                        );
                    fragment.AddEmbeddedParameter(paramSpec);
                }
            }

            JoinProcessor.ProcessDynamicFilterParameters(
                whereFragment,
                fragment,
                hqlSqlWalker
                );

            log.Debug("Using processed WHERE-fragment [" + fragment.Text + "]");

            // Filter conditions need to be inserted before the HQL where condition and the
            // theta join node.  This is because org.hibernate.loader.Loader binds the filter parameters first,
            // then it binds all the HQL query parameters, see org.hibernate.loader.Loader.processFilterParameters().
            if (fragment.FromElement.IsFilter || fragment.HasFilterCondition)
            {
                if (_filters == null)
                {
                    // Find or create the WHERE clause
                    IASTNode where = (IASTNode)query.WhereClause;
                    // Create a new FILTERS node as a parent of all filters
                    _filters = Create(HqlSqlWalker.FILTERS, "{filter conditions}");
                    // Put the FILTERS node before the HQL condition and theta joins
                    where.InsertChild(0, _filters);
                }

                // add the current fragment to the FILTERS node
                _filters.AddChild(fragment);
            }
            else
            {
                if (_thetaJoins == null)
                {
                    // Find or create the WHERE clause
                    IASTNode where = (IASTNode)query.WhereClause;

                    // Create a new THETA_JOINS node as a parent of all filters
                    _thetaJoins = Create(HqlSqlWalker.THETA_JOINS, "{theta joins}");

                    // Put the THETA_JOINS node before the HQL condition, after the filters.
                    if (_filters == null)
                    {
                        where.InsertChild(0, _thetaJoins);
                    }
                    else
                    {
                        _filters.AddSibling(_thetaJoins);
                    }
                }

                // add the current fragment to the THETA_JOINS node
                _thetaJoins.AddChild(fragment);
            }
        }
Exemplo n.º 7
0
		public static void GenerateSingleScalarColumn(IASTFactory factory, IASTNode node, int i)
		{
			node.AddSibling(factory.CreateNode(HqlSqlWalker.SELECT_COLUMNS, " as " + NameGenerator.ScalarName(i, 0)));
		}
Exemplo n.º 8
0
		public static void MakeSiblingOfParent(IASTNode parent, IASTNode child)
		{
			parent.RemoveChild(child);
			parent.AddSibling(child);
		}
Exemplo n.º 9
0
 public static void GenerateSingleScalarColumn(IASTFactory factory, IASTNode node, int i)
 {
     node.AddSibling(factory.CreateNode(HqlSqlWalker.SELECT_COLUMNS, " as " + NameGenerator.ScalarName(i, 0)));
 }