public static void RemoveInvalidReferences(this TableStructure res, DatabaseCopyOptions copyOpts, ISqlDialect dialect) { ((ConstraintCollection)res.Constraints).RemoveIf(cnt => cnt is IForeignKey && !copyOpts.CopyTableStructure(((IForeignKey)cnt).PrimaryKeyTable)); //res.FullName = copyOpts.GetMappedTableName(res.FullName); //foreach (Constraint cnt in res.Constraints) //{ // cnt.Table = copyOpts.GetMappedTableName(cnt.Table); //} //List<Constraint> delCnt = new List<Constraint>(); //foreach (Constraint cnt in res.Constraints) //{ // if (cnt is IForeignKey) // { // ForeignKey fk = (ForeignKey)cnt; // if (copyOpts.CopyTable(fk.PrimaryKeyTable)) // { // fk.PrimaryKeyTable = copyOpts.GetMappedTableName(fk.PrimaryKeyTable); // } // else // { // delCnt.Add(fk); // } // } //} //foreach (Constraint cnt in delCnt) //{ // res.Constraints.Remove(cnt); //} }
public override void LoadFromXml(XmlElement xml) { base.LoadFromXml(xml); m_src = (IDatabaseSource)DatabaseSourceAddonType.Instance.LoadAddon(xml.FindElement("Source")); m_dst = (IDatabaseWriter)DatabaseWriterAddonType.Instance.LoadAddon(xml.FindElement("Target")); m_copyOpts = new DatabaseCopyOptions(); m_copyOpts.LoadFromXml(xml.FindElement("Options")); }
private DatabaseCopyOptions CreateOptions() { DatabaseCopyOptions opts = new DatabaseCopyOptions(); if (m_chooseNode != null) { opts.CopyMembers = m_chooseNode.GetChoosedMembers(); } if (m_target.Dialect != null) { opts.MigrationProfile = m_target.Dialect.CreateMigrationProfile(); } if (rbDefaultSchema.Checked) { opts.SchemaMode = DbCopySchemaMode.Explicit; } if (rbExplicitSchema.Checked) { opts.SchemaMode = DbCopySchemaMode.Explicit; opts.ExplicitSchema = cbxExplicitSchema.Text; } if (rbOriginalSchema.Checked) { opts.SchemaMode = DbCopySchemaMode.Original; } opts.CopyStructure = chbCopyStructure.Checked; opts.DataMode = DbCopyDataMode.None; if (rbtCopyAll.Checked) { opts.DataMode = DbCopyDataMode.All; } if (rbtCopySelected.Checked) { opts.DataMode = DbCopyDataMode.Selected; } if (rbtCopyUnselected.Checked) { opts.DataMode = DbCopyDataMode.Unselected; } foreach (NameWithSchema tbl in lbxSelectedTables.Items) { opts.DataCopyTables.Add(tbl); } opts.TableOptions = tableCopyOptionsFrame1.GetOptions(); return(opts); }
public override void LoadDatabase(IDatabaseSource dst) { var writer = new DatabaseSourceWriter(dst); var reader = new DataArchiveReader(Filename); var dbmem = new DatabaseStructureMembers { TableMembers = TableStructureMembers.AllNoRefs, SpecificObjectDetails = true, }; var copyOpts = new DatabaseCopyOptions { CopyMembers = dbmem, DataMode = DbCopyDataMode.All, CopyStructure = true, SchemaMode = DbCopySchemaMode.Original, }; CopyDbJob.CopyDatabase(reader, writer, ProgressInfo, copyOpts); }
protected override void DoRun(IJobRunEnv env) { string dir = GetBackupDir(); try { Directory.CreateDirectory(dir); } catch { } string bckfile = Path.Combine(dir, CreateFileName()); IDatabaseWriter writer = m_format.GetWriter(bckfile + m_format.Extension, m_src); var copyOpts = new DatabaseCopyOptions { CopyMembers = m_members, DataMode = DbCopyDataMode.All, CopyStructure = true, SchemaMode = m_src.Dialect.DialectCaps.MultipleSchema ? DbCopySchemaMode.Original : DbCopySchemaMode.Explicit, ExplicitSchema = null }; CopyDbJob.CopyDatabase(m_src, writer, ProgressInfo, copyOpts); SetCurWork(Texts.Get("s_finishing")); BackupContainer bc = new BackupContainer(bckfile, m_format); bc.Save(); }
public static DatabaseStructure GetMappedDatabase(this IDatabaseStructure db, DatabaseCopyOptions copyOpts, ISqlDialect dialect) { DatabaseStructure res = new DatabaseStructure(db, copyOpts.CopyMembers); foreach (TableStructure tbl in res.Tables) { tbl.RemoveInvalidReferences(copyOpts, dialect); //tbl.MangleMappedTable(copyOpts, dialect); } if (copyOpts.SchemaMode == DbCopySchemaMode.Explicit) { // no schemata will be created res.Schemata.Clear(); res.RunNameTransformation(new SetSchemaNameTransformation(copyOpts.ExplicitSchema)); } return(res); }
public virtual void RunDirectCopy(IDatabaseSource source, DatabaseCopyOptions copyOpts) { throw new NotImplementedError("DAE-00077"); }
public static void CopyDatabase(IDatabaseSource src, IDatabaseWriter dst, IProgressInfo progress, DatabaseCopyOptions copyOpts) { IDatabaseWriter dst2 = null; for (; ;) { dst2 = dst.GetRedirectedWriter(); if (dst2 == null) { break; } dst = dst2; } dst.SetSourceInfo(new DatabaseWriterSourceInfo { Dialect = src.Dialect, //CopyMode = copyOpts.Mode, SchemaMode = copyOpts.SchemaMode, }); try { dst.ProgressInfo = progress; Async.SafeOpen(src.Connection); dst.OpenConnection(); if (dst.DirectCopy(src)) { dst.RunDirectCopy(src, copyOpts); } else { copyOpts.CopyMembers.IgnoreSystemObjects = true; IDatabaseStructure tmpDb = src.InvokeLoadStructure(copyOpts.CopyMembers, progress); DatabaseStructure sourceDb = new DatabaseStructure(tmpDb); //sourceDb.AutoFillRefs(); DatabaseStructure targetDb = sourceDb.GetMappedDatabase(copyOpts, dst.Dialect); if (dst.Dialect != null) { dst.Dialect.MigrateDatabase(targetDb, copyOpts.MigrationProfile, progress); } if (copyOpts.CopyStructure) { dst.WriteStructureBeforeData(targetDb); } bool copydata = copyOpts.DataMode != DbCopyDataMode.None && src.TableCaps.DataStoreForReading && dst.WriterCaps.AcceptData; if (copydata) { dst.BeforeFillData(); foreach (var tbl in sourceDb.Tables.SortedByKey <ITableStructure, int>(tbl => copyOpts.DataCopyTables.IndexOf(tbl.FullName))) { if (!copyOpts.CopyTableData(tbl.FullName)) { continue; } Logging.Debug("Copying table {0}", tbl); if (progress != null) { progress.SetCurWork(String.Format("{0} {1}", Texts.Get("s_copying_table"), tbl)); } GenericDataQueue queue = new GenericDataQueue(tbl, tbl, new IdentityTransform(tbl)); queue.ProgressInfo = progress; if (dst.WriterCaps.ExecuteSql) { var ada = new RecordToDbAdapter(tbl, tbl, dst.Dialect, new DataFormatSettings()); ada.ProgressInfo = progress; queue.AddOutputAdapter(ada); } ITableSource tsrc = src.GetTable(tbl.FullName); ITabularDataStore srcds = tsrc.GetDataStoreAndReuse(); IAsyncResult async_src = srcds.BeginRead(null, queue); ITableStructure newTableStruct = (ITableStructure)targetDb.FindByGroupId(tbl.GroupId); dst.FillTable(newTableStruct, queue, copyOpts.TableOptions); srcds.EndRead(async_src); } dst.AfterFillData(); } if (copyOpts.CopyStructure) { dst.WriteStructureAfterData(targetDb); } } } catch (Exception) { dst.ProcessFailed(); throw; } finally { Async.SafeClose(src.Connection); dst.CloseConnection(); } }
public static Job CreateJob(IDatabaseSource src, IDatabaseWriter dst, DatabaseCopyOptions copyOpts, JobProperties jobProps) { return(Job.FromCommand(new CopyDbJobCommand(src, dst, copyOpts), jobProps)); }
public CopyDbJobCommand(IDatabaseSource src, IDatabaseWriter dst, DatabaseCopyOptions copyOpts) { m_src = src; m_dst = dst; m_copyOpts = copyOpts; }