Example #1
0
 void IDisposable.Dispose()
 {
     foreach (var bulkOperation in Bulks.Select(bulk => bulk.Value))
     {
         bulkOperation.Dispose();
     }
 }
Example #2
0
        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);
        }
Example #3
0
 public void Abort()
 {
     foreach (var bulkOperation in Bulks.Select(bulk => bulk.Value))
     {
         bulkOperation.Abort();
     }
 }
Example #4
0
        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);
        }
Example #5
0
        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);
        }