Esempio n. 1
0
 private void ProcessAttributes(MetaInfoTable table)
 {
     metaProvider.GetColumns(table);
     foreach (MetaInfoColumn col in table.Columns)
     {
         md.CreateElement("Attribute");
         md.AddAttribute("name", col.Name);
         md.AddAttribute("type", col.Type.Name);
         if (col.HasLength)
         {
             md.AddAttribute("length", col.Length.ToString());
         }
         if (col.HasPrecision)
         {
             md.AddAttribute("precision", col.Precision.ToString());
         }
         md.AddAttribute("persistentType", col.CompletePersistentTypeName);
         md.AddAttribute("persistentName", col.PersistentName);
         if (col.Nullable)
         {
             md.AddAttribute("required", "false");
         }
         table.Node.AppendChild(md.CurrentNode);
     }
 }
        public override string GetUniqueKeysSql(MetaInfoTable table)
        {
            ISqlStringBuilder sql = Importer.Genie.Lamp.GenieLampUtils.GetSqlStringBuilder();

            sql.Select("C.OWNER AS {0}", SqlColName_Schema);
            sql.Select("C.CONSTRAINT_NAME AS {0}", SqlColName_ConstraintName);
            sql.Select("CC.POSITION AS {0}", SqlColName_ColumnPosition);
            sql.Select("C.INDEX_OWNER AS {0}", SqlColName_IndexOwner);
            sql.Select("C.INDEX_NAME AS {0}", SqlColName_IndexName);
            sql.Select("CC.COLUMN_NAME AS {0}", SqlColName_ColumnName);
            sql.From("ALL_CONSTRAINTS C");
            sql.From("INNER JOIN ALL_CONS_COLUMNS CC ON C.OWNER = CC.OWNER AND C.CONSTRAINT_NAME = CC.CONSTRAINT_NAME");
            sql.WhereAnd("C.OWNER='{0}'", table.PersistentSchema);
            sql.WhereAnd("C.TABLE_NAME='{0}'", table.PersistentName);
            sql.WhereAnd("C.CONSTRAINT_TYPE='U'");
            sql.UnionAll();
            sql.Select("I.OWNER AS {0}", SqlColName_Schema);
            sql.Select("I.INDEX_NAME AS {0}", SqlColName_ConstraintName);
            sql.Select("IC.COLUMN_POSITION AS {0}", SqlColName_ColumnPosition);
            sql.Select("I.OWNER AS {0}", SqlColName_IndexOwner);
            sql.Select("I.INDEX_NAME AS {0}", SqlColName_IndexName);
            sql.Select("IC.COLUMN_NAME AS {0}", SqlColName_ColumnName);
            sql.From("ALL_INDEXES I");
            sql.From("INNER JOIN ALL_IND_COLUMNS IC ON I.OWNER = IC.INDEX_OWNER AND I.INDEX_NAME = IC.INDEX_NAME");
            sql.From("LEFT OUTER JOIN ALL_CONSTRAINTS C ON I.OWNER = C.OWNER AND I.INDEX_NAME = C.INDEX_NAME");
            sql.WhereAnd("I.OWNER='{0}'", table.PersistentSchema);
            sql.WhereAnd("I.TABLE_NAME='{0}'", table.PersistentName);
            sql.WhereAnd("I.UNIQUENESS = 'UNIQUE'");
            sql.WhereAnd("C.INDEX_NAME IS NULL");
            sql.OrderBy("1 ASC, 2 ASC, 3 ASC");
            return(sql.ToString());
        }
Esempio n. 3
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. 4
0
        public virtual void GetColumns(MetaInfoTable table)
        {
            table.Columns.Clear();
            foreach (DataRow row in SelectData(GetColumnsSql(table)).Rows)
            {
                MetaInfoColumn col = new MetaInfoColumn();
                col.Table              = table;
                col.PersistentName     = row[SqlColName_ColumnName].ToString();
                col.PersistentTypeName = row[SqlColName_ColumnType].ToString();
                if (!row.IsNull(SqlColName_ColumnTypeLength))
                {
                    col.PersistentLength = int.Parse(row[SqlColName_ColumnTypeLength].ToString());
                    col.Length           = col.PersistentLength;
                }
                if (!row.IsNull(SqlColName_ColumnTypePrecision))
                {
                    col.Precision = int.Parse(row[SqlColName_ColumnTypePrecision].ToString());
                }
                col.Nullable = row[SqlColName_ColumnNullable].ToString().Equals("Y", StringComparison.InvariantCultureIgnoreCase);

                col.Name = Importer.Naming.Convert(col.PersistentName);
                col.Type = this.Environment.ImportType(col.PersistentTypeName, col);

                table.Columns.Add(col);
            }
            Logger.ProgressStep();
            Logger.TraceLine("Table columns {0} imported", table.FullPersistentName);
        }
        public override string GetPrimaryKeySql(MetaInfoTable table)
        {
            ISqlStringBuilder sql = Importer.Genie.Lamp.GenieLampUtils.GetSqlStringBuilder();

            sql.Select("C.CONSTRAINT_NAME AS {0}", SqlColName_ConstraintName);
            sql.Select("CC.COLUMN_NAME AS {0}", SqlColName_ColumnName);
            sql.Select("CC.POSITION AS {0}", SqlColName_ColumnPosition);
            sql.From("ALL_CONSTRAINTS C");
            sql.From("INNER JOIN ALL_CONS_COLUMNS CC ON C.CONSTRAINT_NAME = CC.CONSTRAINT_NAME");
            sql.WhereAnd("C.OWNER='{0}'", table.PersistentSchema);
            sql.WhereAnd("C.TABLE_NAME='{0}'", table.PersistentName);
            sql.WhereAnd("C.CONSTRAINT_TYPE='P'");
            sql.OrderBy("C.CONSTRAINT_NAME, CC.POSITION ASC");
            return(sql.ToString());
        }
