Example #1
0
        public override List <SequenceTable_11> Resolve(DbContextOracle context, Action <SequenceTable_11> action)
        {
            List <SequenceTable_11> List = new List <SequenceTable_11>();

            this.OracleContext = context;
            var db = context.Database;

            if (action == null)
            {
                action =
                    t =>
                {
                    var           name = t.Owner + "." + t.Sequence_name;
                    SequenceModel s;

                    if (db.Sequences.TryGet(name, out s))
                    {
                        s.MinValue    = t.Min_value;
                        s.MaxValue    = t.Max_value;
                        s.IncrementBy = t.Increment_by;
                        s.CycleFlag   = t.Cycle_flag;
                        s.OrderFlag   = t.Order_flag;
                        s.CacheSize   = t.Cache_size;
                    }
                    else
                    {
                        s = new SequenceModel()
                        {
                            Key         = name,
                            Owner       = t.Owner,
                            Name        = t.Sequence_name,
                            MinValue    = t.Min_value,
                            MaxValue    = t.Max_value,
                            IncrementBy = t.Increment_by,
                            CycleFlag   = t.Cycle_flag,
                            OrderFlag   = t.Order_flag,
                            CacheSize   = t.Cache_size,
                            Keep        = SequenceModel.Default.Keep,
                            Session     = SequenceModel.Default.Session,
                        };

                        db.Sequences.Add(s);
                    }
                }
            }
            ;


            SequenceDescriptor_11 view = new SequenceDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition("s", "sequence_owner"));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql))
            {
                List = view.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
Example #2
0
        public override List <TablespacesDto_11> Resolve(DbContextOracle context, Action <TablespacesDto_11> action)
        {
            List <TablespacesDto_11> List = new List <TablespacesDto_11>();
            var db = context.Database;

            this.OracleContext = context;

            if (action == null)
            {
                action =
                    t =>
                {
                    var obj = new TablespaceModel()
                    {
                        Name                   = t.TablespaceName,
                        BlockSize              = t.BlockSize,
                        MaxSize                = t.MaxSize,
                        MinExtlen              = t.MinExtlen,
                        Status                 = t.Status,
                        Contents               = t.Contents,
                        ForceLogging           = t.ForceLogging.ToBoolean(),
                        ExtentManagement       = t.ExtentManagement,
                        AllocationType         = t.AllocationType,
                        PluggedIn              = t.PluggedIn.ToBoolean(),
                        SegmentSpaceManagement = t.SegmentSpaceManagement,
                        DefTabCompression      = t.DefTabCompression,
                        Retention              = t.Retention,
                        Bigfile                = t.Bigfile.ToBoolean(),
                        PredicateEvaluation    = t.PredicateEvaluation,
                        Encrypted              = t.Encrypted.ToBoolean(),
                        CompressFor            = t.CompressFor,
                        GroupName              = t.GroupName,
                    };

                    obj.PhysicalAttributes.Logging       = t.Logging;
                    obj.PhysicalAttributes.InitialExtent = t.InitialExtent;
                    obj.PhysicalAttributes.NextExtent    = t.NextExtent;
                    obj.PhysicalAttributes.MinExtents    = t.MinExtents;
                    obj.PhysicalAttributes.MaxExtents    = t.MaxExtents;
                    obj.PhysicalAttributes.PctIncrease   = t.PctIncrease;

                    db.Tablespaces.Add(obj);
                }
            }
            ;

            TablespacesQueryDescriptor_11 Tablespaces = new TablespacesQueryDescriptor_11(context.Manager.ConnectionString);

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = Tablespaces.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
Example #3
0
        public override List <TriggerQueryTable_11> Resolve(DbContextOracle context, Action <TriggerQueryTable_11> action)
        {
            List <TriggerQueryTable_11> List = new List <TriggerQueryTable_11>();
            var triggers = context.Database.Triggers;

            this.OracleContext = context;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (!string.IsNullOrEmpty(t.table_name) && t.table_name.ExcludIfStartwith(t.table_owner, Models.Configurations.ExcludeKindEnum.Table))
                    {
                        return;
                    }

                    TriggerModel trigger = new TriggerModel()
                    {
                        ActionType     = t.ACTION_TYPE.Trim(),
                        BaseObjectType = t.base_object_type,
                        Code           = string.Empty,
                        Description    = t.DESCRIPTION,
                        Key            = t.owner + "." + t.trigger_name,
                        Status         = t.status,
                        Name           = t.trigger_name,
                        TriggerStatus  = t.trigger_status,
                        TriggerType    = t.TRIGGER_TYPE,
                    };
                    trigger.TableReference.Owner = t.table_owner;
                    trigger.TableReference.Name  = t.table_name;

                    trigger.Key = trigger.BuildKey();

                    if (triggers.TryGet(trigger.Key, out TriggerModel trigger2))
                    {
                        triggers.Remove(trigger2);
                    }

                    triggers.Add(trigger);
                }
            }
            ;

            TriggerQueryDescriptor_11 Trigger = new TriggerQueryDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition("t", "owner"));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = Trigger.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
Example #4
0
        public override List <ModelProc_11> Resolve(DbContextOracle context, Action <ModelProc_11> action)
        {
            List <ModelProc_11> List = new List <ModelProc_11>();
            string colName           = string.Empty;
            var    db = context.Database;

            this.OracleContext = context;

            HashSet <object> _h = new HashSet <object>();

            if (action == null)
            {
                action =
                    t =>
                {
                    ProcedureModel proc = null;

                    if (t.OBJECT_NAME.ExcludIfStartwith(t.OWNER, Models.Configurations.ExcludeKindEnum.Procedure))
                    {
                        return;
                    }

                    if (t.OBJECT_NAME == t.PROCEDURE_NAME)
                    {
                        return;
                    }

                    proc = new ProcedureModel()
                    {
                        Owner       = t.OWNER,
                        PackageName = string.IsNullOrEmpty(t.PROCEDURE_NAME) ? string.Empty : t.OBJECT_NAME,
                        Name        = string.IsNullOrEmpty(t.PROCEDURE_NAME) ? t.OBJECT_NAME : t.PROCEDURE_NAME,
                        IsFunction  = false,
                    };
                    proc.Key = proc.BuildKey();

                    if (!db.Procedures.Contains(proc.Key))
                    {
                        db.Procedures.Add(proc);
                    }
                }
            }
            ;

            sql = string.Format(sql, TableQueryAndCondition());
            ProcDescriptor_11 view = new ProcDescriptor_11(context.Manager.ConnectionString);

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                view.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
        public override List <ContentCodeQueryTable_11> Resolve(DbContextOracle context, Action <ContentCodeQueryTable_11> action)
        {
            List <ContentCodeQueryTable_11> List = new List <ContentCodeQueryTable_11>();
            var db = context.Database;

            this.OracleContext = context;
            var _p = db.Procedures.Cast <ProcedureModel>().ToLookup(c => c.Name);

            Dictionary <string, List <KeyValuePair <int, string> > > _dic = new Dictionary <string, List <KeyValuePair <int, string> > >();

            if (action == null)
            {
                action =
                    t =>
                {
                    if (t.name.ExcludIfStartwith(t.owner, Models.Configurations.ExcludeKindEnum.Procedure))
                    {
                        return;
                    }

                    string key = t.type + "." + t.owner + "." + t.name;

                    List <KeyValuePair <int, string> > sb;
                    if (!_dic.TryGetValue(key, out sb))
                    {
                        sb = new List <KeyValuePair <int, string> >();
                        _dic.Add(key, sb);
                    }
                    sb.Add(new KeyValuePair <int, string>(t.line, t.text));
                }
            }
            ;

            ContentCodeQueryDescriptor_11 ContentCode = new ContentCodeQueryDescriptor_11(context.Manager.ConnectionString);
            string _sql = string.Format(sql, TableQueryWhereCondition("s", "owner", "name"));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, _sql, QueryBase.DbParams.ToArray()))
            {
                List = ContentCode.ReadAll(reader, action).ToList();
            }

            Sources = new List <CodeSource>();

            Build(db, _p, _dic);

            return(List);
        }
