/// <summary> /// Constructor for BulkCopySettings class /// </summary> /// <param name="DestinationTable">Table into which the bulk copy should be done</param> /// <param name="FieldCount">Number of columns that will be copied into the destination table</param> /// <param name="DataMap"> /// Delegate that maps fields of the generic type of the QueryParallelizer instance to ordinal positions /// </param> /// <param name="OutputRowsToExternalEnumerator"> /// If true, the external enumerator will output the same rows that are processed by the bulk copy component. /// If false, the rows will only be output via the bulk component, and the external enumerator will output /// an empty result. /// </param> /// <param name="ConnectionString"> /// Connection string for the destination table. If left null, the loopback connection provider will be used /// </param> /// <param name="CopyOptions"> /// SqlBulkCopyOptions enumeration, used to specify table locking, whether to keep NULLs, and other options /// </param> /// <param name="BatchSize">Number of rows to transfer per batch. Use 0 for unlimited.</param> /// <param name="ColumnMap"> /// Mapping between the DataMap ordinals and the ordinals of columns in the actual destination table. To be /// used when the column order in the base table is different from that specified by the DataMap, or when there /// are fewer columns in the destination table than those that will be populated by the bulk copy operation. /// Can be left null if not needed. /// </param> public BulkCopySettings( string destinationTable, int fieldCount, BulkCopyMappingDelegate dataMap, bool outputRowsToExternalEnumerator, int numThreads, string connectionString, SqlBulkCopyOptions copyOptions, int batchSize, SqlBulkCopyColumnMapping[] columnMap) : this (destinationTable, fieldCount, dataMap, outputRowsToExternalEnumerator, numThreads, connectionString) { this.CopyOptions = copyOptions; this.BatchSize = batchSize; //create an instance of SqlBulkCopy to grab the ColumnMappingCollection SqlBulkCopy bc = new SqlBulkCopy(""); this.ColumnMap = bc.ColumnMappings; if (columnMap != null) { foreach (SqlBulkCopyColumnMapping cm in columnMap) { this.ColumnMap.Add(cm); } } }
public internalDataReader( int fieldCount, BulkCopyMappingDelegate dataMap, roundRobinBuffer bulkRows, ManualResetEvent bulkCompletionEvent, Thread worker, threadMonitor mainThreadMonitor) { this.fieldCount = fieldCount; this.dataMap = dataMap; this.bulkRows = bulkRows; this.bulkCompletionEvent = bulkCompletionEvent; this.worker = worker; this.mainThreadMonitor = mainThreadMonitor; }
/// <summary> /// Constructor for BulkCopySettings class /// </summary> /// <param name="DestinationTable">Table into which the bulk copy should be done</param> /// <param name="FieldCount">Number of columns that will be copied into the destination table</param> /// <param name="DataMap"> /// Delegate that maps fields of the generic type of the QueryParallelizer instance to ordinal positions /// </param> /// <param name="OutputRowsToExternalEnumerator"> /// If true, the external enumerator will output the same rows that are processed by the bulk copy component. /// If false, the rows will only be output via the bulk component, and the external enumerator will output /// an empty result. /// </param> /// <param name="NumThreads">Number of parallel threads to use for the bulk copy operation</param> /// <param name="ConnectionString"> /// Connection string for the destination table. If left null, the loopback connection provider will be used /// </param> public BulkCopySettings( string destinationTable, int fieldCount, BulkCopyMappingDelegate dataMap, bool outputRowsToExternalEnumerator, int numThreads, string connectionString) { if (numThreads < 1 || numThreads > 32) { throw new ArgumentException("Number of bulk copy threads must be between 1 and 32"); } this.DestinationTable = destinationTable; this.FieldCount = fieldCount; this.DataMap = dataMap; this.OutputRowsToExternalEnumerator = outputRowsToExternalEnumerator; this.NumThreads = numThreads; this.ConnectionString = (connectionString == null) ? ConnectionBuilder.LoopbackConnectionString : connectionString; }
public bulkThread( //For the BulkCopy component string connectionString, string destinationTable, SqlBulkCopyOptions copyOptions, int batchSize, SqlBulkCopyColumnMappingCollection columnMap, //for the internalDataReader int fieldCount, BulkCopyMappingDelegate dataMap, roundRobinBuffer bulkRows, ManualResetEvent bulkCompletionEvent, bool impersonateCaller, IntPtr callerIdentityToken, threadMonitor mainThreadMonitor) { this.connectionString = connectionString; this.destinationTable = destinationTable; this.copyOptions = copyOptions; this.batchSize = batchSize; this.columnMap = columnMap; this.impersonateCaller = impersonateCaller; this.callerIdentityToken = callerIdentityToken; Thread t = new Thread(new ThreadStart(this.doWork)); //t.Name = "QueryParallelizer: Bulk Worker Thread (" + this.destinationTable + ")"; this.worker = t; this.bulkDataReader = new internalDataReader( fieldCount, dataMap, bulkRows, bulkCompletionEvent, this.worker, mainThreadMonitor); }