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 15
15
*/
16
16
package org .springframework .data .mongodb .repository .support ;
17
17
18
+ import java .util .Collections ;
19
+ import java .util .HashSet ;
20
+ import java .util .Set ;
18
21
import java .util .regex .Pattern ;
19
22
20
23
import org .springframework .data .mapping .context .MappingContext ;
41
44
*/
42
45
class SpringDataMongodbSerializer extends MongodbSerializer {
43
46
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
+ }
45
58
46
59
private final MongoConverter converter ;
47
60
private final MappingContext <? extends MongoPersistentEntity <?>, MongoPersistentProperty > mappingContext ;
@@ -138,7 +151,7 @@ private MongoPersistentProperty getPropertyFor(Path<?> path) {
138
151
139
152
Path <?> parent = path .getMetadata ().getParent ();
140
153
141
- if (parent == null ) {
154
+ if (parent == null || ! PATH_TYPES . contains ( path . getMetadata (). getPathType ()) ) {
142
155
return null ;
143
156
}
144
157
Original file line number Diff line number Diff line change @@ -46,6 +46,8 @@ public enum Sex {
46
46
@ SuppressWarnings ("unused" ) private Sex sex ;
47
47
Date createdAt ;
48
48
49
+ List <String > skills ;
50
+
49
51
@ GeoSpatialIndexed private Point location ;
50
52
51
53
private Address address ;
@@ -271,6 +273,14 @@ public void setCreator(User creator) {
271
273
this .creator = creator ;
272
274
}
273
275
276
+ public void setSkills (List <String > skills ) {
277
+ this .skills = skills ;
278
+ }
279
+
280
+ public List <String > getSkills () {
281
+ return skills ;
282
+ }
283
+
274
284
/*
275
285
* (non-Javadoc)
276
286
*
Original file line number Diff line number Diff line change 18
18
import static org .hamcrest .CoreMatchers .*;
19
19
import static org .junit .Assert .*;
20
20
21
+ import java .util .Arrays ;
22
+
21
23
import org .junit .Before ;
22
24
import org .junit .Test ;
23
25
import org .junit .runner .RunWith ;
40
42
@ ContextConfiguration ("classpath:infrastructure.xml" )
41
43
public class QuerydslRepositorySupportUnitTests {
42
44
43
- @ Autowired
44
- MongoOperations operations ;
45
+ @ Autowired MongoOperations operations ;
45
46
Person person ;
46
47
47
48
@ Before
@@ -54,9 +55,26 @@ public void setUp() {
54
55
@ Test
55
56
public void providesMongoQuery () {
56
57
QPerson p = QPerson .person ;
57
- QuerydslRepositorySupport support = new QuerydslRepositorySupport (operations ) {
58
- };
58
+ QuerydslRepositorySupport support = new QuerydslRepositorySupport (operations ) {};
59
59
MongodbQuery <Person > query = support .from (p ).where (p .lastname .eq ("Matthews" ));
60
60
assertThat (query .uniqueResult (), is (person ));
61
61
}
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
+ }
62
80
}
You can’t perform that action at this time.
0 commit comments