Skip to content

Refactoring #1467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion driver/src/main/java/org/neo4j/driver/AccessMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* When running a transaction, a write transaction requires a server that supports writes.
* A read transaction, on the other hand, requires a server that supports read operations.
* This classification is key for routing driver to route transactions to a cluster correctly.
*
* <p>
* While any {@link AccessMode} will be ignored while running transactions via a driver towards a single server.
* As the single server serves both read and write operations at the same time.
*/
Expand Down
6 changes: 3 additions & 3 deletions driver/src/main/java/org/neo4j/driver/Bookmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

/**
* Causal chaining is carried out by passing bookmarks between transactions.
*
* <p>
* When starting a session with initial bookmarks, the first transaction will be ensured to run at least after
* the database is as up-to-date as the latest transaction referenced by the supplied bookmarks.
*
* <p>
* Within a session, bookmark propagation is carried out automatically.
* Thus all transactions in a session (both managed and unmanaged) are guaranteed to be carried out one after another.
*
* <p>
* To opt out of this mechanism for unrelated units of work, applications can use multiple sessions.
*/
public interface Bookmark {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static BookmarkManagerConfigBuilder builder() {
/**
* Returns the map of bookmarks used to initialise the bookmark manager.
*
* @return the map of bookmarks
* @return the set of bookmarks
*/
public Set<Bookmark> initialBookmarks() {
return initialBookmarks;
Expand Down
2 changes: 1 addition & 1 deletion driver/src/main/java/org/neo4j/driver/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public Query withParameters(Map<String, Object> newParameters) {
/**
* Create a new query with new parameters derived by updating this'
* query's parameters using the given updates.
*
* <p>
* Every update key that points to a null value will be removed from
* the new query's parameters. All other entries will just replace
* any existing parameter in the new query.
Expand Down
18 changes: 9 additions & 9 deletions driver/src/main/java/org/neo4j/driver/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@

/**
* The result of running a Cypher query, conceptually a stream of {@link Record records}.
*
* <p>
* The standard way of navigating through the result returned by the database is to
* {@link #next() iterate} over it.
*
* <p>
* Results are valid until the next query is run or until the end of the current transaction,
* whichever comes first. To keep a result around while further queries are run, or to use a result outside the scope
* of the current transaction, see {@link #list()}.
Expand All @@ -42,11 +42,11 @@
* In order to handle very large results, and to minimize memory overhead and maximize
* performance, results are retrieved lazily. Please see {@link QueryRunner} for
* important details on the effects of this.
*
* <p>
* The short version is that, if you want a hard guarantee that the underlying query
* has completed, you need to either call {@link Resource#close()} on the {@link Transaction}
* or {@link Session} that created this result, or you need to use the result.
*
* <p>
* Calling any method on this interface will guarantee that any write operation has completed on
* the remote database.
*
Expand Down Expand Up @@ -79,7 +79,7 @@ public interface Result extends Iterator<Record> {
/**
* Return the first record in the result, failing if there is not exactly
* one record left in the stream
*
* <p>
* Calling this method always exhausts the result, even when {@link NoSuchRecordException} is thrown.
*
* @return the first and only record in the stream
Expand Down Expand Up @@ -108,12 +108,12 @@ public interface Result extends Iterator<Record> {
* Retrieve and store the entire result stream.
* This can be used if you want to iterate over the stream multiple times or to store the
* whole result for later use.
*
* <p>
* Note that this method can only be used if you know that the query that
* yielded this result returns a finite stream. Some queries can yield
* infinite results, in which case calling this method will lead to running
* out of memory.
*
* <p>
* Calling this method exhausts the result.
*
* @return list of all remaining immutable records
Expand All @@ -124,12 +124,12 @@ public interface Result extends Iterator<Record> {
* Retrieve and store a projection of the entire result.
* This can be used if you want to iterate over the stream multiple times or to store the
* whole result for later use.
*
* <p>
* Note that this method can only be used if you know that the query that
* yielded this result returns a finite stream. Some queries can yield
* infinite results, in which case calling this method will lead to running
* out of memory.
*
* <p>
* Calling this method exhausts the result.
*
* @param mapFunction a function to map from Record to T. See {@link Records} for some predefined functions.
Expand Down
4 changes: 2 additions & 2 deletions driver/src/main/java/org/neo4j/driver/SessionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ public Builder withDatabase(String database) {
* Specify how many records to fetch in each batch for this session.
* This config will overrides the default value set on {@link Config#fetchSize()}.
* This config is only valid when the driver is used with servers that support Bolt V4 (Server version 4.0 and later).
*
* <p>
* Bolt V4 enables pulling records in batches to allow client to take control of data population and apply back pressure to server.
* This config specifies the default fetch size for all query runs using {@link Session} and {@link AsyncSession}.
* By default, the value is set to {@code 1000}.
* Use {@code -1} to disables back pressure and config client to pull all records at once after each run.
*
* <p>
* This config only applies to run result obtained via {@link Session} and {@link AsyncSession}.
* As with {@link RxSession}, the batch size is provided via {@link Subscription#request(long)} instead.
* @param size the default record fetch size when pulling records in batches using Bolt V4.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public interface SimpleQueryRunner {
*
* Map<String, Object> parameters = new HashMap<String, Object>();
* parameters.put("myNameParam", "Bob");
*
* <p>
* Result result = session.run( "MATCH (n) WHERE n.name = $myNameParam RETURN (n)",
* parameters );
* }
Expand Down
8 changes: 3 additions & 5 deletions driver/src/main/java/org/neo4j/driver/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

/**
* A unit of data that adheres to the Neo4j type system.
*
* <p>
* This interface describes a number of <code>isType</code> methods along with
* <code>typeValue</code> methods. The first set of these correlate with types from
* the Neo4j Type System and are used to determine which Neo4j type is represented.
Expand All @@ -59,7 +59,7 @@
* Because Neo4j often handles dynamic structures, this interface is designed to help
* you handle such structures in Java. Specifically, {@link Value} lets you navigate arbitrary tree
* structures without having to resort to type casting.
*
* <p>
* Given a tree structure like:
*
* <pre>
Expand All @@ -74,15 +74,13 @@
* </pre>
*
* You can retrieve the name of the second user, John, like so:
*
* <pre class="docTest:ValueDocIT#classDocTreeExample">
* {@code
* String username = value.get("users").get(1).get("name").asString();
* }
* </pre>
*
* You can also easily iterate over the users:
*
* <pre class="docTest:ValueDocIT#classDocIterationExample">
* {@code
* List<String> names = new LinkedList<>();
Expand Down Expand Up @@ -497,7 +495,7 @@ public interface Value extends MapAccessor, MapAccessorWithDefaultValue {
/**
* Return as a map of string keys and values converted using
* {@link Value#asObject()}.
*
* <p>
* This is equivalent to calling {@link #asMap(Function, Map)} with {@link Values#ofObject()}.
*
* @param defaultValue default to this value if the value is a {@link NullValue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/**
* Thrown whenever a client expected to read a record that was not available (i.e. because it wasn't returned by the server).
*
* <p>
* This usually indicates an expectation mismatch between client code and database application logic.
*
* @since 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,9 @@ private CompletionStage<Channel> auth(Channel channel, AuthToken overrideAuthTok
.enqueue(new LogonResponseHandler(logonFuture, channel, clock));
authContext.initiateAuth(latestAuthToken);
channel.write(new LogonMessage(((InternalAuthToken) latestAuthToken).toMap()));
// do not await for re-login
result = CompletableFuture.completedStage(channel);
} else {
result = CompletableFuture.completedStage(channel);
}
// do not await for re-login
result = CompletableFuture.completedStage(channel);
} else {
var logonFuture = new CompletableFuture<Void>();
messageDispatcher(channel).enqueue(new LogonResponseHandler(logonFuture, channel, clock));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.neo4j.driver.Value;

public interface ValueUnpacker {
@SuppressWarnings("UnusedReturnValue")
long unpackStructHeader() throws IOException;

int unpackStructSignature() throws IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/**
* Definition of the Bolt Protocol 4.3
*
* <p>
* The version 4.3 use most of the 4.2 behaviours, but it extends it with new messages such as ROUTE
*/
public class BoltProtocolV43 extends BoltProtocolV42 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

/**
* Bolt message writer v4.3
*
* <p>
* This version is able to encode all the versions existing on v4.2, but it encodes
* new messages such as ROUTE
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface ConnectionPoolMetricsListener {
/**
* Invoked before acquiring or creating a connection.
*
* @param acquireEvent
* @param acquireEvent the event
*/
void beforeAcquiringOrCreating(ListenerEvent<?> acquireEvent);

Expand All @@ -54,7 +54,7 @@ interface ConnectionPoolMetricsListener {
/**
* Invoked after a connection is acquired or created successfully.
*
* @param acquireEvent
* @param acquireEvent the event
*/
void afterAcquiredOrCreated(ListenerEvent<?> acquireEvent);

Expand All @@ -66,14 +66,14 @@ interface ConnectionPoolMetricsListener {
/**
* After a connection is acquired from the pool.
*
* @param inUseEvent
* @param inUseEvent the event
*/
void acquired(ListenerEvent<?> inUseEvent);

/**
* After a connection is released back to pool.
*
* @param inUseEvent
* @param inUseEvent the event
*/
void released(ListenerEvent<?> inUseEvent);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ public interface PackOutput {
PackOutput writeByte(byte value) throws IOException;

/** Produce binary data */
@SuppressWarnings("UnusedReturnValue")
PackOutput writeBytes(byte[] data) throws IOException;

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

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

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

/** Produce an 8-byte IEEE 754 "double format" floating-point number */
@SuppressWarnings("UnusedReturnValue")
PackOutput writeDouble(double value) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
* PackStream is a messaging serialisation format heavily inspired by MessagePack.
* The key differences are in the type system itself which (among other things) replaces extensions with structures.
* The Packer and Unpacker implementations are also faster than their MessagePack counterparts.
*
* <p>
* Note that several marker byte values are RESERVED for future use.
* Extra markers should <em>not</em> be added casually and such additions must be follow a strict process involving both client and server software.
*
* <p>
* The table below shows all allocated marker byte values.
* <br>
* <table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,10 @@ protected boolean canRetryOn(Throwable error) {
/**
* Extracts the possible cause of a transaction that has been marked terminated.
*
* @param error
* @return
* @param error the error
* @return the possible cause or the original error
*/
private static Throwable extractPossibleTerminationCause(Throwable error) {

// Having a dedicated "TerminatedException" inheriting from ClientException might be a good idea.
if (error instanceof ClientException && error.getCause() != null) {
return error.getCause();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ public final class CertificateTool {
/**
* Save a certificate to a file. Remove all the content in the file if there is any before.
*
* @param cert
* @param certFile
* @throws GeneralSecurityException
* @throws IOException
* @param cert the certificate
* @param certFile the certificate file
*/
public static void saveX509Cert(Certificate cert, File certFile) throws GeneralSecurityException, IOException {
saveX509Cert(new Certificate[] {cert}, certFile);
Expand All @@ -56,10 +54,8 @@ public static void saveX509Cert(Certificate cert, File certFile) throws GeneralS
/**
* Save a list of certificates into a file
*
* @param certs
* @param certFile
* @throws GeneralSecurityException
* @throws IOException
* @param certs the certificates
* @param certFile the certificate file
*/
public static void saveX509Cert(Certificate[] certs, File certFile) throws GeneralSecurityException, IOException {
try (var writer = new BufferedWriter(new FileWriter(certFile))) {
Expand All @@ -82,10 +78,8 @@ public static void saveX509Cert(Certificate[] certs, File certFile) throws Gener
/**
* Load the certificates written in X.509 format in a file to a key store.
*
* @param certFiles
* @param keyStore
* @throws GeneralSecurityException
* @throws IOException
* @param certFiles the certificate files
* @param keyStore the key store
*/
public static void loadX509Cert(List<File> certFiles, KeyStore keyStore)
throws GeneralSecurityException, IOException {
Expand Down Expand Up @@ -126,8 +120,8 @@ public static void loadX509Cert(X509Certificate[] certificates, KeyStore keyStor
* Load a certificate to a key store with a name
*
* @param certAlias a name to identify different certificates
* @param cert
* @param keyStore
* @param cert the certificate
* @param keyStore the key store
*/
public static void loadX509Cert(Certificate cert, String certAlias, KeyStore keyStore) throws KeyStoreException {
keyStore.setCertificateEntry(certAlias, cert);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ public static boolean isFatal(Throwable error) {
return true;
}

if (isClientOrTransientError(((Neo4jException) error))) {
return false;
}
return !isClientOrTransientError(((Neo4jException) error));
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ public static <T> CompletableFuture<T> completedWithNull() {
return (CompletableFuture<T>) COMPLETED_WITH_NULL;
}

public static <T> CompletableFuture<T> completeWithNullIfNoError(CompletableFuture<T> future, Throwable error) {
public static <T> void completeWithNullIfNoError(CompletableFuture<T> future, Throwable error) {
if (error != null) {
future.completeExceptionally(error);
} else {
future.complete(null);
}
return future;
}

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