コード例 #1
0
 /// <summary>
 /// Renders the clause in EPL.
 /// </summary>
 /// <param name="writer">to output to</param>
 /// <param name="formatter">for NewLine-whitespace formatting</param>
 public void ToEPL(
     TextWriter writer,
     EPStatementFormatter formatter)
 {
     formatter.BeginOnSet(writer);
     UpdateClause.RenderEPLAssignments(writer, Assignments);
 }
コード例 #2
0
 public void ToEPL(TextWriter writer)
 {
     writer.Write("then update ");
     UpdateClause.RenderEPLAssignments(writer, Assignments);
     if (WhereClause != null)
     {
         writer.Write(" where ");
         WhereClause.ToEPL(writer, ExpressionPrecedenceEnum.MINIMUM);
     }
 }
コード例 #3
0
ファイル: OnUpdateClause.cs プロジェクト: lanicon/nesper
        /// <summary>
        /// Renders the clause in textual representation.
        /// </summary>
        /// <param name="writer">to output to</param>
        public void ToEPL(TextWriter writer)
        {
            writer.Write(WindowName);
            if (OptionalAsName != null)
            {
                writer.Write(" as ");
                writer.Write(OptionalAsName);
            }

            writer.Write(" ");
            UpdateClause.RenderEPLAssignments(writer, Assignments);
        }
