org.neo4j.driver.v1.types.Node类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(16.8k)|赞(0)|评价(0)|浏览(156)

本文整理了Java中org.neo4j.driver.v1.types.Node类的一些代码示例,展示了Node类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node类的具体详情如下:
包路径:org.neo4j.driver.v1.types.Node
类名称:Node

Node介绍

[英]The Node interface describes the characteristics of a node from a Neo4j graph.
[中]节点接口描述Neo4j图中节点的特征。

代码示例

代码示例来源:origin: neo4j/neo4j-ogm

public long nodeId(Object node) {
  return ((Node) node).id();
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

private Object toNode(Object value, boolean virtual, Map<Long, Object> nodesCache) {
  Value internalValue = ((InternalEntity) value).asValue();
  Node node = internalValue.asNode();
  if (virtual) {
    List<Label> labels = new ArrayList<>();
    node.labels().forEach(l -> labels.add(Label.label(l)));
    VirtualNode virtualNode = new VirtualNode(node.id(), labels.toArray(new Label[0]), node.asMap(), db);
    nodesCache.put(node.id(), virtualNode);
    return virtualNode;
  } else
    return Util.map("entityType", internalValue.type().name(), "labels", node.labels(), "id", node.id(), "properties", node.asMap());
}

代码示例来源:origin: hibernate/hibernate-ogm

private Object readProperty(Node node, String targetColumnName) {
  if ( node.containsKey( targetColumnName ) ) {
    return node.get( targetColumnName ).asObject();
  }
  return null;
}

代码示例来源:origin: opencypher/cypher-for-gremlin

@Test
public void returnNodeAndRelationship() {
  Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort());
  try (Session session = driver.session()) {
    StatementResult result = session.run("CREATE (n1:Person {name: 'Marko'})-[r:knows {since:1999}]->(n2:Person)" +
        "RETURN n1,r,n2",
      parameters("message", "Hello"));
    Record record = result.single();
    Node n1 = record.get("n1").asNode();
    Relationship r = record.get("r").asRelationship();
    Node n2 = record.get("n2").asNode();
    assertThat(n1.hasLabel("Person")).isTrue();
    assertThat(n1.get("name").asString()).isEqualTo("Marko");
    assertThat(r.hasType("knows")).isTrue();
    assertThat(r.startNodeId()).isEqualTo(n1.id());
    assertThat(r.endNodeId()).isEqualTo(n2.id());
    assertThat(r.get("since").asLong()).isEqualTo(1999L);
    assertThat(n2.hasLabel("Person")).isTrue();
  }
}

代码示例来源:origin: h-omer/neo4j-versioner-core

@Test
public void shouldCreateAndPatchANewStateWithoutAdditionalLabelAndDate() throws Throwable {
  // 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 (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
    session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
    // When
    StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.patch(e, {key:'newValue', newKey:'newestValue'}) YIELD node RETURN node");
    Node currentState = result.single().get("node").asNode();
    StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
    StatementResult nextResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) return s2");
    StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
    // Then
    assertThat(countStateResult.single().get("s").asLong(), equalTo(2L));
    assertThat(nextResult.single().get("s2").asNode().id(), equalTo(1L));
    assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
    assertThat(currentState.get("key").asString(), equalTo("newValue"));
    assertThat(currentState.get("newKey").asString(), equalTo("newestValue"));
  }
}

代码示例来源:origin: h-omer/neo4j-versioner-core

@Test
public void shouldCreateAnEntityWithPropertiesWithAStateAndItsPropertiesWithAdditionalLabelButNoDate() throws Throwable {
  // 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()) {
    // When
    StatementResult result = session.run("CALL graph.versioner.init('Entity', {key:'value'}, {key:'value'}, 'Error')");
    StatementResult entityResult = session.run("MATCH (e:Entity) RETURN properties(e) as props");
    StatementResult stateResult = session.run("MATCH (s:State) RETURN s");
    Node state = stateResult.single().get("s").asNode();
    StatementResult stateProps = session.run("MATCH (s:State) RETURN properties(s) as props");
    StatementResult currentResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN id(e) as id");
    StatementResult hasStatusResult = session.run("MATCH (e:Entity)-[:HAS_STATE]->(s:State) RETURN id(e) as id");
    // Then
    assertThat(result.single().get("node").asNode().id(), equalTo(0L));
    assertThat(entityResult.single().get("props").asMap().isEmpty(), equalTo(false));
    assertThat(state.id(), equalTo(1L));
    assertThat(stateProps.single().get("props").asMap().isEmpty(), equalTo(false));
    assertThat(currentResult.single().get("id").asLong(), equalTo(0L));
    assertThat(hasStatusResult.single().get("id").asLong(), equalTo(0L));
    assertThat(state.hasLabel("Error"), equalTo(true));
  }
}

