private void CreateSelectClauseFromFromClause(IASTNode qn)
        {
            // TODO - check this.  Not *exactly* the same logic as the Java original
            qn.InsertChild(0, (IASTNode)adaptor.Create(SELECT_CLAUSE, "{derived select clause}"));

            _selectClause = ( SelectClause )qn.GetChild(0);
            _selectClause.InitializeDerivedSelectClause(_currentFromClause);

            if (log.IsDebugEnabled())
            {
                log.Debug("Derived SELECT clause created.");
            }
        }
        void PrepareVersioned(IASTNode updateNode, IASTNode versioned)
        {
            var        updateStatement = (UpdateStatement)updateNode;
            FromClause fromClause      = updateStatement.FromClause;

            if (versioned != null)
            {
                // Make sure that the persister is versioned
                IQueryable persister = fromClause.GetFromElement().Queryable;
                if (!persister.IsVersioned)
                {
                    throw new SemanticException("increment option specified for update of non-versioned entity");
                }

                IVersionType versionType = persister.VersionType;
                if (versionType is IUserVersionType)
                {
                    throw new SemanticException("user-defined version types not supported for increment option");
                }

                IASTNode eq = ASTFactory.CreateNode(EQ, "=");
                IASTNode versionPropertyNode = GenerateVersionPropertyNode(persister);

                eq.SetFirstChild(versionPropertyNode);

                IASTNode versionIncrementNode;
                if (typeof(DateTime).IsAssignableFrom(versionType.ReturnedClass))
                {
                    versionIncrementNode = ASTFactory.CreateNode(PARAM, "?");
                    IParameterSpecification paramSpec = new VersionTypeSeedParameterSpecification(versionType);
                    ((ParameterNode)versionIncrementNode).HqlParameterSpecification = paramSpec;
                    Parameters.Insert(0, paramSpec);
                }
                else
                {
                    // Not possible to simply re-use the versionPropertyNode here as it causes
                    // OOM errors due to circularity :(
                    versionIncrementNode = ASTFactory.CreateNode(PLUS, "+");
                    versionIncrementNode.SetFirstChild(GenerateVersionPropertyNode(persister));
                    versionIncrementNode.AddChild(ASTFactory.CreateNode(IDENT, "1"));
                }

                eq.AddChild(versionIncrementNode);

                EvaluateAssignment(eq, persister, 0);

                IASTNode setClause = updateStatement.SetClause;
                setClause.InsertChild(0, eq);
            }
        }
Beispiel #3
0
 public IASTNode AddSibling(IASTNode newSibling)
 {
     return(_parent.InsertChild(this.ChildIndex + 1, newSibling));
 }
Beispiel #4
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);
            }
        }
		private void CreateSelectClauseFromFromClause(IASTNode qn)
		{
			// TODO - check this.  Not *exactly* the same logic as the Java original
			qn.InsertChild(0, (IASTNode)adaptor.Create(SELECT_CLAUSE, "{derived select clause}"));

			_selectClause = ( SelectClause ) qn.GetChild(0);
			_selectClause.InitializeDerivedSelectClause( _currentFromClause );

			if ( log.IsDebugEnabled ) 
			{
				log.Debug( "Derived SELECT clause created." );
			}
		}