Example #6
0
        public override List <EncryptedTableColumnDto_11> Resolve(DbContextOracle context, Action <EncryptedTableColumnDto_11> action)
        {
            List <EncryptedTableColumnDto_11> List = new List <EncryptedTableColumnDto_11>();

            this.OracleContext = context;
            var db = context.Database;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (t.TableName.ExcludIfStartwith(t.Owner, Models.Configurations.ExcludeKindEnum.Table))
                    {
                        return;
                    }

                    string     key = t.Owner + "." + t.TableName;
                    TableModel table;

                    if (db.Tables.TryGet(key, out table))
                    {
                        var u = table.Columns[t.ColumnName];
                        if (u != null)
                        {
                            u.EncryptionAlg = t.EncryptionAlg;
                            u.Salt          = t.Salt.ToBoolean();
                            u.IntegrityAlg  = t.IntegrityAlg;
                        }
                    }
                }
            }
            ;

            EncryptedTableColumnQueryDescriptor_11 EncryptedTableColumn = new EncryptedTableColumnQueryDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition("e", "Owner"));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = EncryptedTableColumn.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
        public Version GetVersion(DbContextOracle context)
        {
            string sql = "select BANNER from v$version WHERE BANNER LIKE 'CORE%'";

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                while (reader.Read())
                {
                    var str = reader.GetString(0)?.Substring(5).Split('\t')[0];
                    var o   = str.Split('.').Select(c => int.Parse(c)).ToArray();
                    var v   = new Version(o[0], o[1], o[2], o[3]);
                    return(v);
                }
            }

            return(null);
        }
Example #8
0
        public override List <AllModelObject> Resolve(DbContextOracle context, Action <AllModelObject> action)
        {
            List <AllModelObject> List = new List <AllModelObject>();
            var db = context.database;

            this.OracleContext = context;

            AllObjectDescriptor objets = new AllObjectDescriptor(context.Manager.ConnectionString);

            sql = string.Format(sql, In(this.OwnerNames.ToArray()));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = objets.ReadAll(reader, action).ToList();
            }

            return(List);
        }
Example #9
0
        public override List <OwnerNameQueryTable_11> Resolve(DbContextOracle context, Action <OwnerNameQueryTable_11> action)
        {
            List <OwnerNameQueryTable_11> List = new List <OwnerNameQueryTable_11>();
            HashSet <string> excluded          = new HashSet <string> {
                "EXFSYS", "MDSYS", "PUBLIC", "OUTLN", "CTXSYS", "HR", "FLOWS_FILES", "SYSTEM", "ORACLE_OCM", "DBSNMP", "APPQOSSYS", "XDB", "SYS", "ORDSYS", "ORDPLUGINS", "SYSMAN", "ORDDATA", "SI_INFORMTN_SCHEMA", "PERFSTAT"
            };

            this.OracleContext = context;
            var db = context.Database;

            StringBuilder _owners = new StringBuilder(100);

            if (action == null)
            {
                action =
                    t =>
                {
                    if (!excluded.Contains(t.OWNER) && !t.OWNER.StartsWith("APEX_"))
                    {
                        _owners.Append(t.OWNER);
                        _owners.Append(";");
                    }
                }
            }
            ;

            OwnerNameQueryDescriptor_11 OwnerName = new OwnerNameQueryDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition("l"));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = OwnerName.ReadAll(reader, action).ToList();
            }

            if (_owners.Length > 0)
            {
                _owners.Remove(_owners.Length - 1, 1);
                db.AvailableOwner = _owners.ToString();
            }

            return(List);
        }
    }
Example #10
0
        public override List <ViewQueryTable_11> Resolve(DbContextOracle context, Action <ViewQueryTable_11> action)
        {
            List <ViewQueryTable_11> List = new List <ViewQueryTable_11>();
            var db = context.Database;

            this.OracleContext = context;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (t.ObjectName.ExcludIfStartwith(t.SchemaName, Models.Configurations.ExcludeKindEnum.View))
                    {
                        return;
                    }

                    string key = t.SchemaName + "." + t.ObjectName;

                    TableModel table;

                    if (db.Tables.TryGet(key, out table))
                    {
                        table.IsView = true;
                    }
                }
            }
            ;


            ViewQueryDescriptor_11 view = new ViewQueryDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition());

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = view.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
        public override List <MaterializedViewSourceQueryTable_11> Resolve(DbContextOracle context, Action <MaterializedViewSourceQueryTable_11> action)
        {
            List <MaterializedViewSourceQueryTable_11> List = new List <MaterializedViewSourceQueryTable_11>();

            this.OracleContext = context;
            var db = context.Database;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (t.ObjectName.ExcludIfStartwith(t.SchemaName, Models.Configurations.ExcludeKindEnum.View))
                    {
                        return;
                    }

                    string key = t.SchemaName + "." + t.ObjectName;

                    TableModel table;
                    if (!db.Tables.TryGet(key, out table))
                    {
                        table = new TableModel()
                        {
                            Key = key, Name = t.ObjectName, IsView = true, IsMaterializedView = true, Owner = t.SchemaName, Comment = "", Generated = false, Parsed = true
                        };
                        db.Tables.Add(table);
                    }

                    StringBuilder sb = new StringBuilder(t.Source.Length + 200);

                    sb.Append(t.Source.Trim().Trim(' ', '\t', '\r', '\n'));

                    if (sb[sb.Length - 1] != ';')
                    {
                        sb.AppendLine(string.Empty);
                        sb.AppendLine(";");
                    }
                    else
                    {
                        sb.AppendLine(string.Empty);
                    }

                    if (!string.IsNullOrEmpty(t.Comments))
                    {
                        table.Comment = t.Comments;
                    }

                    table.IsView             = true;
                    table.IsMaterializedView = true;

                    table.CodeView = GetSource(sb.ToString());
                }
            }
            ;

            MaterializedViewSourceQueryDescriptor_11 view = new MaterializedViewSourceQueryDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition());

//            context.Manager.ExecuteNonQuery(CommandType.Text, @"BEGIN
// DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'TABLESPACE', FALSE);
//END;");
            context.Manager.ExecuteNonQuery(CommandType.Text, @"BEGIN
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM, 'STORAGE', FALSE);
END;");
            context.Manager.ExecuteNonQuery(CommandType.Text, @"BEGIN
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM, 'SEGMENT_ATTRIBUTES', TRUE);
END;");

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = view.ReadAll(reader, action).ToList();
            }

            return(List);
        }
