protected void RaiseProgress(ProgressType progressType, SchemaObjectType schemaObjectType, string name, int?index, int?count) { ReaderEventArgs.RaiseEvent(ReaderProgress, this, progressType, schemaObjectType, name, index, count); }
public DatabaseTable Load(string tableName, CancellationToken ct) { if (ct.IsCancellationRequested) { return(new DatabaseTable()); } ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.ReadingSchema, SchemaObjectType.Tables, tableName, null, null); var schemaOwner = _schemaReader.Owner; DatabaseTable table; using (var ds = _schemaReader.Table(tableName)) { if (ds == null) { return(null); } if (ds.Tables.Count == 0) { return(null); } ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.Processing, SchemaObjectType.Tables, tableName, null, null); table = _databaseSchema.FindTableByName(tableName, schemaOwner); if (table == null) { table = new DatabaseTable(); _databaseSchema.Tables.Add(table); } table.Name = tableName; table.SchemaOwner = schemaOwner; //columns must be done first as it is updated by the others schemaOwner = AddColumns(schemaOwner, tableName, table, ds); AddConstraints(ds, table); AddOthers(schemaOwner, tableName, table, ds); _schemaReader.PostProcessing(table); } return(table); }
protected void RaiseReadingProgress(SchemaObjectType schemaObjectType) { ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.ReadingSchema, schemaObjectType); }
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; } } } //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); } return(views); }
public void Load(CancellationToken ct) { if (ct.IsCancellationRequested) { return; } try { ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.ReadingSchema, SchemaObjectType.Functions); var functions = _schemaReader.Functions(); ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.Processing, SchemaObjectType.Functions); _databaseSchema.Functions.Clear(); _databaseSchema.Functions.AddRange(SchemaProcedureConverter.Functions(functions)); } catch (DbException ex) { Debug.WriteLine("Cannot read functions - database security may prevent access to DDL\n" + ex.Message); throw; //or suppress if not applicable } if (ct.IsCancellationRequested) { return; } ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.ReadingSchema, SchemaObjectType.StoredProcedure); var dt = _schemaReader.StoredProcedures(); if (ct.IsCancellationRequested) { return; } ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.Processing, SchemaObjectType.StoredProcedure); SchemaProcedureConverter.StoredProcedures(_databaseSchema, dt); var procFilter = _exclusions.StoredProcedureFilter; if (procFilter != null) { _databaseSchema.StoredProcedures.RemoveAll(p => procFilter.Exclude(p.Name)); } _databaseSchema.Packages.Clear(); _databaseSchema.Packages.AddRange(SchemaProcedureConverter.Packages(_schemaReader.Packages())); var packFilter = _exclusions.PackageFilter; if (packFilter != null) { _databaseSchema.Packages.RemoveAll(p => packFilter.Exclude(p.Name)); } if (ct.IsCancellationRequested) { return; } //do all the arguments as one call and sort them out. //NB: This is often slow on Oracle ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.ReadingSchema, SchemaObjectType.ProcedureArguments); var args = _schemaReader.StoredProcedureArguments(null); ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.Processing, SchemaObjectType.ProcedureArguments); var converter = new SchemaProcedureConverter(); converter.PackageFilter = _exclusions.PackageFilter; converter.StoredProcedureFilter = _exclusions.StoredProcedureFilter; if (args.Rows.Count == 0) { //MySql v6 won't do all stored procedures. So we have to do them individually. foreach (var sproc in _databaseSchema.StoredProcedures) { if (ct.IsCancellationRequested) { return; } args = _schemaReader.StoredProcedureArguments(sproc.Name); converter.UpdateArguments(_databaseSchema, args); } foreach (var function in _databaseSchema.Functions) { if (ct.IsCancellationRequested) { return; } args = _schemaReader.StoredProcedureArguments(function.Name); converter.UpdateArguments(_databaseSchema, args); } } if (ct.IsCancellationRequested) { return; } //arguments could be for functions too converter.UpdateArguments(_databaseSchema, args); foreach (var function in _databaseSchema.Functions) { //return types are assigned as arguments (in most platforms). Move them to return type. function.CheckArgumentsForReturnType(); } if (ct.IsCancellationRequested) { return; } //procedure, function and view source sql ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.ReadingSchema, SchemaObjectType.ProcedureSource); var srcs = _schemaReader.ProcedureSource(null); if (ct.IsCancellationRequested) { return; } ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.Processing, SchemaObjectType.ProcedureSource); SchemaSourceConverter.AddSources(_databaseSchema, srcs); }
public IList <DatabaseTable> Load(CancellationToken ct) { if (ct.IsCancellationRequested) { return(EmptyList()); } RaiseReadingProgress(SchemaObjectType.Tables); //get full datatables for all tables, to minimize database calls var tabs = _schemaReader.Tables(); //we either use the converters directly (DataTable to our db model) //or loaders, which wrap the schema loader calls and converters //loaders hide the switch between calling for all tables, or a specific table if (ct.IsCancellationRequested) { return(EmptyList()); } RaiseReadingProgress(SchemaObjectType.Columns); var columnLoader = new ColumnLoader(_schemaReader); if (ct.IsCancellationRequested) { return(EmptyList()); } RaiseReadingProgress(SchemaObjectType.Constraints); var constraintLoader = new SchemaConstraintLoader(_schemaReader); var indexLoader = new IndexLoader(_schemaReader); var ids = _schemaReader.IdentityColumns(null); var computeds = _schemaReader.ComputedColumns(null); if (ct.IsCancellationRequested) { return(EmptyList()); } RaiseReadingProgress(SchemaObjectType.Descriptions); var tableDescriptions = new TableDescriptionConverter(_schemaReader.TableDescription(null)); var columnDescriptions = new ColumnDescriptionConverter(_schemaReader.ColumnDescription(null)); DataTable triggers = _schemaReader.Triggers(null); var triggerConverter = new TriggerConverter(triggers); if (ct.IsCancellationRequested) { return(EmptyList()); } ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.Processing, SchemaObjectType.Tables); var tables = SchemaConverter.Tables(tabs); var tableFilter = _exclusions.TableFilter; if (tableFilter != null) { tables.RemoveAll(t => tableFilter.Exclude(t.Name)); } tables.Sort(delegate(DatabaseTable t1, DatabaseTable t2) { //doesn't account for mixed schemas return(string.Compare(t1.Name, t2.Name, StringComparison.OrdinalIgnoreCase)); }); int tablesCount = tables.Count; for (var i = 0; i < tablesCount; i++) { var table = tables[i]; var tableName = table.Name; var schemaName = table.SchemaOwner; if (ct.IsCancellationRequested) { return(tables); } ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.Processing, SchemaObjectType.Tables, tableName, i, tablesCount); table.Description = tableDescriptions.FindDescription(table.SchemaOwner, tableName); var databaseColumns = columnLoader.Load(tableName, schemaName); table.Columns.AddRange(databaseColumns); columnDescriptions.AddDescriptions(table); var pkConstraints = constraintLoader.Load(tableName, schemaName, ConstraintType.PrimaryKey); PrimaryKeyLogic.AddPrimaryKey(table, pkConstraints); var fks = constraintLoader.Load(tableName, schemaName, ConstraintType.ForeignKey); table.AddConstraints(fks); table.AddConstraints(constraintLoader.Load(tableName, schemaName, ConstraintType.UniqueKey)); table.AddConstraints(constraintLoader.Load(tableName, schemaName, ConstraintType.Check)); table.AddConstraints(constraintLoader.Load(tableName, schemaName, ConstraintType.Default)); indexLoader.AddIndexes(table); SchemaConstraintConverter.AddIdentity(ids, table); SchemaConstraintConverter.AddComputed(computeds, table); table.Triggers.Clear(); table.Triggers.AddRange(triggerConverter.Triggers(tableName)); _schemaReader.PostProcessing(table); } return(tables); }