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);
        }
Esempio n. 2
0
        public override void Validate(RootElement root)
        {
            base.Validate(root);
            SqlEntityElement foreignEntity = root.FindSqlEntity(this.foreignEntity.Name);

            if (foreignEntity == null)
            {
                root.AddValidationMessage(ParserValidationMessage.NewError(String.Format("Foreign entity ({0}) not found for constraint ({1}).", this.foreignEntity.Name, this.Name)));
            }
            else
            {
                this.foreignEntity = foreignEntity;
                ArrayList columns = new ArrayList();
                foreach (ColumnElement column in foreignColumns)
                {
                    ColumnElement columnElement = this.foreignEntity.FindColumnByName(column.Name);
                    if (columnElement == null)
                    {
                        root.AddValidationMessage(ParserValidationMessage.NewError(String.Format("Foreign column ({0}) not found for constraint ({1}).", column.Name, this.Name)));
                    }
                    else
                    {
                        columns.Add(columnElement);
                    }
                }
                this.foreignColumns = columns;
            }
        }
Esempio n. 3
0
 public ForeignKeyConstraintElement(XmlNode constraintNode, SqlEntityElement sqlEntity) : base(constraintNode, sqlEntity)
 {
     foreignEntity.Name = GetAttributeValue(constraintNode, FOREIGN_ENTITY, foreignEntity.Name);
     foreach (ColumnElement column in this.Columns)
     {
         this.foreignColumns.Add(new ColumnElement(column.ForeignColumn));
     }
 }
        /// <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="sqlEntityElements"></param>
        public static void ParseFromXml(XmlNode node, IList sqlEntityElements)
        {
            if (node != null && sqlEntityElements != null)
            {
                foreach (XmlNode sqlEntityNode in node.ChildNodes)
                {
                    if (sqlEntityNode.NodeType.Equals(XmlNodeType.Element))
                    {
                        SqlEntityElement sqlEntityElement = new SqlEntityElement();

                        sqlEntityElement.Name                           = GetAttributeValue(sqlEntityNode, NAME, sqlEntityElement.Name);
                        sqlEntityElement.View                           = GetAttributeValue(sqlEntityNode, VIEW, sqlEntityElement.View);
                        sqlEntityElement.SingleFile                     = Boolean.Parse(GetAttributeValue(sqlEntityNode, SCRIPT_SINGLE_FILE, sqlEntityElement.SingleFile.ToString()));
                        sqlEntityElement.Server                         = GetAttributeValue(sqlEntityNode, SERVER, sqlEntityElement.Server);
                        sqlEntityElement.Database                       = GetAttributeValue(sqlEntityNode, DATABASE, sqlEntityElement.Database);
                        sqlEntityElement.User                           = GetAttributeValue(sqlEntityNode, USER, sqlEntityElement.User);
                        sqlEntityElement.Password                       = GetAttributeValue(sqlEntityNode, PASSWORD, sqlEntityElement.Password);
                        sqlEntityElement.SqlScriptDirectory             = GetAttributeValue(sqlEntityNode, SCRIPT_DIRECTORY, sqlEntityElement.SqlScriptDirectory);
                        sqlEntityElement.StoredProcNameFormat           = GetAttributeValue(sqlEntityNode, STORED_PROC_NAME_FORMAT, sqlEntityElement.StoredProcNameFormat);
                        sqlEntityElement.GenerateSqlViewScripts         = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_VIEW_SCRIPT, sqlEntityElement.GenerateSqlViewScripts.ToString()));
                        sqlEntityElement.GenerateSqlTableScripts        = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_TABLE_SCRIPT, sqlEntityElement.GenerateSqlTableScripts.ToString()));
                        sqlEntityElement.GenerateInsertStoredProcScript = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_INSERT_STORED_PROC_SCRIPT, sqlEntityElement.GenerateInsertStoredProcScript.ToString()));
                        sqlEntityElement.GenerateUpdateStoredProcScript = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_UPDATE_STORED_PROC_SCRIPT, sqlEntityElement.GenerateUpdateStoredProcScript.ToString()));
                        sqlEntityElement.GenerateDeleteStoredProcScript = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_DELETE_STORED_PROC_SCRIPT, sqlEntityElement.GenerateDeleteStoredProcScript.ToString()));
                        sqlEntityElement.GenerateSelectStoredProcScript = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_SELECT_STORED_PROC_SCRIPT, sqlEntityElement.GenerateSelectStoredProcScript.ToString()));
                        sqlEntityElement.AllowInsert                    = Boolean.Parse(GetAttributeValue(sqlEntityNode, ALLOW_INSERT, sqlEntityElement.AllowInsert.ToString())) ||
                                                                          sqlEntityElement.GenerateInsertStoredProcScript;
                        sqlEntityElement.AllowUpdate = Boolean.Parse(GetAttributeValue(sqlEntityNode, ALLOW_UPDATE, sqlEntityElement.AllowUpdate.ToString())) ||
                                                       sqlEntityElement.GenerateUpdateStoredProcScript;
                        sqlEntityElement.AllowDelete = Boolean.Parse(GetAttributeValue(sqlEntityNode, ALLOW_DELETE, sqlEntityElement.AllowDelete.ToString())) ||
                                                       sqlEntityElement.GenerateDeleteStoredProcScript;
                        sqlEntityElement.DefaultDirtyRead  = Boolean.Parse(GetAttributeValue(sqlEntityNode, DEFAULT_DIRTY_READ, sqlEntityElement.DefaultDirtyRead.ToString()));
                        sqlEntityElement.UpdateChangedOnly = Boolean.Parse(GetAttributeValue(sqlEntityNode, UPDATE_CHANGED_ONLY, sqlEntityElement.UpdateChangedOnly.ToString())) &&
                                                             sqlEntityElement.AllowUpdate;
                        sqlEntityElement.ScriptDropStatement                 = Boolean.Parse(GetAttributeValue(sqlEntityNode, SCRIPT_DROP_STATEMENT, sqlEntityElement.ScriptDropStatement.ToString()));
                        sqlEntityElement.UseView                             = Boolean.Parse(GetAttributeValue(sqlEntityNode, USE_VIEW, sqlEntityElement.UseView.ToString()));
                        sqlEntityElement.GenerateProcsForForeignKey          = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_PROCS_FOR_FOREIGN_KEYS, sqlEntityElement.GenerateProcsForForeignKey.ToString()));
                        sqlEntityElement.GenerateOnlyPrimaryDeleteStoredProc = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_ONLY_PRIMARY_DELETE_STORED_PROC, sqlEntityElement.GenerateOnlyPrimaryDeleteStoredProc.ToString()));
                        sqlEntityElement.AllowUpdateOfPrimaryKey             = Boolean.Parse(GetAttributeValue(sqlEntityNode, ALLOW_UPDATE_OF_PRIMARY_KEY, sqlEntityElement.AllowUpdateOfPrimaryKey.ToString()));
                        sqlEntityElement.CommandTimeout                      = Int32.Parse(GetAttributeValue(sqlEntityNode, COMMAND_TIMEOUT, sqlEntityElement.CommandTimeout.ToString()));
                        sqlEntityElement.ScriptForIndexedViews               = Boolean.Parse(GetAttributeValue(sqlEntityNode, SCRIPT_FOR_INDEXED_VIEWS, sqlEntityElement.ScriptForIndexedViews.ToString()));

                        ColumnElement.ParseFromXml(GetChildNodeByName(sqlEntityNode, COLUMNS), sqlEntityElement.Columns);
                        ConstraintElement.ParseFromXml(GetChildNodeByName(sqlEntityNode, CONSTRAINTS), sqlEntityElement.Constraints);
                        IndexElement.ParseFromXml(GetChildNodeByName(sqlEntityNode, INDEXES), sqlEntityElement.Indexes);
                        ViewElement.ParseFromXml(GetChildNodeByName(sqlEntityNode, VIEWS), sqlEntityElement.Views);

                        sqlEntityElements.Add(sqlEntityElement);
                    }
                }
            }
        }
        protected ConstraintElement(XmlNode constraintNode, SqlEntityElement sqlEntity) : base(constraintNode)
        {
            this.sqlEntity = sqlEntity;
            if (CONSTRAINT.Equals(constraintNode.Name))
            {
                type   = GetAttributeValue(constraintNode, TYPE, type);
                prefix = GetAttributeValue(constraintNode, PREFIX, prefix);

                foreach (XmlNode node in GetChildNodes(constraintNode, ColumnElement.COLUMN))
                {
                    columns.Add(new ColumnElement(node, null));
                }
            }
            else
            {
                throw new ArgumentException("The XmlNode argument is not a constraint node.");
            }
        }
