Skip to content

Commit 032f928

Browse files
committed
Add support for GQL-status objects
This update adds support for GQL-status objects defined in the GQL standard.
1 parent f229788 commit 032f928

File tree

83 files changed

+1548
-466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1548
-466
lines changed

driver/clirr-ignored-differences.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,4 +603,34 @@
603603
<method>org.neo4j.driver.ExecutableQuery withAuthToken(org.neo4j.driver.AuthToken)</method>
604604
</difference>
605605

606+
<difference>
607+
<className>org/neo4j/driver/summary/ResultSummary</className>
608+
<differenceType>7012</differenceType>
609+
<method>org.neo4j.driver.summary.GqlStatusObject gqlStatusObject()</method>
610+
</difference>
611+
612+
<difference>
613+
<className>org/neo4j/driver/summary/ResultSummary</className>
614+
<differenceType>7012</differenceType>
615+
<method>java.util.Set gqlStatusObjects()</method>
616+
</difference>
617+
618+
<difference>
619+
<className>org/neo4j/driver/summary/Notification</className>
620+
<differenceType>7012</differenceType>
621+
<method>java.util.Optional inputPosition()</method>
622+
</difference>
623+
624+
<difference>
625+
<className>org/neo4j/driver/summary/Notification</className>
626+
<differenceType>7012</differenceType>
627+
<method>java.util.Optional classification()</method>
628+
</difference>
629+
630+
<difference>
631+
<className>org/neo4j/driver/summary/Notification</className>
632+
<differenceType>7012</differenceType>
633+
<method>java.util.Optional rawClassification()</method>
634+
</difference>
635+
606636
</differences>

driver/src/main/java/org/neo4j/driver/Config.java

Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING;
2121
import static org.neo4j.driver.internal.util.DriverInfoUtil.driverVersion;
2222

23+
import io.netty.channel.EventLoop;
2324
import java.io.File;
2425
import java.io.Serial;
2526
import java.io.Serializable;
@@ -28,9 +29,14 @@
2829
import java.util.Collections;
2930
import java.util.List;
3031
import java.util.Objects;
32+
import java.util.Optional;
33+
import java.util.Set;
3134
import java.util.concurrent.TimeUnit;
3235
import java.util.logging.Level;
36+
import java.util.stream.Collectors;
37+
import org.neo4j.driver.async.AsyncSession;
3338
import org.neo4j.driver.exceptions.UnsupportedFeatureException;
39+
import org.neo4j.driver.internal.InternalNotificationConfig;
3440
import org.neo4j.driver.internal.SecuritySettings;
3541
import org.neo4j.driver.internal.async.pool.PoolSettings;
3642
import org.neo4j.driver.internal.cluster.RoutingSettings;
@@ -39,6 +45,7 @@
3945
import org.neo4j.driver.net.ServerAddressResolver;
4046
import org.neo4j.driver.util.Experimental;
4147
import org.neo4j.driver.util.Immutable;
48+
import org.neo4j.driver.util.Resource;
4249

