Skip to content

Commit e5d1bfe

Browse files
authored
Add support for GQL-status objects (#1555)
* Add support for GQL-status objects This update adds support for GQL-status objects defined in the GQL standard. * Add GqlStatusObject defaults assertions * Move API updates into Preview * Update Preview * Update generated GQL status description * Delete redundant suppression
1 parent b5f09d4 commit e5d1bfe

File tree

85 files changed

+1709
-549
lines changed

Some content is hidden

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

85 files changed

+1709
-549
lines changed

driver/clirr-ignored-differences.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,4 +603,28 @@
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>java.util.Set gqlStatusObjects()</method>
610+
</difference>
611+
612+
<difference>
613+
<className>org/neo4j/driver/summary/Notification</className>
614+
<differenceType>7012</differenceType>
615+
<method>java.util.Optional inputPosition()</method>
616+
</difference>
617+
618+
<difference>
619+
<className>org/neo4j/driver/summary/Notification</className>
620+
<differenceType>7012</differenceType>
621+
<method>java.util.Optional classification()</method>
622+
</difference>
623+
624+
<difference>
625+
<className>org/neo4j/driver/summary/Notification</className>
626+
<differenceType>7012</differenceType>
627+
<method>java.util.Optional rawClassification()</method>
628+
</difference>
629+
606630
</differences>

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

Lines changed: 88 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,8 @@
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.Preview;
49+
import org.neo4j.driver.util.Resource;
4250

4351
/**
4452
* A configuration class to config driver properties.
@@ -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,6 +315,7 @@ public long fetchSize() {
304315

305316
/**
306317
* Returns notification config.
318+
*
307319
* @return the notification config
308320
* @since 5.7
309321
*/
@@ -312,7 +324,35 @@ public NotificationConfig notificationConfig() {
312324
}
313325

314326
/**
315-
* Returns the number of {@link io.netty.channel.EventLoop} threads.
327+
* Returns a minimum notification severity.
328+
*
329+
* @return an {@link Optional} of minimum {@link NotificationSeverity} or an empty {@link Optional} if it is not set
330+
* @since 5.22.0
331+
*/
332+
@Preview(name = "GQL-status object")
333+
public Optional<NotificationSeverity> minimumNotificationSeverity() {
334+
return Optional.ofNullable(((InternalNotificationConfig) notificationConfig).minimumSeverity());
335+
}
336+
337+
/**
338+
* Returns a set of disabled notification classifications.
339+
* @return the {@link Set} of disabled {@link NotificationClassification}
340+
* @since 5.22.0
341+
*/
342+
@Preview(name = "GQL-status object")
343+
public Set<NotificationClassification> disabledNotificationClassifications() {
344+
var disabledCategories = ((InternalNotificationConfig) notificationConfig).disabledCategories();
345+
return disabledCategories != null
346+
? ((InternalNotificationConfig) notificationConfig)
347+
.disabledCategories().stream()
348+
.map(NotificationClassification.class::cast)
349+
.collect(Collectors.toUnmodifiableSet())
350+
: Collections.emptySet();
351+
}
352+
353+
/**
354+
* Returns the number of {@link EventLoop} threads.
355+
*
316356
* @return the number of threads
317357
*/
318358
public int eventLoopThreads() {
@@ -328,6 +368,7 @@ public boolean isMetricsEnabled() {
328368

329369
/**
330370
* Returns the {@link MetricsAdapter}.
371+
*
331372
* @return the metrics adapter
332373
*/
333374
public MetricsAdapter metricsAdapter() {
@@ -373,6 +414,7 @@ public static final class ConfigBuilder {
373414
private MetricsAdapter metricsAdapter = MetricsAdapter.DEV_NULL;
374415
private long fetchSize = FetchSizeUtil.DEFAULT_FETCH_SIZE;
375416
private int eventLoopThreads = 0;
417+
376418
private NotificationConfig notificationConfig = NotificationConfig.defaultConfig();
377419

378420
private boolean telemetryDisabled = false;
@@ -399,7 +441,7 @@ public ConfigBuilder withLogging(Logging logging) {
399441
* Enable logging of leaked sessions.
400442
* <p>
401443
* 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.
444+
* {@link Resource resource} that needs to be explicitly closed.
403445
* Unclosed sessions will result in socket leaks and could cause {@link OutOfMemoryError}s.
404446
* <p>
405447
* Session is considered to be leaked when it is finalized via {@link Object#finalize()} while not being
@@ -579,8 +621,8 @@ public ConfigBuilder withTrustStrategy(TrustStrategy trustStrategy) {
579621
public ConfigBuilder withRoutingTablePurgeDelay(long delay, TimeUnit unit) {
580622
var routingTablePurgeDelayMillis = unit.toMillis(delay);
581623
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));
624+
throw new IllegalArgumentException(
625+
format("The routing table purge delay may not be smaller than 0, but was %d %s.", delay, unit));
584626
}
585627
this.routingTablePurgeDelayMillis = routingTablePurgeDelayMillis;
586628
return this;
@@ -591,11 +633,11 @@ public ConfigBuilder withRoutingTablePurgeDelay(long delay, TimeUnit unit) {
591633
* This config is only valid when the driver is used with servers that support Bolt V4 (Server version 4.0 and later).
592634
* <p>
593635
* 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}.
636+
* This config specifies the default fetch size for all query runs using {@link Session} and {@link AsyncSession}.
595637
* By default, the value is set to {@code 1000}.
596638
* Use {@code -1} to disables back pressure and config client to pull all records at once after each run.
597639
* <p>
598-
* This config only applies to run results obtained via {@link Session} and {@link org.neo4j.driver.async.AsyncSession}.
640+
* This config only applies to run results obtained via {@link Session} and {@link AsyncSession}.
599641
* As with the reactive sessions the batch size is managed by the subscription requests instead.
600642
*
601643
* @param size the default record fetch size when pulling records in batches using Bolt V4.
@@ -627,11 +669,11 @@ public ConfigBuilder withConnectionTimeout(long value, TimeUnit unit) {
627669
var connectionTimeoutMillis = unit.toMillis(value);
628670
if (connectionTimeoutMillis < 0) {
629671
throw new IllegalArgumentException(
630-
String.format("The connection timeout may not be smaller than 0, but was %d %s.", value, unit));
672+
format("The connection timeout may not be smaller than 0, but was %d %s.", value, unit));
631673
}
632674
var connectionTimeoutMillisInt = (int) connectionTimeoutMillis;
633675
if (connectionTimeoutMillisInt != connectionTimeoutMillis) {
634-
throw new IllegalArgumentException(String.format(
676+
throw new IllegalArgumentException(format(
635677
"The connection timeout must represent int value when converted to milliseconds %d.",
636678
connectionTimeoutMillis));
637679
}
@@ -655,7 +697,7 @@ public ConfigBuilder withMaxTransactionRetryTime(long value, TimeUnit unit) {
655697
var maxRetryTimeMs = unit.toMillis(value);
656698
if (maxRetryTimeMs < 0) {
657699
throw new IllegalArgumentException(
658-
String.format("The max retry time may not be smaller than 0, but was %d %s.", value, unit));
700+
format("The max retry time may not be smaller than 0, but was %d %s.", value, unit));
659701
}
660702
this.maxTransactionRetryTimeMillis = maxRetryTimeMs;
661703
return this;
@@ -732,7 +774,7 @@ public ConfigBuilder withMetricsAdapter(MetricsAdapter metricsAdapter) {
732774
public ConfigBuilder withEventLoopThreads(int size) {
733775
if (size < 1) {
734776
throw new IllegalArgumentException(
735-
String.format("The event loop thread may not be smaller than 1, but was %d.", size));
777+
format("The event loop thread may not be smaller than 1, but was %d.", size));
736778
}
737779
this.eventLoopThreads = size;
738780
return this;
@@ -768,6 +810,42 @@ public ConfigBuilder withNotificationConfig(NotificationConfig notificationConfi
768810
return this;
769811
}
770812

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

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,48 @@
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
2725
*/
28-
public sealed interface NotificationCategory extends Serializable permits InternalNotificationCategory {
26+
public sealed interface NotificationCategory extends Serializable permits NotificationClassification {
2927
/**
3028
* A hint category.
3129
* <p>
3230
* For instance, the given hint cannot be satisfied.
3331
*/
34-
NotificationCategory HINT = new InternalNotificationCategory(Type.HINT);
32+
NotificationCategory HINT = NotificationClassification.HINT;
3533

3634
/**
3735
* An unrecognized category.
3836
* <p>
3937
* For instance, the query or command mentions entities that are unknown to the system.
4038
*/
41-
NotificationCategory UNRECOGNIZED = new InternalNotificationCategory(Type.UNRECOGNIZED);
39+
NotificationCategory UNRECOGNIZED = NotificationClassification.UNRECOGNIZED;
4240

4341
/**
4442
* An unsupported category.
4543
* <p>
4644
* For instance, the query/command is trying to use features that are not supported by the current system or using
4745
* features that are experimental and should not be used in production.
4846
*/
49-
NotificationCategory UNSUPPORTED = new InternalNotificationCategory(Type.UNSUPPORTED);
47+
NotificationCategory UNSUPPORTED = NotificationClassification.UNSUPPORTED;
5048

5149
/**
5250
* A performance category.
5351
* <p>
5452
* For instance, the query uses costly operations and might be slow.
5553
*/
56-
NotificationCategory PERFORMANCE = new InternalNotificationCategory(Type.PERFORMANCE);
54+
NotificationCategory PERFORMANCE = NotificationClassification.PERFORMANCE;
5755

5856
/**
5957
* A deprecation category.
6058
* <p>
6159
* For instance, the query/command use deprecated features that should be replaced.
6260
*/
63-
NotificationCategory DEPRECATION = new InternalNotificationCategory(Type.DEPRECATION);
61+
NotificationCategory DEPRECATION = NotificationClassification.DEPRECATION;
6462

6563
/**
6664
* A security category.
@@ -72,7 +70,7 @@ public sealed interface NotificationCategory extends Serializable permits Intern
7270
*
7371
* @since 5.14
7472
*/
75-
NotificationCategory SECURITY = new InternalNotificationCategory(Type.SECURITY);
73+
NotificationCategory SECURITY = NotificationClassification.SECURITY;
7674

7775
/**
7876
* A topology category.
@@ -84,12 +82,12 @@ public sealed interface NotificationCategory extends Serializable permits Intern
8482
*
8583
* @since 5.14
8684
*/
87-
NotificationCategory TOPOLOGY = new InternalNotificationCategory(Type.TOPOLOGY);
85+
NotificationCategory TOPOLOGY = NotificationClassification.TOPOLOGY;
8886

8987
/**
9088
* A generic category.
9189
* <p>
9290
* For instance, notifications that are not part of a more specific class.
9391
*/
94-
NotificationCategory GENERIC = new InternalNotificationCategory(Type.GENERIC);
92+
NotificationCategory GENERIC = NotificationClassification.GENERIC;
9593
}

0 commit comments

Comments
 (0)