19
19
20
20
import java .util .Collection ;
21
21
import java .util .Collections ;
22
+ import java .util .Date ;
22
23
import java .util .HashSet ;
23
24
import java .util .List ;
24
25
import java .util .Set ;
42
43
import org .springframework .data .neo4j .core .DatabaseSelectionProvider ;
43
44
import org .springframework .data .neo4j .core .Neo4jOperations ;
44
45
import org .springframework .data .neo4j .core .convert .Neo4jConversions ;
46
+ import org .springframework .data .neo4j .core .support .DateLong ;
45
47
import org .springframework .data .neo4j .core .transaction .Neo4jBookmarkManager ;
46
48
import org .springframework .data .neo4j .core .transaction .Neo4jTransactionManager ;
47
49
import org .springframework .data .neo4j .integration .shared .conversion .PersonWithCustomId ;
@@ -90,7 +92,8 @@ void setupData() {
90
92
try (Session session = driver .session (bookmarkCapture .createSessionConfig ())) {
91
93
session .writeTransaction (transaction -> {
92
94
transaction .run ("MATCH (n) detach delete n" ).consume ();
93
- transaction .run ("CREATE (:CustomTypes{customType:'XYZ'})" ).consume ();
95
+ transaction .run ("CREATE (:CustomTypes{customType:'XYZ', dateAsLong: 1630311077418})" ).consume ();
96
+ transaction .run ("CREATE (:CustomTypes{customType:'ABC'})" ).consume ();
94
97
return null ;
95
98
});
96
99
bookmarkCapture .seedWith (session .lastBookmark ());
@@ -124,7 +127,7 @@ void deleteAllByCustomId() {
124
127
.limit (2 )
125
128
.collect (Collectors .toList ());
126
129
try (
127
- Session session = driver .session (bookmarkCapture .createSessionConfig ());
130
+ Session session = driver .session (bookmarkCapture .createSessionConfig ())
128
131
) {
129
132
ids .forEach (id -> session .writeTransaction (createPersonWithCustomId (id )));
130
133
bookmarkCapture .seedWith (session .lastBookmark ());
@@ -143,7 +146,9 @@ void deleteAllByCustomId() {
143
146
@ Test
144
147
void findByConvertedCustomType (@ Autowired EntityWithCustomTypePropertyRepository repository ) {
145
148
146
- assertThat (repository .findByCustomType (ThingWithCustomTypes .CustomType .of ("XYZ" ))).isNotNull ();
149
+ ThingWithCustomTypes xyz = repository .findByCustomType (ThingWithCustomTypes .CustomType .of ("XYZ" ));
150
+ assertThat (xyz ).isNotNull ();
151
+ assertThat (xyz .getDateAsLong ()).isNotNull ();
147
152
}
148
153
149
154
@ Test
@@ -152,6 +157,31 @@ void findByConvertedCustomTypeWithCustomQuery(@Autowired EntityWithCustomTypePro
152
157
assertThat (repository .findByCustomTypeCustomQuery (ThingWithCustomTypes .CustomType .of ("XYZ" ))).isNotNull ();
153
158
}
154
159
160
+ @ Test // GH-2365
161
+ void customConverterShouldBeApplied (@ Autowired EntityWithCustomTypePropertyRepository repository ) {
162
+
163
+ ThingWithCustomTypes xyz = repository .defaultAttributeWithCoalesce (ThingWithCustomTypes .CustomType .of ("XYZ" ));
164
+ assertThat (xyz ).isNotNull ();
165
+ assertThat (xyz .getDateAsLong ()).isInSameDayAs ("2021-08-30" );
166
+ }
167
+
168
+ @ Test // GH-2365
169
+ void customConverterShouldBeAppliedWithCoalesce (@ Autowired EntityWithCustomTypePropertyRepository repository ) {
170
+
171
+ ThingWithCustomTypes abc = repository .defaultAttributeWithCoalesce (ThingWithCustomTypes .CustomType .of ("ABC" ));
172
+ assertThat (abc ).isNotNull ();
173
+ assertThat (abc .getDateAsLong ()).isInSameDayAs ("2021-09-21" );
174
+ }
175
+
176
+ @ Test // GH-2365
177
+ void converterAndProjection (@ Autowired EntityWithCustomTypePropertyRepository repository ) {
178
+
179
+ ThingWithCustomTypesProjection projection = repository .converterOnProjection (ThingWithCustomTypes .CustomType .of ("XYZ" ));
180
+ assertThat (projection ).isNotNull ();
181
+ assertThat (projection .dateAsLong ).isInSameDayAs ("2021-08-30" );
182
+ assertThat (projection .modified ).isInSameDayAs ("2021-09-21" );
183
+ }
184
+
155
185
@ Test
156
186
void findByConvertedCustomTypeWithSpELPropertyAccessQuery (
157
187
@ Autowired EntityWithCustomTypePropertyRepository repository ) {
@@ -172,13 +202,27 @@ void findByConvertedDifferentTypeWithSpELObjectQuery(@Autowired EntityWithCustom
172
202
assertThat (repository .findByDifferentTypeCustomQuery (ThingWithCustomTypes .DifferentType .of ("XYZ" ))).isNotNull ();
173
203
}
174
204
205
+ static class ThingWithCustomTypesProjection {
206
+
207
+ Date dateAsLong ;
208
+
209
+ @ DateLong
210
+ Date modified ;
211
+ }
212
+
175
213
interface EntityWithCustomTypePropertyRepository extends Neo4jRepository <ThingWithCustomTypes , Long > {
176
214
177
215
ThingWithCustomTypes findByCustomType (ThingWithCustomTypes .CustomType customType );
178
216
179
217
@ Query ("MATCH (c:CustomTypes) WHERE c.customType = $customType return c" )
180
218
ThingWithCustomTypes findByCustomTypeCustomQuery (@ Param ("customType" ) ThingWithCustomTypes .CustomType customType );
181
219
220
+ @ Query ("MATCH (c:CustomTypes) WHERE c.customType = $customType return c, 1632200400000 as modified" )
221
+ ThingWithCustomTypesProjection converterOnProjection (@ Param ("customType" ) ThingWithCustomTypes .CustomType customType );
222
+
223
+ @ Query ("MATCH (thingWithCustomTypes:`CustomTypes`) WHERE thingWithCustomTypes.customType = $0 RETURN thingWithCustomTypes{.customType, dateAsLong: COALESCE(thingWithCustomTypes.dateAsLong, 1632200400000), .dateAsString, .id, __nodeLabels__: labels(thingWithCustomTypes), __internalNeo4jId__: id(thingWithCustomTypes)}" )
224
+ ThingWithCustomTypes defaultAttributeWithCoalesce (@ Param ("customType" ) ThingWithCustomTypes .CustomType customType );
225
+
182
226
@ Query ("MATCH (c:CustomTypes) WHERE c.customType = $differentType return c" )
183
227
ThingWithCustomTypes findByDifferentTypeCustomQuery (
184
228
@ Param ("differentType" ) ThingWithCustomTypes .DifferentType differentType );
0 commit comments