Exemple #1
0
        private SpecificObjectInfo AddSpecificObject(SpecificObjectInfo obj, bool reuseGroupId)
        {
            var res = obj.CloneSpecificObject(this);

            if (!reuseGroupId)
            {
                res.GroupId = Guid.NewGuid().ToString();
            }
            switch (obj.ObjectType)
            {
            case DatabaseObjectType.View:
                Views.Add((ViewInfo)res);
                break;

            case DatabaseObjectType.StoredProcedure:
                StoredProcedures.Add((StoredProcedureInfo)res);
                break;

            case DatabaseObjectType.Function:
                Functions.Add((FunctionInfo)res);
                break;

            case DatabaseObjectType.Trigger:
                Triggers.Add((TriggerInfo)res);
                break;
            }
            return(res);
        }
Exemple #2
0
 private SpecificObjectInfo FindSpecificObject(SpecificObjectInfo obj)
 {
     return
         ((SpecificObjectInfo)FindStoredProcedure(obj.FullName)
          ?? (SpecificObjectInfo)FindFunction(obj.FullName)
          ?? (SpecificObjectInfo)FindView(obj.FullName)
          ?? (SpecificObjectInfo)FindTrigger(obj.FullName));
 }
Exemple #3
0
        public SpecificObjectInfo FindOrCreateSpecificObject(SpecificObjectInfo obj)
        {
            var res = FindSpecificObject(obj);

            if (res == null)
            {
                res = AddSpecificObject(obj, false);
            }
            return(res);
        }
 public static void DropSpecificObject(this IAlterProcessor proc, SpecificObjectInfo obj)
 {
     var view = obj as ViewInfo;
     if (view != null) proc.DropView(view, true);
     var sp = obj as StoredProcedureInfo;
     if (sp != null) proc.DropStoredProcedure(sp, true);
     var func = obj as FunctionInfo;
     if (func != null) proc.DropFunction(func, true);
     var trg = obj as TriggerInfo;
     if (trg != null) proc.DropTrigger(trg, true);
 }
Exemple #5
0
 public static bool EqualsSpecificObjects(SpecificObjectInfo src, SpecificObjectInfo dst, DbDiffOptions options)
 {
     if (!EqualFullNames(src.FullName, dst.FullName, options)) return false;
     if (src.ObjectType != dst.ObjectType) return false;
     if (src.CreateSql == null || dst.CreateSql == null)
     {
         if (src.CreateSql != dst.CreateSql) return false;
     }
     else
     {
         //if (src.SpecificDialect == dst.SpecificDialect && src.SpecificDialect != null)
         //{
         //    var dialect = (ISqlDialect)DialectAddonType.Instance.FindHolder(src.SpecificDialect).CreateInstance();
         //    return dialect.EqualSpecificObjects(src.ObjectType, src.CreateSql, dst.CreateSql);
         //}
         //else
         //{
         //    if (src.CreateSql.Trim() != dst.CreateSql.Trim()) return false;
         //}
         if (src.CreateSql.Trim() != dst.CreateSql.Trim()) return false;
     }
     return true;
 }
Exemple #6
0
 public void ChangeSpecificObject(SpecificObjectInfo obj, SpecificObjectInfo newobj)
 {
     var o = Structure.FindOrCreateSpecificObject(obj);
     AddOperation(new AlterOperation_ChangeSpecificObject {OldObject = o, NewObject = newobj.CloneSpecificObject()});
 }
Exemple #7
0
 public void RenameSpecificObject(SpecificObjectInfo obj, NameWithSchema name)
 {
     var o = Structure.FindOrCreateSpecificObject(obj);
     AddOperation(new AlterOperation_RenameSpecificObject { OldObject = o, NewName = name });
 }
Exemple #8
0
 public void DropSpecificObject(SpecificObjectInfo obj, PlanPosition pos = PlanPosition.End)
 {
     var o = Structure.FindOrCreateSpecificObject(obj);
     AddOperation(new AlterOperation_DropSpecificObject { OldObject = o }, pos);
 }
