public void Cloner_Clone_Param_ReturnNoRow(int id) { var row = Make.Row("color", "id", id); var clones = _executionPlanBuilder.Append(row, true).Compile().Execute(); Assert.Equal(0, clones.Results.Count); }
public void Cloning_With_StaticTable(Connection conn) { //Arrange var config = Utils.MakeDefaultSettings(conn); var tablesConfig = config.GetDefaultSchema(); tablesConfig.AddRange(new List <TableModifier> { new TableModifier { Name = "Artist", IsStatic = true } }); var executionPlanBuilder = new ExecutionPlanBuilder(config); var source = new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Album", Columns = new ColumnsWithValue { { "AlbumId", 1 } } }; var clonedData = new List <RowIdentifier>(); executionPlanBuilder.StatusChanged += (s, e) => { if (e.Status == Status.Cloning) { clonedData.Add(e.SourceRow); } }; //Act var query = executionPlanBuilder.Append(source, false).Compile(); query.Commiting += (s, e) => e.Cancel = true; query.Execute(); //Assert var expectedData = new List <RowIdentifier> { new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Album", Columns = new ColumnsWithValue { { "AlbumId", 1 } } } }; Assert.True(Utils.ScrambledEquals(clonedData, expectedData, RowIdentifierComparer.OrdinalIgnoreCase)); }
/// <summary> /// DataCloner Hello World program /// </summary> static void Main(string[] args) { //Minimal configuration var project = new Project() { ConnectionStrings = new List <Connection> { new Connection { Id = "UNI", ProviderName = "System.Data.SqlClient", ConnectionString = @"Data Source=(localdb)\MSSQLLocalDB;Integrated Security=True;" } } }; //Creating an execution plan for reuse later var builder = new ExecutionPlanBuilder(project, null); builder.StatusChanged += Builder_StatusChanged; Console.WriteLine("Retreiving rows to the execution plan"); NbRowsFetch = 0; var startTime = DateTime.Now.Ticks; builder.Append(new RowIdentifier { ServerId = "UNI", Database = "Chinook", Schema = "dbo", Table = "Customer", Columns = new ColumnsWithValue { { "CustomerId", 1 } } }); var endTime = DateTime.Now.Ticks; //Creating a mew clone of the data inside the database var query = builder.Compile(); query.Commiting += Query_Commiting; query.Execute(); //Results var msElapsed = new TimeSpan(endTime - startTime).TotalMilliseconds; Console.WriteLine($"Rows fetched : {NbRowsFetch}"); Console.WriteLine($"Completed in : {msElapsed} ms"); Console.WriteLine($"Row per second : {NbRowsFetch / (msElapsed / 1000)}"); Console.ReadKey(); }
public void CloningDerivatives_With_GlobalAccessDenied(Connection conn) { //Arrange var project = Utils.MakeDefaultProject(conn); project.ExtractionTemplates[0].Tables.Add(new Table { Name = "Album", DerativeTableGlobal = new DerivativeTableGlobal { GlobalAccess = DerivativeTableAccess.Denied } }); var executionPlanBuilder = new ExecutionPlanBuilder(project, Utils.MakeDefaultContext()); var source = new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Artist", Columns = new ColumnsWithValue { { "ArtistId", 1 } } }; var clonedData = new List <RowIdentifier>(); executionPlanBuilder.StatusChanged += (s, e) => { if (e.Status == Status.Cloning) { clonedData.Add(e.SourceRow); } }; //Act var query = executionPlanBuilder.Append(source, true).Compile(); query.Commiting += (s, e) => e.Cancel = true; query.Execute(); //Assert var expectedData = new List <RowIdentifier> { new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Artist", Columns = new ColumnsWithValue { { "ArtistId", 1 } } }, new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Album", Columns = new ColumnsWithValue { { "AlbumId", 1 } } }, new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Album", Columns = new ColumnsWithValue { { "AlbumId", 4 } } } }; Assert.True(Utils.ScrambledEquals(clonedData, expectedData, RowIdentifierComparer.OrdinalIgnoreCase)); }
public void Cloning_With_DataBuilder(Connection conn) { //Arrange var project = Utils.MakeDefaultProject(conn); project.ExtractionTemplates[0].Tables.AddRange(new List <Table> { new Table { Name = "Employee", DataBuilders = new List <DataBuilder> { new DataBuilder { Name = "FirstName", BuilderName = "StringDataBuilder" }, new DataBuilder { Name = "LastName", BuilderName = "StringDataBuilder" }, new DataBuilder { Name = "ReportsTo", BuilderName = "AutoIncrementDataBuilder" } } } }); var executionPlanBuilder = new ExecutionPlanBuilder(project, Utils.MakeDefaultContext()); var source = new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Employee", Columns = new ColumnsWithValue { { "EmployeeId", 1 } } }; //Act var query = executionPlanBuilder.Append(source, false).Compile(); IDbCommand command = null; query.Commiting += (s, e) => { e.Cancel = true; command = e.Command; }; query.Execute(); //Assert var paramFirstName = command?.Parameters["@FirstName0"] as IDataParameter; Assert.Matches("(.+){20}", paramFirstName.Value.ToString()); var paramLastName = command?.Parameters["@LastName0"] as IDataParameter; Assert.Matches("(.+){20}", paramLastName.Value.ToString()); var paramReportsTo = command?.Parameters["@ReportsTo0"] as IDataParameter; Assert.True(paramReportsTo.Value.IsNumericType()); }
public void Cloning_With_ForeignKeyRemove(Connection conn) { //Arrange var project = Utils.MakeDefaultProject(conn); project.ExtractionTemplates[0].Tables.AddRange(new List <Table> { new Table { Name = "Album", ForeignKeys = new ForeignKeys { ForeignKeyRemove = new ForeignKeyRemove { Columns = new List <ForeignKeyRemoveColumn> { new ForeignKeyRemoveColumn { Name = "ArtistId" } } } } } }); var executionPlanBuilder = new ExecutionPlanBuilder(project, Utils.MakeDefaultContext()); var source = new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Album", Columns = new ColumnsWithValue { { "AlbumId", 1 } } }; var clonedData = new List <RowIdentifier>(); executionPlanBuilder.StatusChanged += (s, e) => { if (e.Status == Status.Cloning) { clonedData.Add(e.SourceRow); } }; //Act var query = executionPlanBuilder.Append(source, false).Compile(); query.Commiting += (s, e) => e.Cancel = true; query.Execute(); //Assert var expectedData = new List <RowIdentifier> { new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Album", Columns = new ColumnsWithValue { { "AlbumId", 1 } } } }; Assert.True(Utils.ScrambledEquals(clonedData, expectedData, RowIdentifierComparer.OrdinalIgnoreCase)); }
public void Cloning_Should_NotCloneDerivativeOfDependancy(Connection conn) { //Arrange var project = Utils.MakeDefaultProject(conn); var executionPlanBuilder = new ExecutionPlanBuilder(project, Utils.MakeDefaultContext()); var source = new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "PlaylistTrack", Columns = new ColumnsWithValue { { "PlaylistId", 1 }, { "TrackId", 1 } } }; var clonedData = new List <RowIdentifier>(); executionPlanBuilder.StatusChanged += (s, e) => { if (e.Status == Status.Cloning) { clonedData.Add(e.SourceRow); } }; //Act var query = executionPlanBuilder.Append(source, false).Compile(); query.Execute(); query.Commiting += (s, e) => e.Cancel = true; //Assert var expectedData = new List <RowIdentifier> { new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "PlaylistTrack", Columns = new ColumnsWithValue { { "PlaylistId", 1 }, { "TrackId", 1 } } }, new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Playlist", Columns = new ColumnsWithValue { { "PlaylistId", 1 } } }, new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Track", Columns = new ColumnsWithValue { { "TrackId", 1 } } }, new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Album", Columns = new ColumnsWithValue { { "AlbumId", 1 } } }, new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Artist", Columns = new ColumnsWithValue { { "ArtistId", 1 } } }, new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Genre", Columns = new ColumnsWithValue { { "GenreId", 1 } } }, new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "MediaType", Columns = new ColumnsWithValue { { "MediaTypeId", 1 } } } }; Assert.True(Utils.ScrambledEquals(clonedData, expectedData, RowIdentifierComparer.OrdinalIgnoreCase)); }
public void CloningDependencies_With_DefaultConfig(Connection conn) { //Arrange var executionPlanBuilder = new ExecutionPlanBuilder(Utils.MakeDefaultProject(conn), Utils.MakeDefaultContext()); var source = new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Customer", Columns = new ColumnsWithValue { { "CustomerId", 1 } } }; var clonedData = new List <RowIdentifier>(); executionPlanBuilder.StatusChanged += (s, e) => { if (e.Status == Status.Cloning) { clonedData.Add(e.SourceRow); } }; //Act var query = executionPlanBuilder.Append(source, false).Compile(); query.Commiting += (s, e) => e.Cancel = true; query.Execute(); //Assert var expectedData = new List <RowIdentifier> { new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Customer", Columns = new ColumnsWithValue { { "CustomerId", 1 } } }, new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Employee", Columns = new ColumnsWithValue { { "EmployeeId", 3 } } }, new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Employee", Columns = new ColumnsWithValue { { "EmployeeId", 2 } } }, new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Employee", Columns = new ColumnsWithValue { { "EmployeeId", 1 } } } }; Assert.True(Utils.ScrambledEquals(clonedData, expectedData, RowIdentifierComparer.OrdinalIgnoreCase)); }
private void InitClonerWorker() { _cloneWorker = new BackgroundWorker(); _cloneWorker.WorkerReportsProgress = true; _cloneWorker.RunWorkerCompleted += (s, e) => { var sbLog = new StringBuilder(); var paramsOut = e.Result as ClonerWorkerOutputArgs; sbLog.Append("\rCloning completed in : ") .Append(DateTime.Now.Subtract(paramsOut.StartDate).ToString("hh':'mm':'ss'.'fff")) .Append("\r"); if (chkSimulation.IsChecked.GetValueOrDefault()) { sbLog.AppendLine("Simulation mode : No clone appended to the database."); } else { foreach (var row in paramsOut.ClonedRow) { sbLog.Append("New clone : ") .Append(row.Database).Append(".").Append(row.Schema) .Append(".").Append(row.Table).Append(" : ("); foreach (var col in row.Columns) { var sqlVar = col.Value as SqlVariable; sbLog.Append(col.Key).Append("=").Append(sqlVar ?? col.Value).Append(", "); } sbLog.Remove(sbLog.Length - 2, 2); sbLog.Append(")").Append("\r"); } } sbLog.Append("\r"); rtbStatus.AppendText(sbLog.ToString()); rtbStatus.ScrollToEnd(); BtnAppend.IsEnabled = BtnExec.IsEnabled = BtnReset.IsEnabled = true; }; _cloneWorker.ProgressChanged += (s, e) => { var statusArgs = e.UserState as StatusChangedEventArgs; if (statusArgs != null) { StatusChanged_event(s, statusArgs); } var queryArgs = e.UserState as QueryCommitingEventArgs; if (queryArgs != null) { QueryCommiting_event(s, queryArgs); } }; _cloneWorker.DoWork += (s, arg) => { var paramsIn = arg.Argument as ClonerWorkerInputArgs; var paramsOut = new ClonerWorkerOutputArgs { StartDate = DateTime.Now, ClonedRow = new List <RowIdentifier>() }; var source = new RowIdentifier(); source.Columns.Clear(); source.ServerId = paramsIn.Server; source.Database = paramsIn.Database; source.Schema = paramsIn.Schema; source.Table = paramsIn.Table; source.Columns = paramsIn.Columns; if (paramsIn.AppendMode) { _executionPlanBuilder.Append(source, true); _lastQuery = null; } else { if (_lastQuery == null) { _lastQuery = _executionPlanBuilder.Compile(); _lastQuery.Commiting += ClonerWorkerQueryCommiting_event; } //Clone for (int i = 0; i < paramsIn.NbCopies; i++) { paramsOut.ClonedRow.AddRange(_lastQuery.Execute().Results); } } arg.Result = paramsOut; }; }