use of org.neo4j.driver.Value in project neo4j by neo4j.
the class BoltStateHandler method changePassword.
public void changePassword(@Nonnull ConnectionConfig connectionConfig) {
if (!connectionConfig.passwordChangeRequired()) {
return;
}
if (isConnected()) {
silentDisconnect();
}
final AuthToken authToken = AuthTokens.basic(connectionConfig.username(), connectionConfig.password());
try {
driver = getDriver(connectionConfig, authToken);
activeDatabaseNameAsSetByUser = SYSTEM_DB_NAME;
// Supply empty command, so that we do not run ping.
reconnect(SYSTEM_DB_NAME, SYSTEM_DB_NAME, () -> {
});
try {
String command = "ALTER CURRENT USER SET PASSWORD FROM $o TO $n";
Value parameters = Values.parameters("o", connectionConfig.password(), "n", connectionConfig.newPassword());
Result run = session.run(command, parameters);
run.consume();
} catch (Neo4jException e) {
if (isPasswordChangeRequiredException(e)) {
// In < 4.0 versions use legacy method.
String oldCommand = "CALL dbms.security.changePassword($n)";
Value oldParameters = Values.parameters("n", connectionConfig.newPassword());
Result run = session.run(oldCommand, oldParameters);
run.consume();
} else {
throw e;
}
}
// If successful, use the new password when reconnecting
connectionConfig.setPassword(connectionConfig.newPassword());
connectionConfig.setNewPassword(null);
silentDisconnect();
} catch (Throwable t) {
try {
silentDisconnect();
} catch (Exception e) {
t.addSuppressed(e);
}
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
// we cannot get that since we supply an empty command.
throw new RuntimeException(t);
}
}
use of org.neo4j.driver.Value in project neo4j by neo4j.
the class CypherShellTest method setParamShouldAddParam.
@Test
public void setParamShouldAddParam() throws ParameterException, CommandException {
Value value = mock(Value.class);
Record recordMock = mock(Record.class);
BoltResult boltResult = mock(ListBoltResult.class);
when(mockedBoltStateHandler.runCypher(anyString(), anyMap())).thenReturn(Optional.of(boltResult));
when(boltResult.getRecords()).thenReturn(asList(recordMock));
when(recordMock.get("bob")).thenReturn(value);
when(value.asObject()).thenReturn("99");
assertTrue(offlineTestShell.getParameterMap().allParameterValues().isEmpty());
Object result = offlineTestShell.getParameterMap().setParameter("`bob`", "99");
assertEquals(99L, result);
assertEquals(99L, offlineTestShell.getParameterMap().allParameterValues().get("bob"));
}
use of org.neo4j.driver.Value in project neo4j by neo4j.
the class OutputFormatterTest method buildOperator.
private Value buildOperator(String operator, long dbHits, long rows, Value child) {
Map<String, Value> operatorMap = new HashMap<>();
operatorMap.put("operatorType", Values.value(operator));
operatorMap.put("dbHits", Values.value(dbHits));
operatorMap.put("rows", Values.value(rows));
if (child != null) {
operatorMap.put("children", new ListValue(child));
}
return new MapValue(operatorMap);
}
use of org.neo4j.driver.Value in project neo4j by neo4j.
the class OutputFormatter method info.
@Nonnull
static Map<String, Value> info(@Nonnull ResultSummary summary) {
Map<String, Value> result = new LinkedHashMap<>();
if (!summary.hasPlan()) {
return result;
}
Plan plan = summary.plan();
result.put("Plan", Values.value(summary.hasProfile() ? "PROFILE" : "EXPLAIN"));
result.put("Statement", Values.value(summary.queryType().name()));
Map<String, Value> arguments = plan.arguments();
Value emptyString = Values.value("");
Value questionMark = Values.value("?");
for (String key : INFO_SUMMARY) {
Value value = arguments.getOrDefault(key, arguments.getOrDefault(key.toLowerCase(), emptyString));
result.put(key, value);
}
result.put("Time", Values.value(summary.resultAvailableAfter(MILLISECONDS) + summary.resultConsumedAfter(MILLISECONDS)));
if (summary.hasProfile()) {
result.put("DbHits", Values.value(collectHits(summary.profile())));
}
if (summary.hasProfile()) {
result.put("Rows", Values.value(summary.profile().records()));
}
if (summary.hasProfile()) {
result.put("Memory (Bytes)", arguments.getOrDefault("GlobalMemory", questionMark));
}
return result;
}
use of org.neo4j.driver.Value in project neo4j by neo4j.
the class TableOutputFormatter method formatInfo.
@Override
@Nonnull
public String formatInfo(@Nonnull ResultSummary summary) {
Map<String, Value> info = OutputFormatter.info(summary);
if (info.isEmpty()) {
return "";
}
String[] columns = info.keySet().toArray(new String[0]);
StringBuilder sb = new StringBuilder();
Record record = new InternalRecord(asList(columns), info.values().toArray(new Value[0]));
formatResultAndCountRows(columns, Collections.singletonList(record).iterator(), line -> sb.append(line).append(OutputFormatter.NEWLINE));
return sb.toString();
}
Aggregations