public DatabaseTable Execute(CancellationToken ct, string tableName) { if (ct.IsCancellationRequested) { return(null); } var tables = _readerAdapter.Tables(tableName); if (tables.Count == 0) { return(null); } if (string.IsNullOrEmpty(_readerAdapter.Parameters.Owner)) { var owner = tables[0].SchemaOwner; Trace.WriteLine("Using first schema " + owner); _readerAdapter.Parameters.Owner = owner; } var columns = _readerAdapter.Columns(tableName); var identityColumns = _readerAdapter.IdentityColumns(tableName); var checkConstraints = _readerAdapter.CheckConstraints(tableName); var pks = _readerAdapter.PrimaryKeys(tableName); var uks = _readerAdapter.UniqueKeys(tableName); var fks = _readerAdapter.ForeignKeys(tableName); var dfs = _readerAdapter.DefaultConstraints(tableName); var triggers = _readerAdapter.Triggers(tableName); var tableDescs = _readerAdapter.TableDescriptions(tableName); var colDescs = _readerAdapter.ColumnDescriptions(tableName); var computed = _readerAdapter.ComputedColumns(tableName); var indexes = MergeIndexColumns(_readerAdapter.Indexes(tableName), _readerAdapter.IndexColumns(tableName)); if (columns.Count == 0) { return(null); } var table = new DatabaseTable { SchemaOwner = _readerAdapter.Parameters.Owner, Name = tableName }; table.Columns.AddRange(columns); UpdateCheckConstraints(table, checkConstraints); UpdateIdentities(table.Columns, identityColumns); UpdateComputed(table.Columns, computed); UpdateConstraints(table, pks, ConstraintType.PrimaryKey); UpdateConstraints(table, uks, ConstraintType.UniqueKey); UpdateConstraints(table, fks, ConstraintType.ForeignKey); UpdateConstraints(table, dfs, ConstraintType.Default); UpdateIndexes(table, indexes); UpdateTriggers(table, triggers); UpdateTableDescriptions(table, tableDescs); UpdateColumnDescriptions(table, colDescs); _readerAdapter.PostProcessing(table); return(table); }
public IList <DatabaseView> Execute(CancellationToken ct) { if (ct.IsCancellationRequested) { return(new List <DatabaseView>()); } RaiseReadingProgress(SchemaObjectType.Views); var views = _readerAdapter.Views(null); if (ct.IsCancellationRequested) { return(views); } ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.Processing, SchemaObjectType.Views); var viewFilter = _exclusions.ViewFilter; if (viewFilter != null) { views = views.Where(t => !viewFilter.Exclude(t.Name)).ToList(); } if (ct.IsCancellationRequested) { return(views); } var sources = _readerAdapter.ViewSources(null); if (sources.Count > 0) { foreach (var view in views) { var owner = view.SchemaOwner; var name = view.Name; var src = sources.FirstOrDefault(x => x.Name == name && x.SchemaOwner == owner); if (src != null) { view.Sql = src.Text; } } } if (ct.IsCancellationRequested) { return(views); } var indexes = _readerAdapter.ViewIndexes(null); //get full datatables for all tables, to minimize database calls if (ct.IsCancellationRequested) { return(views); } RaiseReadingProgress(SchemaObjectType.ViewColumns); var viewColumns = _readerAdapter.ViewColumns(null); var count = views.Count; for (var index = 0; index < count; index++) { if (ct.IsCancellationRequested) { return(views); } DatabaseView v = views[index]; ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.Processing, SchemaObjectType.ViewColumns, v.Name, index, count); IEnumerable <DatabaseColumn> cols; if (viewColumns.Count == 0) { cols = _readerAdapter.ViewColumns(v.Name); } else { cols = viewColumns.Where(x => x.TableName == v.Name && x.SchemaOwner == v.SchemaOwner); } v.Columns.AddRange(cols); v.Indexes = indexes.Where(x => x.TableName == v.Name && x.SchemaOwner == v.SchemaOwner).ToList(); } var triggers = _readerAdapter.Triggers(null); foreach (var view in views) { UpdateTriggers(view, triggers); } return(views); }