Exemple #1
0
        public void LookupConstant(DotNode node)
        {
            string     text      = ASTUtil.GetPathText(node);
            IQueryable persister = _walker.SessionFactoryHelper.FindQueryableUsingImports(text);

            if (persister != null)
            {
                // the name of an entity class
                string discrim = persister.DiscriminatorSQLValue;
                node.DataType = persister.DiscriminatorType;

                if (InFragment.Null == discrim || InFragment.NotNull == discrim)
                {
                    throw new InvalidPathException("subclass test not allowed for null or not null discriminator: '" + text + "'");
                }
                else
                {
                    SetSQLValue(node, text, discrim);                     //the class discriminator value
                }
            }
            else
            {
                Object value = ReflectHelper.GetConstantValue(text);
                if (value == null)
                {
                    throw new InvalidPathException("Invalid path: '" + text + "'");
                }
                else
                {
                    SetConstantValue(node, text, value);
                }
            }
        }
        /// <summary>
        /// Turns a path into an AST.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="factory">The AST factory to use.</param>
        /// <returns>An HQL AST representing the path.</returns>
        public static IASTNode ParsePath(string path, IASTFactory factory)
        {
            string[] identifiers = StringHelper.Split(".", path);
            IASTNode lhs         = null;

            for (int i = 0; i < identifiers.Length; i++)
            {
                string   identifier = identifiers[i];
                IASTNode child      = factory.CreateNode(HqlSqlWalker.IDENT, identifier);
                if (i == 0)
                {
                    lhs = child;
                }
                else
                {
                    lhs = factory.CreateNode(HqlSqlWalker.DOT, ".", lhs, child);
                }
            }
            if (log.IsDebugEnabled())
            {
                log.Debug("parsePath() : {0} -> {1}", path, ASTUtil.GetDebugstring(lhs));
            }
            return(lhs);
        }