Skip to content

Commit aee893b

Browse files
authored
Refactoring (#1467)
1 parent 20e7ce5 commit aee893b

Some content is hidden

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

45 files changed

+106
-97
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/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/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/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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
* PackStream is a messaging serialisation format heavily inspired by MessagePack.
3434
* The key differences are in the type system itself which (among other things) replaces extensions with structures.
3535
* The Packer and Unpacker implementations are also faster than their MessagePack counterparts.
36-
*
36+
* <p>
3737
* Note that several marker byte values are RESERVED for future use.
3838
* Extra markers should <em>not</em> be added casually and such additions must be follow a strict process involving both client and server software.
39-
*
39+
* <p>
4040
* The table below shows all allocated marker byte values.
4141
* <br>
4242
* <table>

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();

driver/src/main/java/org/neo4j/driver/internal/util/CertificateTool.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ public final class CertificateTool {
4444
/**
4545
* Save a certificate to a file. Remove all the content in the file if there is any before.
4646
*
47-
* @param cert
48-
* @param certFile
49-
* @throws GeneralSecurityException
50-
* @throws IOException
47+
* @param cert the certificate
48+
* @param certFile the certificate file
5149
*/
5250
public static void saveX509Cert(Certificate cert, File certFile) throws GeneralSecurityException, IOException {
5351
saveX509Cert(new Certificate[] {cert}, certFile);
@@ -56,10 +54,8 @@ public static void saveX509Cert(Certificate cert, File certFile) throws GeneralS
5654
/**
5755
* Save a list of certificates into a file
5856
*
59-
* @param certs
60-
* @param certFile
61-
* @throws GeneralSecurityException
62-
* @throws IOException
57+
* @param certs the certificates
58+
* @param certFile the certificate file
6359
*/
6460
public static void saveX509Cert(Certificate[] certs, File certFile) throws GeneralSecurityException, IOException {
6561
try (var writer = new BufferedWriter(new FileWriter(certFile))) {
@@ -82,10 +78,8 @@ public static void saveX509Cert(Certificate[] certs, File certFile) throws Gener
8278
/**
8379
* Load the certificates written in X.509 format in a file to a key store.
8480
*
85-
* @param certFiles
86-
* @param keyStore
87-
* @throws GeneralSecurityException
88-
* @throws IOException
81+
* @param certFiles the certificate files
82+
* @param keyStore the key store
8983
*/
9084
public static void loadX509Cert(List<File> certFiles, KeyStore keyStore)
9185
throws GeneralSecurityException, IOException {
@@ -126,8 +120,8 @@ public static void loadX509Cert(X509Certificate[] certificates, KeyStore keyStor
126120
* Load a certificate to a key store with a name
127121
*
128122
* @param certAlias a name to identify different certificates
129-
* @param cert
130-
* @param keyStore
123+
* @param cert the certificate
124+
* @param keyStore the key store
131125
*/
132126
public static void loadX509Cert(Certificate cert, String certAlias, KeyStore keyStore) throws KeyStoreException {
133127
keyStore.setCertificateEntry(certAlias, cert);

driver/src/main/java/org/neo4j/driver/internal/util/ErrorUtil.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ public static boolean isFatal(Throwable error) {
102102
return true;
103103
}
104104

105-
if (isClientOrTransientError(((Neo4jException) error))) {
106-
return false;
107-
}
105+
return !isClientOrTransientError(((Neo4jException) error));
108106
}
109107
return true;
110108
}

driver/src/main/java/org/neo4j/driver/internal/util/Futures.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ public static <T> CompletableFuture<T> completedWithNull() {
4343
return (CompletableFuture<T>) COMPLETED_WITH_NULL;
4444
}
4545

46-
public static <T> CompletableFuture<T> completeWithNullIfNoError(CompletableFuture<T> future, Throwable error) {
46+
public static <T> void completeWithNullIfNoError(CompletableFuture<T> future, Throwable error) {
4747
if (error != null) {
4848
future.completeExceptionally(error);
4949
} else {
5050
future.complete(null);
5151
}
52-
return future;
5352
}
5453

5554
public static <T> CompletionStage<T> asCompletionStage(io.netty.util.concurrent.Future<T> future) {

0 commit comments

Comments
 (0)