Esempio n. 6
0
        public IndexElement(XmlNode indexNode, SqlEntityElement sqlEntity)
        {
            this.sqlEntity = sqlEntity;
            if (indexNode != null && INDEX.Equals(indexNode.Name))
            {
                name      = GetAttributeValue(indexNode, NAME, name);
                unique    = Boolean.Parse(GetAttributeValue(indexNode, UNIQUE, unique.ToString()));
                clustered = Boolean.Parse(GetAttributeValue(indexNode, CLUSTERED, clustered.ToString()));

                foreach (XmlNode node in GetChildNodes(indexNode, ColumnElement.COLUMN))
                {
                    columns.Add(new ColumnElement(node, null));
                }
            }
            else
            {
                throw new ArgumentException("The XmlNode argument is not an index node.");
            }
        }
Esempio n. 7
0
        public override void Validate(RootElement root)
        {
            // Find the sql entity.
            SqlEntityElement sqlEntity = root.FindSqlEntity(this.sqlEntity.Name);

            if (sqlEntity == null)
            {
                root.AddValidationMessage(ParserValidationMessage.NewError(String.Format("Sql Entity ({0}) not found.", this.sqlEntity.Name)));
            }
            else
            {
                this.sqlEntity = sqlEntity;

                // Validate each of the column map entries.
                foreach (ColumnMapElement columnMap in this.columnMaps)
                {
                    columnMap.Validate(root);
                }
            }
        }
        public static ConstraintElement NewInstance(XmlNode constraintNode, SqlEntityElement sqlEntity)
        {
            String type = GetAttributeValue(constraintNode, TYPE, String.Empty);

            switch (type)
            {
            case UNIQUE:
                return(new UniqueConstraintElement(constraintNode, sqlEntity));

            case PRIMARY_KEY:
                return(new PrimaryKeyConstraintElement(constraintNode, sqlEntity));

            case FOREIGN_KEY:
                return(new ForeignKeyConstraintElement(constraintNode, sqlEntity));

            case CHECK:
                return(new CheckConstraintElement(constraintNode, sqlEntity));

            default:
                throw new ArgumentException("The XmlNode argument does not contain a valid constraint type.");
            }
        }
 public ColumnElement(XmlNode columnNode, SqlEntityElement sqlEntity) : base(columnNode)
 {
     if (COLUMN.Equals(columnNode.Name))
     {
         this.sqlEntity = sqlEntity;
         sqlType.Name   = GetAttributeValue(columnNode, SQL_TYPE, sqlType.Name);
         identity       = Boolean.Parse(GetAttributeValue(columnNode, IDENTITY, identity.ToString()));
         length         = Int32.Parse(GetAttributeValue(columnNode, LENGTH, length.ToString()));
         required       = Boolean.Parse(GetAttributeValue(columnNode, REQUIRED, required.ToString()));
         viewColumn     = Boolean.Parse(GetAttributeValue(columnNode, VIEW_COLUMN, viewColumn.ToString()));
         precision      = Int32.Parse(GetAttributeValue(columnNode, PRECISION, precision.ToString()));
         scale          = Int32.Parse(GetAttributeValue(columnNode, SCALE, scale.ToString()));
         expression     = GetAttributeValue(columnNode, EXPRESSION, expression);
         Default        = GetAttributeValue(columnNode, DEFAULT, Default);
         increment      = Int32.Parse(GetAttributeValue(columnNode, INCREMENT, increment.ToString()));
         seed           = Int32.Parse(GetAttributeValue(columnNode, SEED, seed.ToString()));
         foreignColumn  = GetAttributeValue(columnNode, FOREIGN_COLUMN, foreignColumn);
     }
     else
     {
         throw new ArgumentException("The XmlNode argument is not a column node.");
     }
 }
