Search in sources :

Example 1 with DocumentDbFactory

use of com.microsoft.azure.spring.data.documentdb.DocumentDbFactory in project cas by apereo.

the class CosmosDbObjectFactory method createDocumentDbTemplate.

/**
 * Document db template.
 *
 * @param properties the properties
 * @return the document db template
 */
public DocumentDbTemplate createDocumentDbTemplate(final BaseCosmosDbProperties properties) {
    final DocumentDbFactory documentDbFactory = createDocumentDbFactory(properties);
    final DocumentDbMappingContext documentDbMappingContext = createDocumentDbMappingContext();
    final MappingDocumentDbConverter mappingDocumentDbConverter = createMappingDocumentDbConverter(documentDbMappingContext);
    return new DocumentDbTemplate(documentDbFactory, mappingDocumentDbConverter, properties.getDatabase());
}
Also used : MappingDocumentDbConverter(com.microsoft.azure.spring.data.documentdb.core.convert.MappingDocumentDbConverter) DocumentDbFactory(com.microsoft.azure.spring.data.documentdb.DocumentDbFactory) DocumentDbTemplate(com.microsoft.azure.spring.data.documentdb.core.DocumentDbTemplate) DocumentDbMappingContext(com.microsoft.azure.spring.data.documentdb.core.mapping.DocumentDbMappingContext)

Example 2 with DocumentDbFactory

use of com.microsoft.azure.spring.data.documentdb.DocumentDbFactory in project cas by apereo.

the class CosmosDbServiceRegistryConfiguration method cosmosDbServiceRegistry.

@Bean
@RefreshScope
public ServiceRegistry cosmosDbServiceRegistry() {
    final CosmosDbObjectFactory factory = new CosmosDbObjectFactory(this.applicationContext);
    final CosmosDbServiceRegistryProperties cosmosDb = casProperties.getServiceRegistry().getCosmosDb();
    final DocumentDbFactory dbFactory = factory.createDocumentDbFactory(cosmosDb);
    final DocumentDbTemplate db = factory.createDocumentDbTemplate(dbFactory, cosmosDb);
    if (cosmosDb.isDropCollection()) {
        final String collectionLink = CosmosDbObjectFactory.getCollectionLink(cosmosDb.getDatabase(), cosmosDb.getCollection());
        final RequestOptions options = new RequestOptions();
        options.setConsistencyLevel(ConsistencyLevel.valueOf(cosmosDb.getConsistencyLevel()));
        options.setOfferThroughput(cosmosDb.getThroughput());
        try {
            dbFactory.getDocumentClient().deleteCollection(collectionLink, options);
        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    db.createCollectionIfNotExists(cosmosDb.getCollection(), PARTITION_KEY_FIELD_NAME, cosmosDb.getThroughput());
    return new CosmosDbServiceRegistry(db, dbFactory, cosmosDb.getCollection(), cosmosDb.getDatabase());
}
Also used : CosmosDbObjectFactory(org.apereo.cas.cosmosdb.CosmosDbObjectFactory) DocumentDbFactory(com.microsoft.azure.spring.data.documentdb.DocumentDbFactory) DocumentDbTemplate(com.microsoft.azure.spring.data.documentdb.core.DocumentDbTemplate) CosmosDbServiceRegistry(org.apereo.cas.services.CosmosDbServiceRegistry) RequestOptions(com.microsoft.azure.documentdb.RequestOptions) CosmosDbServiceRegistryProperties(org.apereo.cas.configuration.model.support.cosmosdb.CosmosDbServiceRegistryProperties) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Bean(org.springframework.context.annotation.Bean)

Aggregations

DocumentDbFactory (com.microsoft.azure.spring.data.documentdb.DocumentDbFactory)2 DocumentDbTemplate (com.microsoft.azure.spring.data.documentdb.core.DocumentDbTemplate)2 RequestOptions (com.microsoft.azure.documentdb.RequestOptions)1 MappingDocumentDbConverter (com.microsoft.azure.spring.data.documentdb.core.convert.MappingDocumentDbConverter)1 DocumentDbMappingContext (com.microsoft.azure.spring.data.documentdb.core.mapping.DocumentDbMappingContext)1 CosmosDbServiceRegistryProperties (org.apereo.cas.configuration.model.support.cosmosdb.CosmosDbServiceRegistryProperties)1 CosmosDbObjectFactory (org.apereo.cas.cosmosdb.CosmosDbObjectFactory)1 CosmosDbServiceRegistry (org.apereo.cas.services.CosmosDbServiceRegistry)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 Bean (org.springframework.context.annotation.Bean)1