public BulkInsertOperation(string database, IDocumentStore store, CancellationToken token = default(CancellationToken)) { _token = token; _requestExecutor = store.GetRequestExecutor(database); _resetContext = _requestExecutor.ContextPool.AllocateOperationContext(out _context); _streamExposerContent = new StreamExposerContent(); _generateEntityIdOnTheClient = new GenerateEntityIdOnTheClient(_requestExecutor.Conventions, entity => AsyncHelpers.RunSync(() => _requestExecutor.Conventions.GenerateDocumentIdAsync(database, entity))); }
protected string ModifyObjectId(string id, object entity, RavenJObject metadata) { var shardId = shardStrategy.ShardResolutionStrategy.GenerateShardIdFor(entity, this); if (string.IsNullOrEmpty(shardId)) { throw new InvalidOperationException("Could not find shard id for " + entity + " because " + shardStrategy.ShardAccessStrategy + " returned null or empty string for the document shard id."); } metadata[Constants.RavenShardId] = shardId; var modifyDocumentId = shardStrategy.ModifyDocumentId(Conventions, shardId, id); if (modifyDocumentId != id) { GenerateEntityIdOnTheClient.TrySetIdentity(entity, modifyDocumentId); } return(modifyDocumentId); }
private async Task<DocumentMetadata> GetDocumentMetadataAsync<T>(T instance) { DocumentMetadata value; if (entitiesAndMetadata.TryGetValue(instance, out value) == false) { string id; if (GenerateEntityIdOnTheClient.TryGetIdFromInstance(instance, out id) || (instance is IDynamicMetaObjectProvider && GenerateEntityIdOnTheClient.TryGetIdFromDynamic(instance, out id))) { AssertNoNonUniqueInstance(instance, id); var jsonDocument = await GetJsonDocumentAsync(id).ConfigureAwait(false); value = GetDocumentMetadataValue(instance, id, jsonDocument); } else { throw new InvalidOperationException("Could not find the document key for " + instance); } } return value; }
public JsonNetBlittableEntitySerializer(DocumentConventions conventions) { _generateEntityIdOnTheClient = new GenerateEntityIdOnTheClient(conventions, null); _deserializer = new LightWeightThreadLocal <JsonSerializer>(conventions.CreateDeserializer); _reader = new LightWeightThreadLocal <BlittableJsonReader>(() => new BlittableJsonReader()); }
public BulkInsertOperation(string database, IDocumentStore store, CancellationToken token = default) { _disposeOnce = new DisposeOnceAsync <SingleAttempt>(async() => { try { Exception flushEx = null; if (_stream != null) { try { _currentWriter.Write(']'); _currentWriter.Flush(); await _asyncWrite.ConfigureAwait(false); ((MemoryStream)_currentWriter.BaseStream).TryGetBuffer(out var buffer); await _requestBodyStream.WriteAsync(buffer.Array, buffer.Offset, buffer.Count, _token).ConfigureAwait(false); _compressedStream?.Dispose(); await _stream.FlushAsync(_token).ConfigureAwait(false); } catch (Exception e) { flushEx = e; } } _streamExposerContent.Done(); if (_operationId == -1) { // closing without calling a single store. return; } if (_bulkInsertExecuteTask != null) { try { await _bulkInsertExecuteTask.ConfigureAwait(false); } catch (Exception e) { await ThrowBulkInsertAborted(e, flushEx).ConfigureAwait(false); } } } finally { _streamExposerContent?.Dispose(); _resetContext.Dispose(); } }); _token = token; _conventions = store.Conventions; _requestExecutor = store.GetRequestExecutor(database); _resetContext = _requestExecutor.ContextPool.AllocateOperationContext(out _context); _currentWriter = new StreamWriter(new MemoryStream()); _backgroundWriter = new StreamWriter(new MemoryStream()); _streamExposerContent = new StreamExposerContent(); _defaultSerializer = _requestExecutor.Conventions.CreateSerializer(); _customEntitySerializer = _requestExecutor.Conventions.BulkInsert.TrySerializeEntityToJsonStream; _generateEntityIdOnTheClient = new GenerateEntityIdOnTheClient(_requestExecutor.Conventions, entity => AsyncHelpers.RunSync(() => _requestExecutor.Conventions.GenerateDocumentIdAsync(database, entity))); }
public JsonNetBlittableEntitySerializer(DocumentConventions conventions) { _conventions = conventions; _generateEntityIdOnTheClient = new GenerateEntityIdOnTheClient(conventions, null); }
public NewtonsoftJsonBlittableEntitySerializer(ISerializationConventions conventions) { _generateEntityIdOnTheClient = new GenerateEntityIdOnTheClient(conventions.Conventions, null); _deserializer = new LightWeightThreadLocal <IJsonSerializer>(() => conventions.CreateDeserializer()); _reader = new LightWeightThreadLocal <BlittableJsonReader>(() => new BlittableJsonReader()); }