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);
        }
        public override void Validate(RootElement root)
        {
            // Look up the property from the property path.
            PropertyElement propertyElement = this.dataMap.Entity.FindProperty(this.Name);

            if (propertyElement == null)
            {
                root.AddValidationMessage(ParserValidationMessage.NewError(String.Format("ColumnMap: property ({0}) not found.", this.Name)));
            }
            else
            {
                this.property = propertyElement;
            }

            // Look up the column in the sql entity.
            ColumnElement columnElement = this.dataMap.SqlEntity.FindColumnByName(this.column.Name);

            if (columnElement == null)
            {
                root.AddValidationMessage(ParserValidationMessage.NewError(String.Format("ColumnMap: column ({0}) not found.", this.column.Name)));
            }
            else
            {
                this.column = columnElement;

                // Make sure the column and property types are compatible.
//		if (!this.property.Type.Equals(String.Empty) && !columnElement.SqlType.Type.Equals(this.property.Type)) {
//		    this.AddValidationMessage(ParserValidationMessage.NewError(String.Format("The type of column ({0}) is ({1}) and is not compatible with the type ({2}) of property ({3}).", this.column.Name, this.column.SqlType.Type, this.Property.Type, this.property.Name)));
//		}
            }
        }
        /// <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="columnElements"></param>
        public static void ParseFromXml(XmlNode node, IList columnElements)
        {
            if (node != null && columnElements != null)
            {
                foreach (XmlNode columnNode in node.ChildNodes)
                {
                    if (columnNode.NodeType.Equals(XmlNodeType.Element))
                    {
                        ColumnElement columnElement = new ColumnElement();

                        columnElement.Name               = GetAttributeValue(columnNode, NAME, columnElement.Name);
                        columnElement.SqlType.Name       = GetAttributeValue(columnNode, SQL_TYPE, columnElement.SqlType.Name);
                        columnElement.Identity           = Boolean.Parse(GetAttributeValue(columnNode, IDENTITY, columnElement.Identity.ToString()));
                        columnElement.Length             = Int32.Parse(GetAttributeValue(columnNode, LENGTH, columnElement.Length.ToString()));
                        columnElement.Required           = Boolean.Parse(GetAttributeValue(columnNode, REQUIRED, columnElement.Required.ToString()));
                        columnElement.ViewColumn         = Boolean.Parse(GetAttributeValue(columnNode, VIEW_COLUMN, columnElement.ViewColumn.ToString()));
                        columnElement.Precision          = Int32.Parse(GetAttributeValue(columnNode, PRECISION, columnElement.Precision.ToString()));
                        columnElement.Scale              = Int32.Parse(GetAttributeValue(columnNode, SCALE, columnElement.Scale.ToString()));
                        columnElement.Expression         = GetAttributeValue(columnNode, EXPRESSION, columnElement.Expression);
                        columnElement.Default            = GetAttributeValue(columnNode, DEFAULT, columnElement.Default);
                        columnElement.Increment          = Int32.Parse(GetAttributeValue(columnNode, INCREMENT, columnElement.Increment.ToString()));
                        columnElement.Seed               = Int32.Parse(GetAttributeValue(columnNode, SEED, columnElement.Seed.ToString()));
                        columnElement.ForeignColumn      = GetAttributeValue(columnNode, FOREIGN_COLUMN, columnElement.ForeignColumn);
                        columnElement.Obsolete           = Boolean.Parse(GetAttributeValue(columnNode, OBSOLETE, columnElement.Obsolete.ToString()));
                        columnElement.Description        = columnNode.InnerText.Trim();
                        columnElement.Collate            = GetAttributeValue(columnNode, COLLATE, columnElement.Collate);
                        columnElement.RetainNonNullValue = Boolean.Parse(GetAttributeValue(columnNode, RETAINNONNULLVALUE, columnElement.RetainNonNullValue.ToString()));
                        columnElements.Add(columnElement);
                    }
                }
            }
        }
        /// <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="indexElements"></param>
        public static void ParseFromXml(XmlNode node, IList indexElements)
        {
            if (node != null && indexElements != null)
            {
                foreach (XmlNode indexNode in node.ChildNodes)
                {
                    if (indexNode.NodeType.Equals(XmlNodeType.Element))
                    {
                        IndexElement indexElement = new IndexElement();

                        indexElement.Name      = GetAttributeValue(indexNode, NAME, indexElement.Name);
                        indexElement.Unique    = Boolean.Parse(GetAttributeValue(indexNode, UNIQUE, indexElement.Unique.ToString()));
                        indexElement.Clustered = Boolean.Parse(GetAttributeValue(indexNode, CLUSTERED, indexElement.Clustered.ToString()));

                        ColumnElement.ParseFromXml(indexNode, indexElement.Columns);
                        if (indexNode.Name == "includeColumns")
                        {
                            foreach (XmlNode includeNode in indexNode.ChildNodes)
                            {
                                ColumnElement.ParseFromXml(includeNode, indexElement.IncludeColumns);
                            }
                        }

                        indexElements.Add(indexElement);
                    }
                }
            }
        }
