Пример #1
0
 private void initializeFactory()
 {
     if (astFactory == null)
     {
         astFactory = new ASTFactory();
     }
     initializeASTFactory(astFactory);
 }
Пример #2
0
        private IASTNode GenerateVersionPropertyNode(IQueryable persister)
        {
            string versionPropertyName = persister.PropertyNames[persister.VersionProperty];
            var    versionPropertyRef  = ASTFactory.CreateNode(IDENT, versionPropertyName);
            var    versionPropertyNode = LookupNonQualifiedProperty(versionPropertyRef);

            Resolve(versionPropertyNode);
            return(versionPropertyNode);
        }
Пример #3
0
        public IASTNode ProcessMemberOf(IToken n, IASTNode p, IASTNode root)
        {
            ASTFactory factory = new ASTFactory(adaptor);

            return(factory.CreateNode(n == null ? IN : NOT_IN,
                                      n == null ? "in" : "not in",
                                      root.IsNil && root.ChildCount == 1 ? root.GetChild(0) : root,
                                      factory.CreateNode(IN_LIST, "inList",
                                                         CreateSubquery(p))));
        }
Пример #4
0
		public static void Main(string[] args)
		{
			// Create the tree nodes
			ASTFactory factory = new ASTFactory();
			CommonAST r = (CommonAST) factory.create(0, "ROOT");
			r.addChild((CommonAST) factory.create(0, "C1"));
			r.addChild((CommonAST) factory.create(0, "C2"));
			r.addChild((CommonAST) factory.create(0, "C3"));
			
			ASTFrame frame = new ASTFrame("AST JTree Example", r);
			Application.Run(frame);
		}
Пример #5
0
        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;
                IASTNode currentFirstSetElement = setClause.GetFirstChild();
                setClause.SetFirstChild(eq);
                eq.NextSibling = currentFirstSetElement;
            }
        }
Пример #6
0
        public static void Main(string[] args)
        {
            // Create the tree nodes
            ASTFactory factory = new ASTFactory();
            CommonAST  r       = (CommonAST)factory.create(0, "ROOT");

            r.addChild((CommonAST)factory.create(0, "C1"));
            r.addChild((CommonAST)factory.create(0, "C2"));
            r.addChild((CommonAST)factory.create(0, "C3"));

            ASTFrame frame = new ASTFrame("AST JTree Example", r);

            Application.Run(frame);
        }
