Пример #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
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }