Skip to content

Commit 477577b

Browse files
authored
Introduce executeQuery on Driver level (#1321)
* Introduce executeQuery on Driver level This is a new basic high-level API for executing idempotent queries. * Delete DriverQueryBookmarkManagerPlaceholder * Update documentation * Update documentation
1 parent 19edf34 commit 477577b

24 files changed

+1308
-159
lines changed

driver/clirr-ignored-differences.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,4 +391,40 @@
391391
<differenceType>3003</differenceType>
392392
</difference>
393393

394+
<difference>
395+
<className>org/neo4j/driver/Driver</className>
396+
<differenceType>7012</differenceType>
397+
<method>org.neo4j.driver.EagerResult executeQuery(org.neo4j.driver.Query)</method>
398+
</difference>
399+
400+
<difference>
401+
<className>org/neo4j/driver/Driver</className>
402+
<differenceType>7012</differenceType>
403+
<method>java.lang.Object executeQuery(org.neo4j.driver.Query, org.neo4j.driver.QueryConfig)</method>
404+
</difference>
405+
406+
<difference>
407+
<className>org/neo4j/driver/Driver</className>
408+
<differenceType>7012</differenceType>
409+
<method>org.neo4j.driver.EagerResult executeQuery(java.lang.String)</method>
410+
</difference>
411+
412+
<difference>
413+
<className>org/neo4j/driver/Driver</className>
414+
<differenceType>7012</differenceType>
415+
<method>org.neo4j.driver.EagerResult executeQuery(java.lang.String, java.util.Map)</method>
416+
</difference>
417+
418+
<difference>
419+
<className>org/neo4j/driver/Driver</className>
420+
<differenceType>7012</differenceType>
421+
<method>java.lang.Object executeQuery(java.lang.String, java.util.Map, org.neo4j.driver.QueryConfig)</method>
422+
</difference>
423+
424+
<difference>
425+
<className>org/neo4j/driver/Driver</className>
426+
<differenceType>7012</differenceType>
427+
<method>org.neo4j.driver.BookmarkManager queryBookmarkManager()</method>
428+
</difference>
429+
394430
</differences>

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

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ public final class Config implements Serializable {
7575

7676
private static final Config EMPTY = builder().build();
7777

78-
/** User defined logging */
78+
private final BookmarkManager queryBookmarkManager;
79+
80+
/**
81+
* User defined logging
82+
*/
7983
private final Logging logging;
8084

8185
private final boolean logLeakedSessions;
@@ -100,6 +104,7 @@ public final class Config implements Serializable {
100104
private final MetricsAdapter metricsAdapter;
101105

102106
private Config(ConfigBuilder builder) {
107+
this.queryBookmarkManager = builder.queryBookmarkManager;
103108
this.logging = builder.logging;
104109
this.logLeakedSessions = builder.logLeakedSessions;
105110

@@ -121,8 +126,22 @@ private Config(ConfigBuilder builder) {
121126
this.metricsAdapter = builder.metricsAdapter;
122127
}
123128

129+
/**
130+
* A {@link BookmarkManager} implementation for the driver to use on
131+
* {@link Driver#executeQuery(Query, QueryConfig)} method and its variants by default.
132+
* <p>
133+
* Please note that sessions will not use this automatically, but it is possible to enable it explicitly
134+
* using {@link SessionConfig.Builder#withBookmarkManager(BookmarkManager)}.
135+
*
136+
* @return bookmark manager, must not be {@code null}
137+
*/
138+
public BookmarkManager queryBookmarkManager() {
139+
return queryBookmarkManager;
140+
}
141+
124142
/**
125143
* Logging provider
144+
*
126145
* @return the Logging provider to use
127146
*/
128147
public Logging logging() {
@@ -256,6 +275,8 @@ public String userAgent() {
256275
* Used to build new config instances
257276
*/
258277
public static final class ConfigBuilder {
278+
private BookmarkManager queryBookmarkManager =
279+
BookmarkManagers.defaultManager(BookmarkManagerConfig.builder().build());
259280
private Logging logging = DEV_NULL_LOGGING;
260281
private boolean logLeakedSessions;
261282
private int maxConnectionPoolSize = PoolSettings.DEFAULT_MAX_CONNECTION_POOL_SIZE;
@@ -275,6 +296,22 @@ public static final class ConfigBuilder {
275296

276297
private ConfigBuilder() {}
277298

299+
/**
300+
* Sets a {@link BookmarkManager} implementation for the driver to use on
301+
* {@link Driver#executeQuery(Query, QueryConfig)} method and its variants by default.
302+
* <p>
303+
* Please note that sessions will not use this automatically, but it is possible to enable it explicitly
304+
* using {@link SessionConfig.Builder#withBookmarkManager(BookmarkManager)}.
305+
*
306+
* @param queryBookmarkManager bookmark manager, must not be {@code null}
307+
* @return this builder
308+
*/
309+
public ConfigBuilder withQueryBookmarkManager(BookmarkManager queryBookmarkManager) {
310+
Objects.requireNonNull(queryBookmarkManager, "queryBookmarkManager must not be null");
311+
this.queryBookmarkManager = queryBookmarkManager;
312+
return this;
313+
}
314+
278315
/**
279316
* Provide a logging implementation for the driver to use. Java logging framework {@link java.util.logging} with {@link Level#INFO} is used by default.
280317
* Callers are expected to either implement {@link Logging} interface or provide one of the existing implementations available from static factory
@@ -331,7 +368,7 @@ public ConfigBuilder withLeakedSessionsLogging() {
331368
* validity and negative values mean connections will never be tested.
332369
*
333370
* @param value the minimum idle time
334-
* @param unit the unit in which the duration is given
371+
* @param unit the unit in which the duration is given
335372
* @return this builder
336373
*/
337374
public ConfigBuilder withConnectionLivenessCheckTimeout(long value, TimeUnit unit) {
@@ -356,7 +393,7 @@ public ConfigBuilder withConnectionLivenessCheckTimeout(long value, TimeUnit uni
356393
* checked.
357394
*
358395
* @param value the maximum connection lifetime
359-
* @param unit the unit in which the duration is given
396+
* @param unit the unit in which the duration is given
360397
* @return this builder
361398
*/
362399
public ConfigBuilder withMaxConnectionLifetime(long value, TimeUnit unit) {
@@ -402,7 +439,7 @@ public ConfigBuilder withMaxConnectionPoolSize(int value) {
402439
* of {@code 0} is allowed and results in no timeout and immediate failure when connection is unavailable.
403440
*
404441
* @param value the acquisition timeout
405-
* @param unit the unit in which the duration is given
442+
* @param unit the unit in which the duration is given
406443
* @return this builder
407444
* @see #withMaxConnectionPoolSize(int)
408445
*/
@@ -418,6 +455,7 @@ public ConfigBuilder withConnectionAcquisitionTimeout(long value, TimeUnit unit)
418455

419456
/**
420457
* Set to use encrypted traffic.
458+
*
421459
* @return this builder
422460
*/
423461
public ConfigBuilder withEncryption() {
@@ -427,6 +465,7 @@ public ConfigBuilder withEncryption() {
427465

428466
/**
429467
* Set to use unencrypted traffic.
468+
*
430469
* @return this builder
431470
*/
432471
public ConfigBuilder withoutEncryption() {
@@ -461,13 +500,12 @@ public ConfigBuilder withTrustStrategy(TrustStrategy trustStrategy) {
461500
* The routing table of a database get refreshed if the database is used frequently.
462501
* If the database is not used for a long time,
463502
* the driver use the timeout specified here to purge the stale routing table.
464-
*
503+
* <p>
465504
* After a routing table is removed, next time when using the database of the purged routing table,
466505
* the driver will fall back to use seed URI for a new routing table.
467-
* @param delay
468-
* the amount of time to wait before purging routing tables
469-
* @param unit
470-
* the unit in which the duration is given
506+
*
507+
* @param delay the amount of time to wait before purging routing tables
508+
* @param unit the unit in which the duration is given
471509
* @return this builder
472510
*/
473511
public ConfigBuilder withRoutingTablePurgeDelay(long delay, TimeUnit unit) {
@@ -483,15 +521,16 @@ public ConfigBuilder withRoutingTablePurgeDelay(long delay, TimeUnit unit) {
483521
/**
484522
* Specify how many records to fetch in each batch.
485523
* This config is only valid when the driver is used with servers that support Bolt V4 (Server version 4.0 and later).
486-
*
524+
* <p>
487525
* Bolt V4 enables pulling records in batches to allow client to take control of data population and apply back pressure to server.
488526
* This config specifies the default fetch size for all query runs using {@link Session} and {@link org.neo4j.driver.async.AsyncSession}.
489527
* By default, the value is set to {@code 1000}.
490528
* Use {@code -1} to disables back pressure and config client to pull all records at once after each run.
491-
*
529+
* <p>
492530
* This config only applies to run result obtained via {@link Session} and {@link org.neo4j.driver.async.AsyncSession}.
493531
* As with {@link org.neo4j.driver.reactive.RxSession}, the batch size is provided via
494532
* {@link org.reactivestreams.Subscription#request(long)} instead.
533+
*
495534
* @param size the default record fetch size when pulling records in batches using Bolt V4.
496535
* @return this builder
497536
*/
@@ -512,10 +551,10 @@ public ConfigBuilder withFetchSize(long size) {
512551
* The default value of this parameter is {@code 30 SECONDS}.
513552
*
514553
* @param value the timeout duration
515-
* @param unit the unit in which duration is given
554+
* @param unit the unit in which duration is given
516555
* @return this builder
517556
* @throws IllegalArgumentException when given value is negative or does not fit in {@code int} when
518-
* converted to milliseconds.
557+
* converted to milliseconds.
519558
*/
520559
public ConfigBuilder withConnectionTimeout(long value, TimeUnit unit) {
521560
long connectionTimeoutMillis = unit.toMillis(value);
@@ -543,7 +582,7 @@ public ConfigBuilder withConnectionTimeout(long value, TimeUnit unit) {
543582
* Default value is 30 seconds.
544583
*
545584
* @param value the timeout duration
546-
* @param unit the unit in which duration is given
585+
* @param unit the unit in which duration is given
547586
* @return this builder
548587
* @throws IllegalArgumentException when given value is negative
549588
*/
@@ -586,6 +625,7 @@ public ConfigBuilder withDriverMetrics() {
586625

587626
/**
588627
* Disable driver metrics. When disabled, driver metrics cannot be accessed via {@link Driver#metrics()}.
628+
*
589629
* @return this builder.
590630
*/
591631
public ConfigBuilder withoutDriverMetrics() {
@@ -619,6 +659,7 @@ public ConfigBuilder withMetricsAdapter(MetricsAdapter metricsAdapter) {
619659
/**
620660
* Configure the event loop thread count. This specifies how many threads the driver can use to handle network I/O events
621661
* and user's events in driver's I/O threads. By default, 2 * NumberOfProcessors amount of threads will be used instead.
662+
*
622663
* @param size the thread count.
623664
* @return this builder.
624665
* @throws IllegalArgumentException if the value of the size is set to a number that is less than 1.
@@ -634,6 +675,7 @@ public ConfigBuilder withEventLoopThreads(int size) {
634675

635676
/**
636677
* Configure the user_agent field sent to the server to identify the connected client.
678+
*
637679
* @param userAgent the string to configure user_agent.
638680
* @return this builder.
639681
*/
@@ -802,6 +844,7 @@ public static TrustStrategy trustAllCertificates() {
802844

803845
/**
804846
* The revocation strategy used for verifying certificates.
847+
*
805848
* @return this {@link TrustStrategy}'s revocation strategy
806849
*/
807850
public RevocationCheckingStrategy revocationCheckingStrategy() {
@@ -811,6 +854,7 @@ public RevocationCheckingStrategy revocationCheckingStrategy() {
811854
/**
812855
* Configures the {@link TrustStrategy} to not carry out OCSP revocation checks on certificates. This is the
813856
* option that is configured by default.
857+
*
814858
* @return the current trust strategy
815859
*/
816860
public TrustStrategy withoutCertificateRevocationChecks() {
@@ -823,6 +867,7 @@ public TrustStrategy withoutCertificateRevocationChecks() {
823867
* stapled to the certificate. If no stapled response is found, then certificate verification continues
824868
* (and does not fail verification). This setting also requires the server to be configured to enable
825869
* OCSP stapling.
870+
*
826871
* @return the current trust strategy
827872
*/
828873
public TrustStrategy withVerifyIfPresentRevocationChecks() {
@@ -834,9 +879,10 @@ public TrustStrategy withVerifyIfPresentRevocationChecks() {
834879
* Configures the {@link TrustStrategy} to carry out strict OCSP revocation checks for revocation status that
835880
* are stapled to the certificate. If no stapled response is found, then the driver will fail certificate verification
836881
* and not connect to the server. This setting also requires the server to be configured to enable OCSP stapling.
837-
*
882+
* <p>
838883
* Note: enabling this setting will prevent the driver connecting to the server when the server is unable to reach
839884
* the certificate's configured OCSP responder URL.
885+
*
840886
* @return the current trust strategy
841887
*/
842888
public TrustStrategy withStrictRevocationChecks() {

0 commit comments

Comments
 (0)