Skip to content

Commit e361c32

Browse files
committed
Refactoring
This update migrates the `RoutingSettings` to record, fixes code style, removes redundant declarations, simplifies assertions, etc.
1 parent 3f03a8e commit e361c32

File tree

53 files changed

+130
-148
lines changed

Some content is hidden

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

53 files changed

+130
-148
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* When running a transaction, a write transaction requires a server that supports writes.
2424
* A read transaction, on the other hand, requires a server that supports read operations.
2525
* This classification is key for routing driver to route transactions to a cluster correctly.
26-
*
26+
* <p>
2727
* While any {@link AccessMode} will be ignored while running transactions via a driver towards a single server.
2828
* As the single server serves both read and write operations at the same time.
2929
*/

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424

2525
/**
2626
* Causal chaining is carried out by passing bookmarks between transactions.
27-
*
27+
* <p>
2828
* When starting a session with initial bookmarks, the first transaction will be ensured to run at least after
2929
* the database is as up-to-date as the latest transaction referenced by the supplied bookmarks.
30-
*
30+
* <p>
3131
* Within a session, bookmark propagation is carried out automatically.
3232
* Thus all transactions in a session (both managed and unmanaged) are guaranteed to be carried out one after another.
33-
*
33+
* <p>
3434
* To opt out of this mechanism for unrelated units of work, applications can use multiple sessions.
3535
*/
3636
public interface Bookmark {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static BookmarkManagerConfigBuilder builder() {
5151
/**
5252
* Returns the map of bookmarks used to initialise the bookmark manager.
5353
*
54-
* @return the map of bookmarks
54+
* @return the set of bookmarks
5555
*/
5656
public Set<Bookmark> initialBookmarks() {
5757
return initialBookmarks;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public Query withParameters(Map<String, Object> newParameters) {
120120
/**
121121
* Create a new query with new parameters derived by updating this'
122122
* query's parameters using the given updates.
123-
*
123+
* <p>
124124
* Every update key that points to a null value will be removed from
125125
* the new query's parameters. All other entries will just replace
126126
* any existing parameter in the new query.

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929

3030
/**
3131
* The result of running a Cypher query, conceptually a stream of {@link Record records}.
32-
*
32+
* <p>
3333
* The standard way of navigating through the result returned by the database is to
3434
* {@link #next() iterate} over it.
35-
*
35+
* <p>
3636
* Results are valid until the next query is run or until the end of the current transaction,
3737
* whichever comes first. To keep a result around while further queries are run, or to use a result outside the scope
3838
* of the current transaction, see {@link #list()}.
@@ -42,11 +42,11 @@
4242
* In order to handle very large results, and to minimize memory overhead and maximize
4343
* performance, results are retrieved lazily. Please see {@link QueryRunner} for
4444
* important details on the effects of this.
45-
*
45+
* <p>
4646
* The short version is that, if you want a hard guarantee that the underlying query
4747
* has completed, you need to either call {@link Resource#close()} on the {@link Transaction}
4848
* or {@link Session} that created this result, or you need to use the result.
49-
*
49+
* <p>
5050
* Calling any method on this interface will guarantee that any write operation has completed on
5151
* the remote database.
5252
*
@@ -79,7 +79,7 @@ public interface Result extends Iterator<Record> {
7979
/**
8080
* Return the first record in the result, failing if there is not exactly
8181
* one record left in the stream
82-
*
82+
* <p>
8383
* Calling this method always exhausts the result, even when {@link NoSuchRecordException} is thrown.
8484
*
8585
* @return the first and only record in the stream
@@ -108,12 +108,12 @@ public interface Result extends Iterator<Record> {
108108
* Retrieve and store the entire result stream.
109109
* This can be used if you want to iterate over the stream multiple times or to store the
110110
* whole result for later use.
111-
*
111+
* <p>
112112
* Note that this method can only be used if you know that the query that
113113
* yielded this result returns a finite stream. Some queries can yield
114114
* infinite results, in which case calling this method will lead to running
115115
* out of memory.
116-
*
116+
* <p>
117117
* Calling this method exhausts the result.
118118
*
119119
* @return list of all remaining immutable records
@@ -124,12 +124,12 @@ public interface Result extends Iterator<Record> {
124124
* Retrieve and store a projection of the entire result.
125125
* This can be used if you want to iterate over the stream multiple times or to store the
126126
* whole result for later use.
127-
*
127+
* <p>
128128
* Note that this method can only be used if you know that the query that
129129
* yielded this result returns a finite stream. Some queries can yield
130130
* infinite results, in which case calling this method will lead to running
131131
* out of memory.
132-
*
132+
* <p>
133133
* Calling this method exhausts the result.
134134
*
135135
* @param mapFunction a function to map from Record to T. See {@link Records} for some predefined functions.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,12 @@ public Builder withDatabase(String database) {
332332
* Specify how many records to fetch in each batch for this session.
333333
* This config will overrides the default value set on {@link Config#fetchSize()}.
334334
* This config is only valid when the driver is used with servers that support Bolt V4 (Server version 4.0 and later).
335-
*
335+
* <p>
336336
* Bolt V4 enables pulling records in batches to allow client to take control of data population and apply back pressure to server.
337337
* This config specifies the default fetch size for all query runs using {@link Session} and {@link AsyncSession}.
338338
* By default, the value is set to {@code 1000}.
339339
* Use {@code -1} to disables back pressure and config client to pull all records at once after each run.
340-
*
340+
* <p>
341341
* This config only applies to run result obtained via {@link Session} and {@link AsyncSession}.
342342
* As with {@link RxSession}, the batch size is provided via {@link Subscription#request(long)} instead.
343343
* @param size the default record fetch size when pulling records in batches using Bolt V4.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public interface SimpleQueryRunner {
9595
*
9696
* Map<String, Object> parameters = new HashMap<String, Object>();
9797
* parameters.put("myNameParam", "Bob");
98-
*
98+
* <p>
9999
* Result result = session.run( "MATCH (n) WHERE n.name = $myNameParam RETURN (n)",
100100
* parameters );
101101
* }

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
/**
4848
* A unit of data that adheres to the Neo4j type system.
49-
*
49+
* <p>
5050
* This interface describes a number of <code>isType</code> methods along with
5151
* <code>typeValue</code> methods. The first set of these correlate with types from
5252
* the Neo4j Type System and are used to determine which Neo4j type is represented.
@@ -59,7 +59,7 @@
5959
* Because Neo4j often handles dynamic structures, this interface is designed to help
6060
* you handle such structures in Java. Specifically, {@link Value} lets you navigate arbitrary tree
6161
* structures without having to resort to type casting.
62-
*
62+
* <p>
6363
* Given a tree structure like:
6464
*
6565
* <pre>
@@ -74,15 +74,13 @@
7474
* </pre>
7575
*
7676
* You can retrieve the name of the second user, John, like so:
77-
*
7877
* <pre class="docTest:ValueDocIT#classDocTreeExample">
7978
* {@code
8079
* String username = value.get("users").get(1).get("name").asString();
8180
* }
8281
* </pre>
8382
*
8483
* You can also easily iterate over the users:
85-
*
8684
* <pre class="docTest:ValueDocIT#classDocIterationExample">
8785
* {@code
8886
* List<String> names = new LinkedList<>();
@@ -497,7 +495,7 @@ public interface Value extends MapAccessor, MapAccessorWithDefaultValue {
497495
/**
498496
* Return as a map of string keys and values converted using
499497
* {@link Value#asObject()}.
500-
*
498+
* <p>
501499
* This is equivalent to calling {@link #asMap(Function, Map)} with {@link Values#ofObject()}.
502500
*
503501
* @param defaultValue default to this value if the value is a {@link NullValue}

driver/src/main/java/org/neo4j/driver/exceptions/NoSuchRecordException.java

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

2424
/**
2525
* Thrown whenever a client expected to read a record that was not available (i.e. because it wasn't returned by the server).
26-
*
26+
* <p>
2727
* This usually indicates an expectation mismatch between client code and database application logic.
2828
*
2929
* @since 1.0

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public enum Type {
3535
UNSUPPORTED,
3636
PERFORMANCE,
3737
DEPRECATION,
38-
GENERIC;
38+
GENERIC
3939
}
4040

4141
public static Optional<NotificationCategory> valueOf(String value) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static <K, V> Pair<K, V> of(K key, V value) {
4646

4747
@Override
4848
public String toString() {
49-
return String.format("%s: %s", Objects.toString(key), Objects.toString(value));
49+
return String.format("%s: %s", key, value);
5050
}
5151

5252
@Override

driver/src/main/java/org/neo4j/driver/internal/async/pool/NettyChannelPool.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,9 @@ private CompletionStage<Channel> auth(Channel channel, AuthToken overrideAuthTok
190190
.enqueue(new LogonResponseHandler(logonFuture, channel, clock));
191191
authContext.initiateAuth(latestAuthToken);
192192
channel.write(new LogonMessage(((InternalAuthToken) latestAuthToken).toMap()));
193-
// do not await for re-login
194-
result = CompletableFuture.completedStage(channel);
195-
} else {
196-
result = CompletableFuture.completedStage(channel);
197193
}
194+
// do not await for re-login
195+
result = CompletableFuture.completedStage(channel);
198196
} else {
199197
var logonFuture = new CompletableFuture<Void>();
200198
messageDispatcher(channel).enqueue(new LogonResponseHandler(logonFuture, channel, clock));

driver/src/main/java/org/neo4j/driver/internal/cluster/RoutingSettings.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@
2020

2121
import static java.util.concurrent.TimeUnit.SECONDS;
2222

23-
public class RoutingSettings {
23+
public record RoutingSettings(long routingTablePurgeDelayMs, RoutingContext routingContext) {
2424
public static final long STALE_ROUTING_TABLE_PURGE_DELAY_MS = SECONDS.toMillis(30);
25-
26-
private final RoutingContext routingContext;
27-
private final long routingTablePurgeDelayMs;
28-
29-
public RoutingSettings(long routingTablePurgeDelayMs, RoutingContext routingContext) {
30-
this.routingContext = routingContext;
31-
this.routingTablePurgeDelayMs = routingTablePurgeDelayMs;
32-
}
33-
34-
public RoutingContext routingContext() {
35-
return routingContext;
36-
}
37-
38-
public long routingTablePurgeDelayMs() {
39-
return routingTablePurgeDelayMs;
40-
}
4125
}

driver/src/main/java/org/neo4j/driver/internal/messaging/ValueUnpacker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.neo4j.driver.Value;
2424

2525
public interface ValueUnpacker {
26+
@SuppressWarnings("UnusedReturnValue")
2627
long unpackStructHeader() throws IOException;
2728

2829
int unpackStructSignature() throws IOException;

driver/src/main/java/org/neo4j/driver/internal/messaging/common/CommonValuePacker.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ private void packPoint(Point point) throws IOException {
232232
} else if (point instanceof InternalPoint3D) {
233233
packPoint3D(point);
234234
} else {
235-
throw new IOException(
236-
String.format("Unknown type: type: %s, value: %s", point.getClass(), point.toString()));
235+
throw new IOException(String.format("Unknown type: type: %s, value: %s", point.getClass(), point));
237236
}
238237
}
239238

driver/src/main/java/org/neo4j/driver/internal/messaging/v43/BoltProtocolV43.java

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

2626
/**
2727
* Definition of the Bolt Protocol 4.3
28-
*
28+
* <p>
2929
* The version 4.3 use most of the 4.2 behaviours, but it extends it with new messages such as ROUTE
3030
*/
3131
public class BoltProtocolV43 extends BoltProtocolV42 {

driver/src/main/java/org/neo4j/driver/internal/messaging/v43/MessageWriterV43.java

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

4848
/**
4949
* Bolt message writer v4.3
50-
*
50+
* <p>
5151
* This version is able to encode all the versions existing on v4.2, but it encodes
5252
* new messages such as ROUTE
5353
*/

driver/src/main/java/org/neo4j/driver/internal/metrics/ConnectionPoolMetricsListener.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ interface ConnectionPoolMetricsListener {
4242
/**
4343
* Invoked before acquiring or creating a connection.
4444
*
45-
* @param acquireEvent
45+
* @param acquireEvent the event
4646
*/
4747
void beforeAcquiringOrCreating(ListenerEvent<?> acquireEvent);
4848

@@ -54,7 +54,7 @@ interface ConnectionPoolMetricsListener {
5454
/**
5555
* Invoked after a connection is acquired or created successfully.
5656
*
57-
* @param acquireEvent
57+
* @param acquireEvent the event
5858
*/
5959
void afterAcquiredOrCreated(ListenerEvent<?> acquireEvent);
6060

@@ -66,14 +66,14 @@ interface ConnectionPoolMetricsListener {
6666
/**
6767
* After a connection is acquired from the pool.
6868
*
69-
* @param inUseEvent
69+
* @param inUseEvent the event
7070
*/
7171
void acquired(ListenerEvent<?> inUseEvent);
7272

7373
/**
7474
* After a connection is released back to pool.
7575
*
76-
* @param inUseEvent
76+
* @param inUseEvent the event
7777
*/
7878
void released(ListenerEvent<?> inUseEvent);
7979
}

driver/src/main/java/org/neo4j/driver/internal/packstream/PackOutput.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,21 @@ public interface PackOutput {
2828
PackOutput writeByte(byte value) throws IOException;
2929

3030
/** Produce binary data */
31+
@SuppressWarnings("UnusedReturnValue")
3132
PackOutput writeBytes(byte[] data) throws IOException;
3233

3334
/** Produce a 4-byte signed integer */
3435
PackOutput writeShort(short value) throws IOException;
3536

3637
/** Produce a 4-byte signed integer */
38+
@SuppressWarnings("UnusedReturnValue")
3739
PackOutput writeInt(int value) throws IOException;
3840

3941
/** Produce an 8-byte signed integer */
42+
@SuppressWarnings("UnusedReturnValue")
4043
PackOutput writeLong(long value) throws IOException;
4144

4245
/** Produce an 8-byte IEEE 754 "double format" floating-point number */
46+
@SuppressWarnings("UnusedReturnValue")
4347
PackOutput writeDouble(double value) throws IOException;
4448
}

driver/src/main/java/org/neo4j/driver/internal/packstream/PackStream.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525
import java.io.IOException;
2626
import java.io.Serial;
2727
import java.nio.charset.Charset;
28+
import java.nio.charset.StandardCharsets;
2829
import java.util.List;
2930
import java.util.Map;
3031

3132
/**
3233
* PackStream is a messaging serialisation format heavily inspired by MessagePack.
3334
* The key differences are in the type system itself which (among other things) replaces extensions with structures.
3435
* The Packer and Unpacker implementations are also faster than their MessagePack counterparts.
35-
*
36+
* <p>
3637
* Note that several marker byte values are RESERVED for future use.
3738
* Extra markers should <em>not</em> be added casually and such additions must be follow a strict process involving both client and server software.
38-
*
39+
* <p>
3940
* The table below shows all allocated marker byte values.
4041
* <br>
4142
* <table>
@@ -204,7 +205,7 @@ public class PackStream {
204205

205206
private static final String EMPTY_STRING = "";
206207
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
207-
private static final Charset UTF_8 = Charset.forName("UTF-8");
208+
private static final Charset UTF_8 = StandardCharsets.UTF_8;
208209

209210
private PackStream() {}
210211

driver/src/main/java/org/neo4j/driver/internal/retry/ExponentialBackoffRetryLogic.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,10 @@ protected boolean canRetryOn(Throwable error) {
158158
/**
159159
* Extracts the possible cause of a transaction that has been marked terminated.
160160
*
161-
* @param error
162-
* @return
161+
* @param error the error
162+
* @return the possible cause or the original error
163163
*/
164164
private static Throwable extractPossibleTerminationCause(Throwable error) {
165-
166165
// Having a dedicated "TerminatedException" inheriting from ClientException might be a good idea.
167166
if (error instanceof ClientException && error.getCause() != null) {
168167
return error.getCause();

0 commit comments

Comments
 (0)