Esempio n. 10
0
        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 PropertyElement BuildElement(XmlNode node, Hashtable types, Hashtable sqltypes, IPropertyContainer entity, bool isReference, ParserValidationDelegate vd)
        {
            PropertyElement field = new PropertyElement();

            if (node.Attributes["name"] != null)
            {
                field.Name = node.Attributes["name"].Value;
            }
            else
            {
                vd(ParserValidationArgs.NewError("Property in " + entity.Name + " has no name."));
            }

            if (isReference && field.Name != "*")
            {
                PropertyElement refProperty = entity.FindFieldByName(field.Name);

                if (refProperty == null)
                {
                    vd(ParserValidationArgs.NewError("Property " + field.Name + " in " + entity.Name + " refers to a property that does not exist."));
                }
                else
                {
                    field = (PropertyElement)(refProperty.Clone());
                }
            }

            if (node.Attributes["column"] != null)
            {
                if (node.Attributes["column"].Value.Equals("*"))
                {
                    field.Column.Name = field.Name;
                }
                else
                {
                    field.Column.Name = node.Attributes["column"].Value;
                }

                // Column only occurs on entity eement.
                SqlEntityElement sqlEntity = ((EntityElement)entity).SqlEntity;
                ColumnElement    column    = sqlEntity.FindColumnByName(field.Column.Name);
                if (column != null)
                {
                    field.Column = (ColumnElement)column.Clone();
                    if (types.Contains(field.Column.SqlType.Type))
                    {
                        field.Type = (TypeElement)((TypeElement)types[field.Column.SqlType.Type]).Clone();
                    }
                    else
                    {
                        vd(ParserValidationArgs.NewError("Type " + field.Column.SqlType.Type + " was not defined [property=" + field.name + "]"));
                    }
                }
                else
                {
                    vd(ParserValidationArgs.NewError("column (" + field.Column.Name + ") specified for property (" + field.Name + ") on entity (" + entity.Name + ") was not found in sql entity (" + sqlEntity.Name + ")"));
                }
            }

            field.Description = node.InnerText.Trim();

            if (node.Attributes["accessmodifier"] != null)
            {
                field.AccessModifier = node.Attributes["accessmodifier"].Value;
            }

            // the concrete type is the *real* type, type can be the same or can be in interface or coersable type
            if (node.Attributes["type"] != null)
            {
                String type         = node.Attributes[TYPE].Value;
                String concreteType = type;
                if (node.Attributes[CONCRETE_TYPE] != null)
                {
                    concreteType = node.Attributes[CONCRETE_TYPE].Value;
                }
                // if the data type is defined, default it as the property and left be overridden
                if (types.Contains(concreteType))
                {
                    field.Type      = (TypeElement)((TypeElement)types[concreteType]).Clone();
                    field.Type.Name = type;
                }
                else
                {
                    vd(ParserValidationArgs.NewError("Type " + concreteType + " was not defined for property " + field.Name + " in " + entity.Name + "."));
                }

                String dataObjectTypeName = concreteType + "Data";
                if (types.Contains(dataObjectTypeName))
                {
                    field.DataObjectType = (TypeElement)((TypeElement)types[dataObjectTypeName]).Clone();
                }
                else
                {
                    field.DataObjectType = field.Type;
                }
            }

            if (node.Attributes["convertfromsqltypeformat"] != null)
            {
                field.Type.ConvertFromSqlTypeFormat = node.Attributes["convertfromsqltypeformat"].Value;
            }
            if (node.Attributes["converttosqltypeformat"] != null)
            {
                field.Type.ConvertToSqlTypeFormat = node.Attributes["converttosqltypeformat"].Value;
            }
            if (node.Attributes[PARAMETER_NAME] != null)
            {
                field.ParameterName = node.Attributes[PARAMETER_NAME].Value;
            }
            if (node.Attributes[EXPRESSION] != null)
            {
                field.Expression = node.Attributes[EXPRESSION].Value;
            }
            if (node.Attributes[GROUP_FUNCTION] != null)
            {
                field.GroupFunction = node.Attributes[GROUP_FUNCTION].Value;
                if (field.GroupFunction.ToLower() != GROUP_FUNCTION_SUM &&
                    field.GroupFunction.ToLower() != GROUP_FUNCTION_MIN &&
                    field.GroupFunction.ToLower() != GROUP_FUNCTION_MAX &&
                    field.GroupFunction.ToLower() != GROUP_FUNCTION_AVG &&
                    field.GroupFunction.ToLower() != GROUP_FUNCTION_STDEV &&
                    field.GroupFunction.ToLower() != GROUP_FUNCTION_STDEVP &&
                    field.GroupFunction.ToLower() != GROUP_FUNCTION_VAR &&
                    field.GroupFunction.ToLower() != GROUP_FUNCTION_VARP)
                {
                    vd(ParserValidationArgs.NewError("Invalid group function specified for entity reference property " + field.Name + " in " + entity.Name));
                }
            }

            if (node.Attributes[GROUP_BY] != null)
            {
                field.GroupBy = Boolean.Parse(node.Attributes[GROUP_BY].Value);
            }
            if (node.Attributes[SQL_TYPE] != null)
            {
                field.Column.SqlType.Name = node.Attributes[SQL_TYPE].Value;
                if (sqltypes.ContainsKey(field.Column.SqlType.Name))
                {
                    field.Column.SqlType = (SqlTypeElement)((SqlTypeElement)sqltypes[field.Column.SqlType.Name]).Clone();
                }
                else
                {
                    vd(ParserValidationArgs.NewError("SqlType " + field.Column.SqlType.Name + " was not defined in " + entity.Name + " for property " + field.Name + "."));
                }
            }
            if (node.Attributes[ALIAS] != null)
            {
                field.Alias = node.Attributes[ALIAS].Value;
            }

            field.container = entity;

            if (node.Attributes["readable"] != null)
            {
                field.Readable = Boolean.Parse(node.Attributes["readable"].Value);
            }
            if (node.Attributes["writable"] != null)
            {
                field.Writable = Boolean.Parse(node.Attributes["writable"].Value);
            }

            if (node.Attributes["derived"] != null)
            {
                field.Derived = Boolean.Parse(node.Attributes["derived"].Value);
            }

            if (node.Attributes["encrypted"] != null)
            {
                field.Encrypted = Boolean.Parse(node.Attributes["encrypted"].Value);
            }

            if (node.Attributes["log"] != null)
            {
                field.DoLog = Boolean.Parse(node.Attributes["log"].Value);
            }

            if (node.Attributes["returnasidentity"] != null)
            {
                field.ReturnAsIdentity = Boolean.Parse(node.Attributes["returnasidentity"].Value);
            }

            if (node.Attributes[DIRECTION] == null)
            {
                field.Direction = ASCENDING;
            }
            else if (node.Attributes["direction"].Value != ASCENDING && node.Attributes["direction"].Value != DESCENDING)
            {
                vd(ParserValidationArgs.NewError("Comparer in entity " + entity.Name + " has direction value other than 'ascending' or 'descending'"));
            }
            else
            {
                field.Direction = node.Attributes[DIRECTION].Value;
            }

            if (node.Attributes[CONVERT_FOR_COMPARE] != null)
            {
                field.Type.ConvertForCompare = node.Attributes[CONVERT_FOR_COMPARE].Value;
            }

            if (node.Attributes[USE_ENTITY_DAO] != null)
            {
                field.UseEntityDao = Boolean.Parse(node.Attributes[USE_ENTITY_DAO].Value);
            }

            if (node.Attributes["entity"] != null)
            {
                field.Entity.Name = node.Attributes["entity"].Value;
            }

            if (node.Attributes["prefix"] != null)
            {
                field.Prefix = node.Attributes["prefix"].Value;
            }
            else
            {
                field.Prefix = field.Entity.Name + "_";
            }

            return(field);
        }
        public static ArrayList ParseFromXml(XmlNode propertiesNode, IList entities, IPropertyContainer entity, Hashtable sqltypes, Hashtable types, bool isReference, ParserValidationDelegate vd)
        {
            ArrayList fields = new ArrayList();

            if (propertiesNode != null)
            {
                foreach (XmlNode node in propertiesNode.ChildNodes)
                {
                    if (node.NodeType == XmlNodeType.Comment)
                    {
                        continue;
                    }
                    PropertyElement field = BuildElement(node, types, sqltypes, entity, isReference, vd);

                    //Adds all attributes including all non defined by element class
                    foreach (XmlAttribute attribute in node.Attributes)
                    {
                        if (!field.Attributes.ContainsKey(attribute.Name))
                        {
                            field.Attributes.Add(attribute.Name, attribute.Value);
                        }
                    }

                    fields.Add(field);

                    // Add in any subfields...
                    if (field.Entity.Name.Length > 0 && !field.UseEntityDao)
                    {
                        String        subEntityName = node.Attributes["entity"].Value;
                        EntityElement subentity     = EntityElement.FindEntityByName((ArrayList)entities, subEntityName);

                        // check to see if subentity is self
                        if (subentity == null && entity.Name == subEntityName)
                        {
                            subentity = (EntityElement)entity;
                        }

                        if (subentity != null)
                        {
                            // Only entity elements have entity atttribute
                            SqlEntityElement sqlEntity = ((EntityElement)entity).SqlEntity;

                            String prefix = subentity.Name + "_";
                            if (node.Attributes["prefix"] != null)
                            {
                                prefix = node.Attributes["prefix"].Value;
                            }

                            foreach (PropertyElement f in subentity.Fields)
                            {
                                PropertyElement subfield = (PropertyElement)f.Clone();
                                subfield.Name = field.Name + "." + subfield.Name;

                                // if field has sql column defined
                                if (!f.Column.Name.Equals(String.Empty))
                                {
                                    ColumnElement column = sqlEntity.FindColumnByName(prefix + subfield.Column.Name);
                                    if (column != null)
                                    {
                                        subfield.Column = (ColumnElement)column.Clone();
                                    }
                                    else
                                    {
                                        vd(ParserValidationArgs.NewError("column (" + prefix + subfield.Column.Name + ") specified for property (" + subfield.Name + ") on entity (" + entity.Name + ") was not found in sql entity (" + sqlEntity.Name + ")"));
                                    }
                                }
                                fields.Add(subfield);
                            }
                        }
                        else
                        {
                            vd(ParserValidationArgs.NewError("Entity " + entity.Name + " referenced another entity that was not defined (or defined below this one): " + node.Attributes["entity"].Value));
                        }
                    }
                }
            }
            return(fields);
        }
