Exemple #1
0
        public static void BuildContentFromProc(this DbContextOracle connection, StringBuilder sb, List <string> schemas, List <string> names)
        {
            var sources = connection.GetCodeFromProc(schemas, names);

            if (sources.Count == 0)
            {
            }
            else if (sources.Count == 1)
            {
                var item = sources.FirstOrDefault();
                sb.Append("CREATE OR REPLACE ");
                sb.Append(Utils.Unserialize(item.Code, true));
            }
            else
            {
                for (int i = 0; i < sources.Count; i++)
                {
                    var item = sources[i];
                    sb.Append("CREATE OR REPLACE ");
                    var t = Utils.Unserialize(item.Code, true);
                    t = t.Trim()
                        .Trim('/')
                        .Trim();
                    sb.Append(t);
                    sb.AppendLine(String.Empty);
                    sb.AppendLine("/");
                }

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }
            }
        }
Exemple #2
0
 private static void Run <T>(DbContextOracle dbContext, DbQueryBase <T> query, string text, bool exclude = false)
 {
     if (!exclude)
     {
         Trace.WriteLine(text);
         query.Resolve(dbContext, null);
     }
     else
     {
         Trace.WriteLine("exclude " + text);
     }
 }
Exemple #3
0
        private static List <ContentCodeQuery_11.CodeSource> GetCodeFromProc(this DbContextOracle connection, List <string> schemas, List <string> names)
        {
            var db = new OracleDatabase();

            connection.Database = db;
            ContentCodeQuery_11 q1 = new ContentCodeQuery_11()
            {
                OwnerNames     = schemas,
                ProcedureNames = names,
            };

            q1.Resolve(connection, null);

            return(q1.Sources);
        }
Exemple #4
0
        public static void BuildContentFromPackage(this DbContextOracle connection, StringBuilder sb, List <string> schemas, List <string> names, bool isBody)
        {
            var sources = connection.GetCodeFromProc(schemas, names);

            if (isBody)
            {
                foreach (var item in sources)
                {
                    var t  = Utils.Unserialize(item.Code, true);
                    var t2 = Bb.Oracle.Helpers.ContentHelper.FormatSource(t);

                    sb.Append("CREATE OR REPLACE ");
                }
            }
            else
            {
            }
        }
Exemple #5
0
        /// <summary>
        /// Generates the file.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="outputfileFullPath">The outputfile full path.</param>
        /// <param name="use">The use.</param>
        /// <returns></returns>
        public static OracleDatabase GenerateFile(ArgumentContext ctx, Func <string, bool> use = null)
        {
            System.Data.Common.DbConnectionStringBuilder builder = new System.Data.Common.DbConnectionStringBuilder();
            builder.ConnectionString = string.Format(@"Data source={0};USER ID={1};Password={2};", ctx.Source, ctx.Login, ctx.Pwd);

            var manager = new OracleManager(builder.ConnectionString);

            if (System.Diagnostics.Debugger.IsAttached)
            {
                Trace.WriteLine("{0} Success", builder.ConnectionString.Replace(ctx.Pwd, "".PadLeft(ctx.Pwd.Length, '*')));
            }

            if (use == null)
            {
                use = shema => true;
            }

            DbContextOracle dbContext = new DbContextOracle(manager)
            {
                Use = use, ExcludeCode = ctx.ExcludeCode
            };

            dbContext.Database = new OracleDatabase()
            {
                Name         = "Instance server " + ctx.Source,
                SourceScript = false
            };

            if (!string.IsNullOrEmpty(ctx.Name))
            {
                dbContext.Database.Name = ctx.Name;
            }
            else
            {
                dbContext.Database.Name = ctx.Source;
            }

            Filtre(ctx, builder.ConnectionString);

            var version = new OracleVersionQuery().GetVersion(dbContext);

            dbContext.Version = version;

            Trace.WriteLine($"server version {version}");

            Run(dbContext);

            if (!string.IsNullOrEmpty(ctx.Filename))
            {
                FileInfo f = new FileInfo(ctx.Filename);
                if (!f.Directory.Exists)
                {
                    f.Directory.Create();
                }

                Trace.WriteLine("Writing file at " + ctx.Filename);
                dbContext.Database.WriteFile(ctx.Filename);
            }

            Trace.WriteLine("the end");

            return(dbContext.Database);
        }
Exemple #6
0
        private static void Run <T>(DbContextOracle dbContext) where T : RuleBase, new()
        {
            RuleBase processor = new T();

            processor.Process(dbContext);
        }
