16
16
package org .springframework .data .neo4j .core ;
17
17
18
18
import java .util .function .Consumer ;
19
+ import java .util .function .Predicate ;
20
+ import java .util .regex .Pattern ;
19
21
import java .util .stream .Collectors ;
20
22
import java .util .stream .Stream ;
21
23
22
24
import org .apache .commons .logging .LogFactory ;
23
- import org .neo4j .driver .NotificationCategory ;
25
+ import org .neo4j .driver .NotificationClassification ;
26
+ import org .neo4j .driver .NotificationSeverity ;
24
27
import org .neo4j .driver .summary .InputPosition ;
25
28
import org .neo4j .driver .summary .Notification ;
26
29
import org .neo4j .driver .summary .Plan ;
27
30
import org .neo4j .driver .summary .ResultSummary ;
28
31
import org .springframework .core .log .LogAccessor ;
32
+ import org .springframework .lang .Nullable ;
29
33
30
34
/**
31
35
* Utility class for dealing with result summaries.
@@ -46,6 +50,8 @@ final class ResultSummaries {
46
50
private static final LogAccessor cypherSecurityNotificationLog = new LogAccessor (LogFactory .getLog ("org.springframework.data.neo4j.cypher.security" ));
47
51
private static final LogAccessor cypherTopologyNotificationLog = new LogAccessor (LogFactory .getLog ("org.springframework.data.neo4j.cypher.topology" ));
48
52
53
+ private static final Pattern DEPRECATED_ID_PATTERN = Pattern .compile ("(?im)The query used a deprecated function: `id`\\ ." );
54
+
49
55
/**
50
56
* Does some post-processing on the giving result summary, especially logging all notifications
51
57
* and potentially query plans.
@@ -65,48 +71,55 @@ private static void logNotifications(ResultSummary resultSummary) {
65
71
return ;
66
72
}
67
73
74
+ boolean supressIdDeprecations = Neo4jClient .SUPPRESS_ID_DEPRECATIONS .getAcquire ();
75
+ Predicate <Notification > isDeprecationWarningForId ;
76
+ try {
77
+ isDeprecationWarningForId = notification -> supressIdDeprecations
78
+ && notification .classification ().orElse (NotificationClassification .UNRECOGNIZED )
79
+ == NotificationClassification .DEPRECATION && DEPRECATED_ID_PATTERN .matcher (notification .description ())
80
+ .matches ();
81
+ } finally {
82
+ Neo4jClient .SUPPRESS_ID_DEPRECATIONS .setRelease (supressIdDeprecations );
83
+ }
84
+
68
85
String query = resultSummary .query ().text ();
69
86
resultSummary .notifications ()
70
- .forEach (notification -> {
71
- LogAccessor log = notification .category ()
72
- .map (ResultSummaries ::getLogAccessor )
73
- .orElse (Neo4jClient .cypherLog );
74
- Consumer <String > logFunction =
75
- switch (notification .severity ()) {
76
- case "WARNING" -> log ::warn ;
77
- case "INFORMATION" -> log ::info ;
78
- default -> log ::debug ;
79
- };
87
+ .stream ().filter (Predicate .not (isDeprecationWarningForId ))
88
+ .forEach (notification -> notification .severityLevel ().ifPresent (severityLevel -> {
89
+ var category = notification .classification ().orElse (null );
90
+
91
+ var logger = getLogAccessor (category );
92
+ Consumer <String > logFunction ;
93
+ if (severityLevel == NotificationSeverity .WARNING ) {
94
+ logFunction = logger ::warn ;
95
+ } else if (severityLevel == NotificationSeverity .INFORMATION ) {
96
+ logFunction = logger ::info ;
97
+ } else if (severityLevel == NotificationSeverity .OFF ) {
98
+ logFunction = (String message ) -> {
99
+ };
100
+ } else {
101
+ logFunction = logger ::debug ;
102
+ }
103
+
80
104
logFunction .accept (ResultSummaries .format (notification , query ));
81
- });
105
+ })) ;
82
106
}
83
107
84
- private static LogAccessor getLogAccessor (NotificationCategory category ) {
85
- if (category == NotificationCategory .HINT ) {
86
- return cypherHintNotificationLog ;
87
- }
88
- if (category == NotificationCategory .DEPRECATION ) {
89
- return cypherDeprecationNotificationLog ;
90
- }
91
- if (category == NotificationCategory .PERFORMANCE ) {
92
- return cypherPerformanceNotificationLog ;
93
- }
94
- if (category == NotificationCategory .GENERIC ) {
95
- return cypherGenericNotificationLog ;
96
- }
97
- if (category == NotificationCategory .UNSUPPORTED ) {
98
- return cypherUnsupportedNotificationLog ;
99
- }
100
- if (category == NotificationCategory .UNRECOGNIZED ) {
101
- return cypherUnrecognizedNotificationLog ;
102
- }
103
- if (category == NotificationCategory .SECURITY ) {
104
- return cypherSecurityNotificationLog ;
105
- }
106
- if (category == NotificationCategory .TOPOLOGY ) {
107
- return cypherTopologyNotificationLog ;
108
+ private static LogAccessor getLogAccessor (@ Nullable NotificationClassification category ) {
109
+ if (category == null ) {
110
+ return Neo4jClient .cypherLog ;
108
111
}
109
- return Neo4jClient .cypherLog ;
112
+ return switch (category ) {
113
+ case HINT -> cypherHintNotificationLog ;
114
+ case DEPRECATION -> cypherDeprecationNotificationLog ;
115
+ case PERFORMANCE -> cypherPerformanceNotificationLog ;
116
+ case GENERIC -> cypherGenericNotificationLog ;
117
+ case UNSUPPORTED -> cypherUnsupportedNotificationLog ;
118
+ case UNRECOGNIZED -> cypherUnrecognizedNotificationLog ;
119
+ case SECURITY -> cypherSecurityNotificationLog ;
120
+ case TOPOLOGY -> cypherTopologyNotificationLog ;
121
+ default -> Neo4jClient .cypherLog ;
122
+ };
110
123
}
111
124
112
125
/**
0 commit comments