Esempio n. 6
0
 public virtual void GetPrimaryKey(MetaInfoTable table)
 {
     table.PrimaryKey = new MetaInfoPrimaryKey();
     foreach (DataRow row in SelectData(GetPrimaryKeySql(table)).Rows)
     {
         if (String.IsNullOrEmpty(table.PrimaryKey.PersistentName))
         {
             table.PrimaryKey.PersistentName = row[SqlColName_ConstraintName].ToString();
             table.PrimaryKey.Name           = Importer.Naming.Convert(table.PrimaryKey.PersistentName);
         }
         table.PrimaryKey.Columns.Add(table.Columns.FindByPersistentName(
                                          row[SqlColName_ColumnName].ToString(), true));
     }
     Logger.ProgressStep();
 }
Esempio n. 7
0
 private void ProcessUniqueKeys(MetaInfoTable table)
 {
     metaProvider.GetUniqueKeys(table);
     foreach (MetaInfoUniqueConstraint uc in table.UniqueConstraints)
     {
         XmlNode ucNode = md.CreateElement("UniqueId");
         md.AddAttribute("persistentName", uc.PersistentName);
         foreach (MetaInfoColumn col in uc.Columns)
         {
             md.CreateElement("OnAttribute");
             md.AddAttribute("name", col.Name);
             ucNode.AppendChild(md.CurrentNode);
         }
         table.Node.AppendChild(ucNode);
     }
 }
        public override string GetColumnsSql(MetaInfoTable table)
        {
            ISqlStringBuilder sql = Importer.Genie.Lamp.GenieLampUtils.GetSqlStringBuilder();

            sql.Select("COLUMN_NAME AS {0}", SqlColName_ColumnName);
            sql.Select("DATA_TYPE AS {0}", SqlColName_ColumnType);
            sql.Select("NVL(DATA_PRECISION, CHAR_LENGTH) AS {0}", SqlColName_ColumnTypeLength);
            sql.Select("NVL(DATA_SCALE, 0) AS {0}", SqlColName_ColumnTypePrecision);
            sql.Select("NULLABLE AS {0}", SqlColName_ColumnNullable);
            sql.Select("COLUMN_ID AS {0}", SqlColName_ColumnPosition);
            sql.From("ALL_TAB_COLUMNS");
            sql.WhereAnd("OWNER='{0}'", table.PersistentSchema);
            sql.WhereAnd("TABLE_NAME='{0}'", table.PersistentName);
            sql.OrderBy("COLUMN_ID ASC");
            return(sql.ToString());
        }
Esempio n. 9
0
        public virtual void GetTables(MetaInfoTables tables)
        {
            tables.Clear();
            foreach (DataRow row in SelectData(GetTablesSql()).Rows)
            {
                MetaInfoTable table = new MetaInfoTable();
                table.PersistentSchema = row[SqlColName_TableSchema].ToString();
                table.PersistentName   = row[SqlColName_TableName].ToString();

                table.Schema = Importer.Naming.Convert(table.PersistentSchema);
                table.Name   = Importer.Naming.Convert(table.PersistentName);

                tables.Add(table);

                Logger.TraceLine("Table {0} imported", table.FullPersistentName);
            }
            Logger.ProgressStep();
        }