Esempio n. 13
0
        public static ArrayList ParseFromXml(XmlNode root, SqlEntityElement sqlentity, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd)
        {
            ArrayList   columns  = new ArrayList();
            XmlNodeList elements = null;

            foreach (XmlNode n in root.ChildNodes)
            {
                if (n.Name.Equals("columns"))
                {
                    elements = n.ChildNodes;
                    break;
                }
            }
            if (elements != null)
            {
                foreach (XmlNode node in elements)
                {
                    if (node.NodeType == XmlNodeType.Comment)
                    {
                        continue;
                    }
                    if (node.Name.Equals("column"))
                    {
                        ColumnElement column = new ColumnElement();
                        column.Name = GetAttributeValue(node, NAME, String.Empty);
                        if (column.Name.Equals(String.Empty))
                        {
                            vd(ParserValidationArgs.NewError("SqlEntity " + sqlentity.Name + " has a column that a name was not specified or was blank"));
                        }
                        column.Description = node.InnerText.Trim();

                        if (node.Attributes["sqltype"] != null)
                        {
                            column.SqlType.Name = node.Attributes["sqltype"].Value;
                            if (sqltypes.ContainsKey(column.SqlType.Name))
                            {
                                column.SqlType = (SqlTypeElement)((SqlTypeElement)sqltypes[column.SqlType.Name]).Clone();
                            }
                            else
                            {
                                vd(ParserValidationArgs.NewError("SqlType " + column.SqlType.Name + " was not defined [column=" + sqlentity.Name + "." + column.Name + "]"));
                            }
                        }

                        if (node.Attributes["required"] != null)
                        {
                            column.Required = Boolean.Parse(node.Attributes["required"].Value);
                        }
                        if (node.Attributes["identity"] != null)
                        {
                            column.Identity = Boolean.Parse(node.Attributes["identity"].Value);
                        }
                        if (node.Attributes["rowguidcol"] != null)
                        {
                            column.RowGuidCol = Boolean.Parse(node.Attributes["rowguidcol"].Value);
                        }
                        if (node.Attributes["viewcolumn"] != null)
                        {
                            column.ViewColumn = Boolean.Parse(node.Attributes["viewcolumn"].Value);
                        }

                        if (node.Attributes["increment"] != null)
                        {
                            column.Increment = Int32.Parse(node.Attributes["increment"].Value);
                        }
                        if (node.Attributes["seed"] != null)
                        {
                            column.Seed = Int32.Parse(node.Attributes["seed"].Value);
                        }
                        if (node.Attributes["default"] != null)
                        {
                            column.Default = node.Attributes["default"].Value;
                        }
                        if (node.Attributes["formula"] != null)
                        {
                            column.Formula = node.Attributes["formula"].Value;
                        }
                        if (node.Attributes["length"] != null)
                        {
                            column.SqlType.Length = Int32.Parse(node.Attributes["length"].Value);
                        }
                        if (node.Attributes["scale"] != null)
                        {
                            column.SqlType.Scale = Int32.Parse(node.Attributes["scale"].Value);
                        }
                        if (node.Attributes["precision"] != null)
                        {
                            column.SqlType.Precision = Int32.Parse(node.Attributes["precision"].Value);
                        }
                        if (node.Attributes["expression"] != null)
                        {
                            column.Expression = node.Attributes["expression"].Value;
                        }
                        if (node.Attributes["obsolete"] != null)
                        {
                            column.Obsolete = Boolean.Parse(node.Attributes[OBSOLETE].Value);
                        }
                        if (node.Attributes["retainnonnullvalue"] != null)
                        {
                            column.RetainNonNullValue = Boolean.Parse(node.Attributes["retainnonnullvalue"].Value);
                        }
                        if (node.Attributes[COLLATE] != null)
                        {
                            column.Collate = node.Attributes[COLLATE].Value;
                        }

                        //Adds all attributes including all non defined by element class
                        foreach (XmlAttribute attribute in node.Attributes)
                        {
                            if (!column.Attributes.ContainsKey(attribute.Name))
                            {
                                column.Attributes.Add(attribute.Name, attribute.Value);
                            }
                        }

                        column.Description = node.InnerText.Trim();

                        columns.Add(column);
                    }
                }
            }
            return(columns);
        }
 public CheckConstraintElement(XmlNode constraintNode, SqlEntityElement sqlEntity) : base(constraintNode, sqlEntity)
 {
     checkClause = GetAttributeValue(constraintNode, CHECK_CLAUSE, checkClause);
 }
