예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }