/// <summary> /// Generate SQL script to insert /// </summary> /// <param name="listOfTasks">List of record need to be generated insert script</param> /// <param name="tableName">Table name</param> /// <param name="typeAccessor">Type accessor to access column value</param> /// <param name="listColumnInformation">Store column infomration of table</param> /// <param name="filePath">File path to store sql script</param> public void Insert(List<object> listOfTasks, string tableName, TypeAccessor typeAccessor, List<ColumnInformation> listColumnInformation, string filePath) { // // Initialize this._listOfTasks = listOfTasks; this._numberOfTasks = this._listOfTasks.Count; this._currentIndex = 0; if (this._numberOfTasks == 0) { // // Create dump file try { StreamWriter writer = new StreamWriter(filePath); writer.Close(); } catch (Exception excCreateDumpFile) { LogService.Log.Error("Can not create dump file to map " + tableName, excCreateDumpFile); } return; } // // Okay, calculate, how many thread do we need ? int numberOfThreads = this._maxThread; if (this._numberOfTasks < numberOfThreads * this._minTaskForThread) { numberOfThreads = this._numberOfTasks / this._minTaskForThread; if (numberOfThreads == 0) { numberOfThreads = 1; } } // // Create thread LogService.Log.Info("Creating " + numberOfThreads.ToString() + " SQL threads to insert data."); this._listSQLThread = new List<SQLThread>(); for (int counter = 0; counter < numberOfThreads; ++counter) { SQLThread sqlThread = new SQLThread(this, true); this._listSQLThread.Add(sqlThread); sqlThread.Insert(tableName, listColumnInformation, typeAccessor); } // // Wait until done bool isDone = false; while (isDone == false) { isDone = true; foreach (SQLThread sqlThread in this._listSQLThread) { if (sqlThread.IsDone == false) { isDone = false; break; } } } // // Write sql script to file this.WriteSQLScript(tableName, filePath); }
/// <summary> /// Generate SQL script to insert /// </summary> /// <param name="listOfTasks">List of record need to be generated insert script</param> /// <param name="tableName">Table name</param> /// <param name="typeAccessor">Type accessor to access column value</param> /// <param name="listColumnInformation">Store column infomration of table</param> public void Insert(List <object> listOfTasks, string tableName, TypeAccessor typeAccessor, List <ColumnInformation> listColumnInformation) { // // Initialize this._listOfTasks = listOfTasks; this._numberOfTasks = this._listOfTasks.Count; this._currentIndex = 0; if (this._numberOfTasks == 0) { return; } // // Okay, calculate, how many thread do we need ? int numberOfThreads = this._maxThread; if (this._numberOfTasks < numberOfThreads * this._minTaskForThread) { numberOfThreads = this._numberOfTasks / this._minTaskForThread; if (numberOfThreads == 0) { numberOfThreads = 1; } } // /// Tempory disable trigger this._destinationDatabase.GetNewDbContext().Database.ExecuteSqlCommand("ALTER TABLE " + tableName + " DISABLE TRIGGER ALL"); // // Create thread LogService.Log.Info("Creating " + numberOfThreads.ToString() + " SQL threads to insert data."); this._listSQLThread = new List <SQLThread>(); for (int counter = 0; counter < numberOfThreads; ++counter) { SQLThread sqlThread = new SQLThread(this, false); this._listSQLThread.Add(sqlThread); sqlThread.Insert(tableName, listColumnInformation, typeAccessor); } // // Wait until done bool isDone = false; while (isDone == false) { isDone = true; foreach (SQLThread sqlThread in this._listSQLThread) { if (sqlThread.IsDone == false) { isDone = false; break; } } } // // Turn on trigger this._destinationDatabase.GetNewDbContext().Database.ExecuteSqlCommand("ALTER TABLE " + tableName + " ENABLE TRIGGER ALL"); }
/// <summary> /// Generate SQL script to insert /// </summary> /// <param name="listOfTasks">List of record need to be generated insert script</param> /// <param name="tableName">Table name</param> /// <param name="typeAccessor">Type accessor to access column value</param> /// <param name="listColumnInformation">Store column infomration of table</param> public void Insert(List<object> listOfTasks, string tableName, TypeAccessor typeAccessor, List<ColumnInformation> listColumnInformation) { // // Initialize this._listOfTasks = listOfTasks; this._numberOfTasks = this._listOfTasks.Count; this._currentIndex = 0; if (this._numberOfTasks == 0) { return; } // // Okay, calculate, how many thread do we need ? int numberOfThreads = this._maxThread; if (this._numberOfTasks < numberOfThreads * this._minTaskForThread) { numberOfThreads = this._numberOfTasks / this._minTaskForThread; if (numberOfThreads == 0) { numberOfThreads = 1; } } // /// Tempory disable trigger this._destinationDatabase.GetNewDbContext().Database.ExecuteSqlCommand("ALTER TABLE " + tableName + " DISABLE TRIGGER ALL"); // // Create thread LogService.Log.Info("Creating " + numberOfThreads.ToString() + " SQL threads to insert data."); this._listSQLThread = new List<SQLThread>(); for (int counter = 0; counter < numberOfThreads; ++counter) { SQLThread sqlThread = new SQLThread(this, false); this._listSQLThread.Add(sqlThread); sqlThread.Insert(tableName, listColumnInformation, typeAccessor); } // // Wait until done bool isDone = false; while (isDone == false) { isDone = true; foreach(SQLThread sqlThread in this._listSQLThread) { if (sqlThread.IsDone == false) { isDone = false; break; } } } // // Turn on trigger this._destinationDatabase.GetNewDbContext().Database.ExecuteSqlCommand("ALTER TABLE " + tableName + " ENABLE TRIGGER ALL"); }
/// <summary> /// Generate SQL script to insert /// </summary> /// <param name="listOfTasks">List of record need to be generated insert script</param> /// <param name="tableName">Table name</param> /// <param name="typeAccessor">Type accessor to access column value</param> /// <param name="listColumnInformation">Store column infomration of table</param> /// <param name="filePath">File path to store sql script</param> public void Insert(List <object> listOfTasks, string tableName, TypeAccessor typeAccessor, List <ColumnInformation> listColumnInformation, string filePath) { // // Initialize this._listOfTasks = listOfTasks; this._numberOfTasks = this._listOfTasks.Count; this._currentIndex = 0; if (this._numberOfTasks == 0) { // // Create dump file try { StreamWriter writer = new StreamWriter(filePath); writer.Close(); } catch (Exception excCreateDumpFile) { LogService.Log.Error("Can not create dump file to map " + tableName, excCreateDumpFile); } return; } // // Okay, calculate, how many thread do we need ? int numberOfThreads = this._maxThread; if (this._numberOfTasks < numberOfThreads * this._minTaskForThread) { numberOfThreads = this._numberOfTasks / this._minTaskForThread; if (numberOfThreads == 0) { numberOfThreads = 1; } } // // Create thread LogService.Log.Info("Creating " + numberOfThreads.ToString() + " SQL threads to insert data."); this._listSQLThread = new List <SQLThread>(); for (int counter = 0; counter < numberOfThreads; ++counter) { SQLThread sqlThread = new SQLThread(this, true); this._listSQLThread.Add(sqlThread); sqlThread.Insert(tableName, listColumnInformation, typeAccessor); } // // Wait until done bool isDone = false; while (isDone == false) { isDone = true; foreach (SQLThread sqlThread in this._listSQLThread) { if (sqlThread.IsDone == false) { isDone = false; break; } } } // // Write sql script to file this.WriteSQLScript(tableName, filePath); }