15
15
*/
16
16
package org .springframework .data .neo4j .repository .query ;
17
17
18
+ import java .io .Serial ;
18
19
import java .util .Collection ;
19
20
import java .util .LinkedHashMap ;
20
21
import java .util .Locale ;
24
25
import java .util .regex .Pattern ;
25
26
import java .util .stream .Collectors ;
26
27
27
- import org .apache .commons .logging .LogFactory ;
28
28
import org .apiguardian .api .API ;
29
- import org .neo4j .cypherdsl .core .internal .SchemaNames ;
30
- import org .springframework .core .log .LogAccessor ;
29
+ import org .neo4j .cypherdsl .support .schema_name .SchemaNames ;
31
30
import org .springframework .data .domain .Pageable ;
32
31
import org .springframework .data .domain .Sort ;
33
32
import org .springframework .data .neo4j .core .mapping .CypherGenerator ;
@@ -57,8 +56,6 @@ public final class Neo4jSpelSupport {
57
56
public static String FUNCTION_ALL_OF = "allOf" ;
58
57
public static String FUNCTION_ORDER_BY = "orderBy" ;
59
58
60
- private static final LogAccessor LOG = new LogAccessor (LogFactory .getLog (Neo4jSpelSupport .class ));
61
-
62
59
/**
63
60
* Takes {@code arg} and tries to either extract a {@link Sort sort} from it or cast it to a sort. That sort is
64
61
* than past to the {@link CypherGenerator} that renders a valid order by fragment which replaces the SpEL placeholder
@@ -90,9 +87,8 @@ public static LiteralReplacement orderBy(@Nullable Object arg) {
90
87
*/
91
88
public static LiteralReplacement literal (@ Nullable Object arg ) {
92
89
93
- LiteralReplacement literalReplacement = StringBasedLiteralReplacement
90
+ return StringBasedLiteralReplacement
94
91
.withTargetAndValue (LiteralReplacement .Target .UNSPECIFIED , arg == null ? "" : arg .toString ());
95
- return literalReplacement ;
96
92
}
97
93
98
94
public static LiteralReplacement anyOf (@ Nullable Object arg ) {
@@ -113,7 +109,7 @@ private static LiteralReplacement labels(@Nullable Object arg, String joinOn) {
113
109
private static String joinStrings (Object arg , String joinOn ) {
114
110
if (arg instanceof Collection ) {
115
111
return ((Collection <?>) arg ).stream ()
116
- .map (o -> SchemaNames .sanitize (o .toString ()).get ())
112
+ .map (o -> SchemaNames .sanitize (o .toString ()).orElseThrow ())
117
113
.collect (Collectors .joining (joinOn ));
118
114
}
119
115
@@ -130,7 +126,7 @@ private static String joinStrings(Object arg, String joinOn) {
130
126
* comes in handy in places where non-parameterizable things should be created dynamic, for example matching on
131
127
* set of dynamic labels, types order ordering in a dynamic way.
132
128
*/
133
- interface LiteralReplacement {
129
+ public interface LiteralReplacement {
134
130
135
131
/**
136
132
* The target of this replacement. While a replacement can be used theoretically everywhere in the query, the target
@@ -155,7 +151,10 @@ private static class StringBasedLiteralReplacement implements LiteralReplacement
155
151
* the creation of too many small objects.
156
152
*/
157
153
private static final Map <String , LiteralReplacement > INSTANCES =
158
- new LinkedHashMap <String , LiteralReplacement >(DEFAULT_CACHE_SIZE ) {
154
+ new LinkedHashMap <>(DEFAULT_CACHE_SIZE ) {
155
+ @ Serial
156
+ private static final long serialVersionUID = 195460174410223375L ;
157
+
159
158
@ Override
160
159
protected boolean removeEldestEntry (Map .Entry <String , LiteralReplacement > eldest ) {
161
160
return size () > DEFAULT_CACHE_SIZE ;
@@ -167,7 +166,7 @@ protected boolean removeEldestEntry(Map.Entry<String, LiteralReplacement> eldest
167
166
static LiteralReplacement withTargetAndValue (LiteralReplacement .Target target , @ Nullable String value ) {
168
167
169
168
String valueUsed = value == null ? "" : value ;
170
- String key = new StringBuilder ( target .name ()). append ( "_" ). append ( valueUsed ). toString () ;
169
+ String key = target .name () + "_" + valueUsed ;
171
170
172
171
long stamp = LOCK .tryOptimisticRead ();
173
172
if (LOCK .validate (stamp ) && INSTANCES .containsKey (key )) {
0 commit comments