Example #5
0
        /// <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="constraintElements"></param>
        public static void ParseFromXml(XmlNode node, IList constraintElements)
        {
            if (node != null && constraintElements != null)
            {
                foreach (XmlNode constraintNode in node.ChildNodes)
                {
                    if (constraintNode.NodeType.Equals(XmlNodeType.Element))
                    {
                        ConstraintElement constraintElement = new ConstraintElement();

                        constraintElement.Name               = GetAttributeValue(constraintNode, NAME, constraintElement.Name);
                        constraintElement.Type               = GetAttributeValue(constraintNode, TYPE, constraintElement.Type);
                        constraintElement.Clustered          = Boolean.Parse(GetAttributeValue(constraintNode, CLUSTERED, constraintElement.Clustered.ToString()));
                        constraintElement.ForeignEntity.Name = GetAttributeValue(constraintNode, FOREIGN_ENTITY, constraintElement.ForeignEntity.Name);
                        constraintElement.CheckClause        = GetAttributeValue(constraintNode, CHECK_CLAUSE, constraintElement.CheckClause);
                        constraintElement.Prefix             = GetAttributeValue(constraintNode, PREFIX, constraintElement.Prefix);
                        constraintElement.CheckEnum.Name     = GetAttributeValue(constraintNode, CHECK_ENUM, constraintElement.CheckEnum.Name);

                        ColumnElement.ParseFromXml(constraintNode, constraintElement.Columns);

                        constraintElements.Add(constraintElement);
                    }
                }
            }
        }
Example #6
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;
            }
        }
        /// <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);
                    }
                }
            }
        }
        public override void Validate(RootElement root)
        {
            ArrayList columns = new ArrayList();

            foreach (ColumnElement column in this.columns)
            {
                ColumnElement columnElement = this.sqlEntity.FindColumnByName(column.Name);
                if (columnElement == null)
                {
                }
                else
                {
                    columns.Add(columnElement);
                }
            }
            this.columns = columns;
        }
Example #9
0
        public Boolean HasEntityMappedColumn(ColumnElement column)
        {
            foreach (PropertyElement property in Fields)
            {
                if (property.Entity.Name.Length > 0)
                {
                    foreach (PropertyElement p in property.Entity.Fields)
                    {
                        if (column.Name.EndsWith(property.Prefix + p.Name))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        public override void Validate(RootElement root)
        {
            // Replace each column placeholder with the column from the sql entity.
            ArrayList columns = new ArrayList();

            foreach (ColumnElement column in this.columns)
            {
                ColumnElement columnElement = this.sqlEntity.FindColumnByName(column.Name);
                if (columnElement == null)
                {
                    root.AddValidationMessage(ParserValidationMessage.NewError(String.Format("Column specified ({0}) in constraint ({1}) not found as column.", column.Name, this.Name)));
                }
                else
                {
                    columns.Add(columnElement);
                }
            }
            this.columns = columns;
        }
        /// <summary>
        /// return the identity column if it exists, or the primary key columns if they exist
        /// </summary>
        /// <returns></returns>
        public IList GetPrimaryKeyColumns()
        {
            ArrayList     list = new ArrayList();
            ColumnElement id   = GetIdentityColumn();

            if (id != null)
            {
                list.Add(id);
            }
            else
            {
                foreach (ConstraintElement constraint in constraints)
                {
                    if (constraint.Type.ToUpper().Equals("PRIMARY KEY"))
                    {
                        list.AddRange(constraint.Columns);
                    }
                }
            }
            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);
        }
        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);
        }
Example #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 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);
        }
Example #17
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);
        }