コード例 #1
0
        public static void CreateObject()
        {
            XmlDocument xmlDoc = xmlInitialMeta;

            XmlNode database = xmlDoc.GetElementsByTagName("db-schema")[0];
            db = new Database(database.Attributes["name"].Value);

            XmlNodeList tables = xmlDoc.GetElementsByTagName("table");

            foreach (XmlNode t in tables)
            {
                Table table = new Table(t.Attributes["name"].Value);
                db.AddTable(table);

                XmlNodeList columns = t.FirstChild.ChildNodes;
                foreach (XmlNode c in columns)
                {
                    Column column = new Column(c.Attributes["name"].Value, c.Attributes["type"].Value);
                    table.Columns.Add(column.Name, column);
                }

                XmlNodeList constraints = t.LastChild.ChildNodes;

                foreach (XmlNode ct in constraints)
                {
                    if (ct.Name.Equals("primary-key"))
                    {
                        foreach (XmlNode pk in ct.ChildNodes)
                        {
                            table.AddPrimaryKey(pk.Attributes["name"].Value);
                        }
                    }
                    else
                    {
                        String tableRefName = ct.Attributes["references"].Value;
                        Table tableRef;
                        db.Tables.TryGetValue(tableRefName, out tableRef);
                        foreach (XmlNode fk in ct.ChildNodes)
                        {
                            table.AddForeignKey(fk.Attributes["name"].Value, tableRefName, tableRef);
                        }
                    }
                }
            }
            /* Em principio não preciso disto pk as tabelas têm de tar por ordem de FK
             * db.CheckForeignKeys();
             */
        }
コード例 #2
0
ファイル: Database.cs プロジェクト: nmplcpimenta/dw_project
        public void ApplyFlatSchema()
        {
            IEnumerable<Table> minEntities = GetMinEntities();

            Database flat = new Database("Flat Schema");

            foreach (Table t in minEntities)
            {
                Table table = new Table(t.Name);

                Dictionary<String, Column> columns = new Dictionary<string, Column>();
                GetColumns(t, columns, x => false);

                foreach (Column c in columns.Values)
                {
                    table.AddColumn(c);
                }

                foreach (Column pk in t.PrimaryKeys.Values)
                {
                    if (pk.ForeignKeyTable == null)
                        table.AddPrimaryKey(pk.Name);

                    else
                    {
                        IEnumerable<Column> pks = GetPrimaryKey(pk, x => false);

                        foreach (Column c in pks)
                        {
                            table.AddPrimaryKey(c.Name);
                        }
                    }
                }

                flat.AddTable(table);
            }

            Schemas.Add(flat.Name, flat);
        }
コード例 #3
0
ファイル: Table.cs プロジェクト: nmplcpimenta/dw_project
        public void AddForeignKey(String name, String tableName, Table table)
        {
            Column column = Columns[name];

            if (column.ForeignKeyTable == null)
            {
                column.ForeignKeyTableName = tableName;
                column.ForeignKeyTable = table;

                /*Em principio não preciso disto pk as tabelas têm de tar por ordem de FK
                if(table != null)
                {
                    column.ForeignKeyTable = table;
                    column.ForeignKeyTable.NumberOfReferencesByOtherTables++;
                }
                */
            }

            /*Em principio não preciso disto pk as tabelas têm de tar por ordem de FK
            else
            {
                column.ForeignKeyTable.NumberOfReferencesByOtherTables++;
            }
            */

            column.ForeignKeyTable.NumberOfReferencesByOtherTables++;
            Table x;
            if (!column.ForeignKeyTable.IamForeignKeyFor.TryGetValue(Name, out x))
                column.ForeignKeyTable.IamForeignKeyFor.Add(Name, this);
            ForeignKeys.Add(name, column);
            NumberOfForeignKeys++;
        }
コード例 #4
0
ファイル: Column.cs プロジェクト: nmplcpimenta/dw_project
 public void SetTable(Table table)
 {
     ForeignKeyTable = table;
 }
コード例 #5
0
ファイル: Database.cs プロジェクト: nmplcpimenta/dw_project
 public void AddTable(Table table)
 {
     Tables.Add(table.Name, table);
 }
