// When building as node, the columns are interpreted as entries in the parent's view table. public void BuildAsNode(ViewTable parentViewTable, long row, ViewSchema vs, Database.Schema baseSchema, Operation.ExpressionParsingContext parentExpressionParsingContext) { MetaTable metaTable = BuildOrGetMetaTable(parentViewTable, null); if (localSelectSet.select.Count > 0) { DebugUtility.LogError("Node '" + GetFullName() + " ' cannot have any local select statement when the parent data type is 'node'. Ignoring all selects."); } //build columns foreach (var colb in column) { MetaColumn metaColumn = metaTable.GetColumnByName(colb.name); bool hadMetaColumn = metaColumn != null; colb.BuildNodeValue(this, row, vs, baseSchema, parentViewTable, parentExpressionParsingContext, ref metaColumn); // add the metacolum to the metatable if it just got created if (!hadMetaColumn) { metaTable.AddColumn(metaColumn); } } //Build missing column for (int i = 0; i != metaTable.GetColumnCount(); ++i) { var metaColumn = metaTable.GetColumnByIndex(i); if (!HasColumn(metaColumn.Name)) { ViewColumn.Builder.BuildNodeValueDefault(this, row, vs, baseSchema, parentViewTable, parentExpressionParsingContext, metaColumn); } } }
/// <summary> /// Builds the metamodel. /// </summary> /// <returns></returns> public MetaModel Build() { MetaModel result = new MetaModel(); foreach (StructureDomain domain in this.Domains) { MetaDomain metaDomain = new MetaDomain(); metaDomain.Id = null; metaDomain.Name = domain.Name; metaDomain.IsIdentity = domain.IsIdentity; metaDomain.DataType = domain.DataType; metaDomain.DataTypeLength = domain.DataTypeLength; metaDomain.DataTypeDecimals = domain.DataTypeDecimals; metaDomain.IsUsed = false; result.AddDomain(metaDomain); } foreach (StructureEntity entity in this.Entities) { MetaTable table = new MetaTable(); table.Id = null; table.Name = entity.Name; table.PhysicalName = StringUtil.Camelize(table.Name); table.LogicalName = StringUtil.Pascalize(table.Name); result.AddTable(table); foreach (StructureProperty property in entity.Properties) { if ((property.ReferenceItem == null) || (property.ReferenceItem is StructureDomain)) { MetaColumn column = new MetaColumn(); column.TableId = null; column.Ix = null; column.Name = property.Name; MetaDomain metaDomain; if (property.ReferenceItem == null) { string generatedDomainName = this.GenerateDomainName(property.DataType, property.DataTypeLength, property.DataTypeDecimals, property.IsIdentity); metaDomain = result.GetDomain(generatedDomainName); if (metaDomain == null) { metaDomain = new MetaDomain(); metaDomain.Id = null; metaDomain.Name = generatedDomainName; metaDomain.IsIdentity = property.IsIdentity; metaDomain.DataType = property.DataType; metaDomain.DataTypeLength = property.DataTypeLength; metaDomain.DataTypeDecimals = property.DataTypeDecimals; result.AddDomain(metaDomain); } } else { metaDomain = result.GetDomain(property.ReferenceItem.Name); } metaDomain.IsUsed = true; column.Domain = metaDomain; column.IsIdentity = property.IsIdentity || metaDomain.IsIdentity; column.IsPrimaryKey = property.IsPrimaryKey || column.IsPrimaryKey; column.IsNullable = property.IsNullable && !column.IsPrimaryKey; column.DataType = metaDomain.DataType; column.DataTypeLength = metaDomain.DataTypeLength; column.DataTypeDecimals = metaDomain.DataTypeLength; column.IsForeignKey = false; table.AddColumn(column); } else { MetaRelation relation = new MetaRelation(); relation.ParentName = property.ReferenceItem.Name; relation.SonRelationName = property.Name; relation.Son = table; relation.IsKeyInSon = property.IsPrimaryKey; relation.IsNullableInSon = property.IsNullable; result.Relations.Add(relation); } } } result.Build(); return(result); }
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); } }
public void Build(Node node, ViewTable vTable, ViewTable parent, ViewSchema vs, Database.Schema baseSchema, Operation.ExpressionParsingContext parentExpressionParsingContext, MetaTable metaTable) { // build selects vTable.dataSelectSet = dataSelectSet.Build(vTable, vs, baseSchema); if (vTable.dataSelectSet != null) { // add the select set to the expression parsing context hierarchy. see [Figure.1] vTable.expressionParsingContext = new Operation.ExpressionParsingContext(vTable.expressionParsingContext, vTable.dataSelectSet); } // build columns switch (type) { case Data.DataType.Node: // these column are declarations 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); } } // for node type we need to build all child node right away as they defines the entries in this viewtable var validChildNodeIndices = new List <int>(); int iValidChild = 0; for (int iChild = 0; iChild != child.Count; ++iChild) { var c = child[iChild]; if (c.EvaluateCondition(vs, vTable, vTable.expressionParsingContext)) { validChildNodeIndices.Add(iChild); c.BuildAsNode(vTable, (long)iValidChild, vs, baseSchema, vTable.expressionParsingContext); ++iValidChild; } } if (iValidChild != child.Count) { vTable.ValidChildNodeIndices = validChildNodeIndices.ToArray(); } else { vTable.ValidChildNodeIndices = null; } break; case DataType.Select: // these columns are instances of ViewColumn. They have the result of select statement as entries foreach (var colb in column) { MetaColumn metaColumn = metaTable.GetColumnByName(colb.name); bool hadMetaColumn = metaColumn != null; var newColumn = colb.Build(node, vs, baseSchema, vTable, vTable.expressionParsingContext, ref metaColumn); // add the metacolum to the metatable if it just got created if (!hadMetaColumn) { metaTable.AddColumn(metaColumn); } vTable.SetColumn(metaColumn, newColumn.GetColumn()); } break; } }