代码示例来源:origin: neo4j/cypher-shell

when(start.labels()).thenReturn(asList("start"));
when(start.id()).thenReturn(1l);
when(end.labels()).thenReturn(asList("end"));
when(end.id()).thenReturn(2l);

代码示例来源:origin: neo4j/cypher-shell

@Test
public void prettyPrintNode() throws Exception {
  // given
  BoltResult result = mock(BoltResult.class);
  Record record = mock(Record.class);
  Value value = mock(Value.class);
  Node node = mock(Node.class);
  HashMap<String, Object> propertiesAsMap = new HashMap<>();
  propertiesAsMap.put("prop1", "prop1_value");
  propertiesAsMap.put("prop2", "prop2_value");
  when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.NODE());
  when(value.asNode()).thenReturn(node);
  when(node.labels()).thenReturn(asList("label1", "label2"));
  when(node.asMap(anyObject())).thenReturn(unmodifiableMap(propertiesAsMap));
  when(record.keys()).thenReturn(asList("col1", "col2"));
  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("col1, col2\n" +
      "(:label1:label2 {prop2: prop2_value, prop1: prop1_value})"));
}

代码示例来源:origin: neo4j/neo4j-ogm

public List<String> labels(Object value) {
  Node node = (Node) value;
  List<String> labels = new ArrayList<>();
  for (String label : node.labels()) {
    labels.add(label);
  }
  return labels;
}

代码示例来源:origin: hibernate/hibernate-ogm

@Override
public boolean isEmpty() {
  return node.asMap().isEmpty();
}

代码示例来源:origin: h-omer/neo4j-versioner-core

@Test
public void shouldRollbackNthWorkCorrectly() {
  // 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 (:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(:State:Error {key:'initialValue'})"
        + "-[:PREVIOUS {date: localdatetime('1988-10-26T00:00:00')}]->(:State {key:'value'})-[:PREVIOUS {date: localdatetime('1988-10-25T00:00:00')}]->(:State:Test {key:'testValue'})");
    session.run("MATCH (e:Entity)-[:CURRENT]->(s:Error) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
    session.run("MATCH (e:Entity), (s:State {key:'value'}) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-26T00:00:00'), endDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
    session.run("MATCH (e:Entity), (s:Test) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-25T00:00:00'), endDate:localdatetime('1988-10-26T00:00:00')}]->(s)");
    // When
    StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.rollback.nth(e, 2) YIELD node RETURN node");
    // Then
    boolean failure = true;
    while (result.hasNext()) {
      failure = false;
      assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
    }
    session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN s");
    while(!failure && result.hasNext()) {
      assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
    }
    if (failure) {
      fail();
    }
  }
}

代码示例来源:origin: hibernate/hibernate-ogm

private static Object[] keyValues(Node node, EntityKeyMetadata entityKeyMetadata) {
    Object[] values = new Object[entityKeyMetadata.getColumnNames().length];
    for ( int i = 0; i < values.length; i++ ) {
      values[i] = node.get( entityKeyMetadata.getColumnNames()[i] );
    }
    return values;
  }
}

代码示例来源:origin: h-omer/neo4j-versioner-core

@Test
public void shouldCreateACopyOfTheCurrentStateIfPatchedWithoutStateProps() throws Throwable {
  // 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 (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
    session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
    StatementResult stateResult = session.run("MATCH (s:State) RETURN s");
    Node state = stateResult.single().get("s").asNode();
    // When
    StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.patch(e) YIELD node RETURN node");
    // Then
    Node newState = result.single().get("node").asNode();
    assertThat(state.get("key"), equalTo(newState.get("key")));
    assertThat(state.size(), equalTo(newState.size()));
  }
}

代码示例来源:origin: h-omer/neo4j-versioner-core

@Test
public void shouldCreateAndPatchANewStateWithAdditionalLabelButWithoutDate() throws Throwable {
  // 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 (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
    session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
    // When
    StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.patch(e, {key:'newValue', newKey:'newestValue'}, 'Error') YIELD node RETURN node");
    Node currentState = result.single().get("node").asNode();
    StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
    StatementResult nextResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) return s2");
    StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
    StatementResult currentStateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s) return s");
    // Then
    assertThat(countStateResult.single().get("s").asLong(), equalTo(2L));
    assertThat(nextResult.single().get("s2").asNode().id(), equalTo(1L));
    assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
    assertThat(currentStateResult.single().get("s").asNode().hasLabel("Error"), equalTo(true));
    assertThat(currentState.get("key").asString(), equalTo("newValue"));
    assertThat(currentState.get("newKey").asString(), equalTo("newestValue"));
  }
}