Example #12
0
        public override List <ConstraintColumnTable_11> Resolve(DbContextOracle context, Action <ConstraintColumnTable_11> action)
        {
            this.OracleContext = context;
            List <ConstraintColumnTable_11> list = new List <ConstraintColumnTable_11>();
            var db = context.Database;

            if (action == null)
            {
                action = t =>
                {
                    if (!context.Use(t.Owner))
                    {
                        return;
                    }

                    if (t.TableName.ExcludIfStartwith(t.Owner, Models.Configurations.ExcludeKindEnum.Table))
                    {
                        return;
                    }

                    string keyTable = t.Owner + "." + t.TableName;

                    TableModel table;

                    if (db.Tables.TryGet(keyTable, out table))
                    {
                        string keyContraint = t.Owner + "." + t.CONSTRAINT_NAME;

                        var ct = db.Constraints[keyContraint];

                        ct.Columns.Add(new ConstraintColumnModel()
                        {
                            ColumnName = t.ColumnName, Position = t.Position
                        });

                        if (ct.Type.Equals("P"))    // Primary Key check
                        {
                            //table.Columns[t.ColumnName].IsPrimaryKey = true;
                            SetPrimaryKeyColumn(table.Columns, t.ColumnName);
                        }
                        else if (ct.Type.Equals("F")) // Foreign Key check
                        {
                            SetForeignKeyColumn(table.Columns, t.ColumnName);
                        }
                        else
                        {
                        }
                    }
                }
            }
            ;


            ConstraintColumnDescriptor_11 view = new ConstraintColumnDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition());

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                list = view.ReadAll(reader, action).ToList();
            }

            return(list);
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="columns"></param>
        /// <param name="columnName"></param>
        void SetPrimaryKeyColumn(ColumnCollection columns, string columnName)
        {
            foreach (ColumnModel column in columns)
            {
                if (column.Name == columnName)
                {
                    column.IsPrimaryKey = true;
                    break;
                }
            }
        }

        void SetForeignKeyColumn(ColumnCollection columns, string columnName)
        {
            foreach (ColumnModel column in columns)
            {
                if (column.Name == columnName)
                {
                    column.ForeignKey.IsForeignKey = true;
                    break;
                }
            }
        }
    }
