Beispiel #1
0
        private static DatabasePackage FindPackage(DatabaseSchema databaseSchema, string name, string owner)
        {
            var package = databaseSchema.Packages.Find(
                t2 => t2.Name.Equals(name, StringComparison.OrdinalIgnoreCase));

            if (package == null)
            {
                package             = new DatabasePackage();
                package.Name        = name;
                package.SchemaOwner = owner;
                databaseSchema.Packages.Add(package);
            }
            return(package);
        }
Beispiel #2
0
        private static void UpdatePackages(DatabaseSchema databaseSchema)
        {
            var deletedSprocs = new List <DatabaseStoredProcedure>();
            var deletedFuncs  = new List <DatabaseFunction>();

            //find stored procedures that are in packages
            databaseSchema.StoredProcedures.ForEach(delegate(DatabaseStoredProcedure sproc)
            {
                string name = sproc.Package;
                if (name == null)
                {
                    return;
                }
                DatabasePackage package = FindPackage(databaseSchema, name, sproc.SchemaOwner);
                if (!package.StoredProcedures.Contains(sproc))
                {
                    package.StoredProcedures.Add(sproc);
                    deletedSprocs.Add(sproc);
                }
            });
            databaseSchema.Functions.ForEach(delegate(DatabaseFunction function)
            {
                string name = function.Package;
                if (name == null)
                {
                    return;
                }
                DatabasePackage package = FindPackage(databaseSchema, name, function.SchemaOwner);
                if (!package.Functions.Contains(function))
                {
                    package.Functions.Add(function);
                    deletedSprocs.Add(function);
                }
            });
            foreach (var deletedSproc in deletedSprocs)
            {
                //has been moved into a package
                databaseSchema.StoredProcedures.Remove(deletedSproc);
            }
            foreach (var deletedFunc in deletedFuncs)
            {
                //has been moved into a package
                databaseSchema.Functions.Remove(deletedFunc);
            }
        }