本文整理了Java中org.neo4j.driver.v1.Record
类的一些代码示例,展示了Record
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Record
类的具体详情如下:
包路径:org.neo4j.driver.v1.Record
类名称:Record
[英]Container for Cypher result values.
Streams of records are returned from Cypher statement execution, contained within a StatementResult.
A record is a form of ordered map and, as such, contained values can be accessed by either positional #get(int) or textual #get(String).
[中]Cypher结果值的容器。
Cypher语句执行返回的记录流包含在StatementResult中。
记录是有序映射的一种形式,因此,包含的值可以通过位置#get(int)或文本#get(String)访问。
代码示例来源:origin: neo4j/neo4j
@Test
public void calls_simplistic_procedure()
{
try ( Driver driver = GraphDatabase.driver( graphDb.boltURI(), configuration() );
Session session = driver.session() )
{
StatementResult result = session.run( "CALL " + procedureNamespace + ".theAnswer()" );
assertThat( result.single().get( "value" ).asLong() ).isEqualTo( 42L );
}
}
代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures
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;
})));
}
代码示例来源:origin: neo4j/cypher-shell
recordMap.put("node", nodeVal);
List<String> keys = asList("rel", "node");
when(record.keys()).thenReturn(keys);
when(record.get(eq("rel"))).thenReturn(relVal);
when(record.get(eq("node"))).thenReturn(nodeVal);
when(record.<Value>asMap(anyObject())).thenReturn(recordMap);
when(record.values()).thenReturn(asList(relVal, nodeVal));
代码示例来源:origin: org.neo4j.driver/neo4j-java-driver
public static <T> Map<String, T> map( Record record, Function<Value, T> mapFunction )
{
int size = record.size();
switch ( size )
{
case 0:
return emptyMap();
case 1:
return singletonMap( record.keys().get( 0 ), mapFunction.apply( record.get( 0 ) ) );
default:
Map<String,T> map = Iterables.newLinkedHashMapWithSize( size );
List<String> keys = record.keys();
for ( int i = 0; i < size; i++ )
{
map.put( keys.get( i ), mapFunction.apply( record.get( i ) ) );
}
return unmodifiableMap( map );
}
}
代码示例来源:origin: org.neo4j.driver/neo4j-java-driver
public static <V> List<Pair<String, V>> fields( final Record map, final Function<Value, V> mapFunction )
{
int size = map.keys().size();
switch ( size )
{
case 0:
return emptyList();
case 1:
{
String key = map.keys().iterator().next();
Value value = map.get( key );
return singletonList( InternalPair.of( key, mapFunction.apply( value ) ) );
}
default:
{
List<Pair<String, V>> list = new ArrayList<>( size );
List<String> keys = map.keys();
for ( int i = 0; i < size; i++ )
{
String key = keys.get( i );
Value value = map.get( i );
list.add( InternalPair.of( key, mapFunction.apply( value ) ) );
}
return unmodifiableList( list );
}
}
}
代码示例来源:origin: neo4j/cypher-shell
private void checkMapForPrettyPrint(Map<String, String> map, String expectedResult) {
// given
BoltResult result = mock(BoltResult.class);
Record record = mock(Record.class);
Value value = mock(Value.class);
when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.MAP());
when(value.asMap((Function<Value, String>) anyObject())).thenReturn(map);
when(record.keys()).thenReturn(asList("map"));
when(record.values()).thenReturn(asList(value));
when(result.getRecords()).thenReturn(asList(record));
when(result.getSummary()).thenReturn(mock(ResultSummary.class));
// when
String actual = plainPrinter.format(result);
// then
assertThat(actual, is(expectedResult));
}
代码示例来源:origin: net.iot-solutions.graphdb/jcypher
@Override
public List<String> getColumns() {
List<String> columns = new ArrayList<String>();
if (this.records.size() > 0) {
Record rec = this.records.get(0);
columns.addAll(rec.keys());
}
return columns;
}
代码示例来源:origin: neo4j/cypher-shell
@Nonnull
private String formatRecord(@Nonnull final Record record) {
return record.values().stream().map(this::formatValue).collect(Collectors.joining(COMMA_SEPARATOR));
}
代码示例来源:origin: net.iot-solutions.graphdb/jcypher
private Entity getPropertiesObject(long id, int rowIndex, ElemType typ) {
Record rec = this.records.get(rowIndex);
List<Pair<String, Value>> flds = rec.fields();
for (Pair<String, Value> pair : flds) {
if (typ == ElemType.NODE && pair.value() instanceof NodeValue) {
Node nd = pair.value().asNode();
if (nd.id() == id)
return nd;
} else if (typ == ElemType.RELATION && pair.value() instanceof RelationshipValue) {
Relationship rel = pair.value().asRelationship();
if (rel.id() == id)
return rel;
}
}
// element with id may not have been loaded
return this.reloaded.getEntity(id, typ);
}
代码示例来源:origin: org.neo4j.driver/neo4j-java-driver
if ( ! ( size == otherRecord.size() ) )
if ( ! keys.equals( otherRecord.keys() ) )
Value otherValue = otherRecord.get( i );
if ( ! value.equals( otherValue ) )
代码示例来源:origin: neo4j/cypher-shell
@Test
public void prettyPrintList() throws Exception {
// given
BoltResult result = mock(BoltResult.class);
Record record1 = mock(Record.class);
Record record2 = mock(Record.class);
Value value1 = mock(Value.class);
Value value2 = mock(Value.class);
when(value1.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.LIST());
when(value2.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.LIST());
when(value1.asList(Matchers.any(Function.class))).thenReturn(asList("val1_1", "val1_2"));
when(value2.asList(Matchers.any(Function.class))).thenReturn(asList("val2_1"));
when(record1.keys()).thenReturn(asList("col1", "col2"));
when(record1.values()).thenReturn(asList(value1, value2));
when(record2.values()).thenReturn(asList(value2));
when(result.getRecords()).thenReturn(asList(record1, record2));
when(result.getSummary()).thenReturn(mock(ResultSummary.class));
// when
String actual = plainPrinter.format(result);
// then
assertThat(actual, is("col1, col2\n[val1_1, val1_2], [val2_1]\n[val2_1]"));
}
代码示例来源:origin: Wolfgang-Schuetzelhofer/jcypher
@Override
public List<String> getColumns() {
List<String> columns = new ArrayList<String>();
if (this.records.size() > 0) {
Record rec = this.records.get(0);
columns.addAll(rec.keys());
}
return columns;
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test public void shouldDiffGetTheDiffBetweenTwoStatesCorrectly() {
// 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 {keep:'keep', update:'old', delete:'delete'})");
session.run("CREATE (s:State:To {keep:'keep', update:'new', new:'new'})");
// 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::asString).collect(Collectors.toList()), contains(Utility.DIFF_OPERATION_REMOVE, "delete", "delete", "null"));
assertThat(result.next().values().stream().map(Value::asString).collect(Collectors.toList()), contains(Utility.DIFF_OPERATION_UPDATE, "update", "old", "new"));
assertThat(result.next().values().stream().map(Value::asString).collect(Collectors.toList()), contains(Utility.DIFF_OPERATION_ADD, "new", "null", "new"));
assertThat(result.hasNext(), is(false));
}
}
代码示例来源:origin: Wolfgang-Schuetzelhofer/jcypher
private Entity getPropertiesObject(long id, int rowIndex, ElemType typ) {
Record rec = this.records.get(rowIndex);
List<Pair<String, Value>> flds = rec.fields();
for (Pair<String, Value> pair : flds) {
if (typ == ElemType.NODE && pair.value() instanceof NodeValue) {
Node nd = pair.value().asNode();
if (nd.id() == id)
return nd;
} else if (typ == ElemType.RELATION && pair.value() instanceof RelationshipValue) {
Relationship rel = pair.value().asRelationship();
if (rel.id() == id)
return rel;
}
}
// element with id may not have been loaded
return this.reloaded.getEntity(id, typ);
}
代码示例来源:origin: testcontainers/testcontainers-java
@Test
public void shouldStart() {
boolean actual = neo4jContainer.isRunning();
assertThat(actual).isTrue();
try (Driver driver = GraphDatabase
.driver(neo4jContainer.getBoltUrl(), AuthTokens.basic("neo4j", "password"));
Session session = driver.session()
) {
long one = session.run("RETURN 1", Collections.emptyMap()).next().get(0).asLong();
assertThat(one).isEqualTo(1L);
} catch (Exception e) {
fail(e.getMessage());
}
}
代码示例来源:origin: neo4j/neo4j-ogm
private Map<String, Object> buildModel() {
Map<String, Object> row = new LinkedHashMap<>();
if (resultProjection.hasNext()) {
row = restModelAdapter.adapt(resultProjection.next().asMap());
}
return row;
}
代码示例来源:origin: neo4j/cypher-shell
@Test
public void prettyPrintRelationships() throws Exception {
// given
BoltResult result = mock(BoltResult.class);
Record record = mock(Record.class);
Value value = mock(Value.class);
Relationship relationship = mock(Relationship.class);
HashMap<String, Object> propertiesAsMap = new HashMap<>();
propertiesAsMap.put("prop1", "prop1_value");
propertiesAsMap.put("prop2", "prop2_value");
when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.RELATIONSHIP());
when(value.asRelationship()).thenReturn(relationship);
when(relationship.type()).thenReturn("RELATIONSHIP_TYPE");
when(relationship.asMap(anyObject())).thenReturn(unmodifiableMap(propertiesAsMap));
when(record.keys()).thenReturn(asList("rel"));
when(record.values()).thenReturn(asList(value));
when(result.getRecords()).thenReturn(asList(record));
when(result.getSummary()).thenReturn(mock(ResultSummary.class));
// when
String actual = plainPrinter.format(result);
// then
assertThat(actual, is("rel\n[:RELATIONSHIP_TYPE {prop2: prop2_value, prop1: prop1_value}]"));
}
代码示例来源:origin: neo4j/cypher-shell
@Override
@Nonnull
public String format(@Nonnull final BoltResult result) {
StringBuilder sb = new StringBuilder();
List<Record> records = result.getRecords();
if (!records.isEmpty()) {
sb.append(records.get(0).keys().stream().collect(Collectors.joining(COMMA_SEPARATOR)));
sb.append("\n");
sb.append(records.stream().map(this::formatRecord).collect(Collectors.joining("\n")));
}
return sb.toString();
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@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));
}
}
代码示例来源:origin: graphaware/graph-aided-search
private CypherResult buildResult(StatementResult response) {
CypherResult result = new CypherResult();
while (response.hasNext()) {
Record record = response.next();
ResultRow resultRow = new ResultRow();
for (Pair<String, Value> fieldInRecord : record.fields()) {
resultRow.add(fieldInRecord.key(), fieldInRecord.value());
}
result.addRow(resultRow);
}
return result;
}
内容来源于网络,如有侵权,请联系作者删除!