static ViewColumnNode.IViewColumnNode BuildOrGetColumnNode(ViewTable vTable, Database.MetaColumn metaColumn, string columnName, Operation.ExpressionParsingContext expressionParsingContext) { var column = vTable.GetColumnByName(columnName); if (column == null) { var columnNode = (ViewColumnNode.IViewColumnNode)Operation.ColumnCreator.CreateColumn(typeof(ViewColumnNodeTyped <>), metaColumn.Type); ViewColumnNode viewColumnNode = new ViewColumnNode(vTable, metaColumn, expressionParsingContext); columnNode.SetColumn(viewColumnNode); vTable.SetColumn(metaColumn, columnNode.GetColumn()); return(columnNode); } // View table use expand column to decorate the IViewColumnNode with required functionality for expanding rows. // So we need to get the underlying column, which is the IViewColumnNode we want. if (column is IColumnDecorator) { column = (column as IColumnDecorator).GetBaseColumn(); } if (column is ViewColumnNode.IViewColumnNode) { return((ViewColumnNode.IViewColumnNode)column); } else { throw new Exception("Expecting column '" + vTable.GetName() + "." + metaColumn.Name + "' to be a from a node data type (ViewColumnNode) but is of type '" + column.GetType().Name + "'"); } }
public bool EvaluateCondition(ViewSchema vs, ViewTable parentViewTable, Operation.ExpressionParsingContext expressionParsingContext) { if (condition == null) { return(true); } using (ScopeDebugContext.Func(() => { return("EvaluateCondition on Node '" + GetFullName() + "'"); })) { var option = new Operation.Expression.ParseIdentifierOption(vs, parentViewTable, true, true, null, expressionParsingContext); option.formatError = (string s, Operation.Expression.ParseIdentifierOption opt) => { string str = "Error while evaluating node condition."; if (vs != null) { str += " schema '" + vs.name + "'"; } if (parentViewTable != null) { str += " view table '" + parentViewTable.GetName() + "'"; } return(str + " : " + s); }; var resolvedCondition = condition.Build(option); if (resolvedCondition == null) { return(false); } return(resolvedCondition.GetValue(0)); } }
private string FormatErrorContextInfo(ViewSchema vs, ViewTable vTable) { string str = "Error while building view column '" + name + "'"; if (vs != null) { str += " schema '" + vs.name + "'"; } if (vTable != null) { str += " view table '" + vTable.GetName() + "'"; } return(str); }
private string FormatErrorContextInfo(ViewSchema vs, ViewTable vTable, Select select) { string str = ""; if (vs != null && vTable != null) { str += "Error while building view '" + vs.name + "' table '" + vTable.GetName() + "'"; } if (select != null) { str += " select '" + select.name + "'"; } if (str != "") { str += ". "; } return(str); }
public ViewTable Build(ViewTable parent, long row, ViewSchema vs, Database.Schema baseSchema, Operation.ExpressionParsingContext parentExpressionParsingContext) { // Check for usage error from data. if (parent == null && String.IsNullOrEmpty(name)) { DebugUtility.LogError(FormatErrorContextInfo(vs) + ": Table need a name"); return(null); } using (ScopeDebugContext.Func(() => { return("View '" + GetFullName() + "'"); })) { // Check for usage error from code. DebugUtility.CheckCondition(parent == null || (parent.node == this.parent), FormatErrorContextInfo(vs) + ": Parent ViewTable must points to the node's parent while building child node's ViewTable."); if (data == null) { //no data return(null); } ViewTable vTable = new ViewTable(vs, baseSchema); vTable.node = this; vTable.parentExpressionParsingContext = parentExpressionParsingContext; vTable.expressionParsingContext = parentExpressionParsingContext; // If has local select set, create it and add it to the expression parsing context hierarchy. see [Figure.1] vTable.localSelectSet = localSelectSet.Build(vTable, vs, baseSchema); if (vTable.localSelectSet != null) { vTable.expressionParsingContext = new Operation.ExpressionParsingContext(vTable.expressionParsingContext, vTable.localSelectSet); } MetaTable metaTable = BuildOrGetMetaTable(parent, vTable); //declare columns foreach (var colb in column) { MetaColumn metaColumn = metaTable.GetColumnByName(colb.name); bool hadMetaColumn = metaColumn != null; colb.BuildOrUpdateDeclaration(ref metaColumn); // add the metacolum to the metatable if it just got created if (!hadMetaColumn) { metaTable.AddColumn(metaColumn); } } data.Build(this, vTable, parent, vs, baseSchema, parentExpressionParsingContext, metaTable); //Build missing column with default behavior for (int i = 0; i != metaTable.GetColumnCount(); ++i) { var metaColumn = metaTable.GetColumnByIndex(i); var column = vTable.GetColumnByIndex(i); if (column == null) { if (metaColumn.DefaultMergeAlgorithm != null) { //when we have a merge algorithm, set the entries as the result of each group's merge value. column = ViewColumn.Builder.BuildColumnNodeMerge(vTable, metaColumn, parentExpressionParsingContext); } vTable.SetColumn(metaColumn, column); } } if (data.type == Data.DataType.Select && vTable.dataSelectSet.IsManyToMany()) { DebugUtility.LogError("Cannot build the view table '" + vTable.GetName() + "' using a many-to-many select statement. Specify a row value for your select statement where condition(s)."); MemoryProfilerAnalytics.AddMetaDatatoEvent <MemoryProfilerAnalytics.LoadViewXMLEvent>(7); } return(vTable); } }