Esempio n. 15
0
        public static ArrayList ParseFromXml(XmlNode root, SqlEntityElement sqlentity, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd)
        {
            ArrayList   constraints = new ArrayList();
            XmlNodeList elements    = null;

            foreach (XmlNode n in root.ChildNodes)
            {
                if (n.Name.Equals("constraints"))
                {
                    elements = n.ChildNodes;
                    break;
                }
            }
            if (elements != null)
            {
                foreach (XmlNode node in elements)
                {
                    if (node.NodeType == XmlNodeType.Comment)
                    {
                        continue;
                    }
                    ConstraintElement constraint = new ConstraintElement();
                    constraint.Name = node.Attributes["name"].Value;
                    constraint.Type = node.Attributes["type"].Value;

                    if (node.Attributes["clustered"] != null)
                    {
                        constraint.Clustered = Boolean.Parse(node.Attributes["clustered"].Value);
                    }
                    if (node.Attributes["foreignentity"] != null)
                    {
                        constraint.ForeignEntity.Name = node.Attributes["foreignentity"].Value;
                    }
                    if (node.Attributes["checkclause"] != null)
                    {
                        constraint.CheckClause = node.Attributes["checkclause"].Value;
                    }
                    if (node.Attributes["checkenum"] != null)
                    {
                        constraint.CheckEnum.Name = node.Attributes["checkenum"].Value;
                    }
                    foreach (XmlNode n in node.ChildNodes)
                    {
                        if (n.NodeType == XmlNodeType.Comment)
                        {
                            continue;
                        }
                        ColumnElement column = sqlentity.FindColumnByName(n.Attributes["name"].Value);
                        if (column == null)
                        {
                            vd(ParserValidationArgs.NewError("column specified (" + n.Attributes["name"].Value + ") in constraint (" + constraint.Name + ") not found as column."));
                            column      = new ColumnElement();
                            column.Name = n.Attributes["name"].Value;
                        }
                        if (n.Attributes["foreigncolumn"] != null)
                        {
                            column.ForeignColumn = n.Attributes["foreigncolumn"].Value;
                        }
                        constraint.Columns.Add(column);
                    }
                    constraints.Add(constraint);
                }
            }
            return(constraints);
        }
 public UniqueConstraintElement(XmlNode constraintNode, SqlEntityElement sqlEntity) : base(constraintNode, sqlEntity)
 {
     clustered = Boolean.Parse(GetAttributeValue(constraintNode, CLUSTERED, clustered.ToString()));
 }
 public PrimaryKeyConstraintElement(XmlNode node, SqlEntityElement sqlEntity) : base(node, sqlEntity)
 {
 }
