Skip to content

Commit 6685698

Browse files
committed
Make Driver Level Queries API GA
This update removes the Preview status from the Driver Level Queries API, making it GA. A small adjustment has been made to the `RoutingControl` type, which is now a sealed interface with public constants. The names have been updated to `WRITE` and `READ`.
1 parent 7f76fa0 commit 6685698

File tree

18 files changed

+95
-42
lines changed

18 files changed

+95
-42
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ The `neo4j-java-driver-all` includes an explicit module declaration ([module-inf
7878
To run a simple query, the following can be used:
7979
```java
8080
var authToken = AuthTokens.basic("neo4j", "password");
81-
try (var driver = GraphDatabase.driver("bolt://localhost:7687", authToken); var session = driver.session()) {
82-
var result = session.run("CREATE (n)");
83-
var summary = result.consume();
84-
System.out.println(summary.counters().nodesCreated());
81+
try (var driver = GraphDatabase.driver("bolt://localhost:7687", authToken)) {
82+
var result = driver.executableQuery("CREATE (n)").execute();
83+
System.out.println(result.summary().counters().nodesCreated());
8584
}
8685
```
8786

bundle/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.neo4j.driver</groupId>
88
<artifactId>neo4j-java-driver-parent</artifactId>
9-
<version>5.7-SNAPSHOT</version>
9+
<version>5.8-SNAPSHOT</version>
1010
<relativePath>..</relativePath>
1111
</parent>
1212

driver/clirr-ignored-differences.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,4 +503,39 @@
503503
<method>org.neo4j.driver.BookmarkManager executableQueryBookmarkManager()</method>
504504
</difference>
505505

506+
<difference>
507+
<className>org/neo4j/driver/RoutingControl</className>
508+
<differenceType>6001</differenceType>
509+
<field>WRITERS</field>
510+
</difference>
511+
512+
<difference>
513+
<className>org/neo4j/driver/RoutingControl</className>
514+
<differenceType>6001</differenceType>
515+
<field>READERS</field>
516+
</difference>
517+
518+
<difference>
519+
<className>org/neo4j/driver/RoutingControl</className>
520+
<differenceType>2000</differenceType>
521+
</difference>
522+
523+
<difference>
524+
<className>org/neo4j/driver/RoutingControl</className>
525+
<differenceType>4001</differenceType>
526+
<to>java/lang/Comparable</to>
527+
</difference>
528+
529+
<difference>
530+
<className>org/neo4j/driver/RoutingControl</className>
531+
<differenceType>4001</differenceType>
532+
<to>java/lang/constant/Constable</to>
533+
</difference>
534+
535+
<difference>
536+
<className>org/neo4j/driver/RoutingControl</className>
537+
<differenceType>5001</differenceType>
538+
<to>java/lang/Enum</to>
539+
</difference>
540+
506541
</differences>

driver/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.neo4j.driver</groupId>
88
<artifactId>neo4j-java-driver-parent</artifactId>
9-
<version>5.7-SNAPSHOT</version>
9+
<version>5.8-SNAPSHOT</version>
1010
</parent>
1111

1212
<artifactId>neo4j-java-driver</artifactId>

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.neo4j.driver.reactive.RxSession;
2626
import org.neo4j.driver.types.TypeSystem;
2727
import org.neo4j.driver.util.Experimental;
28-
import org.neo4j.driver.util.Preview;
2928

3029
/**
3130
* Accessor for a specific Neo4j graph database.
@@ -72,7 +71,6 @@ public interface Driver extends AutoCloseable {
7271
* @return new executable query instance
7372
* @since 5.7
7473
*/
75-
@Preview(name = "Driver Level Queries")
7674
ExecutableQuery executableQuery(String query);
7775

7876
/**
@@ -81,7 +79,6 @@ public interface Driver extends AutoCloseable {
8179
* @return bookmark manager, must not be {@code null}
8280
* @since 5.7
8381
*/
84-
@Preview(name = "Driver Level Queries")
8582
BookmarkManager executableQueryBookmarkManager();
8683

8784
/**

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020

2121
import java.util.List;
2222
import org.neo4j.driver.summary.ResultSummary;
23-
import org.neo4j.driver.util.Preview;
2423

2524
/**
2625
* An in-memory result of executing a Cypher query that has been consumed in full.
2726
* @since 5.5
2827
*/
29-
@Preview(name = "Driver Level Queries")
3028
public interface EagerResult {
3129
/**
3230
* Returns the keys of the records this result contains.

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.stream.Collectors;
2727
import org.neo4j.driver.internal.EagerResultValue;
2828
import org.neo4j.driver.summary.ResultSummary;
29-
import org.neo4j.driver.util.Preview;
3029

3130
/**
3231
* An executable query that executes a query in a managed transaction with automatic retries on retryable errors.
@@ -96,7 +95,6 @@
9695
*
9796
* @since 5.7
9897
*/
99-
@Preview(name = "Driver Level Queries")
10098
public interface ExecutableQuery {
10199
/**
102100
* Sets query parameters.
@@ -166,7 +164,6 @@ default <T> T execute(Collector<Record, ?, T> recordCollector) {
166164
* @param <T> the final value type
167165
* @since 5.5
168166
*/
169-
@Preview(name = "Driver Level Queries")
170167
@FunctionalInterface
171168
interface ResultFinisher<S, T> {
172169
/**

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424
import java.io.Serializable;
2525
import java.util.Objects;
2626
import java.util.Optional;
27-
import org.neo4j.driver.util.Preview;
2827

2928
/**
3029
* Query configuration used by {@link Driver#executableQuery(String)} and its variants.
3130
* @since 5.5
3231
*/
33-
@Preview(name = "Driver Level Queries")
3432
public final class QueryConfig implements Serializable {
3533
@Serial
3634
private static final long serialVersionUID = -2632780731598141754L;
@@ -154,7 +152,7 @@ public String toString() {
154152
* Builder used to configure {@link QueryConfig} which will be used to execute a query.
155153
*/
156154
public static final class Builder {
157-
private RoutingControl routing = RoutingControl.WRITERS;
155+
private RoutingControl routing = RoutingControl.WRITE;
158156
private String database;
159157
private String impersonatedUser;
160158
private BookmarkManager bookmarkManager;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@
1818
*/
1919
package org.neo4j.driver;
2020

21-
import org.neo4j.driver.util.Preview;
21+
import java.io.Serializable;
22+
import org.neo4j.driver.internal.InternalRoutingControl;
2223

2324
/**
2425
* Defines routing mode for query.
25-
* @since 5.5
26+
* @since 5.8
2627
*/
27-
@Preview(name = "Driver Level Queries")
28-
public enum RoutingControl {
28+
public sealed interface RoutingControl extends Serializable permits InternalRoutingControl {
2929
/**
3030
* Routes to the leader of the cluster.
3131
*/
32-
WRITERS,
32+
RoutingControl WRITE = new InternalRoutingControl("WRITE");
3333
/**
3434
* Routes to the followers in the cluster.
3535
*/
36-
READERS
36+
RoutingControl READ = new InternalRoutingControl("READ");
3737
}

driver/src/main/java/org/neo4j/driver/internal/InternalExecutableQuery.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.neo4j.driver.Query;
2828
import org.neo4j.driver.QueryConfig;
2929
import org.neo4j.driver.Record;
30+
import org.neo4j.driver.RoutingControl;
3031
import org.neo4j.driver.SessionConfig;
3132
import org.neo4j.driver.TransactionCallback;
3233

@@ -77,10 +78,9 @@ public <A, R, T> T execute(Collector<Record, A, R> recordCollector, ResultFinish
7778
var summary = result.consume();
7879
return resultFinisher.finish(result.keys(), finishedValue, summary);
7980
};
80-
return switch (config.routing()) {
81-
case WRITERS -> session.executeWrite(txCallback);
82-
case READERS -> session.executeRead(txCallback);
83-
};
81+
return config.routing().equals(RoutingControl.READ)
82+
? session.executeRead(txCallback)
83+
: session.executeWrite(txCallback);
8484
}
8585
}
8686

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.neo4j.driver.internal;
20+
21+
import org.neo4j.driver.RoutingControl;
22+
23+
public record InternalRoutingControl(String mode) implements RoutingControl {}

driver/src/test/java/org/neo4j/driver/QueryConfigTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
import static org.junit.jupiter.api.Assertions.assertTrue;
2424
import static org.mockito.Mockito.mock;
2525

26+
import java.util.List;
2627
import org.junit.jupiter.api.Test;
2728
import org.junit.jupiter.params.ParameterizedTest;
28-
import org.junit.jupiter.params.provider.EnumSource;
29+
import org.junit.jupiter.params.provider.MethodSource;
2930
import org.mockito.Mockito;
3031
import org.neo4j.driver.summary.ResultSummary;
3132
import org.neo4j.driver.testutil.TestUtil;
@@ -36,14 +37,18 @@ void shouldReturnDefaultValues() {
3637
var config = QueryConfig.defaultConfig();
3738
var manager = Mockito.mock(BookmarkManager.class);
3839

39-
assertEquals(RoutingControl.WRITERS, config.routing());
40+
assertEquals(RoutingControl.WRITE, config.routing());
4041
assertTrue(config.database().isEmpty());
4142
assertTrue(config.impersonatedUser().isEmpty());
4243
assertEquals(manager, config.bookmarkManager(manager).get());
4344
}
4445

46+
static List<RoutingControl> routingControls() {
47+
return List.of(RoutingControl.READ, RoutingControl.WRITE);
48+
}
49+
4550
@ParameterizedTest
46-
@EnumSource(RoutingControl.class)
51+
@MethodSource("routingControls")
4752
void shouldUpdateRouting(RoutingControl routing) {
4853
var config = QueryConfig.builder().withRouting(routing).build();
4954
assertEquals(routing, config.routing());

driver/src/test/java/org/neo4j/driver/internal/InternalExecutableQueryTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import java.util.stream.Collector;
3535
import org.junit.jupiter.api.Test;
3636
import org.junit.jupiter.params.ParameterizedTest;
37-
import org.junit.jupiter.params.provider.EnumSource;
37+
import org.junit.jupiter.params.provider.MethodSource;
3838
import org.mockito.ArgumentCaptor;
3939
import org.neo4j.driver.BookmarkManager;
4040
import org.neo4j.driver.Driver;
@@ -114,8 +114,12 @@ void shouldUpdateConfig() {
114114
assertEquals(config, executableQuery.config());
115115
}
116116

117+
static List<RoutingControl> routingControls() {
118+
return List.of(RoutingControl.READ, RoutingControl.WRITE);
119+
}
120+
117121
@ParameterizedTest
118-
@EnumSource(RoutingControl.class)
122+
@MethodSource("routingControls")
119123
@SuppressWarnings("unchecked")
120124
void shouldExecuteAndReturnResult(RoutingControl routingControl) {
121125
// GIVEN
@@ -126,10 +130,7 @@ void shouldExecuteAndReturnResult(RoutingControl routingControl) {
126130
given(driver.session(any(SessionConfig.class))).willReturn(session);
127131
var txContext = mock(TransactionContext.class);
128132
BiFunction<Session, TransactionCallback<Object>, Object> executeMethod =
129-
switch (routingControl) {
130-
case WRITERS -> Session::executeWrite;
131-
case READERS -> Session::executeRead;
132-
};
133+
routingControl.equals(RoutingControl.READ) ? Session::executeRead : Session::executeWrite;
133134
given(executeMethod.apply(session, any())).willAnswer(answer -> {
134135
TransactionCallback<?> txCallback = answer.getArgument(0);
135136
return txCallback.execute(txContext);

examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.neo4j.driver</groupId>
88
<artifactId>neo4j-java-driver-parent</artifactId>
9-
<version>5.7-SNAPSHOT</version>
9+
<version>5.8-SNAPSHOT</version>
1010
</parent>
1111

1212
<groupId>org.neo4j.doc.driver</groupId>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.neo4j.driver</groupId>
77
<artifactId>neo4j-java-driver-parent</artifactId>
8-
<version>5.7-SNAPSHOT</version>
8+
<version>5.8-SNAPSHOT</version>
99

1010
<packaging>pom</packaging>
1111
<name>Neo4j Java Driver Project</name>

testkit-backend/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<artifactId>neo4j-java-driver-parent</artifactId>
99
<groupId>org.neo4j.driver</groupId>
10-
<version>5.7-SNAPSHOT</version>
10+
<version>5.8-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>testkit-backend</artifactId>

testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/ExecuteQuery.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public TestkitResponse process(TestkitState testkitState) {
4545
var routing = data.getConfig().getRouting();
4646
if (data.getConfig().getRouting() != null) {
4747
switch (routing) {
48-
case "w" -> configBuilder.withRouting(RoutingControl.WRITERS);
49-
case "r" -> configBuilder.withRouting(RoutingControl.READERS);
48+
case "w" -> configBuilder.withRouting(RoutingControl.WRITE);
49+
case "r" -> configBuilder.withRouting(RoutingControl.READ);
5050
default -> throw new IllegalArgumentException();
5151
}
5252
}

testkit-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.neo4j.driver</groupId>
88
<artifactId>neo4j-java-driver-parent</artifactId>
9-
<version>5.7-SNAPSHOT</version>
9+
<version>5.8-SNAPSHOT</version>
1010
<relativePath>..</relativePath>
1111
</parent>
1212

0 commit comments

Comments
 (0)