Example #13
0
        public override List <SynonymTable_11> Resolve(DbContextOracle context, Action <SynonymTable_11> action)
        {
            List <SynonymTable_11> List = new List <SynonymTable_11>();
            var db = context.Database;

            this.OracleContext = context;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (!context.Use(t.SYNONYME_OWNER))
                    {
                        return;
                    }

                    string key = string.Empty;
                    if (!string.IsNullOrEmpty(t.SYNONYME_OWNER))
                    {
                        key = $"{t.SYNONYME_OWNER}.";
                    }
                    else
                    {
                    }
                    key += $"{t.SYNONYME_NAME}:{t.OBJECT_OWNER}.{t.OBJECT_NAME}:{t.DB_LINK ?? string.Empty}";

                    if (!string.IsNullOrEmpty(t.OBJECT_OWNER))
                    {
                        if (!ContextLoader.excluded.Contains(t.OBJECT_OWNER))
                        {
                            var syn = new SynonymModel()
                            {
                                Key = key,
                                //ObjectType = t.OBJECT_TYPE,
                                ObjectTargetName  = t.OBJECT_NAME,
                                Name              = t.SYNONYME_NAME,
                                ObjectTargetOwner = t.OBJECT_OWNER,
                                Owner             = t.SYNONYME_OWNER,
                                IsPublic          = t.SYNONYME_OWNER.ToUpper() == "PUBLIC",
                                DbLink            = t.DB_LINK ?? string.Empty,
                            };
                            db.Synonyms.Add(syn);
                        }
                    }
                }
            }
            ;


            SynonymDescriptor_11 view = new SynonymDescriptor_11(context.Manager.ConnectionString);

            var c = (TableQueryAndCondition("o", "OBJECT_OWNER")
                     + " OR " + GetQueryCondition("t", "OWNER", "")).Trim().Substring(3);

            sql = string.Format(sql, " WHERE " + c);

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql))
            {
                List = view.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
Example #14
0
        public override List <ViewSourceQueryTable_11> Resolve(DbContextOracle context, Action <ViewSourceQueryTable_11> action)
        {
            List <ViewSourceQueryTable_11> List = new List <ViewSourceQueryTable_11>();

            this.OracleContext = context;
            var db = context.Database;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (t.ObjectName.ExcludIfStartwith(t.SchemaName, Models.Configurations.ExcludeKindEnum.View))
                    {
                        return;
                    }

                    string key = t.SchemaName + "." + t.ObjectName;

                    TableModel table;

                    if (db.Tables.TryGet(key, out table))
                    {
                        StringBuilder sb = new StringBuilder(t.Source.Length + 2);
                        sb.Append(t.Source.Trim().Trim(' ', '\t', '\r', '\n'));

                        if (!t.Source.Trim().EndsWith(";"))
                        {
                            sb.AppendLine(string.Empty);
                            sb.AppendLine(";");
                        }
                        else
                        {
                            sb.AppendLine(string.Empty);
                        }

                        //if (!string.IsNullOrEmpty(table.Comment))
                        //    sb.AppendLine(string.Format(@"COMMENT ON TABLE ""{0}"".""{1}"" is '{2}';", table.SchemaName, table.Name, table.Comment.Replace("'", "''")));

                        //foreach (ColumnModel item in table.Columns.OfType<ColumnModel>().OrderBy(c => c.Key))
                        //    if (!string.IsNullOrEmpty(item.Description))
                        //        sb.AppendLine(string.Format(@"COMMENT ON COLUMN ""{0}"".""{1}"".""{2}"" is '{3}';", table.SchemaName, table.Name, item.ColumnName, item.Description.Replace("'", "''")));

                        table.IsView = true;

                        table.CodeView = GetSource(sb.ToString());
                    }
                    else
                    {
                    }
                }
            }
            ;


            ViewSourceQueryDescriptor_11 view = new ViewSourceQueryDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition());

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = view.ReadAll(reader, action).ToList();
            }

            return(List);
        }
        public override List <TableDefaultValueTable_11> Resolve(DbContextOracle context, Action <TableDefaultValueTable_11> action)
        {
            List <TableDefaultValueTable_11> List = new List <TableDefaultValueTable_11>();
            var db = context.Database;

            this.OracleContext = context;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (!context.Use(t.SchemaName))
                    {
                        return;
                    }

                    if (t.TableName.ExcludIfStartwith(t.SchemaName, Models.Configurations.ExcludeKindEnum.Table))
                    {
                        return;
                    }

                    string     key = t.SchemaName + "." + t.TableName;
                    TableModel table;
                    if (db.Tables.TryGet(key, out table))
                    {
                        if (t.DefaultLenght > 0)
                        {
                            if (table != null)
                            {
                                var c = table.Columns.OfType <ColumnModel>().FirstOrDefault(d => d.Name == t.ColumnName);
                                if (c != null)
                                {
                                    var d = t.DefaultValue;
                                    if (d != null)
                                    {
                                        c.Type.DataDefault   = d.ToString()?.Trim();
                                        c.Type.defaultLength = c.Type.DataDefault.Length;

                                        //if (c.Type.DataType.ToUpper().Equals("NUMBER"))
                                        //{
                                        //    Regex digitsOnly = new Regex(@"[^\d]");
                                        //    c.Type.DataDefault = digitsOnly.Replace(d.ToString(), "").PadLeft(c.Type.defaultLength, '0');
                                        //}
                                        //else
                                        //{
                                        //    c.Type.DataDefault = defaultvalue;
                                        //}
                                    }
                                }
                            }
                        }
                    }
                }
            }
            ;


            TableDefaultValueDescriptor_11 view = new TableDefaultValueDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryAndCondition());

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = view.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
Example #16
0
        public override List <TypeTable_11> Resolve(DbContextOracle context, Action <TypeTable_11> action)
        {
            var db = context.Database;
            List <TypeTable_11> List = new List <TypeTable_11>();

            this.OracleContext = context;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (!string.IsNullOrEmpty(t.OWNER) && t.TYPE_NAME.ExcludIfStartwith(t.OWNER, Models.Configurations.ExcludeKindEnum.Type))
                    {
                        return;
                    }

                    if (!context.Use(t.OWNER))
                    {
                        return;
                    }

                    string   key = t.OWNER + "." + t.TYPE_NAME;
                    TypeItem type;

                    if (!db.Types.TryGet(key, out type))
                    {
                        string superType = string.Empty;
                        if (!string.IsNullOrEmpty(t.SUPERTYPE_OWNER))
                        {
                            superType += t.SUPERTYPE_OWNER + ".";
                        }
                        if (!string.IsNullOrEmpty(t.SUPERTYPE_NAME))
                        {
                            superType += t.SUPERTYPE_NAME;
                        }

                        type = new TypeItem()
                        {
                            Key                  = key,
                            Name                 = t.TYPE_NAME,
                            SuperType            = superType,
                            Owner                = t.OWNER,
                            TypeCode             = t.TYPECODE,
                            CollectionSchemaName = t.COLLECTIONTYPE,
                            CollectionTypeName   = t.COLLECTIONNAME
                        };
                        db.Types.Add(type);
                    }

                    var p = new PropertyModel()
                    {
                        Name      = !string.IsNullOrEmpty(t.ATTR_NAME) ? Regex.Replace(t.ATTR_NAME, "[^\\w\\._]", "") : string.Empty,
                        Inherited = t.INHERITED,
                        IsNotNull = false,
                    };

                    p.Type.Name = t.ATTR_TYPE_NAME;
                    //p.Type.CsType = TypeMatchExtension.Match(t.ATTR_TYPE_NAME, t.Lenght, t.Precision, 0);
                    p.Type.DataLength    = t.Lenght;
                    p.Type.DataPrecision = t.Precision;

                    type.Properties.Add(p);
                }
            }
            ;


            TypeDescriptor_11 view = new TypeDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, ProcQueryWhereCondition);

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql))
            {
                List = view.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
Example #17
0
        public override List <GrantQueryTable_11> Resolve(DbContextOracle context, Action <GrantQueryTable_11> action)
        {
            GrantModel grant;

            this.OracleContext = context;
            List <GrantQueryTable_11> List = new List <GrantQueryTable_11>();
            var             db             = context.Database;
            GrantCollection grants         = null;

            if (db != null)
            {
                grants = db.Grants;
            }

            HashSet <string> _grants = new HashSet <string>();

            if (action == null)
            {
                action =
                    t =>
                {
                    if (!t.Table_name.ExcludIfStartwith(t.Owner, ExcludeKindEnum.Table))
                    {
                        string key = t.Owner + "." + t.Table_name
                                     + (!string.IsNullOrEmpty(t.Column_name)
                                       ? ("." + t.Column_name)
                                       : string.Empty) +
                                     "_to_" + t.Role
                        ;

                        if (_grants.Add(key))
                        {
                            string FullObjectName = !string.IsNullOrEmpty(t.Column_name) ? @"""" + t.Column_name + @"""" : string.Empty;

                            if (!string.IsNullOrEmpty(t.Table_name))
                            {
                                if (!string.IsNullOrEmpty(FullObjectName))
                                {
                                    FullObjectName = "." + FullObjectName;
                                }
                                FullObjectName = @"""" + t.Table_name + @"""" + FullObjectName;
                            }

                            if (!string.IsNullOrEmpty(t.Owner))
                            {
                                if (!string.IsNullOrEmpty(FullObjectName))
                                {
                                    FullObjectName = "." + FullObjectName;
                                }
                                FullObjectName = @"""" + t.Owner + @"""" + FullObjectName;
                            }

                            grant = new GrantModel()
                            {
                                Key              = key,
                                Role             = t.Role,
                                ObjectSchema     = t.Owner,
                                ObjectName       = t.Table_name,
                                ColumnObjectName = t.Column_name ?? string.Empty,
                                Grantable        = t.Grantable,
                                Hierarchy        = t.Hierarchy
                            };

                            grants.Add(grant);
                        }
                        else
                        {
                            grant           = grants[key];
                            grant.Grantable = t.Grantable;
                            grant.Hierarchy = t.Hierarchy;
                        }

                        var p = new PrivilegeModel()
                        {
                            Name = t.Privilege
                        };
                        // AddIfNotExist -> can be duplicated because same privilege can given by many grantor
                        grant.Privileges.AddIfNotExist(p);
                    }
                }
            }
            ;

            GrantQueryDescriptor_11 Grant = new GrantQueryDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition("t"), TableQueryWhereCondition("r"));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = Grant.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
Example #18
0
        public override List <ModelObject_11> Resolve(DbContextOracle context, Action <ModelObject_11> action)
        {
            List <ModelObject_11> List = new List <ModelObject_11>();
            var db = context.Database;

            this.OracleContext = context;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (!context.Use(t.Owner))
                    {
                        return;
                    }

                    switch (t.Type)
                    {
                    case "INDEX":
                    case "INDEX PARTITION":
                    case "INDEX SUBPARTITION":
                    case "INDEXTYPE":

                    case "TRIGGER":

                    case "CLUSTER":
                    case "CONSUMER GROUP":
                    case "CONTEXT":
                    case "DATABASE LINK":
                    case "DESTINATION":
                    case "DIRECTORY":
                    case "EDITION":
                    case "EVALUATION CONTEXT":
                    case "JAVA CLASS":
                    case "JAVA DATA":
                    case "JAVA RESOURCE":
                    case "JAVA SOURCE":
                    case "JOB":
                    case "JOB CLASS":
                    case "LIBRARY":
                    case "LOB":
                    case "LOB PARTITION":
                    case "OPERATOR":
                    case "PACKAGE":
                    case "PACKAGE BODY":
                    case "PROGRAM":
                    case "QUEUE":
                    case "RESOURCE PLAN":
                    case "RULE":
                    case "RULE SET":
                    case "SCHEDULE":
                    case "SCHEDULER GROUP":
                    case "SYNONYM":
                    case "TABLE PARTITION":
                    case "TABLE SUBPARTITION":
                    case "TYPE":
                    case "TYPE BODY":
                    case "UNDEFINED":
                    case "WINDOW":
                    case "XML SCHEMA":
                        break;

                    case "FUNCTION":
                        break;
                    //case "SEQUENCE":
                    //    db.Add(new SequenceModel() { SequenceName = t.Name, Name = t.Owner + "." + t.Name, Owner = t.Owner, Comment = t.Comment, Generated = t.GENERATED, Status = t.STATUS, Temporary = t.TEMPORARY, Parsed = true });
                    //    break;

                    case "TABLE":
                        if (!t.Name.ExcludIfStartwith(t.Owner, Models.Configurations.ExcludeKindEnum.Table))
                        {
                            db.Tables.Add(new TableModel()
                            {
                                Key = t.Owner + "." + t.Name, Name = t.Name, Owner = t.Owner, Comment = t.Comment, Generated = t.GENERATED, Status = t.STATUS, Temporary = t.TEMPORARY, Parsed = true
                            });
                        }
                        break;

                    //case "MATERIALIZED VIEW":
                    //    db.Add(new TableModel() { Key = t.Owner + "." + t.Name, Name = t.Name, IsView = true, IsMatrializedView = true, SchemaName = t.Owner, Comment = t.Comment, Generated = t.GENERATED, Status = t.STATUS, Temporary = t.TEMPORARY, Parsed = true });
                    //    break;

                    case "VIEW":
                        if (!t.Name.ExcludIfStartwith(t.Owner, Models.Configurations.ExcludeKindEnum.View))
                        {
                            db.Tables.Add(new TableModel()
                            {
                                Key = t.Owner + "." + t.Name, Name = t.Name, IsView = true, Owner = t.Owner, Comment = t.Comment, Generated = t.GENERATED, Status = t.STATUS, Temporary = t.TEMPORARY, Parsed = true
                            });
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            ;

            ObjectDescriptor_11 objets = new ObjectDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, QueryBase.In("TABLE", "VIEW", "SEQUENCE"), TableQueryAndCondition("t", "OWNER"));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = objets.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
        public override List <TablePartitionColumnDto_11> Resolve(DbContextOracle context, Action <TablePartitionColumnDto_11> action)
        {
            List <TablePartitionColumnDto_11> List = new List <TablePartitionColumnDto_11>();

            this.OracleContext = context;
            var db = context.Database;

            if (action == null)
            {
                action =
                    t =>
                {
                    string k = t.Owner + "." + t.TableName;

                    if (t.TableName.ExcludIfStartwith(t.Owner, Models.Configurations.ExcludeKindEnum.Table))
                    {
                        return;
                    }

                    TableModel table;
                    if (db.Tables.TryGet(k, out table))
                    {
                        table.BlocPartition.PartitioningType    = t.PartitioningType;
                        table.BlocPartition.SubpartitioningType = t.SubpartitioningType;
                        //table.BlocPartition.PartitionCount = t.PartitionCount;
                        //table.BlocPartition.DefSubpartitionCount = t.DefSubpartitionCount;
                        //table.BlocPartition.PartitioningKeyCount = t.PartitioningKeyCount;
                        //table.BlocPartition.SubpartitioningKeyCount = t.SubpartitioningKeyCount;
                        table.BlocPartition.Status               = t.Status;
                        table.BlocPartition.DefMaxSize           = t.DefMaxSize;
                        table.BlocPartition.DefCompression       = t.DefCompression;
                        table.BlocPartition.DefCompressFor       = t.DefCompressFor;
                        table.BlocPartition.DefCellFlashCache    = t.DefCellFlashCache;
                        table.BlocPartition.RefPtnConstraintName = t.RefPtnConstraintName;
                        table.BlocPartition.Interval             = t.Interval;
                        table.BlocPartition.IsNested             = t.IsNested.ToBoolean();
                        table.BlocPartition.DefSegmentCreation   = t.DefSegmentCreation;

                        table.BlocPartition.PhysicalAttributes.Logging       = t.DefLogging;
                        table.BlocPartition.PhysicalAttributes.PctFree       = t.DefPctFree;
                        table.BlocPartition.PhysicalAttributes.PctUsed       = t.DefPctUsed;
                        table.BlocPartition.PhysicalAttributes.IniTrans      = t.DefIniTrans;
                        table.BlocPartition.PhysicalAttributes.MaxTrans      = t.DefMaxTrans;
                        table.BlocPartition.PhysicalAttributes.InitialExtent = t.DefInitialExtent;
                        table.BlocPartition.PhysicalAttributes.NextExtent    = t.DefNextExtent;
                        table.BlocPartition.PhysicalAttributes.MinExtents    = t.DefMinExtents;
                        table.BlocPartition.PhysicalAttributes.MaxExtents    = t.DefMaxExtents;

                        table.BlocPartition.PhysicalAttributes.BufferPool     = t.DefBufferPool;
                        table.BlocPartition.PhysicalAttributes.PctIncrease    = t.DefPctIncrease;
                        table.BlocPartition.PhysicalAttributes.Freelists      = t.DefFreelists;
                        table.BlocPartition.PhysicalAttributes.FreelistGroups = t.DefFreelistGroups;
                        table.BlocPartition.PhysicalAttributes.FlashCache     = t.DefFlashCache;

                        table.BlocPartition.PhysicalAttributes.Tablespace.Name = t.DefTablespaceName;
                    }
                }
            }
            ;

            TablePartitionColumnQueryDescriptor_11 TablePartitionColumn = new TablePartitionColumnQueryDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition("l", "Owner"));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = TablePartitionColumn.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
Example #20
0
        public override List <TableDto_11> Resolve(DbContextOracle context, Action <TableDto_11> action)
        {
            List <TableDto_11> List = new List <TableDto_11>();

            this.OracleContext = context;
            var db = context.Database;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (t.TableName.ExcludIfStartwith(t.Owner, Models.Configurations.ExcludeKindEnum.Table))
                    {
                        return;
                    }

                    string     key = t.Owner + "." + t.TableName;
                    TableModel table;

                    if (db.Tables.TryGet(key, out table))
                    {
                        table.ClusterName    = t.ClusterName;
                        table.Status         = t.Status;
                        table.Cache          = t.Cache.ToBoolean();
                        table.TableLock      = t.TableLock;
                        table.Partitioned    = t.Partitioned.ToBoolean();
                        table.Temporary      = t.Temporary.ToBoolean();
                        table.Secondary      = t.Secondary.ToBoolean();
                        table.Nested         = t.Nested.ToBoolean();
                        table.BufferPool     = t.BufferPool;
                        table.FlashCache     = t.FlashCache;
                        table.CellFlashCache = t.CellFlashCache;
                        table.RowMovement    = t.RowMovement.ToBoolean();
                        table.GlobalStats    = t.GlobalStats.ToBoolean();
                        table.UserStats      = t.UserStats.ToBoolean();
                        table.Duration       = t.Duration;
                        table.SkipCorrupt    = t.SkipCorrupt;
                        table.Monitoring     = t.Monitoring.ToBoolean();
                        table.ClusterOwner   = t.ClusterOwner;
                        table.Dependencies   = t.Dependencies.ToBoolean();
                        table.Compression    = t.Compression.ToBoolean();
                        table.CompressFor    = t.CompressFor;
                        table.Dropped        = t.Dropped.ToBoolean();
                        table.ReadOnly       = t.ReadOnly.ToBoolean();
                        table.SegmentCreated = t.SegmentCreated.ToBoolean();
                        table.ResultCache    = t.ResultCache;

                        table.PhysicalAttributes.PctFree       = t.PctFree;
                        table.PhysicalAttributes.PctUsed       = t.PctUsed;
                        table.PhysicalAttributes.InitialExtent = t.InitialExtent;
                        table.PhysicalAttributes.NextExtent    = t.NextExtent;
                        table.PhysicalAttributes.MinExtents    = t.MinExtents;
                        table.PhysicalAttributes.MaxExtents    = t.MaxExtents;
                        table.PhysicalAttributes.IniTrans      = t.IniTrans;
                        table.PhysicalAttributes.MaxTrans      = t.MaxTrans;
                        table.PhysicalAttributes.Logging       = t.Logging;

                        table.PhysicalAttributes.Tablespace.Name = t.TablespaceName;
                    }
                }
            }
            ;

            TableQueryDescriptor_11 Table = new TableQueryDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition("l", "Owner"));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = Table.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
        public override List <SubPartitionsDto> Resolve(DbContextOracle context, Action <SubPartitionsDto> action)
        {
            List <SubPartitionsDto> List = new List <SubPartitionsDto>();
            var db = context.Database;

            this.OracleContext = context;

            if (action == null)
            {
                action =
                    t =>
                {
                    var partition = db.Partitions[t.PartitionName];

                    if (partition != null)
                    {
                        if (partition.SubPartitions.Contains(t.SubpartitionName))
                        {
                            var sub = new SubPartitionModel()
                            {
                                Name                 = t.SubpartitionName,
                                HighValue            = t.HighValue,
                                HighValueLength      = t.HighValueLength,
                                SubpartitionPosition = t.SubpartitionPosition,
                                MaxSize              = t.MaxSize,
                                Compression          = t.Compression,
                                CompressFor          = t.CompressFor,
                                NumRows              = t.NumRows,
                                Blocks               = t.Blocks,
                                EmptyBlocks          = t.EmptyBlocks,
                                //AvgSpace = t.AvgSpace,
                                ChainCnt = t.ChainCnt,
                                //AvgRowLen = t.AvgRowLen,
                                //SampleSize = t.SampleSize,
                                //LastAnalyzed = t.LastAnalyzed,
                                BufferPool     = t.BufferPool,
                                FlashCache     = t.FlashCache,
                                CellFlashCache = t.CellFlashCache,
                                GlobalStats    = t.GlobalStats.ToBoolean(),
                                UserStats      = t.UserStats.ToBoolean(),
                                Interval       = t.Interval.ToBoolean(),
                                SegmentCreated = t.SegmentCreated.ToBoolean(),
                            };

                            sub.PhysicalAttributes.Logging        = t.Logging;
                            sub.PhysicalAttributes.PctIncrease    = t.PctIncrease;
                            sub.PhysicalAttributes.Freelists      = t.Freelists;
                            sub.PhysicalAttributes.FreelistGroups = t.FreelistGroups;
                            sub.PhysicalAttributes.PctFree        = t.PctFree;
                            sub.PhysicalAttributes.PctUsed        = t.PctUsed;
                            sub.PhysicalAttributes.IniTrans       = t.IniTrans;
                            sub.PhysicalAttributes.MaxTrans       = t.MaxTrans;
                            sub.PhysicalAttributes.InitialExtent  = t.InitialExtent;
                            sub.PhysicalAttributes.NextExtent     = t.NextExtent;
                            sub.PhysicalAttributes.MinExtent      = t.MinExtent;
                            sub.PhysicalAttributes.MaxExtent      = t.MaxExtent;

                            sub.PhysicalAttributes.Tablespace.Name = t.TablespaceName;

                            partition.SubPartitions.Add(sub);
                        }
                    }
                }
            }
            ;

            SubPartitionsQueryDescriptor SubPartitions = new SubPartitionsQueryDescriptor(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition("l", "TABLE_OWNER"));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = SubPartitions.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
Example #22
0
        public override List <IndexColumnQueryTable_11> Resolve(DbContextOracle context, Action <IndexColumnQueryTable_11> action)
        {
            List <IndexColumnQueryTable_11> List = new List <IndexColumnQueryTable_11>();

            this.OracleContext = context;
            var db = context.Database;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (t.Column_Table_name.ExcludIfStartwith(t.Column_Table_Owner, Models.Configurations.ExcludeKindEnum.Table))
                    {
                        return;
                    }

                    string     key  = t.Column_Table_Owner + "." + t.Column_Table_name;
                    var        key2 = t.Index_Owner + "." + t.Index_Name;
                    IndexModel index;

                    if (!db.Indexes.Contains(key2))
                    {
                        index = new IndexModel()
                        {
                            Key        = key2,
                            Name       = t.Index_Name,
                            IndexOwner = t.Index_Owner,
                            IndexType  = t.Index_Type,
                            Unique     = t.uniqueness == "UNIQUE",
                            // Cache = t.Cache,
                            // Chunk = t.Chunk,
                            Compress           = t.Compression,
                            Compression_Prefix = "",
                            // Deduplication = t.Deduplication,
                            // FreePools = t.Freepools,
                            // In_Row = t.In_row,
                            // SecureFile = t.Securefile,
                            // SegmentName = t.Segment_name,
                            // InitialExtent = t.initial_extent,
                            Bitmap = false,
                        };

                        index.TableReference.Owner = t.Column_Table_Owner;
                        index.TableReference.Name  = t.Column_Table_name;

                        // PctVersion = t.Pctversion,

                        index.PhysicalAttributes.Tablespace.Name = t.tablespace_name;
                        index.PhysicalAttributes.BufferPool      = t.buffer_pool;
                        index.PhysicalAttributes.FreelistGroups  = t.freelist_groups;
                        index.PhysicalAttributes.Freelists       = t.freelists;
                        index.PhysicalAttributes.InitialExtent   = t.initial_extent;
                        index.PhysicalAttributes.MaxExtents      = t.max_extents;
                        index.PhysicalAttributes.MinExtents      = t.min_extents;
                        index.PhysicalAttributes.NextExtent      = t.next_extent;
                        index.PhysicalAttributes.PctIncrease     = t.pct_increase;
                        index.PhysicalAttributes.Logging         = t.Logging;

                        db.Indexes.Add(index);
                    }
                    else
                    {
                        index = db.Indexes[key2];
                    }

                    IndexColumnModel col1 = new IndexColumnModel()
                    {
                        Name = t.Column_Name, Rule = t.column_expression ?? t.Column_Name, Asc = t.Descend == "ASC"
                    };
                    index.Columns.Add(col1);
                }
            }
            ;

            IndexColumnQueryDescriptor_11 IndexColumn = new IndexColumnQueryDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition("i"));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = IndexColumn.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
        public override List <ConstraintsTable_11> Resolve(DbContextOracle context, Action <ConstraintsTable_11> action)
        {
            List <ConstraintsTable_11> List = new List <ConstraintsTable_11>();

            this.OracleContext = context;
            var db = context.Database;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (!context.Use(t.SchemaName))
                    {
                        return;
                    }

                    if (t.TABLE_NAME.ExcludIfStartwith(t.SchemaName, Models.Configurations.ExcludeKindEnum.Table))
                    {
                        return;
                    }

                    var c = new ConstraintModel()
                    {
                        Name             = t.CONSTRAINT_NAME,
                        Owner            = t.SchemaName,
                        IndexOwner       = t.INDEX_NAME,
                        IndexName        = t.INDEX_NAME,
                        Type             = t.CONSTRAINT_TYPE,
                        DeleteRule       = t.DELETE_RULE,
                        Generated        = t.GENERATED,
                        Deferrable       = t.DEFERRABLE,
                        Deferred         = t.DEFERRED,
                        Rely             = t.RELY,
                        Search_Condition = Utils.Serialize(t.search_condition, false),
                        ViewRelated      = t.VIEW_RELATED,
                        Invalid          = t.INVALID,
                        Status           = t.Status,
                    };

                    c.Reference.Owner      = t.R_OWNER;
                    c.Reference.Name       = t.R_CONSTRAINT_NAME;
                    c.TableReference.Owner = t.SchemaName;
                    c.TableReference.Name  = t.TABLE_NAME;

                    c.Key = c.BuildKey();
                    if (db.Constraints.TryGet(c.Key, out ConstraintModel c2))
                    {
                        db.Constraints.Remove(c2);
                    }
                    db.Constraints.Add(c);
                }
            }
            ;

            ConstraintDescriptor_11 view = new ConstraintDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition());

            using (var reader = context.Manager.ExecuteReader(System.Data.CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = view.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
        public override List <PartitionsDto_11> Resolve(DbContextOracle context, Action <PartitionsDto_11> action)
        {
            List <PartitionsDto_11> List = new List <PartitionsDto_11>();
            var db = context.Database;

            this.OracleContext = context;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (!db.Partitions.Contains(t.PartitionName))
                    {
                        var partition = new PartitionModel()
                        {
                            Name              = t.PartitionName,
                            Composite         = t.Composite.ToBoolean(),
                            HighValue         = t.HighValue,
                            HighValueLength   = t.HighValueLength,
                            PartitionPosition = t.PartitionPosition,
                            MaxSize           = t.MaxSize,
                            Compression       = t.Compression,
                            CompressFor       = t.CompressFor,
                            NumRows           = t.NumRows,
                            Blocks            = t.Blocks,
                            EmptyBlocks       = t.EmptyBlocks,
                            //AvgSpace = t.AvgSpace,
                            ChainCnt = t.ChainCnt,
                            //AvgRowLen = t.AvgRowLen,
                            //SampleSize = t.SampleSize,
                            //LastAnalyzed = t.LastAnalyzed,
                            CellFlashCache       = t.CellFlashCache,
                            GlobalStats          = t.GlobalStats.ToBoolean(),
                            UserStats            = t.UserStats.ToBoolean(),
                            IsNested             = t.IsNested.ToBoolean(),
                            ParentTablePartition = t.ParentTablePartition,
                            Interval             = t.Interval.ToBoolean(),
                            SegmentCreated       = t.SegmentCreated.ToBoolean(),
                        };

                        partition.PhysicalAttributes.Logging       = t.Logging;
                        partition.PhysicalAttributes.PctFree       = t.PctFree;
                        partition.PhysicalAttributes.PctUsed       = t.PctUsed;
                        partition.PhysicalAttributes.IniTrans      = t.IniTrans;
                        partition.PhysicalAttributes.MaxTrans      = t.MaxTrans;
                        partition.PhysicalAttributes.InitialExtent = t.InitialExtent;
                        partition.PhysicalAttributes.NextExtent    = t.NextExtent;
                        partition.PhysicalAttributes.MinExtent     = t.MinExtent;
                        partition.PhysicalAttributes.MaxExtent     = t.MaxExtent;

                        partition.PhysicalAttributes.BufferPool      = t.BufferPool;
                        partition.PhysicalAttributes.FlashCache      = t.FlashCache;
                        partition.PhysicalAttributes.Tablespace.Name = t.TablespaceName;
                        partition.PhysicalAttributes.PctIncrease     = t.PctIncrease;
                        partition.PhysicalAttributes.Freelists       = t.Freelists;
                        partition.PhysicalAttributes.FreelistGroups  = t.FreelistGroups;

                        db.Partitions.Add(partition);
                    }

                    TableModel ta;

                    string key = t.TableOwner + "." + t.TableName;
                    if (db.Tables.TryGet(key, out ta))
                    {
                        var partionRef = new PartitionRefModel()
                        {
                            PartitionName = t.PartitionName
                        };
                        ta.Partitions.Add(partionRef);
                    }
                }
            }
            ;

            PartitionsQueryDescriptor_11 Partitions = new PartitionsQueryDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition("l", "TABLE_OWNER"));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = Partitions.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