Esempio n. 18
0
        public static ArrayList ParseFromXml(Configuration options, XmlDocument doc, Hashtable sqltypes, Hashtable types, ArrayList sqlentities, ParserValidationDelegate vd)
        {
            ArrayList entities     = new ArrayList();
            XmlNode   entitiesNode = doc.DocumentElement.Cast <XmlNode>().FirstOrDefault(x => x.Name.ToLowerInvariant() == "entities");

            if (entitiesNode == null)
            {
                return(entities);
            }

            IEnumerable <XmlNode> elements = entitiesNode.ChildNodes.Cast <XmlNode>().Where(x => x.Name.ToLowerInvariant() == "entity");

            foreach (XmlNode node in elements)
            {
                if (node.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }
                EntityElement entity = new EntityElement();
                entity.Name = node.Attributes["name"].Value;
                if (node.Attributes["namespace"] != null)
                {
                    entity.Namespace = node.Attributes["namespace"].Value;
                }
                if (node.Attributes["sqlentity"] != null)
                {
                    SqlEntityElement sqlentity = SqlEntityElement.FindByName(sqlentities, node.Attributes["sqlentity"].Value);
                    if (sqlentity != null)
                    {
                        entity.SqlEntity = (SqlEntityElement)sqlentity.Clone();
                    }
                    else
                    {
                        entity.SqlEntity.Name = node.Attributes["sqlentity"].Value;
                        vd(ParserValidationArgs.NewError("sqlentity (" + entity.SqlEntity.Name + ") specified in entity " + entity.Name + " could not be found as an defined sql entity"));
                    }
                }

                if (node.Attributes["baseentity"] != null)
                {
                    EntityElement baseentity = EntityElement.FindEntityByName(entities, node.Attributes["baseentity"].Value);
                    if (baseentity != null)
                    {
                        entity.BaseEntity = (EntityElement)baseentity.Clone();
                    }
                    else
                    {
                        entity.BaseEntity.Name = node.Attributes["baseentity"].Value;
                        vd(ParserValidationArgs.NewError("baseentity (" + entity.BaseEntity.Name + ") specified in entity " + entity.Name + " could not be found as an defined entity (or is defined after this entity in the config file)"));
                    }
                }

                if (node.Attributes["abstract"] != null)
                {
                    entity.IsAbstract = Boolean.Parse(node.Attributes["abstract"].Value);
                }

                if (node.Attributes["namespace"] != null)
                {
                    entity.HasNamespace = !String.IsNullOrEmpty(node.Attributes["namespace"].Value);
                }

                if (node.Attributes["log"] != null)
                {
                    entity.DoLog = Boolean.Parse(node.Attributes["log"].Value);
                }

                if (node.Attributes["returnwholeobject"] != null)
                {
                    entity.ReturnWholeObject = Boolean.Parse(node.Attributes["returnwholeobject"].Value);
                }

                if (node.Attributes["prepareforinsert"] != null)
                {
                    entity.PrepareForInsert = Boolean.Parse(node.Attributes["prepareforinsert"].Value);
                }

                if (node.Attributes["dependententity"] != null)
                {
                    entity.DependentEntity = Boolean.Parse(node.Attributes["dependententity"].Value);
                }

                if (node.Attributes["jointable"] != null)
                {
                    entity.JoinTable = Boolean.Parse(node.Attributes["jointable"].Value);
                }

                XmlNode descriptionNode = node.SelectSingleNode(DESCRIPTION);
                if (descriptionNode != null)
                {
                    entity.Description = descriptionNode.InnerText.Trim();
                }

                //Adds all attributes including all not defined by element class
                foreach (XmlAttribute attribute in node.Attributes)
                {
                    if (!entity.Attributes.ContainsKey(attribute.Name))
                    {
                        entity.Attributes.Add(attribute.Name, attribute.Value);
                    }
                }

                entity.dependents = ParseDependentsFromXml(node, vd);

                entity.fields    = PropertyElement.ParseFromXml(doc, entities, entity, sqltypes, types, vd);
                entity.finders   = FinderElement.ParseFromXml(doc, node, entities, entity, sqltypes, types, vd);
                entity.comparers = ComparerElement.ParseFromXml(node, entities, entity, sqltypes, types, vd);
                entities.Add(entity);
            }

            StringCollection names = new StringCollection();

            foreach (EntityElement entity in entities)
            {
                if (names.Contains(entity.Name))
                {
                    vd(new ParserValidationArgs(ParserValidationSeverity.ERROR, "duplicate entity definition for " + entity.Name));
                }
                else
                {
                    names.Add(entity.Name);
                }
            }
            return(entities);
        }
