void IDisposable.Dispose() { foreach (var bulkOperation in Bulks.Select(bulk => bulk.Value)) { bulkOperation.Dispose(); } }
public void Store(object entity) { var shardId = shardResolutionStrategy.GenerateShardIdFor(entity, this); var shard = shards[shardId]; BulkInsertOperation bulkInsertOperation; if (Bulks.TryGetValue(shardId, out bulkInsertOperation) == false) { var actualDatabaseName = database ?? ((dynamic)shard).DefaultDatabase ?? MultiDatabase.GetDatabaseName(shard.Url); bulkInsertOperation = new BulkInsertOperation(actualDatabaseName, shard, shard.Listeners, options, shard.Changes()); Bulks.Add(shardId, bulkInsertOperation); } DatabaseCommands = string.IsNullOrWhiteSpace(database) ? shard.AsyncDatabaseCommands : shard.AsyncDatabaseCommands.ForDatabase(database); string id; if (generateEntityIdOnTheClient.TryGetIdFromInstance(entity, out id) == false) { id = generateEntityIdOnTheClient.GetOrGenerateDocumentKey(entity); } var modifyDocumentId = shardStrategy.ModifyDocumentId(shardedDocumentStore.Conventions, shardId, id); bulkInsertOperation.Store(entity, modifyDocumentId); }
public void Abort() { foreach (var bulkOperation in Bulks.Select(bulk => bulk.Value)) { bulkOperation.Abort(); } }
public void Store(object entity) { var shardId = shardResolutionStrategy.GenerateShardIdFor(entity, this); DatabaseCommands = Shards[shardId].AsyncDatabaseCommands; database = MultiDatabase.GetDatabaseName(Shards[shardId].Url); string id; if (generateEntityIdOnTheClient.TryGetIdFromInstance(entity, out id) == false) { id = generateEntityIdOnTheClient.GetOrGenerateDocumentKey(entity); } var modifyDocumentId = shardStrategy.ModifyDocumentId(shardedDocumentStore.Conventions, shardId, id); BulkInsertOperation bulkInsertOperation; if (Bulks.TryGetValue(shardId, out bulkInsertOperation) == false) { var shard = Shards[shardId]; bulkInsertOperation = new BulkInsertOperation(database, shard, shard.Listeners, options, shard.Changes()); Bulks.Add(shardId, bulkInsertOperation); } bulkInsertOperation.Store(entity, modifyDocumentId); }
public async Task StoreAsync(object entity) { var shardId = shardResolutionStrategy.GenerateShardIdFor(entity, this); var shard = shards[shardId]; BulkInsertOperation bulkInsertOperation; if (Bulks.TryGetValue(shardId, out bulkInsertOperation) == false) { var actualDatabaseName = database ?? ((DocumentStore)shard).DefaultDatabase ?? MultiDatabase.GetDatabaseName(shard.Url); bulkInsertOperation = new BulkInsertOperation(actualDatabaseName, shard, shard.Listeners); Bulks.Add(shardId, bulkInsertOperation); } DatabaseCommands = shard.AsyncDatabaseCommands; string id; if (generateEntityIdOnTheClient.TryGetIdFromInstance(entity, out id) == false) { id = generateEntityIdOnTheClient.GetOrGenerateDocumentKey(entity); } var modifyDocumentId = shardStrategy.ModifyDocumentId(shardedDocumentStore.Conventions, shardId, id); await bulkInsertOperation.StoreAsync(entity, modifyDocumentId).ConfigureAwait(false); }