37
37
import org .springframework .data .domain .Example ;
38
38
import org .springframework .data .domain .ExampleMatcher ;
39
39
import org .springframework .data .mapping .PropertyPath ;
40
+ import org .springframework .data .neo4j .core .Neo4jPropertyValueTransformers ;
40
41
import org .springframework .data .neo4j .core .convert .Neo4jConversionService ;
41
42
import org .springframework .data .neo4j .core .mapping .Constants ;
42
43
import org .springframework .data .neo4j .core .mapping .GraphPropertyDescription ;
@@ -159,18 +160,19 @@ private static void addConditionAndParameters(Neo4jMappingContext mappingContext
159
160
Neo4jConversionService conversionService = mappingContext .getConversionService ();
160
161
boolean isRootNode = predicate .neo4jPersistentEntity .equals (nodeDescription );
161
162
163
+ var theValue = optionalValue .map (v -> v instanceof Neo4jPropertyValueTransformers .NegatedValue negatedValue ? negatedValue .value () : v ).get ();
164
+ Condition condition ;
165
+
162
166
if (graphProperty .isIdProperty () && nodeDescription .isUsingInternalIds ()) {
163
167
if (isRootNode ) {
164
- predicate .add (mode ,
165
- predicate .neo4jPersistentEntity .getIdExpression ().isEqualTo (literalOf (optionalValue .get ())));
168
+ condition = predicate .neo4jPersistentEntity .getIdExpression ().isEqualTo (literalOf (theValue ));
166
169
} else {
167
- predicate .add (mode ,
168
- nodeDescription .getIdExpression ().isEqualTo (literalOf (optionalValue .get ())));
170
+ condition = nodeDescription .getIdExpression ().isEqualTo (literalOf (theValue ));
169
171
}
170
172
} else {
171
173
Expression property = !isRootNode ? property (wrapper .getNodeName (), propertyName ) : property (Constants .NAME_OF_TYPED_ROOT_NODE .apply (nodeDescription ), propertyName );
172
174
Expression parameter = parameter (wrapper .getNodeName () + propertyName );
173
- Condition condition = property .isEqualTo (parameter );
175
+ condition = property .isEqualTo (parameter );
174
176
175
177
if (String .class .equals (graphProperty .getActualType ())) {
176
178
@@ -180,24 +182,26 @@ private static void addConditionAndParameters(Neo4jMappingContext mappingContext
180
182
}
181
183
182
184
condition = switch (matcherAccessor .getStringMatcherForPath (currentPath )) {
183
- case DEFAULT , EXACT ->
184
- // This needs to be recreated as both property and parameter might have changed above
185
- property .isEqualTo (parameter );
185
+ case DEFAULT , EXACT -> property .isEqualTo (parameter );
186
186
case CONTAINING -> property .contains (parameter );
187
187
case STARTING -> property .startsWith (parameter );
188
188
case ENDING -> property .endsWith (parameter );
189
189
case REGEX -> property .matches (parameter );
190
190
};
191
191
}
192
- predicate .add (mode , condition );
193
- predicate .parameters .put (wrapper .getNodeName () + propertyName , optionalValue .map (
194
- v -> {
195
- Neo4jPersistentProperty neo4jPersistentProperty = (Neo4jPersistentProperty ) graphProperty ;
196
- return conversionService .writeValue (v , neo4jPersistentProperty .getTypeInformation (),
197
- neo4jPersistentProperty .getOptionalConverter ());
198
- })
199
- .get ());
192
+
193
+ Neo4jPersistentProperty neo4jPersistentProperty = (Neo4jPersistentProperty ) graphProperty ;
194
+ predicate .parameters .put (wrapper .getNodeName () + propertyName , conversionService .writeValue (theValue ,
195
+ neo4jPersistentProperty .getTypeInformation (), neo4jPersistentProperty .getOptionalConverter ()));
196
+ }
197
+ predicate .add (mode , postProcess (condition , optionalValue .get ()));
198
+ }
199
+
200
+ private static Condition postProcess (Condition condition , Object transformedValue ) {
201
+ if (transformedValue instanceof Neo4jPropertyValueTransformers .NegatedValue ) {
202
+ return condition .not ();
200
203
}
204
+ return condition ;
201
205
}
202
206
203
207
private final Neo4jPersistentEntity neo4jPersistentEntity ;
0 commit comments