Skip to content

Commit

Permalink
refactor: Address all Maven, Javac and JavaDoc warnings, and surpress…
Browse files Browse the repository at this point in the history
… banners where applicable.
  • Loading branch information
michael-simons committed Mar 7, 2024
1 parent 4926da2 commit 75e8834
Show file tree
Hide file tree
Showing 53 changed files with 304 additions and 99 deletions.
1 change: 1 addition & 0 deletions benchkit/src/main/resources/benchkit-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ paths:
summary: Executes the given workload.
description: |-
Drivers should load all the records to memory and then discard.
operationId: executeWorkload
responses:
'204':
description: Workload executed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
# To enable logging for the JDBC driver use standard Spring Boot facilities
# logging.level.org.neo4j.jdbc = TRACE
# logging.level.org.neo4j.it.mybatis = DEBUG

spring.main.banner-mode=off
7 changes: 7 additions & 0 deletions neo4j-jdbc-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@

import org.jdbi.v3.core.mapper.reflect.ColumnName;

/**
* A movie with a title.
*
* @param title a title
* @author Michael J. Simons
*/
public record Movie(@ColumnName("title") String title) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,28 @@
import jakarta.ws.rs.core.MediaType;
import org.jdbi.v3.core.Jdbi;

/**
* Produces a list of movies.
*
* @author Michael J. Simons
*/
@Path("/movies")
public class MovieResource {

private final Jdbi db;

/**
* Creates a new resource.
* @param db required for database access
*/
public MovieResource(Jdbi db) {
this.db = db;
}

/**
* Mapped as GET method.
* @return a list of movies, empty but never null
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Movie> get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@

quarkus.datasource.db-kind=other
quarkus.datasource.jdbc.driver=org.neo4j.jdbc.Neo4jDriver

quarkus.banner.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@

# To enable logging for the JDBC driver use standard Spring Boot facilities
# logging.level.org.neo4j.jdbc = TRACE

spring.main.banner-mode=off
4 changes: 4 additions & 0 deletions neo4j-jdbc/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* The Neo4j JDBC Driver exposes both the actual JDBC API and the Neo4j value system being used. The value system can be used with methods like {@link java.sql.ResultSet#getObject(int, Class)}, for retrieving Neo4j nodes, relationships, paths and especially, the original value objects.
*/
@SuppressWarnings({"requires-automatic"}) // Netty is an automatic module :(
module org.neo4j.jdbc {
requires transitive java.sql;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import org.neo4j.jdbc.internal.bolt.response.PullResponse;
import org.neo4j.jdbc.internal.bolt.response.ResultSummary;
import org.neo4j.jdbc.internal.bolt.response.RunResponse;
import org.neo4j.jdbc.internal.bolt.value.RecordImpl;
import org.neo4j.jdbc.values.Neo4jTypeToSqlTypeMapper;
import org.neo4j.jdbc.values.Record;
import org.neo4j.jdbc.values.Value;
import org.neo4j.jdbc.values.Values;
Expand Down Expand Up @@ -820,7 +818,7 @@ public ResultSet getSchemas() {
@Override
public List<Record> records() {
var values = new Value[] { Values.value("public"), Values.value("") };
return Collections.singletonList(new RecordImpl(keys, values));
return Collections.singletonList(Record.of(keys, values));
}

@Override
Expand Down Expand Up @@ -863,7 +861,7 @@ public ResultSet getTableTypes() {
@Override
public List<Record> records() {
var values = new Value[] { Values.value("TABLE") };
return Collections.singletonList(new RecordImpl(keys, values));
return Collections.singletonList(Record.of(keys, values));
}

@Override
Expand Down Expand Up @@ -975,7 +973,7 @@ public List<Record> records() {
var records = new ArrayList<Record>(rows.size());

for (Value[] values : rows) {
records.add(new RecordImpl(keys, values));
records.add(Record.of(keys, values));
}

return records;
Expand Down
5 changes: 5 additions & 0 deletions neo4j-jdbc/src/main/java/org/neo4j/jdbc/Neo4jDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public final class Neo4jDataSource implements Neo4jDataSourceExtensions {

private final Properties connectionProperties = new Properties();

/**
* Creates a new {@link DataSource} which is not yet usable without further
* configuration. This constructor is mainly used for tooling that loads data sources
* via reflection.
*/
public Neo4jDataSource() {
}

Expand Down
12 changes: 10 additions & 2 deletions neo4j-jdbc/src/main/java/org/neo4j/jdbc/Neo4jDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,13 @@ public static Optional<Connection> fromEnv(Path directory, String filename) thro
return new BuilderImpl(false, Map.of()).fromEnv(directory, filename);
}

/**
* Creates a new instance of the {@link Neo4jDriver}. The instance is usable and is
* able to provide connections. The public constructor is provided mainly for tooling
* that directly accesses vendor specific classes and circumvents the service loader
* machinery for JDBC.
*/
public Neo4jDriver() {
// Having a public default constructor is not only fine here, but also required on
// the module path so that this public class can be properly exported.
this(BoltConnectionProviders.netty(eventLoopGroup, Clock.systemUTC()));
}

Expand Down Expand Up @@ -762,6 +766,10 @@ Map<String, Object> rawConfig() {
}
}

/**
* Configuration step for creating new {@link Neo4jDriver driver instances} in a
* fluent way.
*/
public interface SpecifyEnvStep {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.jdbc.values;
package org.neo4j.jdbc;

import java.sql.Types;
import java.util.Locale;

public final class Neo4jTypeToSqlTypeMapper {
import org.neo4j.jdbc.values.Type;

final class Neo4jTypeToSqlTypeMapper {

private Neo4jTypeToSqlTypeMapper() {
}
Expand All @@ -30,16 +33,16 @@ private Neo4jTypeToSqlTypeMapper() {
* db.schema.nodeTypeProperties() procedure In 6 this will change so will need to add
* another method to handle the new types returned here when working with 6
*/
public static int toSqlTypeFromOldCypherType(String neo4jType) {
return toSqlType(Type.valueOfV5Name(neo4jType));
static int toSqlTypeFromOldCypherType(String neo4jType) {
return toSqlType(valueOfV5Name(neo4jType));
}

/*
* This is required because of a bug in 5 where java types are returned from the
* db.schema.nodeTypeProperties() procedure In 6 this will change so will need to add
* another method to handle the new types returned here when working with 6
*/
public static String oldCypherTypesToNew(String neo4jType) {
static String oldCypherTypesToNew(String neo4jType) {
return switch (neo4jType) {
// Simple
case "Boolean" -> "BOOLEAN";
Expand All @@ -66,7 +69,7 @@ public static String oldCypherTypesToNew(String neo4jType) {
};
}

public static int toSqlType(Type neo4jType) {
static int toSqlType(Type neo4jType) {
return switch (neo4jType) {
case ANY, DURATION -> Types.OTHER;
case BOOLEAN -> Types.BOOLEAN;
Expand All @@ -84,4 +87,17 @@ public static int toSqlType(Type neo4jType) {
};
}

static Type valueOfV5Name(String in) {

var value = in.replaceAll("([A-Z]+)([A-Z][a-z])", "$1_$2")
.replaceAll("([a-z])([A-Z])", "$1_$2")
.toUpperCase(Locale.ROOT);
value = switch (value) {
case "LONG" -> Type.INTEGER.name();
case "DOUBLE" -> Type.FLOAT.name();
default -> value.endsWith("ARRAY") ? Type.LIST.name() : value;
};
return Type.valueOf(value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.neo4j.jdbc.values.LocalDateTimeValue;
import org.neo4j.jdbc.values.LocalTimeValue;
import org.neo4j.jdbc.values.MapValue;
import org.neo4j.jdbc.values.Neo4jTypeToSqlTypeMapper;
import org.neo4j.jdbc.values.NodeValue;
import org.neo4j.jdbc.values.NullValue;
import org.neo4j.jdbc.values.PathValue;
Expand All @@ -47,7 +46,7 @@
import org.neo4j.jdbc.values.Type;
import org.neo4j.jdbc.values.Value;

public class ResultSetMetaDataImpl implements ResultSetMetaData {
final class ResultSetMetaDataImpl implements ResultSetMetaData {

private final List<String> keys;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.neo4j.jdbc.internal.bolt.response.PullResponse;
import org.neo4j.jdbc.internal.bolt.response.ResultSummary;
import org.neo4j.jdbc.internal.bolt.response.RunResponse;
import org.neo4j.jdbc.internal.bolt.value.RecordImpl;
import org.neo4j.jdbc.values.BooleanValue;
import org.neo4j.jdbc.values.Record;
import org.neo4j.jdbc.values.Value;
Expand Down Expand Up @@ -63,8 +62,7 @@ public void onFailure(Throwable error) {
@Override
public void onRecord(Value[] fields) {
var runResponse = this.runStage.toCompletableFuture().join();
var record = new RecordImpl(runResponse.keys(), fields);
this.records.add(record);
this.records.add(Record.of(runResponse.keys(), fields));
}

private record InternalPullResponse(List<Record> records, ResultSummary summary) implements PullResponse {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@
import java.util.Map;
import java.util.function.Function;

public abstract class AbstractMapAccessorWithDefaultValue implements MapAccessorWithDefaultValue {

public AbstractMapAccessorWithDefaultValue() {
}

public abstract Value get(String key);
abstract class AbstractMapAccessorWithDefaultValue implements MapAccessorWithDefaultValue {

@Override
public Value get(String key, Value defaultValue) {
Expand Down Expand Up @@ -267,10 +262,16 @@ private double get(Value value, double defaultValue) {
}
}

// formats map using ':' as key-value separator instead of default '='
protected static <V> String formatPairs(Map<String, V> entries) {
var iterator = entries.entrySet().iterator();
switch (entries.size()) {
/**
* Formats the content of a bolt map into a string reassembling the shape of a Cypher
* map, i.e. using {@code :} instead of {@code =} as the key-value separator.
* @param map the map to format
* @param <V> the type of the maps values.
* @return a string representation of the map
*/
protected static <V> String formatPairs(Map<String, V> map) {
var iterator = map.entrySet().iterator();
switch (map.size()) {
case 0 -> {
return "{}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
*/
package org.neo4j.jdbc.values;

public abstract class AbstractNumberValue<V extends Number> extends AbstractValue {

public AbstractNumberValue() {
}
abstract class AbstractNumberValue<V extends Number> extends AbstractValue {

@Override
public final V asObject() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

abstract class AbstractObjectValue<V> extends AbstractValue {

protected final V adapted;
final V adapted;

protected AbstractObjectValue(V adapted) {
if (adapted == null) {
Expand Down
6 changes: 6 additions & 0 deletions neo4j-jdbc/src/main/java/org/neo4j/jdbc/values/AsValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
*/
package org.neo4j.jdbc.values;

/**
* Represents an object that might be usable as a {@link Value}.
*
* @author Neo4j Drivers Team
* @since 6.0.0
*/
public interface AsValue {

/**
Expand Down
10 changes: 6 additions & 4 deletions neo4j-jdbc/src/main/java/org/neo4j/jdbc/values/BooleanValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

import java.util.Objects;

/**
* Representation of a boolean value inside the Neo4j type system.
*
* @author Neo4j Drivers Team
* @since 6.0.0
*/
public abstract sealed class BooleanValue extends AbstractValue {

private BooleanValue() {
Expand All @@ -36,10 +42,6 @@ private BooleanValue() {
*/
public static final BooleanValue FALSE = new FalseValue();

public static BooleanValue fromBoolean(boolean value) {
return value ? TRUE : FALSE;
}

@Override
public abstract Boolean asObject();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
import java.util.Arrays;
import java.util.HexFormat;

/**
* Representing a byte-array. Note that in Cypher byte arrays cannot be directly used.
* They are however natively storable in Neo4j.
*
* @author Neo4j Drivers Team
* @since 6.0.0
*/
public final class BytesValue extends AbstractValue {

private final byte[] val;
Expand Down
Loading

0 comments on commit 75e8834

Please sign in to comment.