public DatabaseElement(DatabaseElement data) { this.Key = data.Key; this.AllowUpdateOfPrimaryKey = data.AllowUpdateOfPrimaryKey; this.AutoDiscoverAttributes = data.AutoDiscoverAttributes; this.AutoDiscoverEntities = data.AutoDiscoverEntities; this.AutoDiscoverProperties = data.AutoDiscoverProperties; this.GenerateDeleteStoredProcScript = data.GenerateDeleteStoredProcScript; this.GenerateInsertStoredProcScript = data.GenerateInsertStoredProcScript; this.GenerateOnlyPrimaryDeleteStoredProc = data.GenerateOnlyPrimaryDeleteStoredProc; this.GenerateProcsForForeignKey = data.GenerateProcsForForeignKey; this.GenerateSelectStoredProcScript = data.GenerateSelectStoredProcScript; this.GenerateSqlTableScripts = data.GenerateSqlTableScripts; this.GenerateSqlViewScripts = data.GenerateSqlViewScripts; this.GenerateUpdateStoredProcScript = data.GenerateUpdateStoredProcScript; this.AllowInsert = data.AllowInsert || data.GenerateInsertStoredProcScript; this.AllowUpdate = data.AllowUpdate || data.GenerateUpdateStoredProcScript; this.AllowDelete = data.AllowDelete || data.GenerateDeleteStoredProcScript; this.DefaultDirtyRead = data.DefaultDirtyRead; this.UpdateChangedOnly = data.UpdateChangedOnly && this.AllowUpdate; this.Name = data.Name; this.Password = data.Password; this.ScriptDropStatement = data.ScriptDropStatement; this.Server = data.Server; this.SingleFile = data.SingleFile; this.SqlScriptDirectory = data.SqlScriptDirectory; this.StoredProcNameFormat = data.StoredProcNameFormat; this.User = data.User; this.UseView = data.UseView; this.CommandTimeout = data.CommandTimeout; this.ScriptForIndexedViews = data.ScriptForIndexedViews; this.Audit = data.Audit; }
public static ArrayList ParseFromXml(DatabaseElement database, XmlNode databaseNode, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd) { ArrayList sqlentities = new ArrayList(); //databaseNode.ChildNodes corresponds to each <sqlentity> entry in the databases xml file(s) (such as dtg-databases.xml) foreach (XmlNode node in databaseNode.ChildNodes) { if (node.Name.Equals("sqlentity")) { SqlEntityElement sqlentity = new SqlEntityElement(database); ParseNodeAttributes(node, sqlentity); sqlentity.View = "vw" + sqlentity.Name; if (node.Attributes["view"] != null) { sqlentity.View = node.Attributes["view"].Value; } if (node.Attributes["audit"] != null) { sqlentity.Audit = Boolean.Parse(node.Attributes["audit"].Value); } //Adds all attributes including all not defined by element class foreach (XmlAttribute attribute in node.Attributes) { if (!sqlentity.Attributes.ContainsKey(attribute.Name)) { sqlentity.Attributes.Add(attribute.Name, attribute.Value); } } sqlentity.Columns = ColumnElement.ParseFromXml(node, sqlentity, sqltypes, types, vd); sqlentity.Constraints = ConstraintElement.ParseFromXml(node, sqlentity, sqltypes, types, vd); sqlentity.Indexes = IndexElement.ParseFromXml(node, sqlentity, sqltypes, types, vd); // TODO: this is a hack as many things need to be restructured. the Elements all need to be parsed first, then // relationships and links need to be created. Otherwise, the config file becomes order dependent. DatabaseElement d = new DatabaseElement(); d.SqlEntities = sqlentities; sqlentity.Views = ViewElement.ParseFromXml(node, d, sqlentity, sqltypes, types, vd); sqlentities.Add(sqlentity); } } StringCollection names = new StringCollection(); foreach (SqlEntityElement sqlentity in sqlentities) { if (names.Contains(sqlentity.Name)) { vd(new ParserValidationArgs(ParserValidationSeverity.ERROR, "duplicate sqlentity definition for " + sqlentity.Name)); } else { names.Add(sqlentity.Name); } } return(sqlentities); }
/// <summary> /// Parse only method. Parses and adds all entities found in the given node and adds them to the given /// list. /// </summary> /// <param name="node"></param> /// <param name="databaseElements"></param> public static void ParseFromXml(XmlNode node, IList databaseElements) { if (node != null && databaseElements != null) { foreach (XmlNode databaseNode in node.ChildNodes) { if (databaseNode.NodeType.Equals(XmlNodeType.Element)) { DatabaseElement databaseElement = new DatabaseElement(); databaseElement.Name = GetAttributeValue(databaseNode, NAME, databaseElement.Name); databaseElement.Audit = Boolean.Parse(GetAttributeValue(databaseNode, AUDIT, databaseElement.Audit.ToString())); databaseElement.SingleFile = Boolean.Parse(GetAttributeValue(databaseNode, SCRIPT_SINGLE_FILE, databaseElement.SingleFile.ToString())); databaseElement.Server = GetAttributeValue(databaseNode, SERVER, databaseElement.Server); databaseElement.Database = GetAttributeValue(databaseNode, DATABASE, databaseElement.Database); databaseElement.User = GetAttributeValue(databaseNode, USER, databaseElement.User); databaseElement.Password = GetAttributeValue(databaseNode, PASSWORD, databaseElement.Password); databaseElement.SqlScriptDirectory = GetAttributeValue(databaseNode, SCRIPT_DIRECTORY, databaseElement.SqlScriptDirectory); databaseElement.StoredProcNameFormat = GetAttributeValue(databaseNode, STORED_PROC_NAME_FORMAT, databaseElement.StoredProcNameFormat); databaseElement.GenerateSqlViewScripts = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_VIEW_SCRIPT, databaseElement.GenerateSqlViewScripts.ToString())); databaseElement.GenerateSqlTableScripts = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_TABLE_SCRIPT, databaseElement.GenerateSqlTableScripts.ToString())); databaseElement.GenerateInsertStoredProcScript = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_INSERT_STORED_PROC_SCRIPT, databaseElement.GenerateInsertStoredProcScript.ToString())); databaseElement.GenerateUpdateStoredProcScript = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_UPDATE_STORED_PROC_SCRIPT, databaseElement.GenerateUpdateStoredProcScript.ToString())); databaseElement.GenerateDeleteStoredProcScript = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_DELETE_STORED_PROC_SCRIPT, databaseElement.GenerateDeleteStoredProcScript.ToString())); databaseElement.GenerateSelectStoredProcScript = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_SELECT_STORED_PROC_SCRIPT, databaseElement.GenerateSelectStoredProcScript.ToString())); databaseElement.AllowInsert = Boolean.Parse(GetAttributeValue(databaseNode, ALLOW_INSERT, databaseElement.AllowInsert.ToString())) || databaseElement.GenerateInsertStoredProcScript; databaseElement.AllowUpdate = Boolean.Parse(GetAttributeValue(databaseNode, ALLOW_UPDATE, databaseElement.AllowUpdate.ToString())) || databaseElement.GenerateUpdateStoredProcScript; databaseElement.AllowDelete = Boolean.Parse(GetAttributeValue(databaseNode, ALLOW_DELETE, databaseElement.AllowDelete.ToString())) || databaseElement.GenerateDeleteStoredProcScript; databaseElement.DefaultDirtyRead = Boolean.Parse(GetAttributeValue(databaseNode, DEFAULT_DIRTY_READ, databaseElement.DefaultDirtyRead.ToString())); databaseElement.UpdateChangedOnly = Boolean.Parse(GetAttributeValue(databaseNode, UPDATE_CHANGED_ONLY, databaseElement.UpdateChangedOnly.ToString())) && databaseElement.AllowUpdate; databaseElement.ScriptDropStatement = Boolean.Parse(GetAttributeValue(databaseNode, SCRIPT_DROP_STATEMENT, databaseElement.ScriptDropStatement.ToString())); databaseElement.UseView = Boolean.Parse(GetAttributeValue(databaseNode, USE_VIEW, databaseElement.UseView.ToString())); databaseElement.GenerateProcsForForeignKey = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_PROCS_FOR_FOREIGN_KEYS, databaseElement.GenerateProcsForForeignKey.ToString())); databaseElement.GenerateOnlyPrimaryDeleteStoredProc = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_ONLY_PRIMARY_DELETE_STORED_PROC, databaseElement.GenerateOnlyPrimaryDeleteStoredProc.ToString())); databaseElement.AllowUpdateOfPrimaryKey = Boolean.Parse(GetAttributeValue(databaseNode, ALLOW_UPDATE_OF_PRIMARY_KEY, databaseElement.AllowUpdateOfPrimaryKey.ToString())); databaseElement.CommandTimeout = Int32.Parse(GetAttributeValue(databaseNode, COMMAND_TIMEOUT, databaseElement.CommandTimeout.ToString())); databaseElement.ScriptForIndexedViews = Boolean.Parse(GetAttributeValue(databaseNode, SCRIPT_FOR_INDEXED_VIEWS, databaseElement.ScriptForIndexedViews.ToString())); SqlEntityElement.ParseFromXml(GetChildNodeByName(databaseNode, SQLENTITIES), databaseElement.SqlEntities); databaseElements.Add(databaseElement); } } } }
/// <summary> /// Parse only method. Parses and adds all entities found in the given node and adds them to the given /// list. /// </summary> /// <param name="node"></param> /// <param name="entityElements"></param> public static void ParseFromXml(XmlNode rootNode) { if (rootNode != null) { RootElement rootElement = new RootElement(); // ConfigElement.ParseFromXml(GetChildNodeByName(rootNode, "config"), rootElement.ConfigElements); ReportExtractionElement.ParseFromXml(GetChildNodeByName(rootNode, "reportextractions"), rootElement.ReportExtractions); EntityElement.ParseFromXml(GetChildNodeByName(rootNode, "entities"), rootElement.EntityElements); CollectionElement.ParseFromXml(GetChildNodeByName(rootNode, "collections"), rootElement.CollectionElements); EnumElement.ParseFromXml(GetChildNodeByName(rootNode, "enums"), rootElement.EnumElements); TypeElement.ParseFromXml(GetChildNodeByName(rootNode, "types"), rootElement.TypeElements); SqlTypeElement.ParseFromXml(GetChildNodeByName(rootNode, "sqltypes"), rootElement.SqlTypeElements); DatabaseElement.ParseFromXml(GetChildNodeByName(rootNode, "databases"), rootElement.DatabaseElements); GeneratorElement.ParseFromXml(GetChildNodeByName(rootNode, "generator"), rootElement.GeneratorElements); } }
public static ArrayList ParseFromXml(Configuration options, XmlDocument doc, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd) { DatabaseElement defaults = new DatabaseElement(); XmlNodeList elements = doc.DocumentElement.GetElementsByTagName("databases"); if (elements.Count < 1) { vd(ParserValidationArgs.NewError("No databases tags found. You must have at least one databases tag.")); } else { SqlEntityElement.ParseNodeAttributes(elements[0], defaults); } // loop through each 'database' tag in the xml file (ex: file=dtg-databases.xml) ArrayList list = new ArrayList(); elements = doc.DocumentElement.GetElementsByTagName("database"); foreach (XmlNode node in elements) { if (node.NodeType == XmlNodeType.Comment) { continue; } DatabaseElement database = new DatabaseElement(defaults); SqlEntityElement.ParseNodeAttributes(node, database); if (node.Attributes["key"] != null) { database.Key = node.Attributes["key"].Value; } database.SqlEntities = SqlEntityElement.ParseFromXml(database, GetSqlEntitiesNode(node), sqltypes, types, vd); list.Add(database); } return(list); }
public static ArrayList ParseFromXml(XmlNode root, DatabaseElement database, SqlEntityElement sqlentity, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd) { ArrayList list = new ArrayList(); XmlNodeList elements = root.SelectNodes("views/view"); if (elements != null) { foreach (XmlNode node in elements) { if (node.NodeType == XmlNodeType.Comment) { continue; } ViewElement view = new ViewElement(); view.Name = ParseStringAttribute(node, "name", String.Empty); foreach (XmlNode n in node.ChildNodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } ConstraintElement constraint = sqlentity.FindConstraintByName(n.Attributes["name"].Value); if (constraint == null) { vd(ParserValidationArgs.NewError("constraint specified (" + n.Attributes["name"].Value + ") in view (" + view.Name + ") not found.")); constraint = new ConstraintElement(); constraint.Name = n.Attributes["name"].Value; } else { if (!constraint.Type.Equals(ConstraintElement.FOREIGN_KEY)) { vd(ParserValidationArgs.NewError("View [" + view.Name + "] references a constraint that is not a foreign key constraint: " + constraint.Name)); } } constraint.Prefix = ParseStringAttribute(n, "prefix", constraint.ForeignEntity.Name + "_"); SqlEntityElement foreignEntity = database.FindSqlEntityByName(constraint.ForeignEntity.Name); // check to see if the foreignEntity is itself if (foreignEntity == null && sqlentity.Name == constraint.ForeignEntity.Name) { foreignEntity = sqlentity; } if (foreignEntity == null) { vd(ParserValidationArgs.NewError("View [" + view.Name + "] references a constraint that references an sql entity that was not defined (or was not defined before this sql entity): " + constraint.ForeignEntity)); } else { ArrayList columnsToAdd = new ArrayList(); foreach (ColumnElement column in foreignEntity.Columns) { ColumnElement viewColumn = (ColumnElement)column.Clone(); if (!constraint.Prefix.Equals(String.Empty)) { viewColumn.Name = constraint.Prefix + viewColumn.Name; } viewColumn.Prefix = constraint.Prefix; viewColumn.ForeignSqlEntity = constraint.ForeignEntity.Name; viewColumn.ViewColumn = true; columnsToAdd.Add(viewColumn); } sqlentity.Columns.AddRange(columnsToAdd); } view.Constraints.Add(constraint); } // validation if (view.Name.Equals(String.Empty)) { vd(ParserValidationArgs.NewError("View does not have a name: " + Environment.NewLine + node.OuterXml)); } list.Add(view); } } return(list); }