Search in sources :

Example 1 with DocumentDbTemplate

use of com.microsoft.azure.spring.data.documentdb.core.DocumentDbTemplate 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 DocumentDbTemplate

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

the class CosmosDbObjectFactory method createDocumentDbTemplate.

/**
 * Create document db template document db template.
 *
 * @param documentDbFactory the document db factory
 * @param properties        the properties
 * @return the document db template
 */
public DocumentDbTemplate createDocumentDbTemplate(final DocumentDbFactory documentDbFactory, final BaseCosmosDbProperties 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) DocumentDbTemplate(com.microsoft.azure.spring.data.documentdb.core.DocumentDbTemplate) DocumentDbMappingContext(com.microsoft.azure.spring.data.documentdb.core.mapping.DocumentDbMappingContext)

Example 3 with DocumentDbTemplate

use of com.microsoft.azure.spring.data.documentdb.core.DocumentDbTemplate 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

DocumentDbTemplate (com.microsoft.azure.spring.data.documentdb.core.DocumentDbTemplate)3 DocumentDbFactory (com.microsoft.azure.spring.data.documentdb.DocumentDbFactory)2 MappingDocumentDbConverter (com.microsoft.azure.spring.data.documentdb.core.convert.MappingDocumentDbConverter)2 DocumentDbMappingContext (com.microsoft.azure.spring.data.documentdb.core.mapping.DocumentDbMappingContext)2 RequestOptions (com.microsoft.azure.documentdb.RequestOptions)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