Exemple #9
0
 public void CreateSpecificObject(SpecificObjectInfo obj, PlanPosition pos = PlanPosition.End)
 {
     var o = obj.CloneSpecificObject();
     AddOperation(new AlterOperation_CreateSpecificObject { NewObject = o }, pos);
 }
 public static void CreateSpecificObject(this IAlterProcessor proc, SpecificObjectInfo obj)
 {
     var view = obj as ViewInfo;
     if (view != null) proc.CreateView(view);
     var sp = obj as StoredProcedureInfo;
     if (sp != null) proc.CreateStoredProcedure(sp);
     var func = obj as FunctionInfo;
     if (func != null) proc.CreateFunction(func);
     var trg = obj as TriggerInfo;
     if (trg != null) proc.CreateTrigger(trg);
 }
 public static void RenameSpecificObject(this IAlterProcessor proc, SpecificObjectInfo obj, string newName)
 {
     var view = obj as ViewInfo;
     if (view != null) proc.RenameView(view, newName);
     var sp = obj as StoredProcedureInfo;
     if (sp != null) proc.RenameStoredProcedure(sp, newName);
     var func = obj as FunctionInfo;
     if (func != null) proc.RenameFunction(func, newName);
 }
 public static void ChangeSpecificObjectSchema(this IAlterProcessor proc, SpecificObjectInfo obj, string newSchema)
 {
     var view = obj as ViewInfo;
     if (view != null) proc.ChangeViewSchema(view, newSchema);
     var sp = obj as StoredProcedureInfo;
     if (sp != null) proc.ChangeStoredProcedureSchema(sp, newSchema);
     var func = obj as FunctionInfo;
     if (func != null) proc.ChangeFunctionSchema(func, newSchema);
 }
Exemple #13
0
 public static void AlterSpecificObject(SpecificObjectInfo osrc, SpecificObjectInfo odst, AlterPlan plan, DbDiffOptions opts, DbObjectPairing pairing)
 {
     //bool altered = false;
     if (osrc.CreateSql == odst.CreateSql)
     {
         plan.RenameSpecificObject(osrc, odst.FullName);
         //altered = GenerateRename(osrc.ObjectName, odst.ObjectName,
         //    (old, sch) =>
         //    {
         //        var o2 = new SpecificObjectStructure(osrc);
         //        o2.ObjectName = old;
         //        proc.ChangeSpecificObjectSchema(o2, sch);
         //    },
         //    (old, nam) =>
         //    {
         //        var o2 = new SpecificObjectStructure(osrc);
         //        o2.ObjectName = old;
         //        proc.RenameSpecificObject(o2, nam);
         //    }, caps[osrc.ObjectType].ChangeSchema, caps[osrc.ObjectType].Rename, opts);
     }
     else
     {
         plan.ChangeSpecificObject(osrc, odst);
     }
     //if (!altered)
     //{
     //    proc.DropSpecificObject(osrc);
     //    SpecificObjectStructure odst2 = new SpecificObjectStructure(odst);
     //    odst2.ObjectName = GenerateNewName(osrc.ObjectName, odst.ObjectName, opts);
     //    proc.CreateSpecificObject(odst);
     //}
 }
Exemple #14
0
 public static bool GenerateRenameSpecificObject(SpecificObjectInfo oldObj, NameWithSchema newName, Action<SpecificObjectInfo, string> changeSchema, Action<SpecificObjectInfo, string> rename, bool allowChangeSchema, bool allowRename, DbDiffOptions opts)
 {
     newName = GenerateNewName(oldObj.FullName, newName, opts);
     if (DbDiffTool.EqualFullNames(oldObj.FullName, newName, opts)) return true;
     if (!EqualSchemas(oldObj.FullName.Schema, newName.Schema, opts) && !allowChangeSchema) return false;
     if (oldObj.FullName.Name != newName.Name && !allowRename) return false;
     if (!EqualSchemas(oldObj.FullName.Schema, newName.Schema, opts)) changeSchema(oldObj, newName.Schema);
     if (oldObj.FullName.Name != newName.Name)
     {
         var tmpo = oldObj.CloneSpecificObject();
         tmpo.FullName = new NameWithSchema(newName.Schema, oldObj.FullName.Name);
         rename(tmpo, newName.Name);
     }
     return true;
 }