Esempio n. 19
0
        public static ArrayList ParseFromXml(XmlNode root, SqlEntityElement sqlentity, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd)
        {
            ArrayList   indexes  = new ArrayList();
            XmlNodeList elements = null;

            foreach (XmlNode n in root.ChildNodes)
            {
                if (n.Name.Equals("indexes"))
                {
                    elements = n.ChildNodes;
                    break;
                }
            }
            if (elements != null)
            {
                foreach (XmlNode node in elements)
                {
                    if (node.NodeType == XmlNodeType.Comment)
                    {
                        continue;
                    }
                    IndexElement index = new IndexElement();
                    index.Name = node.Attributes["name"].Value;

                    if (node.Attributes["clustered"] != null)
                    {
                        index.Clustered = Boolean.Parse(node.Attributes["clustered"].Value);
                    }
                    if (node.Attributes["unique"] != null)
                    {
                        index.Unique = Boolean.Parse(node.Attributes["unique"].Value);
                    }

                    foreach (XmlNode n in node.ChildNodes)
                    {
                        if (node.NodeType == XmlNodeType.Comment)
                        {
                            continue;
                        }
                        if (n.Name == "include")
                        {
                            foreach (XmlNode includeNode in n.ChildNodes)
                            {
                                ColumnElement includeColumn = sqlentity.FindColumnByName(includeNode.Attributes["name"].Value);
                                if (includeColumn == null)
                                {
                                    vd(ParserValidationArgs.NewError("column specified (" + includeNode.Attributes["name"].Value + ") in index (" + index.Name + ") not found as column."));
                                    includeColumn      = new ColumnElement();
                                    includeColumn.Name = includeNode.Attributes["name"].Value;
                                }
                                index.IncludeColumns.Add(includeColumn);
                            }
                            continue;
                        }
                        ColumnElement column = sqlentity.FindColumnByName(n.Attributes["name"].Value);
                        if (column == null)
                        {
                            vd(ParserValidationArgs.NewError("column specified (" + n.Attributes["name"].Value + ") in index (" + index.Name + ") not found as column."));
                            column      = new ColumnElement();
                            column.Name = n.Attributes["name"].Value;
                        }
                        if (n.Attributes["sortdirection"] != null)
                        {
                            column.SortDirection = n.Attributes["sortdirection"].Value;
                        }
                        index.Columns.Add(column);
                    }
                    indexes.Add(index);
                }
            }
            return(indexes);
        }
Esempio n. 20
0
        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);
        }