public HashStorage(ISimpleDataProvider dataProvider, IDbConnectionProvider dbConnection, ILogger logger) { _dataProvider = dataProvider; _dbConnection = dbConnection; _logger = logger; _hashStorage = new ResettableLazy <HashSet <byte[]> >(InitHashSet); _tableName = OrmUtils.GetTableName <TData>(); }
public static DateTime GetLastQueryDate <T>(this IDbConnectionProvider connectionProvider) where T : class, IRecordWithDate { string tableName = OrmUtils.GetTableName <T>(); DateTime result = DateTime.MinValue; connectionProvider.GetConnection(connection => { result = connection.ExecuteScalar <DateTime>($"SELECT MAX(Date) FROM [{tableName}]"); }); return(result); }
private Dictionary <byte[], TData> InitMap() { var result = new Dictionary <byte[], TData>(ByteArrayComparer.Instance); _dbConnection.GetConnection(connection => { var query = OrmUtils.GetHashQueryText <TStorage>(); var items = connection.Query <BaseHashEntity <TData> >(query); foreach (var storageItem in items) { result[storageItem.Hash] = storageItem.Id; } }); return(result); }
private static void Insert <T>(DbConnection connection, IEnumerable <T> items, bool checkConstraints = true) where T : class { string tableName = OrmUtils.GetTableName <T>(); var options = SqlBulkCopyOptions.FireTriggers | SqlBulkCopyOptions.UseInternalTransaction; if (checkConstraints) { options = options | SqlBulkCopyOptions.CheckConstraints; } using (var sqlBulkCopy = new SqlBulkCopy(connection.ConnectionString, options)) { sqlBulkCopy.BulkCopyTimeout = 0; sqlBulkCopy.DestinationTableName = tableName; sqlBulkCopy.EnableStreaming = true; foreach (var columnName in OrmUtils.GetColumnNames <T>()) { sqlBulkCopy.ColumnMappings.Add(new SqlBulkCopyColumnMapping(columnName.Item1, columnName.Item2)); } using (var reader = ObjectReader.Create(items)) { sqlBulkCopy.WriteToServer(reader); } } }