Example #25
0
        public override List <SubpartitionColumnDto_11> Resolve(DbContextOracle context, Action <SubpartitionColumnDto_11> action)
        {
            List <SubpartitionColumnDto_11> List = new List <SubpartitionColumnDto_11>();
            var db = context.Database;

            this.OracleContext = context;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (t.Name.ExcludIfStartwith(t.Owner, Models.Configurations.ExcludeKindEnum.Table))
                    {
                        return;
                    }

                    string k = t.Owner + "." + t.Name;

                    var p = new PartitionColumnModel()
                    {
                        ColumnName     = t.ColumnName,
                        ColumnPosition = t.ColumnPosition.ToInt16(),
                    };

                    if (t.ObjectType == "TABLE")
                    {
                        TableModel table;
                        if (db.Tables.TryGet(k, out table))
                        {
                            table.BlocPartition.SubColumns.Add(p);
                        }
                    }
                    else if (t.ObjectType == "INDEX")
                    {
                        IndexModel index;
                        if (db.Indexes.TryGet(k, out index))
                        {
                            index.BlocPartition.SubColumns.Add(p);
                        }
                    }
                    else
                    {
                        System.Diagnostics.Debugger.Break();
                    }
                }
            }
            ;

            SubpartitionColumnQueryDescriptor_11 SubpartitionColumn = new SubpartitionColumnQueryDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition("l", "Owner"));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = SubpartitionColumn.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
