Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #179 from pontusmelke/4.0-update-driver
Browse files Browse the repository at this point in the history
Update driver version 4.0
  • Loading branch information
henriknyman authored Nov 29, 2019
2 parents 6e2583a + 722f0c1 commit 174e8cf
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 123 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ext {
argparse4jVersion = '0.7.0'
junitVersion = '4.12'
evaluatorVersion = '3.5.4'
neo4jJavaDriverVersion = '4.0.0-beta03'
neo4jJavaDriverVersion = '4.0.0-rc1'
findbugsVersion = '3.0.0'
jansiVersion = '1.13'
jlineVersion = '2.14.6'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package org.neo4j.shell.prettyprint;

import org.neo4j.driver.internal.types.TypeRepresentation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;

import org.neo4j.driver.Value;
import org.neo4j.driver.Values;
import org.neo4j.driver.internal.types.TypeRepresentation;
import org.neo4j.driver.summary.Plan;
import org.neo4j.driver.summary.ProfiledPlan;
import org.neo4j.driver.summary.ResultSummary;
Expand All @@ -12,10 +21,6 @@
import org.neo4j.driver.types.Relationship;
import org.neo4j.shell.state.BoltResult;

import javax.annotation.Nonnull;
import java.util.*;
import java.util.stream.Collectors;

import static java.util.Arrays.asList;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.neo4j.shell.prettyprint.CypherVariablesFormatter.escape;
Expand Down Expand Up @@ -197,7 +202,7 @@ static Map<String, Value> info(@Nonnull ResultSummary summary) {

Plan plan = summary.plan();
result.put("Plan", Values.value(summary.hasProfile() ? "PROFILE" : "EXPLAIN"));
result.put("Statement", Values.value(summary.statementType().name()));
result.put("Statement", Values.value(summary.queryType().name()));
Map<String, Value> arguments = plan.arguments();
Value defaultValue = Values.value("");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,21 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.neo4j.driver.*;
import org.neo4j.driver.AccessMode;
import org.neo4j.driver.AuthToken;
import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Bookmark;
import org.neo4j.driver.Config;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
import org.neo4j.driver.Query;
import org.neo4j.driver.Record;
import org.neo4j.driver.Result;
import org.neo4j.driver.Session;
import org.neo4j.driver.SessionConfig;
import org.neo4j.driver.Transaction;
import org.neo4j.driver.Value;
import org.neo4j.driver.Values;
import org.neo4j.driver.exceptions.ClientException;
import org.neo4j.driver.exceptions.SessionExpiredException;
import org.neo4j.driver.summary.DatabaseInfo;
Expand All @@ -32,7 +46,7 @@ public class BoltStateHandler implements TransactionHandler, Connector, Database
protected Driver driver;
Session session;
private String version;
private List<Statement> transactionStatements;
private List<Query> transactionStatements;
private String activeDatabaseNameAsSetByUser;
private String actualDatabaseNameAsReportedByServer;
private final boolean isInteractive;
Expand Down Expand Up @@ -182,7 +196,7 @@ private void reconnect(boolean keepBookmark) {
String query = activeDatabaseNameAsSetByUser.compareToIgnoreCase(SYSTEM_DB_NAME) == 0 ? "SHOW DEFAULT DATABASE" : "RETURN 1";

resetActualDbName(); // Set this to null first in case run throws an exception
StatementResult run = session.run(query);
Result run = session.run(query);
ResultSummary summary = null;
try {
summary = run.consume();
Expand Down Expand Up @@ -220,7 +234,7 @@ public Optional<BoltResult> runCypher(@Nonnull String cypher,
throw new CommandException("Not connected to Neo4j");
}
if (this.transactionStatements != null) {
transactionStatements.add(new Statement(cypher, queryParams));
transactionStatements.add(new Query(cypher, queryParams));
return Optional.empty();
} else {
try {
Expand Down Expand Up @@ -272,7 +286,7 @@ public void changePassword(@Nonnull ConnectionConfig connectionConfig) {
parameters = Values.parameters("n", connectionConfig.newPassword());
}

StatementResult run = session.run(command, parameters);
Result run = session.run(command, parameters);
run.consume();

// If successful, use the new password when reconnecting
Expand All @@ -298,7 +312,7 @@ public void changePassword(@Nonnull ConnectionConfig connectionConfig) {
*/
@Nonnull
private Optional<BoltResult> getBoltResult(@Nonnull String cypher, @Nonnull Map<String, Object> queryParams) throws SessionExpiredException {
StatementResult statementResult = session.run(new Statement(cypher, queryParams));
Result statementResult = session.run(new Query(cypher, queryParams));

if (statementResult == null) {
return Optional.empty();
Expand Down Expand Up @@ -358,7 +372,7 @@ public void disconnect() {
silentDisconnect();
}

List<Statement> getTransactionStatements() {
List<Query> getTransactionStatements() {
return this.transactionStatements;
}

Expand All @@ -376,10 +390,10 @@ private Driver getDriver(@Nonnull ConnectionConfig connectionConfig, @Nullable A
return driverProvider.apply(connectionConfig.driverUrl(), authToken, configBuilder.build());
}

private Optional<List<BoltResult>> captureResults(@Nonnull List<Statement> transactionStatements) {
private Optional<List<BoltResult>> captureResults(@Nonnull List<Query> transactionStatements) {
List<BoltResult> results = executeWithRetry(transactionStatements, (statement, transaction) -> {
// calling list() is what actually executes cypher on the server
StatementResult sr = transaction.run(statement);
Result sr = transaction.run(statement);
List<Record> list = sr.list();
List<String> keys = sr.keys();
ResultSummary summary = sr.consume();
Expand All @@ -395,7 +409,7 @@ private Optional<List<BoltResult>> captureResults(@Nonnull List<Statement> trans
return Optional.of(results);
}

private List<BoltResult> executeWithRetry(List<Statement> transactionStatements, BiFunction<Statement, Transaction, BoltResult> biFunction) {
private List<BoltResult> executeWithRetry(List<Query> transactionStatements, BiFunction<Query, Transaction, BoltResult> biFunction) {
return session.writeTransaction(tx ->
transactionStatements.stream()
.map(transactionStatement -> biFunction.apply(transactionStatement, tx))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package org.neo4j.shell.state;

import org.neo4j.driver.Record;
import org.neo4j.driver.StatementResult;
import org.neo4j.driver.summary.ResultSummary;

import javax.annotation.Nonnull;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Nonnull;

import org.neo4j.driver.Record;
import org.neo4j.driver.Result;
import org.neo4j.driver.summary.ResultSummary;

/**
* Wrapper around {@link StatementResult}. Might or might not be materialized.
* Wrapper around {@link Result}. Might or might not be materialized.
*/
public class StatementBoltResult implements BoltResult {

private final StatementResult result;
private final Result result;

public StatementBoltResult(StatementResult result) {
public StatementBoltResult(Result result) {
this.result = result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import java.util.HashMap;
import java.util.Map;

import org.neo4j.driver.Query;
import org.neo4j.driver.Value;
import org.neo4j.driver.Values;
import org.neo4j.driver.internal.BoltServerAddress;
import org.neo4j.driver.internal.summary.InternalDatabaseInfo;
import org.neo4j.driver.internal.summary.InternalResultSummary;
import org.neo4j.driver.internal.summary.InternalServerInfo;
import org.neo4j.driver.internal.util.ServerVersion;
import org.neo4j.driver.internal.value.ListValue;
import org.neo4j.driver.internal.value.MapValue;
import org.neo4j.driver.Statement;
import org.neo4j.driver.Value;
import org.neo4j.driver.Values;
import org.neo4j.driver.summary.ProfiledPlan;
import org.neo4j.driver.summary.QueryType;
import org.neo4j.driver.summary.ResultSummary;
import org.neo4j.driver.summary.StatementType;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -34,10 +34,10 @@ public void shouldReportTotalDBHits() {

ProfiledPlan plan = PROFILED_PLAN_FROM_VALUE.apply( planMap );
ResultSummary summary = new InternalResultSummary(
new Statement( "PROFILE MATCH (n:LABEL) WHERE 20 < n.age < 35 return n" ),
new Query( "PROFILE MATCH (n:LABEL) WHERE 20 < n.age < 35 return n" ),
new InternalServerInfo( new BoltServerAddress( "localhost:7687" ), ServerVersion.vInDev ),
new InternalDatabaseInfo("neo4j"),
StatementType.READ_ONLY,
QueryType.READ_ONLY,
null,
plan,
plan,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

import org.junit.Test;

import org.neo4j.driver.internal.types.InternalTypeSystem;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;

import org.neo4j.driver.Record;
import org.neo4j.driver.Value;
import org.neo4j.driver.Values;
import org.neo4j.driver.internal.types.InternalTypeSystem;
import org.neo4j.driver.summary.ProfiledPlan;
import org.neo4j.driver.summary.QueryType;
import org.neo4j.driver.summary.ResultSummary;
import org.neo4j.driver.summary.StatementType;
import org.neo4j.driver.summary.SummaryCounters;
import org.neo4j.driver.types.Node;
import org.neo4j.driver.types.Path;
Expand All @@ -17,12 +23,6 @@
import org.neo4j.shell.state.BoltResult;
import org.neo4j.shell.state.ListBoltResult;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static java.util.Collections.unmodifiableMap;
Expand Down Expand Up @@ -73,7 +73,7 @@ public void prettyPrintProfileInformation() {
when(resultSummary.profile()).thenReturn(plan);
when(resultSummary.resultAvailableAfter(anyObject())).thenReturn(5L);
when(resultSummary.resultConsumedAfter(anyObject())).thenReturn(7L);
when(resultSummary.statementType()).thenReturn(StatementType.READ_ONLY);
when(resultSummary.queryType()).thenReturn(QueryType.READ_ONLY);
Map<String, Value> argumentMap = Values.parameters("Version", "3.1", "Planner", "COST", "Runtime", "INTERPRETED").asMap(v -> v);
when(plan.arguments()).thenReturn(argumentMap);

Expand Down Expand Up @@ -108,7 +108,7 @@ public void prettyPrintExplainInformation() {
when(resultSummary.plan()).thenReturn(plan);
when(resultSummary.resultAvailableAfter(anyObject())).thenReturn(5L);
when(resultSummary.resultConsumedAfter(anyObject())).thenReturn(7L);
when(resultSummary.statementType()).thenReturn(StatementType.READ_ONLY);
when(resultSummary.queryType()).thenReturn(QueryType.READ_ONLY);
Map<String, Value> argumentMap = Values.parameters("Version", "3.1", "Planner", "COST", "Runtime", "INTERPRETED").asMap(v -> v);
when(plan.arguments()).thenReturn(argumentMap);

Expand Down
Loading

0 comments on commit 174e8cf

Please sign in to comment.