33
33
import org .neo4j .cypherdsl .core .StatementBuilder ;
34
34
import org .springframework .data .domain .Example ;
35
35
import org .springframework .data .domain .ExampleMatcher ;
36
+ import org .springframework .data .neo4j .core .Neo4jPropertyValueTransformers ;
36
37
import org .springframework .data .neo4j .core .convert .Neo4jConversionService ;
37
38
import org .springframework .data .neo4j .core .mapping .Constants ;
38
39
import org .springframework .data .neo4j .core .mapping .GraphPropertyDescription ;
@@ -91,15 +92,17 @@ static <S> Predicate create(Neo4jMappingContext mappingContext, Example<S> examp
91
92
92
93
Neo4jConversionService conversionService = mappingContext .getConversionService ();
93
94
95
+ var theValue = optionalValue .map (v -> v instanceof Neo4jPropertyValueTransformers .NegatedValue negatedValue ? negatedValue .value () : v ).get ();
96
+ Condition condition = null ;
97
+
94
98
if (graphProperty .isRelationship ()) {
95
99
Neo4jQuerySupport .REPOSITORY_QUERY_LOG .error ("Querying by example does not support traversing of relationships." );
96
100
} else if (graphProperty .isIdProperty () && probeNodeDescription .isUsingInternalIds ()) {
97
- predicate .add (mode ,
98
- predicate .neo4jPersistentEntity .getIdExpression ().isEqualTo (literalOf (optionalValue .get ())));
101
+ condition = predicate .neo4jPersistentEntity .getIdExpression ().isEqualTo (literalOf (theValue ));
99
102
} else {
100
103
Expression property = property (Constants .NAME_OF_TYPED_ROOT_NODE .apply (probeNodeDescription ), propertyName );
101
104
Expression parameter = parameter (propertyName );
102
- Condition condition = property .isEqualTo (parameter );
105
+ condition = property .isEqualTo (parameter );
103
106
104
107
if (String .class .equals (graphProperty .getActualType ())) {
105
108
@@ -109,29 +112,33 @@ static <S> Predicate create(Neo4jMappingContext mappingContext, Example<S> examp
109
112
}
110
113
111
114
condition = switch (matcherAccessor .getStringMatcherForPath (currentPath )) {
112
- case DEFAULT , EXACT ->
113
- // This needs to be recreated as both property and parameter might have changed above
114
- property .isEqualTo (parameter );
115
+ case DEFAULT , EXACT -> property .isEqualTo (parameter );
115
116
case CONTAINING -> property .contains (parameter );
116
117
case STARTING -> property .startsWith (parameter );
117
118
case ENDING -> property .endsWith (parameter );
118
119
case REGEX -> property .matches (parameter );
119
120
};
120
121
}
121
- predicate .add (mode , condition );
122
- predicate .parameters .put (propertyName , optionalValue .map (
123
- v -> {
124
- Neo4jPersistentProperty neo4jPersistentProperty = (Neo4jPersistentProperty ) graphProperty ;
125
- return conversionService .writeValue (v , neo4jPersistentProperty .getTypeInformation (),
126
- neo4jPersistentProperty .getOptionalConverter ());
127
- })
128
- .get ());
122
+
123
+ Neo4jPersistentProperty neo4jPersistentProperty = (Neo4jPersistentProperty ) graphProperty ;
124
+ predicate .parameters .put (propertyName , conversionService .writeValue (theValue ,
125
+ neo4jPersistentProperty .getTypeInformation (), neo4jPersistentProperty .getOptionalConverter ()));
126
+ }
127
+ if (condition != null ) {
128
+ predicate .add (mode , postProcess (condition , optionalValue .get ()));
129
129
}
130
130
}
131
131
132
132
return predicate ;
133
133
}
134
134
135
+ private static Condition postProcess (Condition condition , Object transformedValue ) {
136
+ if (transformedValue instanceof Neo4jPropertyValueTransformers .NegatedValue ) {
137
+ return condition .not ();
138
+ }
139
+ return condition ;
140
+ }
141
+
135
142
private final Neo4jPersistentEntity neo4jPersistentEntity ;
136
143
137
144
private Condition condition = Conditions .noCondition ();
0 commit comments