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();
             */
        }
Beispiel #2
0
 public void AddColumn(Column c)
 {
     Columns.Add(c.Name, c);
 }
Beispiel #3
0
        private IEnumerable<Column> GetPrimaryKey(Column column, Check check)
        {
            var pks = new LinkedList<Column>();

            foreach (Column c in column.ForeignKeyTable.PrimaryKeys.Values)
            {
                if (c.ForeignKeyTable == null || c.ForeignKeyTable != null && check(c.ForeignKeyTable))
                    pks.AddLast(c);
                else
                {
                    pks = (LinkedList<Column>)pks.Concat(GetPrimaryKey(c, check));
                }
            }
            return pks;
        }