コード例 #4
0
        /// <summary>
        ///     Renders the object model in it's EPL syntax textual representation, using a whitespace-formatter as provided.
        /// </summary>
        /// <param name="formatter">the formatter to use</param>
        /// <param name="writer">writer to use</param>
        /// <throws>IllegalStateException if required clauses do not exist</throws>
        public void ToEPL(
            EPStatementFormatter formatter,
            TextWriter writer)
        {
            AnnotationPart.ToEPL(writer, Annotations, formatter);
            ExpressionDeclaration.ToEPL(writer, ExpressionDeclarations, formatter);
            ScriptExpression.ToEPL(writer, ScriptExpressions, formatter);
            ClassProvidedExpression.ToEPL(writer, ClassProvidedExpressions, formatter);

            if (ContextName != null)
            {
                formatter.BeginContext(writer);
                writer.Write("context ");
                writer.Write(ContextName);
            }

            if (CreateIndex != null)
            {
                formatter.BeginCreateIndex(writer);
                CreateIndex.ToEPL(writer);
                return;
            }

            if (CreateSchema != null)
            {
                formatter.BeginCreateSchema(writer);
                CreateSchema.ToEPL(writer);
                return;
            }

            if (CreateExpression != null)
            {
                formatter.BeginCreateExpression(writer);
                CreateExpression.ToEPL(writer);
                return;
            }

            if (CreateClass != null)
            {
                formatter.BeginCreateExpression(writer);
                CreateClass.ToEPL(writer);
                return;
            }

            if (CreateContext != null)
            {
                formatter.BeginCreateContext(writer);
                CreateContext.ToEPL(writer, formatter);
                return;
            }

            if (CreateWindow != null)
            {
                formatter.BeginCreateWindow(writer);
                CreateWindow.ToEPL(writer);

                writer.Write(" as ");

                if (SelectClause == null || SelectClause.SelectList.IsEmpty() && !CreateWindow.Columns.IsEmpty())
                {
                    CreateWindow.ToEPLCreateTablePart(writer);
                }
                else
                {
                    SelectClause.ToEPL(writer, formatter, false, false);
                    if (CreateWindow.AsEventTypeName != null)
                    {
                        writer.Write(" from ");
                        writer.Write(CreateWindow.AsEventTypeName);
                    }

                    CreateWindow.ToEPLInsertPart(writer);
                }

                return;
            }

            if (CreateVariable != null)
            {
                formatter.BeginCreateVariable(writer);
                CreateVariable.ToEPL(writer);
                return;
            }

            if (CreateTable != null)
            {
                formatter.BeginCreateTable(writer);
                CreateTable.ToEPL(writer);
                return;
            }

            if (CreateDataFlow != null)
            {
                formatter.BeginCreateDataFlow(writer);
                CreateDataFlow.ToEPL(writer, formatter);
                return;
            }

            var displayWhereClause = true;

            if (UpdateClause != null)
            {
                formatter.BeginUpdate(writer);
                UpdateClause.ToEPL(writer);
            }
            else if (OnExpr != null)
            {
                formatter.BeginOnTrigger(writer);
                writer.Write("on ");
                FromClause.Streams[0].ToEPL(writer, formatter);

                if (OnExpr is OnDeleteClause onDeleteClause)
                {
                    formatter.BeginOnDelete(writer);
                    writer.Write("delete from ");
                    onDeleteClause.ToEPL(writer);
                }
                else if (OnExpr is OnUpdateClause onUpdateClause)
                {
                    formatter.BeginOnUpdate(writer);
                    writer.Write("update ");
                    onUpdateClause.ToEPL(writer);
                }
                else if (OnExpr is OnSelectClause onSelectClause)
                {
                    InsertInto?.ToEPL(writer, formatter, true);
                    SelectClause.ToEPL(writer, formatter, true, onSelectClause.IsDeleteAndSelect);
                    writer.Write(" from ");
                    onSelectClause.ToEPL(writer);
                }
                else if (OnExpr is OnSetClause onSetClause)
                {
                    onSetClause.ToEPL(writer, formatter);
                }
                else if (OnExpr is OnMergeClause onMergeClause)
                {
                    onMergeClause.ToEPL(writer, WhereClause, formatter);
                    displayWhereClause = false;
                }
                else
                {
                    var split = (OnInsertSplitStreamClause)OnExpr;
                    InsertInto.ToEPL(writer, formatter, true);
                    SelectClause.ToEPL(writer, formatter, true, false);
                    if (WhereClause != null)
                    {
                        writer.Write(" where ");
                        WhereClause.ToEPL(writer, ExpressionPrecedenceEnum.MINIMUM);
                    }

                    split.ToEPL(writer, formatter);
                    displayWhereClause = false;
                }
            }
            else
            {
                IntoTableClause?.ToEPL(writer);

                if (SelectClause == null)
                {
                    throw new IllegalStateException("Select-clause has not been defined");
                }

                if (FromClause == null)
                {
                    throw new IllegalStateException("From-clause has not been defined");
                }

                if (FireAndForgetClause is FireAndForgetUpdate fireAndForgetUpdate)
                {
                    writer.Write("update ");
                    FromClause.ToEPLOptions(writer, formatter, false);
                    writer.Write(" ");
                    UpdateClause.RenderEPLAssignments(writer, fireAndForgetUpdate.Assignments);
                }
                else if (FireAndForgetClause is FireAndForgetInsert fireAndForgetInsert)
                {
                    InsertInto.ToEPL(writer, formatter, true);
                    if (fireAndForgetInsert.IsUseValuesKeyword)
                    {
                        writer.Write(" values (");
                        var delimiter = "";
                        foreach (var element in SelectClause.SelectList)
                        {
                            writer.Write(delimiter);
                            element.ToEPLElement(writer);
                            delimiter = ", ";
                        }

                        writer.Write(")");
                    }
                    else
                    {
                        SelectClause.ToEPL(writer, formatter, true, false);
                    }
                }
                else if (FireAndForgetClause is FireAndForgetDelete)
                {
                    writer.Write("delete ");
                    FromClause.ToEPLOptions(writer, formatter, true);
                }
                else
                {
                    InsertInto?.ToEPL(writer, formatter, true);
                    SelectClause.ToEPL(writer, formatter, true, false);
                    FromClause.ToEPLOptions(writer, formatter, true);
                }
            }

            MatchRecognizeClause?.ToEPL(writer);

            if (WhereClause != null && displayWhereClause)
            {
                formatter.BeginWhere(writer);
                writer.Write("where ");
                WhereClause.ToEPL(writer, ExpressionPrecedenceEnum.MINIMUM);
            }

            if (GroupByClause != null)
            {
                formatter.BeginGroupBy(writer);
                writer.Write("group by ");
                GroupByClause.ToEPL(writer);
            }

            if (HavingClause != null)
            {
                formatter.BeginHaving(writer);
                writer.Write("having ");
                HavingClause.ToEPL(writer, ExpressionPrecedenceEnum.MINIMUM);
            }

            if (OutputLimitClause != null)
            {
                formatter.BeginOutput(writer);
                writer.Write("output ");
                OutputLimitClause.ToEPL(writer);
            }

            if (OrderByClause != null)
            {
                formatter.BeginOrderBy(writer);
                writer.Write("order by ");
                OrderByClause.ToEPL(writer);
            }

            if (RowLimitClause != null)
            {
                formatter.BeginLimit(writer);
                writer.Write("limit ");
                RowLimitClause.ToEPL(writer);
            }

            if (ForClause != null)
            {
                formatter.BeginFor(writer);
                ForClause.ToEPL(writer);
            }
        }