public override void RunCommand() { if (Template == null) { throw new CommandLineError("DAE-00153 Missing template argument"); } IDatabaseSource db = m_connection.GetConnection(); Async.SafeOpen(db.Connection); IAppObjectSqlGenerator sqlgen = (IAppObjectSqlGenerator)AppObjectSqlGeneratorAddonType.Instance.FindHolder(Template).CreateInstance(); ISqlDialect dial; if (Dialect != null) { dial = (ISqlDialect)DialectAddonType.Instance.FindHolder(Dialect).CreateInstance(); } else { dial = new GenericDialect(); } using (TextWriter fw = GetOutputStream()) { SqlOutputStream so = new SqlOutputStream(dial, fw, new SqlFormatProperties()); ISqlDumper dmp = dial.CreateDumper(so, new SqlFormatProperties()); var name = new FullDatabaseRelatedName { ObjectName = new NameWithSchema(Objschema, Objname), ObjectType = Objtype, SubName = Subname }; sqlgen.GenerateSql(db, name, dmp, dial); } Async.SafeClose(db.Connection); }
public override void RunCommand() { IDatabaseSource db = m_connection.GetConnection(); Async.SafeOpen(db.Connection); db.RunScript(RunScript); Async.SafeClose(db.Connection); }
public void RemoveByKey(string connkey) { lock (m_connCache) { Async.SafeClose(m_connCache[connkey].Connection); m_connCache.Remove(connkey); } }
protected override void DoRun(IJobRunEnv env) { m_job.m_process.Info("Executing SQL:" + ToString()); Async.SafeOpen(Database.Connection); Database.Connection.Invoke(RunQueries); Async.SafeClose(Database.Connection); }
private void btnCloseConnection_Click(object sender, EventArgs e) { var conn = SelectedConnection; if (conn != null && conn.IsOpened) { Async.SafeClose(conn); } }
public override void Cancel() { try { m_cancelSrc.Cancel(); } catch { } try { m_cancelDst.Cancel(); } catch { } Async.SafeClose(m_source.Connection); Async.SafeClose(m_target.Connection); }
private void btnChooseOtherServer_Click(object sender, EventArgs e) { var db = TreeSelectForm.SelectDatabase(); if (db != null) { Async.SafeClose(m_conn.Connection); SetDatabase(db.CloneSource()); } }
//public override void DoRenameFile(string newfile) //{ // CloseConnection(); // base.DoRenameFile(newfile); //} //public override void DoDeleteFile() //{ // CloseConnection(); // base.DoDeleteFile(); //} private void CloseConnection() { if (!HConnection.CallRemoveByKey(m_conn.Connection.GetConnKey())) { throw new InternalError("DAE-00192 " + Texts.Get("s_connection_cannot_be_closed")); } Async.SafeClose(m_conn.Connection); RealNode.CollapseNode(); RealNode.ClearChilds(); }
//public CopyDbWizard(CopyDbJobCommand command) //{ // InitializeComponent(); // m_source = command.Source; // m_target = command.Target; //} void CopyDbWizard_Disposed(object sender, EventArgs e) { if (m_source != null) { Async.SafeClose(m_source.Connection); } if (addonSelectFrame1.SelectedObject != null) { m_lastSelectedAddon = AddonTool.ExtractAddonName(addonSelectFrame1.SelectedObject); } }
public void CloseAll() { lock (m_connCache) { foreach (var item in m_connCache.Values) { Async.SafeClose(item.Connection); } m_connCache.Clear(); } }
protected override void DoRun(IJobRunEnv env) { try { Async.SafeOpen(m_dst.Connection); m_loader.ProgressInfo = ProgressInfo; m_dst.Connection.Invoke1(m_loader.LoadDatabase, m_dst); } finally { Async.SafeClose(m_dst.Connection); } }
public override void RunCommand() { if (Format == null) { if (Outfile.EndsWith(".dbk")) { Format = "dbk"; } else if (Outfile.EndsWith(".ddf")) { Format = "ddf"; } else { throw new CommandLineError("DAE-00151 Unknown output format, cannot be deduced from file extension"); } } IDatabaseSource db = m_connection.GetConnection(); Async.SafeOpen(db.Connection); try { switch (Format) { case "ddf": { var s = new DatabaseStructure(db.InvokeLoadStructure(DatabaseStructureMembers.FullStructure, null)); s.Save(Outfile); } break; case "dbk": { DataArchiveWriter dw = new DataArchiveWriter(); dw.FilePlace = FilePlaceAddonType.PlaceFromVirtualFile(Outfile); CopyDbJob.CopyDatabase(db, dw, null, new DatabaseCopyOptions { CopyMembers = DatabaseStructureMembers.FullStructure }); Async.SafeClose(db.Connection); } break; default: throw new CommandLineError("DAE-00152 Unknown format:" + Format); } } finally { Async.SafeClose(db.Connection); } }
public void Close(IPhysicalConnectionFactory fact) { string key = fact.GetConnectionKey(); lock (m_connCache) { if (!m_connCache.ContainsKey(key)) { throw new InternalError("DAE-00029 Connection key not found"); } m_connCache[key].RefCount--; if (m_connCache[key].RefCount <= 0 && !m_connCache[key].KeepAlive) { Async.SafeClose(m_connCache[key].Connection); } } }
protected override void AfterWriteAction(string file) { var connf = ContainerInfo.RelatedConnection; var conn = connf.CreateConnection(); IDatabaseSource db = connf.CreateDatabaseSource(conn, ContainerInfo.RelatedDatabase); db.Connection.SetOnOpenDatabase(ContainerInfo.RelatedDatabase); Async.SafeOpen(db.Connection); try { using (var sr = new StreamReader(file)) { var loader = db.Dialect.CreateDumpLoader(); loader.Connection = db.Connection.SystemConnection; loader.ProgressInfo = ProgressInfo; loader.Run(sr); } } finally { Async.SafeClose(db.Connection); } }
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 override void CloseAllResources() { Async.SafeClose(m_conn); }
private void RestoreDbForm_FormClosed(object sender, FormClosedEventArgs e) { Async.SafeClose(m_conn.Connection); }
protected override void DoRun(IJobRunEnv env) { m_source.Mode = TabularDataStoreMode.Read; m_target.Mode = TabularDataStoreMode.Write; m_target.CopyOptions = m_copyOptions; Async.SafeOpen(m_source.Connection); Async.SafeOpen(m_target.Connection); IAsyncResult asyncs = m_source.BeginGetRowFormat(null); m_sourceStruct = m_source.EndGetRowFormat(asyncs); IAsyncResult asynct = m_target.BeginGetRowFormat(null); m_targetStruct = m_target.EndGetRowFormat(asynct); var targetFull = m_targetStruct; if (m_transform == null) { m_transform = RowTransformAddonType.Instance.LoadRowTransform(m_transformXml, m_sourceStruct, m_targetStruct); if (!m_target.AvailableRowFormat) { m_target.SetRowFormat(m_transform.OutputFormat); m_targetStruct = m_transform.OutputFormat; } } GenericDataQueue queue = new GenericDataQueue(m_sourceStruct, m_transform.OutputFormat, m_transform); if (m_target.Connection != null && m_target.Connection.SystemConnection != null) { var fi = m_source as IDataFormatHolder; var fmt = fi != null ? fi.FormatSettings : new DataFormatSettings(); var outputAdapter = new RecordToDbAdapter(m_transform.OutputFormat, targetFull, m_target.Connection.Dialect, fmt); outputAdapter.ProgressInfo = ProgressInfo; queue.AddOutputAdapter(outputAdapter); } m_source.ProgressInfo = ProgressInfo; m_target.ProgressInfo = ProgressInfo; IAsyncResult async_src = m_source.BeginRead(null, queue); IAsyncResult async_dst = m_target.BeginWrite(null, queue); if (async_src is ICancelable) { m_cancelSrc = (ICancelable)async_src; } if (async_dst is ICancelable) { m_cancelDst = (ICancelable)async_dst; } try { m_source.EndRead(async_src); } finally { m_target.EndWrite(async_dst); } Async.SafeClose(m_source.Connection); Async.SafeClose(m_target.Connection); }