Esempio n. 1
0
 public void GetIndexes(MetaInfoIndexes indexes, MetaInfoTables tables)
 {
     //table.Indexes.Clear();
     foreach (DataRow row in SelectData(GetIndexesSql()).Rows)
     {
         string        persistentSchema = row[SqlColName_IndexOwner].ToString();
         string        persistentName   = row[SqlColName_IndexName].ToString();
         bool          isUnique         = int.Parse(row[SqlColName_IsUnique].ToString()) == 1 ? true : false;
         MetaInfoIndex ix          = indexes.FindByPersistentName(persistentSchema, persistentName, false);
         bool          indexExists = ix != null;
         if (!indexExists)
         {
             ix = new MetaInfoIndex();
             ix.PersistentSchema = persistentSchema;
             ix.PersistentName   = persistentName;
             ix.IsUnique         = isUnique;
         }
         string        tableSchema = row[SqlColName_TableSchema].ToString();
         string        tableName   = row[SqlColName_TableName].ToString();
         MetaInfoTable table       = tables.FindByPersistentName(tableSchema, tableName, true);
         if (table != null)
         {
             ix.Table = table;
             ix.Columns.Add(table.Columns.FindByPersistentName(row[SqlColName_ColumnName].ToString(), true));
             if (!indexExists)
             {
                 table.Indexes.Add(ix);
                 indexes.Add(ix);
             }
         }
         Logger.ProgressStep();
     }
 }
Esempio n. 2
0
        private void ProcessForeignKeys()
        {
            metaProvider.GetForeignKeys(this.Tables);
            metaProvider.GetIndexes(this.Indexes, this.Tables);

            foreach (MetaInfoTable table in this.Tables)
            {
                foreach (MetaInfoForeignKey fk in table.ForeignKeys)
                {
                    md.SetCurrentToRoot();
                    fk.Node = md.CreateElement("Relation");
                    XmlNode commentNode = md.CreateComment("Relation imported from FK {0}", fk.FullPersistentName);
                    md.AddAttribute("name", fk.Name);
                    md.AddAttribute("entity", fk.Child.Name);
                    // name2 will be generated by GL
                    md.AddAttribute("entity2", fk.Parent.Name);
                    md.AddAttribute("cardinality", "M:1");
                    md.AddAttribute("persistentName", fk.PersistentName);

                    // Try to associate with index
                    MetaInfoColumns fkCols = new MetaInfoColumns();
                    foreach (MetaInfoColumnsMatch cm in fk.ColumnsMatches)
                    {
                        fkCols.Add(cm.Child);
                    }
                    MetaInfoIndex ix = this.Indexes.FindByColumns(fkCols);
                    if (ix != null)
                    {
                        md.AddAttribute("indexName", ix.PersistentName);
                        ix.Generate = false;
                    }

                    foreach (MetaInfoColumnsMatch cm in fk.ColumnsMatches)
                    {
                        md.CreateElement("AttributeMatch");
                        md.AddAttribute("attribute", cm.Child.Name);
                        md.AddAttribute("attribute2", cm.Parent.Name);
                        fk.Node.AppendChild(md.CurrentNode);
                    }

                    // Place node after child entity declaration
                    if (fk.Child != null)
                    {
                        md.Document.DocumentElement.InsertAfter(fk.Node, fk.Child.Node);
                    }
                    else
                    {
                        md.Document.DocumentElement.AppendChild(commentNode);
                        md.Document.DocumentElement.AppendChild(fk.Node);
                    }
                }
            }
        }
Esempio n. 3
0
        private void ProcessIndexes()
        {
            // Mark non-generated indexes
            foreach (MetaInfoTable table in this.Tables)
            {
                if (table.PrimaryKey != null)
                {
                    MetaInfoIndex ix = this.Indexes.FindByPersistentName(table.PersistentSchema, table.PrimaryKey.PersistentName, false);
                    if (ix != null)
                    {
                        ix.Generate = false;
                    }
                }

                foreach (MetaInfoUniqueConstraint uc in table.UniqueConstraints)
                {
                    MetaInfoIndex ix = this.Indexes.FindByPersistentName(uc.PersistentSchema, uc.PersistentName, false);
                    if (ix != null)
                    {
                        ix.Generate = false;
                    }
                }
            }


            foreach (MetaInfoIndex ix in this.Indexes)
            {
                if (!ix.Generate)
                {
                    continue;
                }
                md.SetCurrentToRoot();
                md.CreateComment("Index imported from {0}", ix.FullPersistentName);
                ix.Node = md.CreateElement("Index");
                md.AddAttribute("name", ix.PersistentName);
                md.AddAttribute("unique", ix.IsUnique ? "true" : "false");
                md.AddAttribute("entitySchema", ix.Table.Schema);
                md.AddAttribute("entityName", ix.Table.Name);
                foreach (MetaInfoColumn col in ix.Columns)
                {
                    md.CreateElement("OnAttribute");
                    md.AddAttribute("name", col.Name);
                    ix.Node.AppendChild(md.CurrentNode);
                }

                md.Document.DocumentElement.AppendChild(ix.Node);
            }
        }