Exemple #7
0
        private static void Run(DbContextOracle dbContext)
        {
            switch (dbContext.Version.Major)
            {
            case 11:

                Run(dbContext, new TablespacesQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve tablespaces", dbContext.ExcludeCode);

                Run(dbContext, new OwnerNameQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "collect of schema");
                Run(dbContext, new ObjectQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve objects");
                Run(dbContext, new SequenceQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve sequences");
                Run(dbContext, new TableQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve tables");
                //Run(dbContext, new ViewSourceQuery() { OwnerNames = Database.OwnerNames, OracleContext = dbContext }, "Resolve code views");
                Run(dbContext, new MaterializedViewSourceQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve code materialized views");
                Run(dbContext, new TableColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve columns of tables");
                Run(dbContext, new IndexColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve indexes of tables");
                Run(dbContext, new ConstraintsQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve constraints tables");
                Run(dbContext, new ConstraintColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve IndexColumnQuery columns");
                Run(dbContext, new TableDefaultValueQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve columns default values");
                Run(dbContext, new EncryptedTableColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve Encrypted columns");

                Run(dbContext, new PartitionsQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve partitions");
                Run(dbContext, new SubPartitionsQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve sub partitions");
                Run(dbContext, new TablePartitionColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve table partitions");
                Run(dbContext, new IndexPartitionColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames
                }, "Resolve index partitions");
                Run(dbContext, new PartitionColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve partition index");
                Run(dbContext, new SubpartitionColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve sub partition index");

                Run(dbContext, new ProcQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext, ProcedureNames = Database.ProcedureNames
                }, "Resolve oracle stored procedures");
                Run(dbContext, new ProcQueryWithArgument_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext, ProcedureNames = Database.ProcedureNames
                }, "Resolve oracle stored procedures with arguments");
                Run(dbContext, new TypeQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve oracle types");
                //Run(dbContext, new ViewQuery() { OwnerNames = Database.OwnerNames, OracleContext = dbContext }, "Resolve oracle views");
                Run(dbContext, new SynonymQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve oracle synonyms");
                Run(dbContext, new GrantQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve database grants");
                Run(dbContext, new TriggerQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve triggers");
                Run(dbContext, new ContentCodeQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve sources", dbContext.ExcludeCode);

                //TODO : Il faut identifier dans les objets OTypeReference la valeur de KindTypeReference a partir du type d'object referencé

                break;

            case 12:
                Run(dbContext, new TablespacesQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve tablespaces", dbContext.ExcludeCode);

                Run(dbContext, new OwnerNameQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "collect of schema");
                Run(dbContext, new ObjectQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve objects");
                Run(dbContext, new SequenceQuery_12()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve sequences");
                Run(dbContext, new TableQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve tables");
                //Run(dbContext, new ViewSourceQuery() { OwnerNames = Database.OwnerNames, OracleContext = dbContext }, "Resolve code views");
                Run(dbContext, new MaterializedViewSourceQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve code materialized views");
                Run(dbContext, new TableColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve columns of tables");
                Run(dbContext, new IndexColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve indexes of tables");
                Run(dbContext, new ConstraintsQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve constraints tables");
                Run(dbContext, new ConstraintColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve IndexColumnQuery columns");
                Run(dbContext, new TableDefaultValueQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve columns default values");
                Run(dbContext, new EncryptedTableColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve Encrypted columns");

                Run(dbContext, new PartitionsQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve partitions");
                Run(dbContext, new SubPartitionsQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve sub partitions");
                Run(dbContext, new TablePartitionColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve table partitions");
                Run(dbContext, new IndexPartitionColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames
                }, "Resolve index partitions");
                Run(dbContext, new PartitionColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve partition index");
                Run(dbContext, new SubpartitionColumnQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve sub partition index");

                Run(dbContext, new ProcQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext, ProcedureNames = Database.ProcedureNames
                }, "Resolve oracle stored procedures");
                Run(dbContext, new ProcQueryWithArgument_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext, ProcedureNames = Database.ProcedureNames
                }, "Resolve oracle stored procedures with arguments");
                Run(dbContext, new TypeQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve oracle types");
                //Run(dbContext, new ViewQuery() { OwnerNames = Database.OwnerNames, OracleContext = dbContext }, "Resolve oracle views");
                Run(dbContext, new SynonymQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve oracle synonyms");
                Run(dbContext, new GrantQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve database grants");
                Run(dbContext, new TriggerQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve triggers");
                Run(dbContext, new ContentCodeQuery_11()
                {
                    OwnerNames = Database.OwnerNames, OracleContext = dbContext
                }, "Resolve sources", dbContext.ExcludeCode);
                break;

            default:
                throw new NotImplementedException(dbContext.Version.ToString());
            }

            Run <RebuildMethodKeys>(dbContext);
        }
Exemple #8
0
 public static void BuildContentFromTrigger(this DbContextOracle connection, StringBuilder sb, List <string> schemas, List <string> names)
 {
     BuildContentFromProc(connection, sb, schemas, names);
 }