Пример #7
0
        internal static int Main(string[] args)
        {
            string?path = args?.FirstOrDefault();

            if (string.IsNullOrWhiteSpace(path))
            {
                Log.Fatal("Missing source to visualize");
                return(1);
            }

            ASTNode ast = ASTFactory.BuildFromFile(path);

            return(new ASTVisualizer().Visualize(ast));
        }
    public override HqlTreeNode BuildHql(
        MethodInfo method,
        System.Linq.Expressions.Expression targetObject,
        ReadOnlyCollection <System.Linq.Expressions.Expression> arguments,
        HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
    {
        // Is there a better way to do this?
        var               factory        = new ASTFactory(new ASTTreeAdaptor());
        HqlTreeNode       escapeCharNode = visitor.Visit(arguments[2]).AsExpression();
        var               escapeNode     = new HqlEscape(factory, escapeCharNode);
        HqlLikeWithEscape likeClauseNode =
            new HqlLikeWithEscape(
                factory,
                visitor.Visit(arguments[0]).AsExpression(),
                visitor.Visit(arguments[1]).AsExpression(),
                escapeNode);

        return(likeClauseNode);
    }
Пример #9
0
        void PostProcessInsert(IASTNode insert)
        {
            var insertStatement = (InsertStatement)insert;

            insertStatement.Validate();

            SelectClause selectClause = insertStatement.SelectClause;
            var          persister    = insertStatement.IntoClause.Queryable;

            if (!insertStatement.IntoClause.IsExplicitIdInsertion)
            {
                // We need to generate ids as part of this bulk insert.
                //
                // Note that this is only supported for sequence-style generators and
                // post-insert-style generators; basically, only in-db generators
                IIdentifierGenerator generator = persister.IdentifierGenerator;
                if (!SupportsIdGenWithBulkInsertion(generator))
                {
                    throw new QueryException("can only generate ids as part of bulk insert with either sequence or post-insert style generators");
                }

                IASTNode idSelectExprNode = null;

                var seqGenerator = generator as SequenceGenerator;
                if (seqGenerator != null)
                {
                    string seqName = seqGenerator.GeneratorKey();
                    string nextval = SessionFactoryHelper.Factory.Dialect.GetSelectSequenceNextValString(seqName);
                    idSelectExprNode = ASTFactory.CreateNode(SQL_TOKEN, nextval);
                }
                else
                {
                    //Don't need this, because we should never ever be selecting no columns in an insert ... select...
                    //and because it causes a bug on DB2

                    /*String idInsertString = sessionFactoryHelper.getFactory().getDialect().getIdentityInsertString();
                     * if ( idInsertString != null ) {
                     * idSelectExprNode = getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, idInsertString );
                     * }*/
                }

                if (idSelectExprNode != null)
                {
                    selectClause.InsertChild(0, idSelectExprNode);

                    insertStatement.IntoClause.PrependIdColumnSpec();
                }
            }

            bool includeVersionProperty = persister.IsVersioned && !insertStatement.IntoClause.IsExplicitVersionInsertion && persister.VersionPropertyInsertable;

            if (includeVersionProperty)
            {
                // We need to seed the version value as part of this bulk insert
                IVersionType versionType = persister.VersionType;
                IASTNode     versionValueNode;

                if (SessionFactoryHelper.Factory.Dialect.SupportsParametersInInsertSelect)
                {
                    versionValueNode = ASTFactory.CreateNode(PARAM, "?");
                    IParameterSpecification paramSpec = new VersionTypeSeedParameterSpecification(versionType);
                    ((ParameterNode)versionValueNode).HqlParameterSpecification = paramSpec;
                    _parameters.Insert(0, paramSpec);
                }
                else
                {
                    if (IsIntegral(versionType))
                    {
                        try
                        {
                            object seedValue = versionType.Seed(null);
                            versionValueNode = ASTFactory.CreateNode(SQL_TOKEN, seedValue.ToString());
                        }
                        catch (Exception t)
                        {
                            throw new QueryException("could not determine seed value for version on bulk insert [" + versionType + "]", t);
                        }
                    }
                    else if (IsDatabaseGeneratedTimestamp(versionType))
                    {
                        string functionName = SessionFactoryHelper.Factory.Dialect.CurrentTimestampSQLFunctionName;
                        versionValueNode = ASTFactory.CreateNode(SQL_TOKEN, functionName);
                    }
                    else
                    {
                        throw new QueryException("cannot handle version type [" + versionType + "] on bulk inserts with dialects not supporting parameters in insert-select statements");
                    }
                }

                selectClause.InsertChild(0, versionValueNode);

                insertStatement.IntoClause.PrependVersionColumnSpec();
            }

            if (insertStatement.IntoClause.IsDiscriminated)
            {
                string   sqlValue     = insertStatement.IntoClause.Queryable.DiscriminatorSQLValue;
                IASTNode discrimValue = ASTFactory.CreateNode(SQL_TOKEN, sqlValue);
                insertStatement.SelectClause.AddChild(discrimValue);
            }
        }
Пример #10
0
 static public void initializeASTFactory(ASTFactory factory)
 {
     factory.setMaxNodeType(17);
 }
Пример #11
0
	static public void initializeASTFactory( ASTFactory factory )
	{
		factory.setMaxNodeType(173);
	}
Пример #12
0
	private void initializeFactory()
	{
		if (astFactory == null)
		{
			astFactory = new ASTFactory();
		}
		initializeASTFactory( astFactory );
	}
Пример #13
0
 public void SourceNotFoundTest()
 {
     Assert.Throws <FileNotFoundException>(() => ASTFactory.BuildFromFile("404.c"));
 }