4350
/**
4451
* A configuration class to config driver properties.
@@ -140,6 +147,7 @@ public final class Config implements Serializable {
140147
/**
141148
* The notification config.
142149
*/
150+
@SuppressWarnings("deprecation")
143151
private final NotificationConfig notificationConfig;
144152
/**
145153
* The {@link MetricsAdapter}.
@@ -223,6 +231,7 @@ public int connectionTimeoutMillis() {
223231

224232
/**
225233
* Returns the maximum connection pool size.
234+
*
226235
* @return the maximum size
227236
*/
228237
public int maxConnectionPoolSize() {
@@ -231,6 +240,7 @@ public int maxConnectionPoolSize() {
231240

232241
/**
233242
* Returns the connection acquisition timeout in milliseconds.
243+
*
234244
* @return the acquisition timeout
235245
*/
236246
public long connectionAcquisitionTimeoutMillis() {
@@ -296,6 +306,7 @@ public long maxTransactionRetryTimeMillis() {
296306

297307
/**
298308
* Returns the fetch size.
309+
*
299310
* @return the fetch size
300311
*/
301312
public long fetchSize() {
@@ -304,15 +315,42 @@ public long fetchSize() {
304315

305316
/**
306317
* Returns notification config.
318+
*
307319
* @return the notification config
308320
* @since 5.7
321+
* @deprecated superseded by {@link #minimumNotificationSeverity()} and
322+
* {@link #disabledNotificationClassifications()}
309323
*/
324+
@Deprecated
310325
public NotificationConfig notificationConfig() {
311326
return notificationConfig;
312327
}
313328

314329
/**
315-
* Returns the number of {@link io.netty.channel.EventLoop} threads.
330+
* Returns a minimum notification severity.
331+
*
332+
* @return an {@link Optional} of minimum {@link NotificationSeverity} or an empty {@link Optional} if it is not set
333+
* @since 5.22.0
334+
*/
335+
public Optional<NotificationSeverity> minimumNotificationSeverity() {
336+
return Optional.ofNullable(((InternalNotificationConfig) notificationConfig).minimumSeverity());
337+
}
338+
339+
/**
340+
* Returns a set of disabled notification classifications.
341+
* @return the {@link Set} of disabled {@link NotificationClassification}
342+
* @since 5.22.0
343+
*/
344+
public Set<NotificationClassification> disabledNotificationClassifications() {
345+
return ((InternalNotificationConfig) notificationConfig)
346+
.disabledCategories().stream()
347+
.map(NotificationClassification.class::cast)
348+
.collect(Collectors.toUnmodifiableSet());
349+
}
350+
351+
/**
352+
* Returns the number of {@link EventLoop} threads.
353+
*
316354
* @return the number of threads
317355
*/
318356
public int eventLoopThreads() {
@@ -328,6 +366,7 @@ public boolean isMetricsEnabled() {
328366

329367
/**
330368
* Returns the {@link MetricsAdapter}.
369+
*
331370
* @return the metrics adapter
332371
*/
333372
public MetricsAdapter metricsAdapter() {
@@ -373,6 +412,8 @@ public static final class ConfigBuilder {
373412
private MetricsAdapter metricsAdapter = MetricsAdapter.DEV_NULL;
374413
private long fetchSize = FetchSizeUtil.DEFAULT_FETCH_SIZE;
375414
private int eventLoopThreads = 0;
415+
416+
@SuppressWarnings("deprecation")
376417
private NotificationConfig notificationConfig = NotificationConfig.defaultConfig();
377418

378419
private boolean telemetryDisabled = false;
@@ -399,7 +440,7 @@ public ConfigBuilder withLogging(Logging logging) {
399440
* Enable logging of leaked sessions.
400441
* <p>
401442
* Each {@link Session session} is associated with a network connection and thus is a
402-
* {@link org.neo4j.driver.util.Resource resource} that needs to be explicitly closed.
443+
* {@link Resource resource} that needs to be explicitly closed.
403444
* Unclosed sessions will result in socket leaks and could cause {@link OutOfMemoryError}s.
404445
* <p>
405446
* Session is considered to be leaked when it is finalized via {@link Object#finalize()} while not being
@@ -579,8 +620,8 @@ public ConfigBuilder withTrustStrategy(TrustStrategy trustStrategy) {
579620
public ConfigBuilder withRoutingTablePurgeDelay(long delay, TimeUnit unit) {
580621
var routingTablePurgeDelayMillis = unit.toMillis(delay);
581622
if (routingTablePurgeDelayMillis < 0) {
582-
throw new IllegalArgumentException(String.format(
583-
"The routing table purge delay may not be smaller than 0, but was %d %s.", delay, unit));
623+
throw new IllegalArgumentException(
624+
format("The routing table purge delay may not be smaller than 0, but was %d %s.", delay, unit));
584625
}
585626
this.routingTablePurgeDelayMillis = routingTablePurgeDelayMillis;
586627
return this;
@@ -591,11 +632,11 @@ public ConfigBuilder withRoutingTablePurgeDelay(long delay, TimeUnit unit) {
591632
* This config is only valid when the driver is used with servers that support Bolt V4 (Server version 4.0 and later).
592633
* <p>
593634
* Bolt V4 enables pulling records in batches to allow client to take control of data population and apply back pressure to server.
594-
* This config specifies the default fetch size for all query runs using {@link Session} and {@link org.neo4j.driver.async.AsyncSession}.
635+
* This config specifies the default fetch size for all query runs using {@link Session} and {@link AsyncSession}.
595636
* By default, the value is set to {@code 1000}.
596637
* Use {@code -1} to disables back pressure and config client to pull all records at once after each run.
597638
* <p>
598-
* This config only applies to run results obtained via {@link Session} and {@link org.neo4j.driver.async.AsyncSession}.
639+
* This config only applies to run results obtained via {@link Session} and {@link AsyncSession}.
599640
* As with the reactive sessions the batch size is managed by the subscription requests instead.
600641
*
601642
* @param size the default record fetch size when pulling records in batches using Bolt V4.
@@ -627,11 +668,11 @@ public ConfigBuilder withConnectionTimeout(long value, TimeUnit unit) {
627668
var connectionTimeoutMillis = unit.toMillis(value);
628669
if (connectionTimeoutMillis < 0) {
629670
throw new IllegalArgumentException(
630-
String.format("The connection timeout may not be smaller than 0, but was %d %s.", value, unit));
671+
format("The connection timeout may not be smaller than 0, but was %d %s.", value, unit));
631672
}
632673
var connectionTimeoutMillisInt = (int) connectionTimeoutMillis;
633674
if (connectionTimeoutMillisInt != connectionTimeoutMillis) {
634-
throw new IllegalArgumentException(String.format(
675+
throw new IllegalArgumentException(format(
635676
"The connection timeout must represent int value when converted to milliseconds %d.",
636677
connectionTimeoutMillis));
637678
}
@@ -655,7 +696,7 @@ public ConfigBuilder withMaxTransactionRetryTime(long value, TimeUnit unit) {
655696
var maxRetryTimeMs = unit.toMillis(value);
656697
if (maxRetryTimeMs < 0) {
657698
throw new IllegalArgumentException(
658-
String.format("The max retry time may not be smaller than 0, but was %d %s.", value, unit));
699+
format("The max retry time may not be smaller than 0, but was %d %s.", value, unit));
659700
}
660701
this.maxTransactionRetryTimeMillis = maxRetryTimeMs;
661702
return this;
@@ -732,7 +773,7 @@ public ConfigBuilder withMetricsAdapter(MetricsAdapter metricsAdapter) {
732773
public ConfigBuilder withEventLoopThreads(int size) {
733774
if (size < 1) {
734775
throw new IllegalArgumentException(
735-
String.format("The event loop thread may not be smaller than 1, but was %d.", size));
776+
format("The event loop thread may not be smaller than 1, but was %d.", size));
736777
}
737778
this.eventLoopThreads = size;
738779
return this;
@@ -762,12 +803,50 @@ public ConfigBuilder withUserAgent(String userAgent) {
762803
* @param notificationConfig the notification config
763804
* @return this builder
764805
* @since 5.7
806+
* @deprecated superseded by {@link #withMinimumNotificationSeverity(NotificationSeverity)} and {@link #withDisabledNotificationClassifications(Set)}
765807
*/
808+
@Deprecated
766809
public ConfigBuilder withNotificationConfig(NotificationConfig notificationConfig) {
767810
this.notificationConfig = Objects.requireNonNull(notificationConfig, "notificationConfig must not be null");
768811
return this;
769812
}
770813

814+
/**
815+
* Sets a minimum severity for notifications produced by the server.
816+
*
817+
* @param minimumNotificationSeverity the minimum notification severity
818+
* @return this builder
819+
* @since 5.22.0
820+
*/
821+
@SuppressWarnings("deprecation")
822+
public ConfigBuilder withMinimumNotificationSeverity(NotificationSeverity minimumNotificationSeverity) {
823+
if (minimumNotificationSeverity == null) {
824+
notificationConfig = NotificationConfig.disableAllConfig();
825+
} else {
826+
notificationConfig = notificationConfig.enableMinimumSeverity(minimumNotificationSeverity);
827+
}
828+
return this;
829+
}
830+
831+
/**
832+
* Sets a set of disabled classifications for notifications produced by the server.
833+
*
834+
* @param disabledNotificationClassifications the set of disabled notification classifications
835+
* @return this builder
836+
* @since 5.22.0
837+
*/
838+
@SuppressWarnings("deprecation")
839+
public ConfigBuilder withDisabledNotificationClassifications(
840+
Set<NotificationClassification> disabledNotificationClassifications) {
841+
var disabledCategories = disabledNotificationClassifications == null
842+
? Collections.<NotificationCategory>emptySet()
843+
: disabledNotificationClassifications.stream()
844+
.map(NotificationCategory.class::cast)
845+
.collect(Collectors.toSet());
846+
notificationConfig = notificationConfig.disableCategories(disabledCategories);
847+
return this;
848+
}
849+
771850
/**
772851
* Sets if telemetry is disabled on the driver side.
773852
* <p>

driver/src/main/java/org/neo4j/driver/NotificationCategory.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,50 @@
1717
package org.neo4j.driver;
1818

1919
import java.io.Serializable;
20-
import org.neo4j.driver.internal.InternalNotificationCategory;
21-
import org.neo4j.driver.internal.InternalNotificationCategory.Type;
2220

2321
/**
2422
* Notification category.
2523
*
2624
* @since 5.7
25+
* @deprecated superseded by {@link NotificationClassification}
2726
*/
28-
public sealed interface NotificationCategory extends Serializable permits InternalNotificationCategory {
27+
@Deprecated
28+
public sealed interface NotificationCategory extends Serializable permits NotificationClassification {
2929
/**
3030
* A hint category.
3131
* <p>
3232
* For instance, the given hint cannot be satisfied.
3333
*/
34-
NotificationCategory HINT = new InternalNotificationCategory(Type.HINT);
34+
NotificationCategory HINT = NotificationClassification.HINT;
3535

3636
/**
3737
* An unrecognized category.
3838
* <p>
3939
* For instance, the query or command mentions entities that are unknown to the system.
4040
*/
41-
NotificationCategory UNRECOGNIZED = new InternalNotificationCategory(Type.UNRECOGNIZED);
41+
NotificationCategory UNRECOGNIZED = NotificationClassification.UNRECOGNIZED;
4242

4343
/**
4444
* An unsupported category.
4545
* <p>
4646
* For instance, the query/command is trying to use features that are not supported by the current system or using
4747
* features that are experimental and should not be used in production.
4848
*/
49-
NotificationCategory UNSUPPORTED = new InternalNotificationCategory(Type.UNSUPPORTED);
49+
NotificationCategory UNSUPPORTED = NotificationClassification.UNSUPPORTED;
5050

5151
/**
5252
* A performance category.
5353
* <p>
5454
* For instance, the query uses costly operations and might be slow.
5555
*/
56-
NotificationCategory PERFORMANCE = new InternalNotificationCategory(Type.PERFORMANCE);
56+
NotificationCategory PERFORMANCE = NotificationClassification.PERFORMANCE;
5757

5858
/**
5959
* A deprecation category.
6060
* <p>
6161
* For instance, the query/command use deprecated features that should be replaced.
6262
*/
63-
NotificationCategory DEPRECATION = new InternalNotificationCategory(Type.DEPRECATION);
63+
NotificationCategory DEPRECATION = NotificationClassification.DEPRECATION;
6464

6565
/**
6666
* A security category.
@@ -72,7 +72,7 @@ public sealed interface NotificationCategory extends Serializable permits Intern
7272
*
7373
* @since 5.14
7474
*/
75-
NotificationCategory SECURITY = new InternalNotificationCategory(Type.SECURITY);
75+
NotificationCategory SECURITY = NotificationClassification.SECURITY;
7676

7777
/**
7878
* A topology category.
@@ -84,12 +84,12 @@ public sealed interface NotificationCategory extends Serializable permits Intern
8484
*
8585
* @since 5.14
8686
*/
87-
NotificationCategory TOPOLOGY = new InternalNotificationCategory(Type.TOPOLOGY);
87+
NotificationCategory TOPOLOGY = NotificationClassification.TOPOLOGY;
8888

8989
/**
9090
* A generic category.
9191
* <p>
9292
* For instance, notifications that are not part of a more specific class.
9393
*/
94-
NotificationCategory GENERIC = new InternalNotificationCategory(Type.GENERIC);
94+
NotificationCategory GENERIC = NotificationClassification.GENERIC;
9595
}

0 commit comments

Comments
 (0)