File tree Expand file tree Collapse file tree 3 files changed +47
-6
lines changed
main/java/org/springframework/data/mongodb/repository/support
test/java/org/springframework/data/mongodb/repository Expand file tree Collapse file tree 3 files changed +47
-6
lines changed Original file line number Diff line number Diff line change 1515 */
1616package org .springframework .data .mongodb .repository .support ;
1717
18+ import java .util .Collections ;
19+ import java .util .HashSet ;
20+ import java .util .Set ;
1821import java .util .regex .Pattern ;
1922
2023import org .springframework .data .mapping .context .MappingContext ;
4144 */
4245class SpringDataMongodbSerializer extends MongodbSerializer {
4346
44- private final String ID_KEY = "_id" ;
47+ private static final String ID_KEY = "_id" ;
48+ private static final Set <PathType > PATH_TYPES ;
49+
50+ static {
51+
52+ Set <PathType > pathTypes = new HashSet <PathType >();
53+ pathTypes .add (PathType .VARIABLE );
54+ pathTypes .add (PathType .PROPERTY );
55+
56+ PATH_TYPES = Collections .unmodifiableSet (pathTypes );
57+ }
4558
4659 private final MongoConverter converter ;
4760 private final MappingContext <? extends MongoPersistentEntity <?>, MongoPersistentProperty > mappingContext ;
@@ -138,7 +151,7 @@ private MongoPersistentProperty getPropertyFor(Path<?> path) {
138151
139152 Path <?> parent = path .getMetadata ().getParent ();
140153
141- if (parent == null ) {
154+ if (parent == null || ! PATH_TYPES . contains ( path . getMetadata (). getPathType ()) ) {
142155 return null ;
143156 }
144157
Original file line number Diff line number Diff line change @@ -46,6 +46,8 @@ public enum Sex {
4646 @ SuppressWarnings ("unused" ) private Sex sex ;
4747 Date createdAt ;
4848
49+ List <String > skills ;
50+
4951 @ GeoSpatialIndexed private Point location ;
5052
5153 private Address address ;
@@ -271,6 +273,14 @@ public void setCreator(User creator) {
271273 this .creator = creator ;
272274 }
273275
276+ public void setSkills (List <String > skills ) {
277+ this .skills = skills ;
278+ }
279+
280+ public List <String > getSkills () {
281+ return skills ;
282+ }
283+
274284 /*
275285 * (non-Javadoc)
276286 *
Original file line number Diff line number Diff line change 1818import static org .hamcrest .CoreMatchers .*;
1919import static org .junit .Assert .*;
2020
21+ import java .util .Arrays ;
22+
2123import org .junit .Before ;
2224import org .junit .Test ;
2325import org .junit .runner .RunWith ;
4042@ ContextConfiguration ("classpath:infrastructure.xml" )
4143public class QuerydslRepositorySupportUnitTests {
4244
43- @ Autowired
44- MongoOperations operations ;
45+ @ Autowired MongoOperations operations ;
4546 Person person ;
4647
4748 @ Before
@@ -54,9 +55,26 @@ public void setUp() {
5455 @ Test
5556 public void providesMongoQuery () {
5657 QPerson p = QPerson .person ;
57- QuerydslRepositorySupport support = new QuerydslRepositorySupport (operations ) {
58- };
58+ QuerydslRepositorySupport support = new QuerydslRepositorySupport (operations ) {};
5959 MongodbQuery <Person > query = support .from (p ).where (p .lastname .eq ("Matthews" ));
6060 assertThat (query .uniqueResult (), is (person ));
6161 }
62+
63+ /**
64+ * @see DATAMONGO-1063
65+ */
66+ @ Test
67+ public void shouldAllowAny () {
68+
69+ person .setSkills (Arrays .asList ("vocalist" , "songwriter" , "guitarist" ));
70+
71+ operations .save (person );
72+
73+ QPerson p = QPerson .person ;
74+ QuerydslRepositorySupport support = new QuerydslRepositorySupport (operations ) {};
75+
76+ MongodbQuery <Person > query = support .from (p ).where (p .skills .any ().in ("guitarist" ));
77+
78+ assertThat (query .uniqueResult (), is (person ));
79+ }
6280}
You can’t perform that action at this time.
0 commit comments