Skip to content

DATAMONGO-1406 - Propagate PersistentEntity when mapping query criteria for nested keywords. #384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>1.10.0.DATAMONGO-1406-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data MongoDB</name>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-mongodb-cross-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>1.10.0.DATAMONGO-1406-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>1.10.0.DATAMONGO-1406-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>1.10.0.DATAMONGO-1406-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-log4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>1.10.0.DATAMONGO-1406-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>1.10.0.DATAMONGO-1406-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
* @author Patryk Wasik
* @author Thomas Darimont
* @author Christoph Strobl
* @author Mark Paluch
*/
public class QueryMapper {

Expand All @@ -66,7 +67,7 @@ public class QueryMapper {
static final ClassTypeInformation<?> NESTED_DOCUMENT = ClassTypeInformation.from(NestedDocument.class);

private enum MetaMapping {
FORCE, WHEN_PRESENT, IGNORE;
FORCE, WHEN_PRESENT, IGNORE
}

private final ConversionService conversionService;
Expand Down Expand Up @@ -316,7 +317,7 @@ protected Object getMappedValue(Field documentField, Object value) {
}

if (isNestedKeyword(value)) {
return getMappedKeyword(new Keyword((DBObject) value), null);
return getMappedKeyword(new Keyword((DBObject) value), documentField.getPropertyEntity());
}

if (isAssociationConversionNecessary(documentField, value)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2015 the original author or authors.
* Copyright 2011-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,6 +35,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import org.springframework.data.annotation.Id;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
Expand All @@ -54,6 +55,7 @@
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.test.util.BasicDbListBuilder;

import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
Expand All @@ -68,6 +70,7 @@
* @author Patryk Wasik
* @author Thomas Darimont
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
public class QueryMapperUnitTests {
Expand Down Expand Up @@ -595,6 +598,28 @@ public void classInformationShouldNotBePresentInDBObjectUsedInFinderMethods() {
assertThat(dbo.toString(), equalTo("{ \"embedded\" : { \"$in\" : [ { \"_id\" : \"1\"} , { \"_id\" : \"2\"}]}}"));
}

/**
* @see DATAMONGO-1406
*/
@Test
public void shouldMapQueryForNestedCustomizedPropertiesUsingConfiguredFieldNames() {

EmbeddedClass embeddedClass = new EmbeddedClass();
embeddedClass.customizedField = "hello";

Foo foo = new Foo();
foo.listOfItems = Arrays.asList(embeddedClass);

Query query = new Query(Criteria.where("listOfItems") //
.elemMatch(new Criteria(). //
andOperator(Criteria.where("customizedField").is(embeddedClass.customizedField))));

DBObject dbo = mapper.getMappedObject(query.getQueryObject(), context.getPersistentEntity(Foo.class));

assertThat(dbo, isBsonObject().containing("my_items.$elemMatch.$and",
new BasicDbListBuilder().add(new BasicDBObject("fancy_custom_name", embeddedClass.customizedField)).get()));
}

/**
* @see DATAMONGO-647
*/
Expand Down Expand Up @@ -792,8 +817,7 @@ public void intersectsShouldUseGeoJsonRepresentationCorrectly() {
}

/**
* <<<<<<< HEAD
*
*
* @see DATAMONGO-1269
*/
@Test
Expand Down Expand Up @@ -859,10 +883,15 @@ public void exampleShouldBeMappedCorrectlyWhenContainingLegacyPoint() {
public class Foo {
@Id private ObjectId id;
EmbeddedClass embedded;

@Field("my_items")
List<EmbeddedClass> listOfItems;
}

public class EmbeddedClass {
public String id;

@Field("fancy_custom_name") public String customizedField;
}

class IdWrapper {
Expand Down