using System;
using System.Data;
using System.Data.SqlClient;
using JetBrains.Annotations;
namespace SDA.DataProvider.MSSQLWrappers
{
///
/// Microsoft SQL Server alapú bulk insert implementáció.
///
public class MSSQLBulkAdapter : SDABulkAdapter
{
private readonly SqlBulkCopy bulkCopy;
///
/// Létrehoz egy Microsoft SQL Server specifikus bulk adapter példányt.
///
/// Egy SQL Server SqlBulkCopy példány, a
/// tényleges bulk implementáció.
/// Ha a kapott paraméter null.
///
internal MSSQLBulkAdapter([NotNull] SqlBulkCopy bulkCopy)
{
if (bulkCopy == null)
{
throw new ArgumentNullException(nameof(bulkCopy));
}
this.bulkCopy = bulkCopy;
}
///
public override void BulkInsert(DataTable source)
{
if (string.IsNullOrWhiteSpace(source.TableName))
{
throw new ArgumentException("TableName property must be set to the target table name", nameof(source));
}
if (source.Columns.Count == 0)
{
throw new ArgumentException("should contain at least 1 column to bulk insert", nameof(source));
}
if (source.Rows.Count == 0)
{
return;
}
bulkCopy.DestinationTableName = source.TableName;
bulkCopy.WriteToServer(source);
//bulkCopy.NotifyAfter = 1000;
//bulkCopy.SqlRowsCopied += (sender, args) =>
//{
//};
}
}
}