コード例 #6
0
ファイル: Database.cs プロジェクト: nmplcpimenta/dw_project
        private void GetColumns(Table table, Dictionary<String, Column> columns, Check check)
        {
            foreach (Column column in table.Columns.Values)
            {
                if ((column.ForeignKeyTable == null || (column.ForeignKeyTable != null && check(column.ForeignKeyTable))) && !columns.ContainsKey(column.Name))
                    columns.Add(column.Name, new Column(column.Name, column.Type));
            }

            foreach (Column c in table.ForeignKeys.Values)
            {
                if (!check(c.ForeignKeyTable))
                    GetColumns(c.ForeignKeyTable, columns, check);
            }
        }
コード例 #7
0
ファイル: Database.cs プロジェクト: nmplcpimenta/dw_project
        public void ApplyTerraceSchema()
        {
            IEnumerable<Table> transactionEntities = Tables.Values.Where(t => t.EntityType == EntityType.Transaction);

            Database terrace = new Database("Terrace Schema");

            foreach (Table transactionEntity in transactionEntities)
            {
                Table table = new Table(transactionEntity.Name);

                Dictionary<String, Column> columns = new Dictionary<string, Column>();
                GetColumns(transactionEntity, columns, x => x.EntityType == EntityType.Transaction);

                foreach (Column c in columns.Values)
                {
                    table.AddColumn(c);
                }

                foreach (Column pk in transactionEntity.PrimaryKeys.Values)
                {
                    if (pk.ForeignKeyTable == null || (pk.ForeignKeyTable != null && pk.ForeignKeyTable.EntityType == EntityType.Transaction))
                        table.AddPrimaryKey(pk.Name);

                    else
                    {
                        IEnumerable<Column> pks = GetPrimaryKey(pk, x => x.EntityType == EntityType.Transaction);

                        foreach (Column c in pks)
                        {
                            table.AddPrimaryKey(c.Name);
                        }
                    }
                }

                foreach (Column fk in transactionEntity.ForeignKeys.Values)
                {
                    if (fk.ForeignKeyTable.EntityType == EntityType.Transaction)
                    {
                        table.AddForeignKey(fk.Name, fk.ForeignKeyTableName, fk.ForeignKeyTable);
                    }
                }

                terrace.AddTable(table);
            }

            Schemas.Add(terrace.Name, terrace);
        }
コード例 #8
0
ファイル: Database.cs プロジェクト: nmplcpimenta/dw_project
        public void ApplyStarSchema(Table t)
        {
            if (t.EntityType != EntityType.Transaction)
                return; //dar erro

            Database star = new Database("Star Schema For " + t.Name);

            Table factTable = new Table(t.Name);

            foreach (Column column in t.Columns.Values)
            {
                factTable.AddColumn(new Column(column.Name, column.Type));
            }

            foreach (Column column in t.PrimaryKeys.Values)
            {
                factTable.AddPrimaryKey(column.Name);
            }

            star.AddTable(factTable);

            foreach (Column column in t.ForeignKeys.Values)
            {
                if (column.ForeignKeyTable.EntityType != EntityType.Transaction)
                {
                    Table dimensionTable = new Table(column.ForeignKeyTable.Name);

                    Dictionary<String, Column> columns = new Dictionary<string, Column>();
                    GetColumns(column.ForeignKeyTable, columns, x => false);

                    foreach (Column c in columns.Values)
                    {
                        dimensionTable.AddColumn(c);
                    }

                    foreach (Column pk in column.ForeignKeyTable.PrimaryKeys.Values)
                    {
                        if (pk.ForeignKeyTable == null)
                            dimensionTable.AddPrimaryKey(pk.Name);

                        else
                        {
                            IEnumerable<Column> pks = GetPrimaryKey(pk, x => false);

                            foreach (Column c in pks)
                            {
                                dimensionTable.AddPrimaryKey(c.Name);
                            }
                        }
                    }

                    factTable.AddForeignKey(column.Name, dimensionTable.Name, dimensionTable);

                    star.AddTable(dimensionTable);
                }

            }
            Schemas.Add(star.Name, star);
        }