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); }
//private void selectTemplateComboFrame1_ChangedSelectedItem(object sender, EventArgs e) //{ // RecreateBackupFormat(); //} //private void RecreateBackupFormat() //{ // AddonHolder item = selectTemplateComboFrame1.SelectedAddonHolder; // if (item != null) m_format = (IBackupFormat)item.CreateInstance(); // else m_format = new DataArchiveBackupFormat(); // propertyFrame1.SelectedObject = m_format; //} private void InitPropertiesPage() { try { Async.SafeOpen(m_source.Connection); DatabaseStructureMembers dbmem = new DatabaseStructureMembers { TableList = true, SpecificObjectList = true, SchemaList = true, IgnoreSystemObjects = true, }; IDatabaseStructure dbs = m_source.InvokeLoadStructure(dbmem, null); if (m_chooseNode == null) { m_chooseNode = new DbDefChooseTreeNode(dbs); treObjects.Root = m_chooseNode; } } catch (Exception err) { Errors.Report(err); wizard1.Back(); } }
public void SetBindings(ITabularDataStore source, ITabularDataStore target) { Async.SafeOpen(source.Connection); Async.SafeOpen(target.Connection); //lbsource.Enabled = false; //lbtarget.Enabled = false; lbsource.Items.Clear(); lbtarget.Rows.Clear(); //lbtarget.Items.Clear(); Errors.Assert(source.AvailableRowFormat); //Async.CreateInvokeCallback(m_invoker, GotRowFormat)); m_source = source; m_target = target; //lbsource.Enabled = true; //lbtarget.Enabled = true; try { IAsyncResult async = m_source.BeginGetRowFormat(null); Async.WaitFor(async); m_srcformat = m_source.EndGetRowFormat(async); } catch (Exception err) { throw new BulkCopyInputError("DAE-00184", err); } foreach (IColumnStructure col in m_srcformat.Columns) { lbsource.Items.Add(col.ColumnName); lbtarget.Rows.Add(col.ColumnName, new GenericTransform.ColumnColExprType().ToString(), col.ColumnName); //lbtarget.Items.Add(col.ColumnName); } }
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); }
public override IAsyncResult BeginLoadChildren(AsyncCallback callback) { if (AutoConnect && !m_usageConn.Connection.IsOpened) { Async.SafeOpen(m_usageConn.Connection); } return(m_usageConn.Connection.BeginInvoke((Action)DoGetChildren, callback)); }
public override void RunCommand() { IDatabaseSource db = m_connection.GetConnection(); Async.SafeOpen(db.Connection); db.RunScript(RunScript); Async.SafeClose(db.Connection); }
public ITabularDataView GetTabularData() { Async.SafeOpen(Connection); // get tabular data requires allready opened connection GridTable tbl = new GridTable(m_table, m_table.FullName.ToString()); IDataQueue queue = new GenericDataQueue(m_table, m_table, new IdentityTransform(m_table)); tbl.FillOnBackground(queue); Conn.BeginReadTable(m_table.FullName, queue, FinishedReadTable); return(tbl); }
public override bool AllowExpand() { if (AutoConnect) { Async.SafeOpen(m_conn); return(true); } else { return(base.AllowExpand()); } }
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); } }
private void PrepareSource() { if (m_showSource) { m_source = source.DataStore; Async.SafeOpen(m_source.Connection); } if (m_source != null && !m_sourceCacheCleared) { m_source.ClearCaches(); m_sourceCacheCleared = true; } }
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); } }
private void InitColumnMap() { PrepareSource(); if (m_showTarget) { m_target = target.DataStore; Async.SafeOpen(m_target.Connection); } if (m_target != null) { m_target.ClearCaches(); } columnMapFrame1.SetBindings(m_source, m_target); }
private void WantStructure() { Async.SafeOpen(m_source.Connection); DatabaseStructureMembers dbmem = new DatabaseStructureMembers { TableList = true, DomainList = true, SpecificObjectList = true, SchemaList = true, IgnoreSystemObjects = true, }; m_structure = m_source.InvokeLoadStructure(dbmem, null); }
void SetDatabase(IDatabaseSource conn) { cbxDatabase.Items.Clear(); m_conn = conn; m_conn.Connection.Owner = this; Async.SafeOpen(m_conn.Connection); foreach (string s in m_conn.Connection.InvokeR1<List<string>, IPhysicalConnection>(m_conn.Dialect.GetDatabaseNames, m_conn.Connection)) { if (s != null) { cbxDatabase.Items.Add(s); } } if (conn.DatabaseName != null) { cbxDatabase.Text = conn.DatabaseName; } tbxDestServer.Text = m_conn.Connection.ToString(); }
protected override void DoRun(IJobRunEnv env) { var dbconn = Args[0].FindDatabaseConnection(ConnPack); if (dbconn != null) { Async.SafeOpen(dbconn.Connection); } Place.ProgressInfo = ProgressInfo; Generator.ProgressInfo = ProgressInfo; var holder = new ExtendedFileNameHolderInfo { DirectionIsSave = true, FileExtension = "sql", Filter = "*.sql|{s_sql_script} (*.sql)", RelatedConnection = Args[0].GetConnection(), RelatedDatabase = Args[0].FindDatabaseName() }; Place.SetFileHolderInfo(holder); string fn = Place.GetWorkingFileName(); using (var tw = new StreamWriter(fn)) { var dmp = (Dialect ?? (dbconn != null ? dbconn.Dialect : null) ?? (Args[0].Dialect != null ? Args[0].Dialect : null) ?? GenericDialect.Instance).CreateDumper(tw, FormatProps); foreach (var obj in Args) { if (dbconn != null) { Generator.GenerateSql(dbconn, obj.GetFullDatabaseRelatedName(), dmp, dmp.Dialect); } else { Generator.GenerateSql(obj, dmp, dmp.Dialect); } } } Place.FinalizeFileName(); }
protected override void DoRun(IJobRunEnv env) { IPhysicalConnection dbconn = null; if (m_dataFrame.TabularData.Connection != null) { ConnPack.GetConnection(m_dataFrame.TabularData.Connection.PhysicalFactory, false); Async.SafeOpen(dbconn); } Place.ProgressInfo = ProgressInfo; Generator.ProgressInfo = ProgressInfo; var holder = new ExtendedFileNameHolderInfo { DirectionIsSave = true, FileExtension = "sql", Filter = "*.sql|{s_sql_script} (*.sql)", RelatedConnection = m_dataFrame.TabularData.Connection != null ? m_dataFrame.TabularData.Connection.PhysicalFactory : null, RelatedDatabase = m_dataFrame.TabularData.DatabaseSource != null ? m_dataFrame.TabularData.DatabaseSource.DatabaseName : null, }; Place.SetFileHolderInfo(holder); string fn = Place.GetWorkingFileName(); using (var tw = new StreamWriter(fn)) { m_dmp = (Dialect ?? (dbconn != null ? dbconn.Dialect : null) ?? m_dataFrame.TabularData.Dialect ?? GenericDialect.Instance).CreateDumper(tw, FormatProps); if (Generator.IsRowEnumerator) { m_rows.LoadAllRows(ForEachRow); } else { Generator.GenerateSql(m_dmp); } } Place.FinalizeFileName(); }
private IPhysicalConnection _OpenCore(IPhysicalConnectionFactory fact, bool keepAlive, bool incref, bool open) { if (fact == null) { return(null); } string key = fact.GetConnectionKey(); IPhysicalConnection res; lock (m_connCache) { if (!m_connCache.ContainsKey(key)) { var item = new CacheItem(); item.Connection = fact.CreateConnection(); if (Cache != null) { // use shared cache item.Connection.Cache = Cache.Connection(key); } item.Connection.Owner = this; m_connCache[key] = item; } if (incref) { m_connCache[key].RefCount++; } if (keepAlive) { m_connCache[key].KeepAlive = true; } res = m_connCache[key].Connection; } if (open) { Async.SafeOpen(res); } return(res); }
private void Initialize(AppObject[] objs) { m_objs = objs; foreach (var gen in m_objs[0].GetSqlGenerators()) { lbxGenerator.Items.Add(gen); } InitiDialects(); addonSelectFrame1.Reload(false); if (lbxGenerator.Items.Count > 0) { lbxGenerator.SelectedIndex = 0; } m_db = m_objs[0].FindDatabaseConnection(ConnPack); if (m_db != null) { Async.SafeOpen(m_db.Connection); } m_initialized = true; tbxRows.Enabled = btnOkPreviewRows.Enabled = false; RefreshPreview(); }
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 void SetBindings(ITabularDataStore source, ITabularDataStore target) { using (WaitContext wc = new WaitContext()) { Async.SafeOpen(source.Connection); Async.SafeOpen(target.Connection); try { IAsyncResult res1 = source.BeginGetRowFormat(null); Async.WaitFor(res1); m_source = source.EndGetRowFormat(res1); } catch (Exception err) { throw new BulkCopyInputError("DAE-00181", err); } if (m_source.Columns.Count == 0) { throw new ExpectedError("DAE-00182 " + Texts.Get("s_no_columns_detected_in_imported_source")); } IAsyncResult res2 = target.BeginGetRowFormat(null); Async.WaitFor(res2); m_target = target.EndGetRowFormat(res2); int acty = labValue.Top + labValue.Height + 10; int colindex = 0; foreach (IColumnStructure col in m_target.Columns) { Label lab = new Label(); Controls.Add(lab); lab.Left = labTarget.Left; lab.Top = acty; lab.Text = col.ColumnName + " :"; CheckBox skip = new CheckBox(); Controls.Add(skip); skip.Top = acty; skip.Width = 30; skip.Left = labSkip.Left; m_checks.Add(skip); skip.Tag = colindex; skip.CheckedChanged += new EventHandler(skip_CheckedChanged); ComboBox type = new ComboBox(); Controls.Add(type); type.Left = labType.Left; type.Top = acty; type.DropDownStyle = ComboBoxStyle.DropDownList; GenericTransform.GetColExprTypes(type.Items); type.SelectedIndex = 0; type.Tag = colindex; m_typeCombos.Add(type); ComboBox sel = new ComboBox(); Controls.Add(sel); sel.Left = labValue.Left; sel.Top = acty; sel.DropDownStyle = ComboBoxStyle.DropDown; sel.DropDownClosed += new EventHandler(sel_DropDownClosed); sel.Tag = colindex; foreach (IColumnStructure srccol in m_source.Columns) { sel.Items.Add(srccol.ColumnName); } sel.SelectedIndex = sel.Items.IndexOf(col.ColumnName); if (sel.SelectedIndex < 0) { if (col.ColumnOrder < sel.Items.Count) { sel.SelectedIndex = col.ColumnOrder; } else { sel.SelectedIndex = 0; } } m_combos.Add(sel); acty += Math.Max(sel.Height, lab.Height) * 5 / 4; colindex++; } } }
public override bool AllowExpand() { Async.SafeOpen(m_conn.Connection); RealNode.RefreshChilds(false); return(true); }
public override void OpenConnection() { Async.SafeOpen(m_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(); } }
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); }