Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions driver/src/main/java/org/neo4j/driver/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.io.Serial;
import java.io.Serializable;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -808,7 +807,7 @@ private TrustStrategy(Strategy strategy) {
private TrustStrategy(Strategy strategy, List<File> certFiles) {
Objects.requireNonNull(certFiles, "certFiles can't be null");
this.strategy = strategy;
this.certFiles = Collections.unmodifiableList(new ArrayList<>(certFiles));
this.certFiles = List.copyOf(certFiles);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,11 @@ protected static MetricsProvider getOrCreateMetricsProvider(Config config, Clock
if (metricsAdapter == null) {
metricsAdapter = config.isMetricsEnabled() ? MetricsAdapter.DEFAULT : MetricsAdapter.DEV_NULL;
}
switch (metricsAdapter) {
case DEV_NULL:
return DevNullMetricsProvider.INSTANCE;
case DEFAULT:
return new InternalMetricsProvider(clock, config.logging());
case MICROMETER:
return MicrometerMetricsProvider.forGlobalRegistry();
}
throw new IllegalStateException("Unknown or unsupported MetricsAdapter: " + metricsAdapter);
return switch (metricsAdapter) {
case DEV_NULL -> DevNullMetricsProvider.INSTANCE;
case DEFAULT -> new InternalMetricsProvider(clock, config.logging());
case MICROMETER -> MicrometerMetricsProvider.forGlobalRegistry();
};
}

protected ChannelConnector createConnector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import static java.time.temporal.ChronoUnit.MONTHS;
import static java.time.temporal.ChronoUnit.NANOS;
import static java.time.temporal.ChronoUnit.SECONDS;
import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;

import java.time.Duration;
import java.time.Period;
Expand All @@ -36,7 +34,7 @@

public class InternalIsoDuration implements IsoDuration {
private static final long NANOS_PER_SECOND = 1_000_000_000;
private static final List<TemporalUnit> SUPPORTED_UNITS = unmodifiableList(asList(MONTHS, DAYS, SECONDS, NANOS));
private static final List<TemporalUnit> SUPPORTED_UNITS = List.of(MONTHS, DAYS, SECONDS, NANOS);

private final long months;
private final long days;
Expand Down
34 changes: 1 addition & 33 deletions driver/src/main/java/org/neo4j/driver/internal/InternalPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,7 @@
* {@link Path} implementation that directly contains all nodes and relationships.
*/
public class InternalPath implements Path, AsValue {
public static class SelfContainedSegment implements Segment {
private final Node start;
private final Relationship relationship;
private final Node end;

public SelfContainedSegment(Node start, Relationship relationship, Node end) {
this.start = start;
this.relationship = relationship;
this.end = end;
}

@Override
public Node start() {
return start;
}

@Override
public Relationship relationship() {
return relationship;
}

@Override
public Node end() {
return end;
}
public record SelfContainedSegment(Node start, Relationship relationship, Node end) implements Segment {

@Override
public boolean equals(Object other) {
Expand All @@ -73,14 +49,6 @@ public boolean equals(Object other) {
return start.equals(that.start) && end.equals(that.end) && relationship.equals(that.relationship);
}

@Override
public int hashCode() {
var result = start.hashCode();
result = 31 * result + relationship.hashCode();
result = 31 * result + end.hashCode();
return result;
}

@Override
@SuppressWarnings("deprecation")
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,9 @@
*/
package org.neo4j.driver.internal;

import java.util.Objects;
import org.neo4j.driver.types.Point;

public class InternalPoint2D implements Point {
private final int srid;
private final double x;
private final double y;

public InternalPoint2D(int srid, double x, double y) {
this.srid = srid;
this.x = x;
this.y = y;
}

@Override
public int srid() {
return srid;
}

@Override
public double x() {
return x;
}

@Override
public double y() {
return y;
}
public record InternalPoint2D(int srid, double x, double y) implements Point {

@Override
public double z() {
Expand All @@ -64,11 +39,6 @@ public boolean equals(Object o) {
return srid == that.srid && Double.compare(that.x, x) == 0 && Double.compare(that.y, y) == 0;
}

@Override
public int hashCode() {
return Objects.hash(srid, x, y);
}

@Override
public String toString() {
return "Point{" + "srid=" + srid + ", x=" + x + ", y=" + y + '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,9 @@
*/
package org.neo4j.driver.internal;

import java.util.Objects;
import org.neo4j.driver.types.Point;

public class InternalPoint3D implements Point {
private final int srid;
private final double x;
private final double y;
private final double z;

public InternalPoint3D(int srid, double x, double y, double z) {
this.srid = srid;
this.x = x;
this.y = y;
this.z = z;
}

@Override
public int srid() {
return srid;
}

@Override
public double x() {
return x;
}

@Override
public double y() {
return y;
}

@Override
public double z() {
return z;
}
public record InternalPoint3D(int srid, double x, double y, double z) implements Point {

@Override
public boolean equals(Object o) {
Expand All @@ -69,11 +37,6 @@ public boolean equals(Object o) {
&& Double.compare(that.z, z) == 0;
}

@Override
public int hashCode() {
return Objects.hash(srid, x, y, z);
}

@Override
public String toString() {
return "Point{" + "srid=" + srid + ", x=" + x + ", y=" + y + ", z=" + z + '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ public String toString() {
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof Record) {
var otherRecord = (Record) other;
} else if (other instanceof Record otherRecord) {
var size = size();
if (!(size == otherRecord.size())) {
return false;
Expand Down
16 changes: 8 additions & 8 deletions driver/src/main/java/org/neo4j/driver/internal/Scheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public static void validateScheme(String scheme) {
throw new IllegalArgumentException("Scheme must not be null");
}
switch (scheme) {
case BOLT_URI_SCHEME:
case BOLT_LOW_TRUST_URI_SCHEME:
case BOLT_HIGH_TRUST_URI_SCHEME:
case NEO4J_URI_SCHEME:
case NEO4J_LOW_TRUST_URI_SCHEME:
case NEO4J_HIGH_TRUST_URI_SCHEME:
case BOLT_URI_SCHEME,
BOLT_LOW_TRUST_URI_SCHEME,
BOLT_HIGH_TRUST_URI_SCHEME,
NEO4J_URI_SCHEME,
NEO4J_LOW_TRUST_URI_SCHEME,
NEO4J_HIGH_TRUST_URI_SCHEME -> {
return;
default:
throw new IllegalArgumentException("Invalid address format " + scheme);
}
default -> throw new IllegalArgumentException("Invalid address format " + scheme);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,18 @@
import java.io.Serializable;
import org.neo4j.driver.Config;

public class SecuritySettings implements Serializable {
public record SecuritySettings(boolean encrypted, Config.TrustStrategy trustStrategy) implements Serializable {
private static final long serialVersionUID = 4494615367164106576L;

private static final boolean DEFAULT_ENCRYPTED = false;
private static final Config.TrustStrategy DEFAULT_TRUST_STRATEGY = Config.TrustStrategy.trustSystemCertificates();
public static final SecuritySettings DEFAULT = new SecuritySettings(DEFAULT_ENCRYPTED, DEFAULT_TRUST_STRATEGY);
private final boolean encrypted;
private final Config.TrustStrategy trustStrategy;

public SecuritySettings(boolean encrypted, Config.TrustStrategy trustStrategy) {
this.encrypted = encrypted;
this.trustStrategy = trustStrategy == null ? DEFAULT_TRUST_STRATEGY : trustStrategy;
}

public boolean encrypted() {
return encrypted;
}

public Config.TrustStrategy trustStrategy() {
return trustStrategy;
}

public static class SecuritySettingsBuilder {
private boolean isCustomized = false;
private boolean encrypted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ public class SessionFactoryImpl implements SessionFactory {
private final Logging logging;
private final boolean leakedSessionsLoggingEnabled;
private final long defaultFetchSize;
private final NotificationConfig driverNotificationConfig;

SessionFactoryImpl(ConnectionProvider connectionProvider, RetryLogic retryLogic, Config config) {
this.connectionProvider = connectionProvider;
this.leakedSessionsLoggingEnabled = config.logLeakedSessions();
this.retryLogic = retryLogic;
this.logging = config.logging();
this.defaultFetchSize = config.fetchSize();
this.driverNotificationConfig = config.notificationConfig();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public NettyDomainNameResolverGroup(DomainNameResolver domainNameResolver) {
}

@Override
protected AddressResolver<InetSocketAddress> newResolver(EventExecutor executor) throws Exception {
protected AddressResolver<InetSocketAddress> newResolver(EventExecutor executor) {
return new NettyDomainNameResolver(executor, domainNameResolver).asAddressResolver();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,23 @@

import java.util.concurrent.TimeUnit;

public class PoolSettings {
public record PoolSettings(
int maxConnectionPoolSize,
long connectionAcquisitionTimeout,
long maxConnectionLifetime,
long idleTimeBeforeConnectionTest) {
public static final int NOT_CONFIGURED = -1;

public static final int DEFAULT_MAX_CONNECTION_POOL_SIZE = 100;
public static final long DEFAULT_IDLE_TIME_BEFORE_CONNECTION_TEST = NOT_CONFIGURED;
public static final long DEFAULT_MAX_CONNECTION_LIFETIME = TimeUnit.HOURS.toMillis(1);
public static final long DEFAULT_CONNECTION_ACQUISITION_TIMEOUT = TimeUnit.SECONDS.toMillis(60);

private final int maxConnectionPoolSize;
private final long connectionAcquisitionTimeout;
private final long maxConnectionLifetime;
private final long idleTimeBeforeConnectionTest;

public PoolSettings(
int maxConnectionPoolSize,
long connectionAcquisitionTimeout,
long maxConnectionLifetime,
long idleTimeBeforeConnectionTest) {
this.maxConnectionPoolSize = maxConnectionPoolSize;
this.connectionAcquisitionTimeout = connectionAcquisitionTimeout;
this.maxConnectionLifetime = maxConnectionLifetime;
this.idleTimeBeforeConnectionTest = idleTimeBeforeConnectionTest;
}

public long idleTimeBeforeConnectionTest() {
return idleTimeBeforeConnectionTest;
}

public boolean idleTimeBeforeConnectionTestEnabled() {
return idleTimeBeforeConnectionTest >= 0;
}

public long maxConnectionLifetime() {
return maxConnectionLifetime;
}

public boolean maxConnectionLifetimeEnabled() {
return maxConnectionLifetime > 0;
}

public int maxConnectionPoolSize() {
return maxConnectionPoolSize;
}

public long connectionAcquisitionTimeout() {
return connectionAcquisitionTimeout;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,11 @@ private static long expirationTimestamp(long now, Record record) {
}

private Set<BoltServerAddress> servers(String role) {
switch (role) {
case "READ":
return readers;
case "WRITE":
return writers;
case "ROUTE":
return routers;
default:
throw new IllegalArgumentException("invalid server role: " + role);
}
return switch (role) {
case "READ" -> readers;
case "WRITE" -> writers;
case "ROUTE" -> routers;
default -> throw new IllegalArgumentException("invalid server role: " + role);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static Map<String, String> parseParameters(URI uri) {
}

var previousValue =
parameters.put(trimAndVerifyKey(keyValue[0], "key", uri), trimAndVerify(keyValue[1], "value", uri));
parameters.put(trimAndVerifyKey(keyValue[0], uri), trimAndVerify(keyValue[1], "value", uri));
if (previousValue != null) {
throw new IllegalArgumentException(
"Duplicated query parameters with key '" + previousValue + "' in URI '" + uri + "'");
Expand All @@ -95,8 +95,8 @@ private static Map<String, String> parseParameters(URI uri) {
return parameters;
}

private static String trimAndVerifyKey(String s, String key, URI uri) {
var trimmed = trimAndVerify(s, key, uri);
private static String trimAndVerifyKey(String s, URI uri) {
var trimmed = trimAndVerify(s, "key", uri);

if (trimmed.equals(ROUTING_ADDRESS_KEY)) {
throw new IllegalArgumentException("The key 'address' is reserved for routing context.");
Expand Down
Loading