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

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

本文整理了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

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

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

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

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

  1. private Object readProperty(Node node, String targetColumnName) {
  2. if ( node.containsKey( targetColumnName ) ) {
  3. return node.get( targetColumnName ).asObject();
  4. }
  5. return null;
  6. }

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

  1. @Test
  2. public void returnNodeAndRelationship() {
  3. Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort());
  4. try (Session session = driver.session()) {
  5. StatementResult result = session.run("CREATE (n1:Person {name: 'Marko'})-[r:knows {since:1999}]->(n2:Person)" +
  6. "RETURN n1,r,n2",
  7. parameters("message", "Hello"));
  8. Record record = result.single();
  9. Node n1 = record.get("n1").asNode();
  10. Relationship r = record.get("r").asRelationship();
  11. Node n2 = record.get("n2").asNode();
  12. assertThat(n1.hasLabel("Person")).isTrue();
  13. assertThat(n1.get("name").asString()).isEqualTo("Marko");
  14. assertThat(r.hasType("knows")).isTrue();
  15. assertThat(r.startNodeId()).isEqualTo(n1.id());
  16. assertThat(r.endNodeId()).isEqualTo(n2.id());
  17. assertThat(r.get("since").asLong()).isEqualTo(1999L);
  18. assertThat(n2.hasLabel("Person")).isTrue();
  19. }
  20. }

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

  1. @Test
  2. public void shouldCreateAndPatchANewStateWithoutAdditionalLabelAndDate() throws Throwable {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
  8. session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
  9. // When
  10. StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.patch(e, {key:'newValue', newKey:'newestValue'}) YIELD node RETURN node");
  11. Node currentState = result.single().get("node").asNode();
  12. StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
  13. StatementResult nextResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) return s2");
  14. StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
  15. // Then
  16. assertThat(countStateResult.single().get("s").asLong(), equalTo(2L));
  17. assertThat(nextResult.single().get("s2").asNode().id(), equalTo(1L));
  18. assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
  19. assertThat(currentState.get("key").asString(), equalTo("newValue"));
  20. assertThat(currentState.get("newKey").asString(), equalTo("newestValue"));
  21. }
  22. }

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

  1. @Test
  2. public void shouldCreateAnEntityWithPropertiesWithAStateAndItsPropertiesWithAdditionalLabelButNoDate() throws Throwable {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // When
  7. StatementResult result = session.run("CALL graph.versioner.init('Entity', {key:'value'}, {key:'value'}, 'Error')");
  8. StatementResult entityResult = session.run("MATCH (e:Entity) RETURN properties(e) as props");
  9. StatementResult stateResult = session.run("MATCH (s:State) RETURN s");
  10. Node state = stateResult.single().get("s").asNode();
  11. StatementResult stateProps = session.run("MATCH (s:State) RETURN properties(s) as props");
  12. StatementResult currentResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN id(e) as id");
  13. StatementResult hasStatusResult = session.run("MATCH (e:Entity)-[:HAS_STATE]->(s:State) RETURN id(e) as id");
  14. // Then
  15. assertThat(result.single().get("node").asNode().id(), equalTo(0L));
  16. assertThat(entityResult.single().get("props").asMap().isEmpty(), equalTo(false));
  17. assertThat(state.id(), equalTo(1L));
  18. assertThat(stateProps.single().get("props").asMap().isEmpty(), equalTo(false));
  19. assertThat(currentResult.single().get("id").asLong(), equalTo(0L));
  20. assertThat(hasStatusResult.single().get("id").asLong(), equalTo(0L));
  21. assertThat(state.hasLabel("Error"), equalTo(true));
  22. }
  23. }

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

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

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

  1. @Test
  2. public void prettyPrintNode() throws Exception {
  3. // given
  4. BoltResult result = mock(BoltResult.class);
  5. Record record = mock(Record.class);
  6. Value value = mock(Value.class);
  7. Node node = mock(Node.class);
  8. HashMap<String, Object> propertiesAsMap = new HashMap<>();
  9. propertiesAsMap.put("prop1", "prop1_value");
  10. propertiesAsMap.put("prop2", "prop2_value");
  11. when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.NODE());
  12. when(value.asNode()).thenReturn(node);
  13. when(node.labels()).thenReturn(asList("label1", "label2"));
  14. when(node.asMap(anyObject())).thenReturn(unmodifiableMap(propertiesAsMap));
  15. when(record.keys()).thenReturn(asList("col1", "col2"));
  16. when(record.values()).thenReturn(asList(value));
  17. when(result.getRecords()).thenReturn(asList(record));
  18. when(result.getSummary()).thenReturn(mock(ResultSummary.class));
  19. // when
  20. String actual = plainPrinter.format(result);
  21. // then
  22. assertThat(actual, is("col1, col2\n" +
  23. "(:label1:label2 {prop2: prop2_value, prop1: prop1_value})"));
  24. }

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

  1. public List<String> labels(Object value) {
  2. Node node = (Node) value;
  3. List<String> labels = new ArrayList<>();
  4. for (String label : node.labels()) {
  5. labels.add(label);
  6. }
  7. return labels;
  8. }

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

  1. @Override
  2. public boolean isEmpty() {
  3. return node.asMap().isEmpty();
  4. }

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

  1. @Test
  2. public void shouldRollbackNthWorkCorrectly() {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(:State:Error {key:'initialValue'})"
  8. + "-[:PREVIOUS {date: localdatetime('1988-10-26T00:00:00')}]->(:State {key:'value'})-[:PREVIOUS {date: localdatetime('1988-10-25T00:00:00')}]->(:State:Test {key:'testValue'})");
  9. session.run("MATCH (e:Entity)-[:CURRENT]->(s:Error) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
  10. 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)");
  11. 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)");
  12. // When
  13. StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.rollback.nth(e, 2) YIELD node RETURN node");
  14. // Then
  15. boolean failure = true;
  16. while (result.hasNext()) {
  17. failure = false;
  18. assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
  19. }
  20. session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN s");
  21. while(!failure && result.hasNext()) {
  22. assertThat(result.next().get("node").asNode().hasLabel("Test"), equalTo(true));
  23. }
  24. if (failure) {
  25. fail();
  26. }
  27. }
  28. }

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

  1. private static Object[] keyValues(Node node, EntityKeyMetadata entityKeyMetadata) {
  2. Object[] values = new Object[entityKeyMetadata.getColumnNames().length];
  3. for ( int i = 0; i < values.length; i++ ) {
  4. values[i] = node.get( entityKeyMetadata.getColumnNames()[i] );
  5. }
  6. return values;
  7. }
  8. }

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

  1. @Test
  2. public void shouldCreateACopyOfTheCurrentStateIfPatchedWithoutStateProps() throws Throwable {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
  8. session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
  9. StatementResult stateResult = session.run("MATCH (s:State) RETURN s");
  10. Node state = stateResult.single().get("s").asNode();
  11. // When
  12. StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.patch(e) YIELD node RETURN node");
  13. // Then
  14. Node newState = result.single().get("node").asNode();
  15. assertThat(state.get("key"), equalTo(newState.get("key")));
  16. assertThat(state.size(), equalTo(newState.size()));
  17. }
  18. }

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

  1. @Test
  2. public void shouldCreateAndPatchANewStateWithAdditionalLabelButWithoutDate() throws Throwable {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})");
  8. session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)");
  9. // When
  10. StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.patch(e, {key:'newValue', newKey:'newestValue'}, 'Error') YIELD node RETURN node");
  11. Node currentState = result.single().get("node").asNode();
  12. StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
  13. StatementResult nextResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) return s2");
  14. StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
  15. StatementResult currentStateResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s) return s");
  16. // Then
  17. assertThat(countStateResult.single().get("s").asLong(), equalTo(2L));
  18. assertThat(nextResult.single().get("s2").asNode().id(), equalTo(1L));
  19. assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
  20. assertThat(currentStateResult.single().get("s").asNode().hasLabel("Error"), equalTo(true));
  21. assertThat(currentState.get("key").asString(), equalTo("newValue"));
  22. assertThat(currentState.get("newKey").asString(), equalTo("newestValue"));
  23. }
  24. }

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

  1. @Test
  2. public void shouldCreateACopyOfTheGivenStateWithoutAdditionalDate() throws Throwable {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // Given
  7. session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue', newKey:'oldestValue'})");
  8. 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)");
  9. 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'})");
  10. session.run("MATCH (sc:State)<-[:CURRENT]-(e:Entity)-[:HAS_STATE]->(s:Test) CREATE (sc)-[:PREVIOUS {date:localdatetime('1988-10-26T00:00:00')}]->(s)");
  11. StatementResult stateResult = session.run("MATCH (s:Test) RETURN s");
  12. Node originalState = stateResult.single().get("s").asNode();
  13. // When
  14. 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");
  15. Node currentState = result.single().get("node").asNode();
  16. StatementResult countStateResult = session.run("MATCH (s:State) RETURN count(s) as s");
  17. StatementResult correctStateResult = session.run("MATCH (s1:State)-[:PREVIOUS]->(s2:State) WITH s1 MATCH (e:Entity)-[:CURRENT]->(s1) return e");
  18. // Then
  19. assertThat(countStateResult.single().get("s").asLong(), equalTo(3L));
  20. assertThat(correctStateResult.single().get("e").asNode().id(), equalTo(0L));
  21. assertThat(currentState.get("key").asString(), equalTo("initialValue"));
  22. assertThat(currentState.get("newKey").asString(), equalTo("newestValue"));
  23. }
  24. }

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

  1. @Test
  2. public void shouldCreateAnEntityWithPropertiesWithAStateAndItsPropertiesWithAdditionalLabelAndDate() throws Throwable {
  3. // This is in a try-block, to make sure we close the driver after the test
  4. try (Driver driver = GraphDatabase
  5. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  6. // When
  7. StatementResult result = session.run("CALL graph.versioner.init('Entity', {key:'value'}, {key:'value'}, 'Error', localdatetime('1988-10-27T02:46:40'))");
  8. StatementResult entityResult = session.run("MATCH (e:Entity) RETURN properties(e) as props");
  9. StatementResult stateResult = session.run("MATCH (s:State) RETURN s");
  10. Node state = stateResult.single().get("s").asNode();
  11. StatementResult stateProps = session.run("MATCH (s:State) RETURN properties(s) as props");
  12. StatementResult currentResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN id(e) as id");
  13. StatementResult hasStatusResult = session.run("MATCH (e:Entity)-[:HAS_STATE]->(s:State) RETURN id(e) as id");
  14. StatementResult hasStatusDateResult = session.run("MATCH (e:Entity)-[rel:CURRENT]->(s:State) RETURN rel.date as date");
  15. // Then
  16. assertThat(result.single().get("node").asNode().id(), equalTo(0L));
  17. assertThat(entityResult.single().get("props").asMap().isEmpty(), equalTo(false));
  18. assertThat(state.id(), equalTo(1L));
  19. assertThat(stateProps.single().get("props").asMap().isEmpty(), equalTo(false));
  20. assertThat(currentResult.single().get("id").asLong(), equalTo(0L));
  21. assertThat(hasStatusResult.single().get("id").asLong(), equalTo(0L));
  22. assertThat(state.hasLabel("Error"), equalTo(true));
  23. assertThat(hasStatusDateResult.single().get("date").asLocalDateTime(), equalTo(convertEpochToLocalDateTime(593920000000L)));
  24. }
  25. }

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

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

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

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

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

  1. public List<String> labels(Object value) {
  2. Node node = (Node) value;
  3. List<String> labels = new ArrayList<>();
  4. for (String label : node.labels()) {
  5. labels.add(label);
  6. }
  7. return labels;
  8. }

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

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

相关文章