/// <summary> /// Initializes a new instance of the <see cref="FhirDataStore"/> class. /// </summary> /// <param name="documentClient"> /// A function that returns an <see cref="IDocumentClient"/>. /// Note that this is a function so that the lifetime of the instance is not directly controlled by the IoC container. /// </param> /// <param name="cosmosDataStoreConfiguration">The data store configuration</param> /// <param name="cosmosDocumentQueryFactory">The factory used to create the document query.</param> /// <param name="retryExceptionPolicyFactory">The retry exception policy factory.</param> /// <param name="fhirRequestContextAccessor">The fhir request context accessor.</param> /// <param name="namedCosmosCollectionConfigurationAccessor">The IOptions accessor to get a named version.</param> /// <param name="logger">The logger instance.</param> public FhirDataStore( IScoped <IDocumentClient> documentClient, CosmosDataStoreConfiguration cosmosDataStoreConfiguration, FhirCosmosDocumentQueryFactory cosmosDocumentQueryFactory, RetryExceptionPolicyFactory retryExceptionPolicyFactory, IFhirRequestContextAccessor fhirRequestContextAccessor, IOptionsMonitor <CosmosCollectionConfiguration> namedCosmosCollectionConfigurationAccessor, ILogger <FhirDataStore> logger) { EnsureArg.IsNotNull(documentClient, nameof(documentClient)); EnsureArg.IsNotNull(cosmosDataStoreConfiguration, nameof(cosmosDataStoreConfiguration)); EnsureArg.IsNotNull(cosmosDocumentQueryFactory, nameof(cosmosDocumentQueryFactory)); EnsureArg.IsNotNull(retryExceptionPolicyFactory, nameof(retryExceptionPolicyFactory)); EnsureArg.IsNotNull(namedCosmosCollectionConfigurationAccessor, nameof(namedCosmosCollectionConfigurationAccessor)); EnsureArg.IsNotNull(logger, nameof(logger)); _collectionConfiguration = namedCosmosCollectionConfigurationAccessor.Get(Constants.CollectionConfigurationName); _cosmosDocumentQueryFactory = cosmosDocumentQueryFactory; _retryExceptionPolicyFactory = retryExceptionPolicyFactory; _logger = logger; _documentClient = new FhirDocumentClient(documentClient.Value, fhirRequestContextAccessor, cosmosDataStoreConfiguration.ContinuationTokenSizeLimitInKb); _cosmosDataStoreConfiguration = cosmosDataStoreConfiguration; _collectionUri = cosmosDataStoreConfiguration.GetRelativeCollectionUri(_collectionConfiguration.CollectionId); _upsertWithHistoryProc = new UpsertWithHistory(); _hardDelete = new HardDelete(); }
/// <summary> /// Initializes a new instance of the <see cref="CosmosFhirDataStore"/> class. /// </summary> /// <param name="documentClientScope"> /// A function that returns an <see cref="IDocumentClient"/>. /// Note that this is a function so that the lifetime of the instance is not directly controlled by the IoC container. /// </param> /// <param name="cosmosDataStoreConfiguration">The data store configuration.</param> /// <param name="namedCosmosCollectionConfigurationAccessor">The IOptions accessor to get a named version.</param> /// <param name="cosmosDocumentQueryFactory">The factory used to create the document query.</param> /// <param name="retryExceptionPolicyFactory">The retry exception policy factory.</param> /// <param name="logger">The logger instance.</param> /// <param name="modelInfoProvider">The model provider</param> public CosmosFhirDataStore( IScoped <IDocumentClient> documentClientScope, CosmosDataStoreConfiguration cosmosDataStoreConfiguration, IOptionsMonitor <CosmosCollectionConfiguration> namedCosmosCollectionConfigurationAccessor, FhirCosmosDocumentQueryFactory cosmosDocumentQueryFactory, RetryExceptionPolicyFactory retryExceptionPolicyFactory, ILogger <CosmosFhirDataStore> logger, IModelInfoProvider modelInfoProvider) { EnsureArg.IsNotNull(documentClientScope, nameof(documentClientScope)); EnsureArg.IsNotNull(cosmosDataStoreConfiguration, nameof(cosmosDataStoreConfiguration)); EnsureArg.IsNotNull(namedCosmosCollectionConfigurationAccessor, nameof(namedCosmosCollectionConfigurationAccessor)); EnsureArg.IsNotNull(cosmosDocumentQueryFactory, nameof(cosmosDocumentQueryFactory)); EnsureArg.IsNotNull(retryExceptionPolicyFactory, nameof(retryExceptionPolicyFactory)); EnsureArg.IsNotNull(logger, nameof(logger)); EnsureArg.IsNotNull(modelInfoProvider, nameof(modelInfoProvider)); _documentClientScope = documentClientScope; _cosmosDocumentQueryFactory = cosmosDocumentQueryFactory; _retryExceptionPolicyFactory = retryExceptionPolicyFactory; _logger = logger; _modelInfoProvider = modelInfoProvider; CosmosCollectionConfiguration collectionConfiguration = namedCosmosCollectionConfigurationAccessor.Get(Constants.CollectionConfigurationName); DatabaseId = cosmosDataStoreConfiguration.DatabaseId; CollectionId = collectionConfiguration.CollectionId; CollectionUri = cosmosDataStoreConfiguration.GetRelativeCollectionUri(collectionConfiguration.CollectionId); _upsertWithHistoryProc = new UpsertWithHistory(); _hardDelete = new HardDelete(); }
public DocumentStorage(StorageStyle storageStyle, DocumentMapping document) { _mapping = document; Fields = document; TableName = document.TableName; determineDefaultWhereFragment(); _idType = PostgresqlProvider.Instance.ToParameterType(typeof(TId)); var table = _mapping.Schema.Table; _selectFields = table.SelectColumns(storageStyle).Select(x => $"d.{x.Name}").ToArray(); var fieldSelector = _selectFields.Join(", "); _selectClause = $"select {fieldSelector} from {document.TableName.QualifiedName} as d"; _loaderSql = $"select {fieldSelector} from {document.TableName.QualifiedName} as d where id = :id"; _loadArraySql = $"select {fieldSelector} from {document.TableName.QualifiedName} as d where id = ANY(:ids)"; if (document.TenancyStyle == TenancyStyle.Conjoined) { _loaderSql += $" and {CurrentTenantFilter.Filter}"; _loadArraySql += $" and {CurrentTenantFilter.Filter}"; } UseOptimisticConcurrency = document.UseOptimisticConcurrency; _setter = LambdaBuilder.Setter <T, TId>(document.IdMember) !; DeleteFragment = _mapping.DeleteStyle == DeleteStyle.Remove ? (IOperationFragment) new HardDelete(this) : new SoftDelete(this); HardDeleteFragment = new HardDelete(this); DuplicatedFields = _mapping.DuplicatedFields; }
/// <summary> /// Initializes a new instance of the <see cref="CosmosDataStore"/> class. /// </summary> /// <param name="documentClient"> /// A function that returns an <see cref="IDocumentClient"/>. /// Note that this is a function so that the lifetime of the instance is not directly controlled by the IoC container. /// </param> /// <param name="cosmosDataStoreConfiguration">The data store configuration</param> /// <param name="cosmosDocumentQueryFactory">The factory used to create the document query.</param> /// <param name="retryExceptionPolicyFactory">The retry exception policy factory.</param> /// <param name="logger">The logger instance.</param> public CosmosDataStore( IScoped <IDocumentClient> documentClient, CosmosDataStoreConfiguration cosmosDataStoreConfiguration, ICosmosDocumentQueryFactory cosmosDocumentQueryFactory, RetryExceptionPolicyFactory retryExceptionPolicyFactory, ILogger <CosmosDataStore> logger) { EnsureArg.IsNotNull(documentClient, nameof(documentClient)); EnsureArg.IsNotNull(cosmosDataStoreConfiguration, nameof(cosmosDataStoreConfiguration)); EnsureArg.IsNotNull(cosmosDocumentQueryFactory, nameof(cosmosDocumentQueryFactory)); EnsureArg.IsNotNull(retryExceptionPolicyFactory, nameof(retryExceptionPolicyFactory)); EnsureArg.IsNotNull(logger, nameof(logger)); _cosmosDocumentQueryFactory = cosmosDocumentQueryFactory; _retryExceptionPolicyFactory = retryExceptionPolicyFactory; _logger = logger; _documentClient = documentClient; _collectionUri = cosmosDataStoreConfiguration.RelativeCollectionUri; _upsertWithHistoryProc = new UpsertWithHistory(); _hardDelete = new HardDelete(); }