private Stream<RowResult> getRowResultStream(boolean virtual, Session session, Map<String, Object> params, String statement, boolean read) { Map<Long, Object> nodesCache = new HashMap<>(); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(runStatement(statement, session, params, read), 0), true) .map(record -> new RowResult(record.asMap(value -> { Object entity = value.asObject(); if (entity instanceof Node) return toNode(entity, virtual, nodesCache); if (entity instanceof Relationship) return toRelationship(entity, virtual, nodesCache); if (entity instanceof Path) return toPath(entity, virtual, nodesCache); return entity; }))); }
private Object get(Value value, Object defaultValue ) { if( value.equals( Values.NULL ) ) { return defaultValue; } else { return value.asObject(); } }
private Object toMapped(Value value) { if (value == null) { return null; } Object object = value.asObject(); return this.typeSystem.getNativeToMappedTypeAdapter(object.getClass()) .apply(object); } }
private static Map<String, Object> getArguments(Plan plan) { return plan.arguments().entrySet().stream() .collect(toMap(Map.Entry::getKey, e -> e.getValue().asObject())); }
private Object readProperty(Node node, String targetColumnName) { if ( node.containsKey( targetColumnName ) ) { return node.get( targetColumnName ).asObject(); } return null; }
@Override @Nonnull public Optional set(@Nonnull String name, @Nonnull String valueString) throws CommandException { final BoltResult result = setParamsAndValidate(name, valueString); String parameterName = CypherVariablesFormatter.unescapedCypherVariable(name); final Object value = result.getRecords().get(0).get(parameterName).asObject(); queryParams.put(parameterName, new ParamValue(valueString, value)); return Optional.ofNullable(value); }
@Override protected TupleSnapshot tupleSnapshot(Record record, List<String> keys) { // Requires a LinkedHashMap as the order of the entries is important Map<String, Object> properties = new LinkedHashMap<>(); for ( String column : keys ) { Value value = record.get( column ); if ( value != null && !value.isNull() ) { properties.put( column, value.asObject() ); } else { properties.put( column, null ); } } return new MapTupleSnapshot( properties ); } }
static Object convert(Value value) { switch (value.type().name()) { case "PATH": return value.asList(BoltCypherExecutor::convert); case "NODE": case "RELATIONSHIP": return value.asMap(); } return value.asObject(); }
ret = val.asObject();
@Test public void setParamShouldAddParam() throws CommandException { Value value = mock(Value.class); Record recordMock = mock(Record.class); BoltResult boltResult = mock(BoltResult.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.getAll().isEmpty()); Optional result = offlineTestShell.set("`bob`", "99"); assertEquals("99", result.get()); assertEquals("99", offlineTestShell.getAll().get("bob")); }
ret = val.asObject();
@Test public void setParamShouldAddParamWithSpecialCharactersAndValue() throws CommandException { Value value = mock(Value.class); Record recordMock = mock(Record.class); BoltResult boltResult = mock(BoltResult.class); when(mockedBoltStateHandler.runCypher(anyString(), anyMap())).thenReturn(Optional.of(boltResult)); when(boltResult.getRecords()).thenReturn(asList(recordMock)); when(recordMock.get("bo`b")).thenReturn(value); when(value.asObject()).thenReturn("99"); assertTrue(offlineTestShell.getAll().isEmpty()); Optional result = offlineTestShell.set("`bo``b`", "99"); assertEquals("99", result.get()); assertEquals("99", offlineTestShell.getAll().get("bo`b")); }
@Test public void shouldDiffGetTheDiffBetweenTwoStatesCorrectlyWithDifferentObjectTypes() { // This is in a try-block, to make sure we close the driver after the test try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) { // Given session.run("CREATE (s:State:From {a:1, b:1, c:'stringA', d:'string', e: [1, 2], f: [1, 2]})"); session.run("CREATE (s:State:To {a:2, b:1, c:'stringB', d:'string', e:[1, 2], f: [1, 3]})"); // When StatementResult result = session .run("MATCH (stateTo:State:To), (stateFrom:State:From) WITH stateFrom, stateTo CALL graph.versioner.diff(stateFrom, stateTo) YIELD operation, label, oldValue, newValue RETURN operation, label, oldValue, newValue"); // Then assertThat(result.next().values().stream().map(value -> value.asObject().toString()).collect(Collectors.toList()), contains(Utility.DIFF_OPERATION_UPDATE, "a", "1", "2")); assertThat(result.next().values().stream().map(value -> value.asObject().toString()).collect(Collectors.toList()), contains(Utility.DIFF_OPERATION_UPDATE, "c", "stringA", "stringB")); assertThat(result.next().values().stream().map(value -> value.asObject().toString()).collect(Collectors.toList()), contains(Utility.DIFF_OPERATION_UPDATE, "f", "[1, 2]", "[1, 3]")); assertThat(result.hasNext(), is(false)); } }
return v.asNumber().toString(); default: return v.asObject().toString();
@Test public void originalIds() throws ExecutionException, InterruptedException { String uri = "//localhost:" + gremlinServer.getPort(); String uuid = "ef8b80c9-f8f9-40b6-bad2-ee4757d5bb33"; gremlinServer.gremlinClient().submit(format("g.addV('VertexWithStringId').property(id, '%s')", uuid)).all().get(); // freshReadmeSnippet: originalIds Config config = Config.build() .withTranslation(TranslatorFlavor.gremlinServer()) .ignoreIds() .toConfig(); Driver driver = GremlinDatabase.driver(uri, config); try (Session session = driver.session()) { StatementResult getOriginal = session.run("MATCH (n:VertexWithStringId) RETURN id(n) as id"); Object originalId = getOriginal.single().get("id").asObject(); assertThat(originalId).isEqualTo(uuid); // ef8b80c9-f8f9-40b6-bad2-ee4757d5bb33 StatementResult result = session.run("MATCH (n) WHERE id(n) = $originalId RETURN n", singletonMap("originalId", originalId)); Node n = result.single().get("n").asNode(); assertThat(n.id()).isEqualTo(-1); // -1 } // freshReadmeSnippet: originalIds } }