// this structure is incrementally loaded, when needed //int m_fixedOrderCounter = 0; public void RecreateObject(AbstractObjectStructure recreatedObject, AbstractObjectStructure newVersion) { foreach (var it in RecreatedItems) { if (it.RecreatedObject == recreatedObject) { if (it.NewVersion != null && newVersion != null) { throw new InternalError("DAE-00033 Two new versions of object " + recreatedObject.ToString()); } it.NewVersion = newVersion ?? it.NewVersion; return; } } RecreatedItems.Add(new RecreatedItem { RecreatedObject = recreatedObject, NewVersion = newVersion }); }
// this structure is incrementally loaded, when needed //int m_fixedOrderCounter = 0; public void RecreateObject(DatabaseObjectInfo recreatedObject, DatabaseObjectInfo newVersion) { foreach (var it in RecreatedItems) { if (it.RecreatedObject == recreatedObject) { if (it.NewVersion != null && newVersion != null) { throw new InternalError("DBSH-00140 Two new versions of object " + recreatedObject.ToString()); } it.NewVersion = newVersion ?? it.NewVersion; return; } } RecreatedItems.Add(new RecreatedItem { RecreatedObject = recreatedObject, NewVersion = newVersion }); }
public void Transform(AlterProcessorCaps caps, DbDiffOptions opts, IDatabaseSource targetDb) { // transform operations for (int index = 0; index < Operations.Count;) { var list = new List <AlterOperation>(); list.Add(Operations[index]); Operations[index].TransformToImplementedOps(caps, opts, list, this, targetDb); if (list.Count == 1) { Operations[index] = list[0]; index++; } else { Operations.RemoveAt(index); Operations.InsertRange(index, list); index += list.Count; } } // add physical dependencies for (int index = 0; index < Operations.Count; index++) { var before = new List <AlterOperation>(); var after = new List <AlterOperation>(); Operations[index].AddPhysicalDependencies(caps, opts, before, after, this, targetDb); Operations.InsertRange(index, before); index += before.Count; Operations.InsertRange(index + 1, after); index += after.Count; } // join recreate table operations for (int index = 0; index < Operations.Count; index++) { var rop = Operations[index] as AlterOperation_RecreateTable; if (rop != null) { for (int i = index - 1; i >= 0; i--) { if (Operations[i].ParentTable == rop.ParentTable) { rop.InsertOp(Operations[i]); Operations.RemoveAt(i); index--; } } for (int i = index + 1; i < Operations.Count;) { if (Operations[i].ParentTable == rop.ParentTable) { rop.AppendOp(Operations[i]); Operations.RemoveAt(i); } else { i++; } } } } // absorb operatios for (int index = 0; index < Operations.Count; index++) { if (Operations[index].MustRunAbsorbTest(caps)) { for (int i = 0; i < Operations.Count; i++) { if (i == index) { continue; } if (Operations[index].AbsorbOperation(caps, Operations[i])) { Operations.RemoveAt(i); if (i < index) { index--; } } } } } // remove recreates which are dropped for (int index = 0; index < RecreatedItems.Count;) { bool remove = false; foreach (var op in Operations) { if (op.GetDropObject() == RecreatedItems[index].RecreatedObject) { remove = true; } } if (remove) { RecreatedItems.RemoveAt(index); } else { index++; } } // transform recreations into regular operations so that they can be sorted foreach (var dep in RecreatedItems) { opts.AlterLogger.Info(Texts.Get("s_recreated_object$object", "object", dep.RecreatedObject)); } foreach (var cls in RecreatedItem.DropClassOrder) { foreach (var dep in RecreatedItems) { if (dep.ItemClass != cls) { continue; } dep.PlanDrop(this, opts); } } foreach (var cls in RecreatedItem.DropClassOrder) { foreach (var dep in RecreatedItems) { if (dep.ItemClass != cls) { continue; } dep.PlanCreate(this, opts); } } // reorder operations // foreign key creation should be at last // simulate stable order (List.Sort is not stable!!) for (int i = 0; i < Operations.Count; i++) { Operations[i].m_tmpOrder = i; } Operations.Sort(OrderGroupCompare); foreach (var op in Operations) { if (op.DenyTransaction()) { DenyTransaction = true; } } }