Esempio n. 10
0
 public void GetUniqueKeys(MetaInfoTable table)
 {
     table.UniqueConstraints.Clear();
     foreach (DataRow row in SelectData(GetUniqueKeysSql(table)).Rows)
     {
         string persistentSchema     = row[SqlColName_Schema].ToString();
         string persistentName       = row[SqlColName_ConstraintName].ToString();
         MetaInfoUniqueConstraint uc = table.UniqueConstraints.FindByPersistentName(persistentSchema, persistentName, false);
         if (uc == null)
         {
             uc = new MetaInfoUniqueConstraint();
             uc.PersistentSchema = persistentSchema;
             uc.PersistentName   = persistentName;
             table.UniqueConstraints.Add(uc);
         }
         uc.Columns.Add(table.Columns.FindByPersistentName(row[SqlColName_ColumnName].ToString(), true));
     }
     Logger.ProgressStep();
 }
Esempio n. 11
0
        private void ProcessPrimaryKey(MetaInfoTable table)
        {
            metaProvider.GetPrimaryKey(table);
            if (table.PrimaryKey != null)
            {
                XmlNode pkNode = md.CreateElement("PrimaryId");
                if (table.PrimaryKey.Columns.Count > 1)
                {
                    md.AddAttribute("name", table.PrimaryKey.Name);
                }
                md.AddAttribute("persistentName", table.PrimaryKey.PersistentName);
                foreach (MetaInfoColumn col in table.PrimaryKey.Columns)
                {
                    md.CreateElement("OnAttribute");
                    md.AddAttribute("name", col.Name);
                    pkNode.AppendChild(md.CurrentNode);
                }

                // Try to attach generator by name
                if (table.PrimaryKey.Columns.Count == 1)
                {
                    IMacroExpander macro = Genie.Config.Macro.CreateChild();
                    macro.SetMacro("%TABLE%", table.Name);
                    string            generatorTemplate = PersistenceLayerConfig.NamingConvention.Params.ValueByName("Generator.Template", "%TABLE%");
                    MetaInfoGenerator gen = Generators.FindByName(table.Schema, macro.Subst(generatorTemplate), false);
                    if (gen == null)
                    {
                        macro.SetMacro("%TABLE%", table.PersistentName);
                        gen = Generators.FindByPersistentName(table.PersistentSchema, macro.Subst(generatorTemplate), false);
                    }
                    if (gen != null)
                    {
                        md.CurrentNode = pkNode;
                        md.AddAttribute("generator", gen.Name);
                        gen.Node = md.Document.DocumentElement.RemoveChild(gen.Node);
                        md.Document.DocumentElement.InsertBefore(gen.Node, table.Node);
                    }
                }

                table.Node.AppendChild(pkNode);
            }
        }
        public override string GetForeignKeysSql(MetaInfoTable table)
        {
            ISqlStringBuilder sql = Importer.Genie.Lamp.GenieLampUtils.GetSqlStringBuilder();

            sql.Select("C.CONSTRAINT_NAME AS {0}", SqlColName_ConstraintName);
            sql.Select("C.OWNER AS {0}", SqlColName_FKTableSchema);
            sql.Select("C.TABLE_NAME AS {0}", SqlColName_FKTableName);
            sql.Select("CC.COLUMN_NAME AS {0}", SqlColName_ColumnName);
            sql.Select("CC.POSITION AS {0}", SqlColName_ColumnPosition);
            sql.Select("C2.OWNER AS {0}", SqlColName_FKParentTableSchema);
            sql.Select("C2.TABLE_NAME AS {0}", SqlColName_FKParentTableName);
            sql.Select("CC2.COLUMN_NAME AS {0}", SqlColName_FKParentColumnName);
            sql.From("ALL_CONSTRAINTS C");
            sql.From("INNER JOIN ALL_CONS_COLUMNS CC ON C.OWNER = CC.OWNER AND C.CONSTRAINT_NAME = CC.CONSTRAINT_NAME");
            sql.From("INNER JOIN ALL_CONSTRAINTS C2 ON C.R_OWNER = C2.OWNER AND C.R_CONSTRAINT_NAME = C2.CONSTRAINT_NAME");
            sql.From("INNER JOIN ALL_CONS_COLUMNS CC2 ON C2.OWNER = CC2.OWNER AND C2.CONSTRAINT_NAME = CC2.CONSTRAINT_NAME AND CC.POSITION = CC2.POSITION");
            sql.WhereAnd("C.OWNER='{0}'", table.PersistentSchema);
            sql.WhereAnd("C.TABLE_NAME='{0}'", table.PersistentName);
            sql.WhereAnd("C.CONSTRAINT_TYPE='R'");
            sql.OrderBy("C.OWNER, C.TABLE_NAME, C.CONSTRAINT_NAME, CC.POSITION ASC");
            return(sql.ToString());
        }
Esempio n. 13
0
 public abstract string GetForeignKeysSql(MetaInfoTable tabel);
Esempio n. 14
0
 public abstract string GetUniqueKeysSql(MetaInfoTable table);
Esempio n. 15
0
 public abstract string GetPrimaryKeySql(MetaInfoTable table);
Esempio n. 16
0
 public abstract string GetColumnsSql(MetaInfoTable table);