Search in sources :

Example 1 with Granularity

use of org.springframework.data.mongodb.core.timeseries.Granularity in project spring-data-mongodb by spring-projects.

the class MongoTemplate method convertToDocument.

/**
 * Convert given {@link CollectionOptions} to a document and take the domain type information into account when
 * creating a mapped schema for validation. <br />
 * This method calls {@link #convertToDocument(CollectionOptions)} for backwards compatibility and potentially
 * overwrites the validator with the mapped validator document. In the long run
 * {@link #convertToDocument(CollectionOptions)} will be removed so that this one becomes the only source of truth.
 *
 * @param collectionOptions can be {@literal null}.
 * @param targetType must not be {@literal null}. Use {@link Object} type instead.
 * @return never {@literal null}.
 * @since 2.1
 */
protected Document convertToDocument(@Nullable CollectionOptions collectionOptions, Class<?> targetType) {
    Document doc = convertToDocument(collectionOptions);
    if (collectionOptions != null) {
        collectionOptions.getValidationOptions().ifPresent(it -> // 
        it.getValidator().ifPresent(val -> doc.put("validator", getMappedValidator(val, targetType))));
        collectionOptions.getTimeSeriesOptions().map(operations.forType(targetType)::mapTimeSeriesOptions).ifPresent(it -> {
            Document timeseries = new Document("timeField", it.getTimeField());
            if (StringUtils.hasText(it.getMetaField())) {
                timeseries.append("metaField", it.getMetaField());
            }
            if (!Granularity.DEFAULT.equals(it.getGranularity())) {
                timeseries.append("granularity", it.getGranularity().name().toLowerCase());
            }
            doc.put("timeseries", timeseries);
        });
    }
    return doc;
}
Also used : Document(org.bson.Document) EntityCallbacks(org.springframework.data.mapping.callback.EntityCallbacks) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) NumberUtils(org.springframework.util.NumberUtils) BsonUtils(org.springframework.data.mongodb.util.BsonUtils) MongoDatabase(com.mongodb.client.MongoDatabase) BigDecimal(java.math.BigDecimal) QueryContext(org.springframework.data.mongodb.core.QueryOperations.QueryContext) BulkOperationContext(org.springframework.data.mongodb.core.DefaultBulkOperations.BulkOperationContext) Optionals(org.springframework.data.util.Optionals) UpdateResult(com.mongodb.client.result.UpdateResult) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) MapReduceResults(org.springframework.data.mongodb.core.mapreduce.MapReduceResults) CursorOption(org.springframework.data.mongodb.core.query.Meta.CursorOption) MongoJsonSchemaMapper(org.springframework.data.mongodb.core.convert.MongoJsonSchemaMapper) Resource(org.springframework.core.io.Resource) AggregationOperationContext(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext) ClassUtils(org.springframework.util.ClassUtils) NearQuery(org.springframework.data.mongodb.core.query.NearQuery) AggregateIterable(com.mongodb.client.AggregateIterable) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) CollectionUtils(org.springframework.util.CollectionUtils) LogFactory(org.apache.commons.logging.LogFactory) DistinctQueryContext(org.springframework.data.mongodb.core.QueryOperations.DistinctQueryContext) ApplicationContextAware(org.springframework.context.ApplicationContextAware) MongoDatabaseUtils(org.springframework.data.mongodb.MongoDatabaseUtils) java.util(java.util) Validator(org.springframework.data.mongodb.core.validation.Validator) IndexOperationsProvider(org.springframework.data.mongodb.core.index.IndexOperationsProvider) MongoCollection(com.mongodb.client.MongoCollection) MongoCustomConversions(org.springframework.data.mongodb.core.convert.MongoCustomConversions) GroupByResults(org.springframework.data.mongodb.core.mapreduce.GroupByResults) MappingContext(org.springframework.data.mapping.context.MappingContext) UpdateDefinition(org.springframework.data.mongodb.core.query.UpdateDefinition) Bson(org.bson.conversions.Bson) DbRefResolver(org.springframework.data.mongodb.core.convert.DbRefResolver) MappingException(org.springframework.data.mapping.MappingException) Nullable(org.springframework.lang.Nullable) JsonSchemaMapper(org.springframework.data.mongodb.core.convert.JsonSchemaMapper) com.mongodb.client.model(com.mongodb.client.model) CountContext(org.springframework.data.mongodb.core.QueryOperations.CountContext) org.springframework.data.mongodb.core.mapping.event(org.springframework.data.mongodb.core.mapping.event) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) ObjectUtils(org.springframework.util.ObjectUtils) DeleteContext(org.springframework.data.mongodb.core.QueryOperations.DeleteContext) TypedAggregation(org.springframework.data.mongodb.core.aggregation.TypedAggregation) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) MongoMappingEventPublisher(org.springframework.data.mongodb.core.index.MongoMappingEventPublisher) Criteria(org.springframework.data.mongodb.core.query.Criteria) ResourceUtils(org.springframework.util.ResourceUtils) DistinctIterable(com.mongodb.client.DistinctIterable) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MongoIterable(com.mongodb.client.MongoIterable) CloseableIterator(org.springframework.data.util.CloseableIterator) Collation(org.springframework.data.mongodb.core.query.Collation) EntityProjection(org.springframework.data.projection.EntityProjection) PersistenceExceptionTranslator(org.springframework.dao.support.PersistenceExceptionTranslator) OptimisticLockingFailureException(org.springframework.dao.OptimisticLockingFailureException) MapReduceOptions(org.springframework.data.mongodb.core.mapreduce.MapReduceOptions) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) MapReduceIterable(com.mongodb.client.MapReduceIterable) AdaptibleEntity(org.springframework.data.mongodb.core.EntityOperations.AdaptibleEntity) MongoWriter(org.springframework.data.mongodb.core.convert.MongoWriter) RoundingMode(java.math.RoundingMode) Meta(org.springframework.data.mongodb.core.query.Meta) ResourceLoader(org.springframework.core.io.ResourceLoader) MongoPersistentEntityIndexCreator(org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator) SerializationUtils(org.springframework.data.mongodb.core.query.SerializationUtils) MongoException(com.mongodb.MongoException) ApplicationListener(org.springframework.context.ApplicationListener) AggregationResults(org.springframework.data.mongodb.core.aggregation.AggregationResults) Collectors(java.util.stream.Collectors) FindIterable(com.mongodb.client.FindIterable) UpdateMapper(org.springframework.data.mongodb.core.convert.UpdateMapper) TypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext) UpdateContext(org.springframework.data.mongodb.core.QueryOperations.UpdateContext) Metric(org.springframework.data.geo.Metric) ReadPreference(com.mongodb.ReadPreference) DataAccessException(org.springframework.dao.DataAccessException) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MongoPersistentProperty(org.springframework.data.mongodb.core.mapping.MongoPersistentProperty) MongoClient(com.mongodb.client.MongoClient) BulkMode(org.springframework.data.mongodb.core.BulkOperations.BulkMode) InvalidDataAccessApiUsageException(org.springframework.dao.InvalidDataAccessApiUsageException) MongoDatabaseFactory(org.springframework.data.mongodb.MongoDatabaseFactory) MongoConverter(org.springframework.data.mongodb.core.convert.MongoConverter) Distance(org.springframework.data.geo.Distance) IndexOperations(org.springframework.data.mongodb.core.index.IndexOperations) EntityReader(org.springframework.data.convert.EntityReader) ArrayFilter(org.springframework.data.mongodb.core.query.UpdateDefinition.ArrayFilter) MongoCursor(com.mongodb.client.MongoCursor) Granularity(org.springframework.data.mongodb.core.timeseries.Granularity) MongoPersistentEntity(org.springframework.data.mongodb.core.mapping.MongoPersistentEntity) AggregationDefinition(org.springframework.data.mongodb.core.QueryOperations.AggregationDefinition) GroupBy(org.springframework.data.mongodb.core.mapreduce.GroupBy) ApplicationEventPublisherAware(org.springframework.context.ApplicationEventPublisherAware) AggregationOptions(org.springframework.data.mongodb.core.aggregation.AggregationOptions) ApplicationContext(org.springframework.context.ApplicationContext) Query(org.springframework.data.mongodb.core.query.Query) TimeUnit(java.util.concurrent.TimeUnit) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) ClientSessionOptions(com.mongodb.ClientSessionOptions) GeoResults(org.springframework.data.geo.GeoResults) DeleteResult(com.mongodb.client.result.DeleteResult) Log(org.apache.commons.logging.Log) ClientSession(com.mongodb.client.ClientSession) GeoResult(org.springframework.data.geo.GeoResult) SessionSynchronization(org.springframework.data.mongodb.SessionSynchronization) WriteConcern(com.mongodb.WriteConcern) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) Document(org.bson.Document)

Aggregations

ClientSessionOptions (com.mongodb.ClientSessionOptions)1 MongoException (com.mongodb.MongoException)1 ReadPreference (com.mongodb.ReadPreference)1 WriteConcern (com.mongodb.WriteConcern)1 AggregateIterable (com.mongodb.client.AggregateIterable)1 ClientSession (com.mongodb.client.ClientSession)1 DistinctIterable (com.mongodb.client.DistinctIterable)1 FindIterable (com.mongodb.client.FindIterable)1 MapReduceIterable (com.mongodb.client.MapReduceIterable)1 MongoClient (com.mongodb.client.MongoClient)1 MongoCollection (com.mongodb.client.MongoCollection)1 MongoCursor (com.mongodb.client.MongoCursor)1 MongoDatabase (com.mongodb.client.MongoDatabase)1 MongoIterable (com.mongodb.client.MongoIterable)1 com.mongodb.client.model (com.mongodb.client.model)1 DeleteResult (com.mongodb.client.result.DeleteResult)1 UpdateResult (com.mongodb.client.result.UpdateResult)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 RoundingMode (java.math.RoundingMode)1