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());
}
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());
}
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());
}
Aggregations