Search in sources :

Example 26 with QueryMapper

use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.

the class SetOperationUnitTests method contextFor.

private static AggregationOperationContext contextFor(@Nullable Class<?> type) {
    if (type == null) {
        return Aggregation.DEFAULT_CONTEXT;
    }
    MappingMongoConverter mongoConverter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, new MongoMappingContext());
    mongoConverter.afterPropertiesSet();
    return new RelaxedTypeBasedAggregationOperationContext(type, mongoConverter.getMappingContext(), new QueryMapper(mongoConverter));
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper)

Example 27 with QueryMapper

use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.

the class ProjectionOperationUnitTests method nestedMappedFieldReferenceInArrayField.

// DATAMONGO-2312
@Test
void nestedMappedFieldReferenceInArrayField() {
    MongoMappingContext mappingContext = new MongoMappingContext();
    Document doc = // 
    project("author").andArrayOf(Fields.field("title"), "plain - string", ArithmeticOperators.valueOf("title").sum().and(10)).as(// 
    "myArray").toDocument(new TypeBasedAggregationOperationContext(BookWithFieldAnnotation.class, mappingContext, new QueryMapper(new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext))));
    assertThat(doc).isEqualTo(Document.parse("{ $project: { \"author\" : 1,  \"myArray\" : [ \"$ti_t_le\", \"plain - string\", { \"$sum\" : [\"$ti_t_le\", 10] } ] } } ] }"));
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Document(org.bson.Document) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) Test(org.junit.jupiter.api.Test)

Example 28 with QueryMapper

use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.

the class MergeOperationUnitTests method contextFor.

private static AggregationOperationContext contextFor(@Nullable Class<?> type) {
    if (type == null) {
        return Aggregation.DEFAULT_CONTEXT;
    }
    MappingMongoConverter mongoConverter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, new MongoMappingContext());
    mongoConverter.afterPropertiesSet();
    return new TypeBasedAggregationOperationContext(type, mongoConverter.getMappingContext(), new QueryMapper(mongoConverter)).continueOnMissingFieldReference();
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper)

Example 29 with QueryMapper

use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.

the class TypeBasedAggregationOperationContextUnitTests method setUp.

@BeforeEach
public void setUp() {
    this.context = new MongoMappingContext();
    this.converter = new MappingMongoConverter(dbRefResolver, context);
    this.mapper = new QueryMapper(converter);
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

QueryMapper (org.springframework.data.mongodb.core.convert.QueryMapper)29 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)19 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)19 Test (org.junit.jupiter.api.Test)14 Document (org.bson.Document)11 BulkOperationContext (org.springframework.data.mongodb.core.DefaultBulkOperations.BulkOperationContext)7 UpdateMapper (org.springframework.data.mongodb.core.convert.UpdateMapper)7 BsonDocument (org.bson.BsonDocument)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)3 Index (org.springframework.data.mongodb.core.index.Index)3 IndexDefinition (org.springframework.data.mongodb.core.index.IndexDefinition)3 IndexInfo (org.springframework.data.mongodb.core.index.IndexInfo)3 BeforeConvertEvent (org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent)3 BeforeSaveEvent (org.springframework.data.mongodb.core.mapping.event.BeforeSaveEvent)3 Test (org.junit.Test)2 MongoConverter (org.springframework.data.mongodb.core.convert.MongoConverter)2 AfterSaveEvent (org.springframework.data.mongodb.core.mapping.event.AfterSaveEvent)2 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)2 MongoWriteException (com.mongodb.MongoWriteException)1