代码示例来源:origin: h-omer/neo4j-versioner-core

@Test
public void shouldCreateACopyOfTheGivenStateWithoutAdditionalDate() throws Throwable {
  // 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 (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue', newKey:'oldestValue'})");
    session.run("MATCH (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'}) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
    session.run("MATCH (e:Entity) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-26T00:00:00'), endDate:localdatetime('1988-10-27T00:00:00')}]->(s:State:Test {newKey:'newestValue'})");
    session.run("MATCH (sc:State)<-[:CURRENT]-(e:Entity)-[:HAS_STATE]->(s:Test) CREATE (sc)-[:PREVIOUS {date:localdatetime('1988-10-26T00:00:00')}]->(s)");
    StatementResult stateResult = session.run("MATCH (s:Test) RETURN s");
    Node originalState = stateResult.single().get("s").asNode();
    // When
    StatementResult result = session.run("MATCH (e:Entity)-[:HAS_STATE]->(s:Test) WITH e, s CALL graph.versioner.patch.from(e, s) YIELD node RETURN node");
    Node currentState = result.single().get("node").asNode();
    StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
    StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
    // Then
    assertThat(countStateResult.single().get("s").asLong(), equalTo(3L));
    assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
    assertThat(currentState.get("key").asString(), equalTo("initialValue"));
    assertThat(currentState.get("newKey").asString(), equalTo("newestValue"));
  }
}

代码示例来源:origin: h-omer/neo4j-versioner-core

@Test
public void shouldCreateAnEntityWithPropertiesWithAStateAndItsPropertiesWithAdditionalLabelAndDate() throws Throwable {
  // 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()) {
    // When
    StatementResult result = session.run("CALL graph.versioner.init('Entity', {key:'value'}, {key:'value'}, 'Error', localdatetime('1988-10-27T02:46:40'))");
    StatementResult entityResult = session.run("MATCH (e:Entity) RETURN properties(e) as props");
    StatementResult stateResult = session.run("MATCH (s:State) RETURN s");
    Node state = stateResult.single().get("s").asNode();
    StatementResult stateProps = session.run("MATCH (s:State) RETURN properties(s) as props");
    StatementResult currentResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN id(e) as id");
    StatementResult hasStatusResult = session.run("MATCH (e:Entity)-[:HAS_STATE]->(s:State) RETURN id(e) as id");
    StatementResult hasStatusDateResult = session.run("MATCH (e:Entity)-[rel:CURRENT]->(s:State) RETURN rel.date as date");
    // Then
    assertThat(result.single().get("node").asNode().id(), equalTo(0L));
    assertThat(entityResult.single().get("props").asMap().isEmpty(), equalTo(false));
    assertThat(state.id(), equalTo(1L));
    assertThat(stateProps.single().get("props").asMap().isEmpty(), equalTo(false));
    assertThat(currentResult.single().get("id").asLong(), equalTo(0L));
    assertThat(hasStatusResult.single().get("id").asLong(), equalTo(0L));
    assertThat(state.hasLabel("Error"), equalTo(true));
    assertThat(hasStatusDateResult.single().get("date").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
  }
}

代码示例来源:origin: neo4j/cypher-shell

when(start.labels()).thenReturn(asList("start"));
when(start.id()).thenReturn(1l);
when(second.labels()).thenReturn(asList("second"));
when(second.id()).thenReturn(2l);
when(third.labels()).thenReturn(asList("third"));
when(third.id()).thenReturn(3l);
when(end.labels()).thenReturn(asList("end"));
when(end.id()).thenReturn(4l);

代码示例来源:origin: neo4j/cypher-shell

when(node.labels()).thenReturn(asList("label `1", "label2"));
when(node.asMap(anyObject())).thenReturn(unmodifiableMap(nodeProp));

代码示例来源:origin: org.neo4j/neo4j-ogm-bolt-driver

public List<String> labels(Object value) {
  Node node = (Node) value;
  List<String> labels = new ArrayList<>();
  for (String label : node.labels()) {
    labels.add(label);
  }
  return labels;
}

代码示例来源:origin: neo4j/cypher-shell

@Nonnull default String nodeAsString(@Nonnull final Node node) {
  List<String> nodeAsString = new ArrayList<>();
  nodeAsString.add(collectNodeLabels(node));
  nodeAsString.add(mapAsStringWithEmpty(node.asMap(this::formatValue)));
  return "(" + joinWithSpace(nodeAsString) + ")";
}

相关文章

微信公众号

最新文章

更多