Search in sources :

Example 1 with DomainTypeMapping

use of org.springframework.data.mongodb.core.aggregation.AggregationOptions.DomainTypeMapping in project spring-data-mongodb by spring-projects.

the class AggregationUtil method createAggregationContext.

AggregationOperationContext createAggregationContext(Aggregation aggregation, @Nullable Class<?> inputType) {
    DomainTypeMapping domainTypeMapping = aggregation.getOptions().getDomainTypeMapping();
    if (domainTypeMapping == DomainTypeMapping.NONE) {
        return Aggregation.DEFAULT_CONTEXT;
    }
    if (!(aggregation instanceof TypedAggregation)) {
        if (inputType == null) {
            return untypedMappingContext.get();
        }
        if (domainTypeMapping == DomainTypeMapping.STRICT && !aggregation.getPipeline().containsUnionWith()) {
            return new TypeBasedAggregationOperationContext(inputType, mappingContext, queryMapper);
        }
        return new RelaxedTypeBasedAggregationOperationContext(inputType, mappingContext, queryMapper);
    }
    inputType = ((TypedAggregation<?>) aggregation).getInputType();
    if (domainTypeMapping == DomainTypeMapping.STRICT && !aggregation.getPipeline().containsUnionWith()) {
        return new TypeBasedAggregationOperationContext(inputType, mappingContext, queryMapper);
    }
    return new RelaxedTypeBasedAggregationOperationContext(inputType, mappingContext, queryMapper);
}
Also used : DomainTypeMapping(org.springframework.data.mongodb.core.aggregation.AggregationOptions.DomainTypeMapping) RelaxedTypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.RelaxedTypeBasedAggregationOperationContext) TypedAggregation(org.springframework.data.mongodb.core.aggregation.TypedAggregation) RelaxedTypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.RelaxedTypeBasedAggregationOperationContext) TypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext)

Aggregations

DomainTypeMapping (org.springframework.data.mongodb.core.aggregation.AggregationOptions.DomainTypeMapping)1 RelaxedTypeBasedAggregationOperationContext (org.springframework.data.mongodb.core.aggregation.RelaxedTypeBasedAggregationOperationContext)1 TypeBasedAggregationOperationContext (org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext)1 TypedAggregation (org.springframework.data.mongodb.core.aggregation.TypedAggregation)1