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 .NegatedValue ;
37
+ import org .springframework .data .neo4j .core .convert .Neo4jConversionService ;
36
38
import org .springframework .data .neo4j .core .mapping .Constants ;
37
39
import org .springframework .data .neo4j .core .mapping .GraphPropertyDescription ;
38
- import org .springframework .data .neo4j .core .convert .Neo4jConversionService ;
39
40
import org .springframework .data .neo4j .core .mapping .Neo4jMappingContext ;
40
41
import org .springframework .data .neo4j .core .mapping .Neo4jPersistentEntity ;
41
42
import org .springframework .data .neo4j .core .mapping .Neo4jPersistentProperty ;
@@ -91,15 +92,17 @@ static <S> Predicate create(Neo4jMappingContext mappingContext, Example<S> examp
91
92
92
93
Neo4jConversionService conversionService = mappingContext .getConversionService ();
93
94
95
+ Object theValue = optionalValue .map (v -> v instanceof NegatedValue ? ((NegatedValue ) v ).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
@@ -111,7 +114,6 @@ static <S> Predicate create(Neo4jMappingContext mappingContext, Example<S> examp
111
114
switch (matcherAccessor .getStringMatcherForPath (currentPath )) {
112
115
case DEFAULT :
113
116
case EXACT :
114
- // This needs to be recreated as both property and parameter might have changed above
115
117
condition = property .isEqualTo (parameter );
116
118
break ;
117
119
case CONTAINING :
@@ -132,20 +134,26 @@ static <S> Predicate create(Neo4jMappingContext mappingContext, Example<S> examp
132
134
.getStringMatcherForPath (currentPath ));
133
135
}
134
136
}
135
- predicate .add (mode , condition );
136
- predicate .parameters .put (propertyName , optionalValue .map (
137
- v -> {
138
- Neo4jPersistentProperty neo4jPersistentProperty = (Neo4jPersistentProperty ) graphProperty ;
139
- return conversionService .writeValue (v , neo4jPersistentProperty .getTypeInformation (),
140
- neo4jPersistentProperty .getOptionalConverter ());
141
- })
142
- .get ());
137
+
138
+ Neo4jPersistentProperty neo4jPersistentProperty = (Neo4jPersistentProperty ) graphProperty ;
139
+ predicate .parameters .put (propertyName , conversionService .writeValue (theValue ,
140
+ neo4jPersistentProperty .getTypeInformation (), neo4jPersistentProperty .getOptionalConverter ()));
141
+ }
142
+ if (condition != null ) {
143
+ predicate .add (mode , postProcess (condition , optionalValue .get ()));
143
144
}
144
145
}
145
146
146
147
return predicate ;
147
148
}
148
149
150
+ private static Condition postProcess (Condition condition , Object transformedValue ) {
151
+ if (transformedValue instanceof NegatedValue ) {
152
+ return condition .not ();
153
+ }
154
+ return condition ;
155
+ }
156
+
149
157
private final Neo4jPersistentEntity neo4jPersistentEntity ;
150
158
151
159
private Condition condition = Conditions .noCondition ();
0 commit comments