Example #26
0
 public void Process(DbContextOracle dbContext)
 {
     Process_Impl(dbContext.Database);
 }
Example #27
0
        public override List <ModelProcWithArgument_11> Resolve(DbContextOracle context, Action <ModelProcWithArgument_11> action)
        {
            this.OracleContext = context;
            List <ModelProcWithArgument_11> List = new List <ModelProcWithArgument_11>();
            string colName = string.Empty;
            var    db      = context.Database;

            HashSet <object> _h = new HashSet <object>();

            if (action == null)
            {
                action =
                    t =>
                {
                    ProcedureModel proc = null;

                    if (!context.Use(t.PackageName) && !string.IsNullOrEmpty(t.Owner))
                    {
                        return;
                    }

                    if (t.ObjectName.ExcludIfStartwith(t.Owner, Models.Configurations.ExcludeKindEnum.Procedure))
                    {
                        return;
                    }

                    if (t.PackageName == t.ObjectName)
                    {
                        return;
                    }

                    string key = t.ObjectId.ToString() + ":" + t.PackageName + "::" + t.Owner + "." + t.ObjectName;

                    if (!db.Procedures.TryGet(key, out proc))
                    {
                        proc = new ProcedureModel()
                        {
                            Owner        = t.Owner,
                            SubProgramId = t.subprogram_id,
                            PackageName  = t.PackageName,
                            Name         = t.ObjectName,
                            Key          = key,
                            IsFunction   = false,
                        };

                        proc.ResultType.Type.DataType.Owner = t.TypeOwner;
                        proc.ResultType.Type.DataType.Name  = t.TypeName;

                        db.Procedures.Add(proc);
                    }

                    int index = proc.Arguments.Count;
                    colName = (!string.IsNullOrEmpty(t.ArgumentName) ? t.ArgumentName : "arg" + index.ToString());
                    OTypeReference _type = new OTypeReference();

                    if (colName != "arg0")
                    {
                        var arg = new ArgumentModel()
                        {
                            Key      = (proc.Arguments.Count + 1).ToString(),
                            Name     = colName,
                            In       = t.In,
                            Out      = t.Out,
                            Position = t.Position,
                            Sequence = t.Sequence,
                            IsValid  = true,     // !string.IsNullOrEmpty(t.ArgumentName)
                        };
                        _type = arg.Type;
                        proc.Arguments.Add(arg);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(t.DataType))
                        {
                            var c = new ColumnModel()
                            {
                                Key      = (proc.ResultType.Columns.Count + 1).ToString(),
                                Name     = colName,
                                ColumnId = t.Position,
                            };
                            _type.DataType = c.Type;
                            proc.ResultType.Columns.Add(c);
                        }
                    }

                    if (_type != null)
                    {
                        _type.DataType.DataDefault = t.DataDefault != null?t.DataDefault.ToString()?.Trim() : string.Empty;

                        _type.DataType.DataLength    = t.DataLength;
                        _type.DataType.DataPrecision = t.DataPrecision;
                        _type.DataType.Name          = t.DataType;
                        _type.DataType.defaultLength = t.DefaultLength;
                        _type.DataType.DataLevel     = t.Data_Level;
                        _type.DataType.Owner         = t.TypeOwner;
                        _type.DataType.Name          = t.TypeName;

                        if (_type.DataType.Name != null)
                        {
                            _type.DataType.DbType = TypeMatchExtension.ConvertToDbType(t.DataType).ToString();

                            if (t.DataType.StartsWith("PL/SQL"))
                            {
                                _type.DataType.IsRecord = t.DataType == "PL/SQL RECORD";
                            }

                            else if (_type.DataType.Name == "TABLE")
                            {
                                _type.DataType.IsRecord = true;
                            }


                            //TODO : Recopier le nom du type dans le path
                        }
                    }

                    proc.IsFunction = proc.ResultType.Columns.Count > 0 && (proc.ResultType.Columns.OfType <ColumnModel>().Count(col => col.Name == "arg0") == proc.ResultType.Columns.Count);
                }
            }
            ;

            string _sql = string.Format(sql, ProcQueryWhereCondition);
            ProcDescriptorWithArgument_11 view = new ProcDescriptorWithArgument_11(context.Manager.ConnectionString);

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, _sql, QueryBase.DbParams.ToArray()))
            {
                List = view.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }
        public override List <IndexPartitionColumnDto_11> Resolve(DbContextOracle context, Action <IndexPartitionColumnDto_11> action)
        {
            this.OracleContext = context;
            List <IndexPartitionColumnDto_11> List = new List <IndexPartitionColumnDto_11>();
            var db = context.Database;

            if (action == null)
            {
                action =
                    t =>
                {
                    if (t.TableName.ExcludIfStartwith(t.Owner, Models.Configurations.ExcludeKindEnum.Table))
                    {
                        return;
                    }

                    string k = t.Owner + "." + t.TableName;

                    TableModel table;
                    if (db.Tables.TryGet(k, out table))
                    {
                        string k2 = t.Owner + "." + t.IndexName;

                        if (!db.Indexes.TryGet(k2, out IndexModel index))
                        {
                            index = new IndexModel()
                            {
                                Key        = k2,
                                IndexOwner = t.Owner,
                                Name       = t.IndexName,
                            };

                            index.TableReference.Owner = t.Owner;
                            index.TableReference.Name  = t.TableName;
                            db.Indexes.Add(index);
                        }

                        index.BlocPartition.PartitioningType    = t.PartitioningType;
                        index.BlocPartition.SubpartitioningType = t.SubpartitioningType;
                        //index.BlocPartition.PartitionCount = t.PartitionCount;
                        //index.BlocPartition.DefSubpartitionCount = t.DefSubpartitionCount;
                        //index.BlocPartition.PartitioningKeyCount = t.PartitioningKeyCount;
                        //index.BlocPartition.SubpartitioningKeyCount = t.SubpartitioningKeyCount;
                        index.BlocPartition.Locality  = t.Locality;
                        index.BlocPartition.Alignment = t.Alignment;
                        index.BlocPartition.PhysicalAttributes.Tablespace.Name = t.DefTablespaceName;

                        index.BlocPartition.DefMaxSize = t.DefMaxSize;
                        index.BlocPartition.PhysicalAttributes.PctIncrease    = t.DefPctIncrease;
                        index.BlocPartition.PhysicalAttributes.Freelists      = t.DefFreelists;
                        index.BlocPartition.PhysicalAttributes.FreelistGroups = t.DefFreelistGroups;
                        index.BlocPartition.PhysicalAttributes.BufferPool     = t.DefBufferPool;
                        index.BlocPartition.PhysicalAttributes.FlashCache     = t.DefFlashCache;
                        index.BlocPartition.DefCellFlashCache = t.DefCellFlashCache;
                        index.BlocPartition.DefParameters     = t.DefParameters;
                        index.BlocPartition.Interval          = t.Interval;


                        index.BlocPartition.PhysicalAttributes.Logging = t.DefLogging;

                        index.BlocPartition.PhysicalAttributes.PctFree  = t.DefPctFree;
                        index.BlocPartition.PhysicalAttributes.IniTrans = t.DefIniTrans;
                        index.BlocPartition.PhysicalAttributes.MaxTrans = t.DefMaxTrans;

                        index.BlocPartition.PhysicalAttributes.InitialExtent = t.DefInitialExtent;
                        index.BlocPartition.PhysicalAttributes.NextExtent    = t.DefNextExtent;
                        index.BlocPartition.PhysicalAttributes.MinExtents    = t.DefMinExtents;
                        index.BlocPartition.PhysicalAttributes.MaxExtents    = t.DefMaxExtents;
                    }
                }
            }
            ;

            IndexPartitionColumnQueryDescriptor_11 IndexPartitionColumn = new IndexPartitionColumnQueryDescriptor_11(context.Manager.ConnectionString);

            sql = string.Format(sql, TableQueryWhereCondition("l", "Owner"));

            using (var reader = context.Manager.ExecuteReader(CommandType.Text, sql, QueryBase.DbParams.ToArray()))
            {
                List = IndexPartitionColumn.ReadAll(reader, action).ToList();
            }

            return(List);
        }
    }