1616package org .springframework .data .neo4j .core ;
1717
1818import java .util .function .Consumer ;
19+ import java .util .function .Predicate ;
20+ import java .util .regex .Pattern ;
1921import java .util .stream .Collectors ;
2022import java .util .stream .Stream ;
2123
2224import org .apache .commons .logging .LogFactory ;
23- import org .neo4j .driver .NotificationCategory ;
25+ import org .neo4j .driver .NotificationClassification ;
26+ import org .neo4j .driver .NotificationSeverity ;
2427import org .neo4j .driver .summary .InputPosition ;
2528import org .neo4j .driver .summary .Notification ;
2629import org .neo4j .driver .summary .Plan ;
2730import org .neo4j .driver .summary .ResultSummary ;
2831import org .springframework .core .log .LogAccessor ;
32+ import org .springframework .lang .Nullable ;
2933
3034/**
3135 * Utility class for dealing with result summaries.
@@ -46,6 +50,8 @@ final class ResultSummaries {
4650 private static final LogAccessor cypherSecurityNotificationLog = new LogAccessor (LogFactory .getLog ("org.springframework.data.neo4j.cypher.security" ));
4751 private static final LogAccessor cypherTopologyNotificationLog = new LogAccessor (LogFactory .getLog ("org.springframework.data.neo4j.cypher.topology" ));
4852
53+ private static final Pattern DEPRECATED_ID_PATTERN = Pattern .compile ("(?im)The query used a deprecated function: `id`\\ ." );
54+
4955 /**
5056 * Does some post-processing on the giving result summary, especially logging all notifications
5157 * and potentially query plans.
@@ -65,48 +71,55 @@ private static void logNotifications(ResultSummary resultSummary) {
6571 return ;
6672 }
6773
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+
6885 String query = resultSummary .query ().text ();
6986 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+
80104 logFunction .accept (ResultSummaries .format (notification , query ));
81- });
105+ })) ;
82106 }
83107
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 ;
108111 }
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+ };
110123 }
111124
112125 /**
0 commit comments