org.neo4j.driver.v1.types.Node.id()方法的使用及代码示例

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

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

Node.id介绍

暂无

代码示例

代码示例来源: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: neo4j/neo4j-ogm

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

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

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

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

  1. @Override
  2. public String toString()
  3. {
  4. return String.format( relationship.startNodeId() == start.id() ?
  5. "(%s)-[%s:%s]->(%s)" : "(%s)<-[%s:%s]-(%s)",
  6. start.id(), relationship.id(), relationship.type(), end.id() );
  7. }
  8. }

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

  1. private static boolean isEndpoint( Node node, Relationship relationship )
  2. {
  3. return node.id() == relationship.startNodeId() || node.id() == relationship.endNodeId();
  4. }

代码示例来源:origin: net.iot-solutions.graphdb/jcypher

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public long gePathtNodeIdAt(PathInfo pathInfo, int index) {
  4. Object obj = pathInfo.getContentObject();
  5. List<Node> nodes = null;
  6. if (obj instanceof List<?>)
  7. nodes = (List<Node>) obj;
  8. else if (obj instanceof Path) {
  9. nodes = new ArrayList<Node>();
  10. Iterator<Node> it = ((Path)obj).nodes().iterator();
  11. while(it.hasNext())
  12. nodes.add(it.next());
  13. pathInfo.setContentObject(nodes);
  14. }
  15. return nodes.get(index).id();
  16. }

代码示例来源:origin: Wolfgang-Schuetzelhofer/jcypher

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public long gePathtNodeIdAt(PathInfo pathInfo, int index) {
  4. Object obj = pathInfo.getContentObject();
  5. List<Node> nodes = null;
  6. if (obj instanceof List<?>)
  7. nodes = (List<Node>) obj;
  8. else if (obj instanceof Path) {
  9. nodes = new ArrayList<Node>();
  10. Iterator<Node> it = ((Path)obj).nodes().iterator();
  11. while(it.hasNext())
  12. nodes.add(it.next());
  13. pathInfo.setContentObject(nodes);
  14. }
  15. return nodes.get(index).id();
  16. }

代码示例来源:origin: neueda/jetbrains-plugin-graph-database-support

  1. public Neo4jBoltNode(Node value) {
  2. this.id = String.valueOf(value.id());
  3. this.types = Iterables.asList(value.labels());
  4. this.propertyContainer = new Neo4jBoltPropertyContainer(value.asMap());
  5. }

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

  1. @Nonnull
  2. default String pathAsString(@Nonnull Path path) {
  3. List<String> list = new ArrayList<>(path.length());
  4. Node lastTraversed = path.start();
  5. if (lastTraversed != null) {
  6. list.add(nodeAsString(lastTraversed));
  7. for (Path.Segment segment : path) {
  8. Relationship relationship = segment.relationship();
  9. if (relationship.startNodeId() == lastTraversed.id()) {
  10. list.add("-" + relationshipAsString(relationship) + "->");
  11. } else {
  12. list.add("<-" + relationshipAsString(relationship) + "-");
  13. }
  14. list.add(nodeAsString(segment.end()));
  15. lastTraversed = segment.end();
  16. }
  17. }
  18. return list.stream().collect(Collectors.joining());
  19. }

代码示例来源:origin: net.iot-solutions.graphdb/jcypher

  1. public static ElementInfo fromRecordValue(Value val) {
  2. if (val instanceof ListValue)
  3. return ElementInfo.fromRecordValue(((ListValue)val).get(0));
  4. ElementInfo ret = null;
  5. if (val != null) {
  6. String typName = val.type().name(); // NODE, RELATIONSHIP, NULL
  7. if ("NODE".equals(typName)) {
  8. ret = new ElementInfo();
  9. ret.isNull = false;
  10. ret.id = val.asNode().id();
  11. ret.type = ElemType.NODE;
  12. } else if ("RELATIONSHIP".equals(typName)) {
  13. ret = new ElementInfo();
  14. ret.isNull = false;
  15. ret.id = val.asRelationship().id();
  16. ret.type = ElemType.RELATION;
  17. } else if ("NULL".equals(typName))
  18. ret = ElementInfo.nullElement();
  19. }
  20. return ret;
  21. }

代码示例来源:origin: net.iot-solutions.graphdb/jcypher

  1. private Entity getPropertiesObject(long id, int rowIndex, ElemType typ) {
  2. Record rec = this.records.get(rowIndex);
  3. List<Pair<String, Value>> flds = rec.fields();
  4. for (Pair<String, Value> pair : flds) {
  5. if (typ == ElemType.NODE && pair.value() instanceof NodeValue) {
  6. Node nd = pair.value().asNode();
  7. if (nd.id() == id)
  8. return nd;
  9. } else if (typ == ElemType.RELATION && pair.value() instanceof RelationshipValue) {
  10. Relationship rel = pair.value().asRelationship();
  11. if (rel.id() == id)
  12. return rel;
  13. }
  14. }
  15. // element with id may not have been loaded
  16. return this.reloaded.getEntity(id, typ);
  17. }

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

  1. @Test
  2. public void shouldMaintainTheRelationshipsFromTheCurrentState() throws Throwable {
  3. try (Driver driver = GraphDatabase
  4. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  5. // Given
  6. Node entityA = initEntity(session);
  7. Node entityB = initEntity(session);
  8. String createEntityRelationshipQuery = "MATCH (a:Entity)-[:CURRENT]->(s: State), (b:Entity)<-[:FOR]-(r:R) WHERE id(a) = %d AND id(b) = %d CREATE (s)-[:testType]->(r)";
  9. session.run(String.format(createEntityRelationshipQuery, entityA.id(), entityB.id()));
  10. // When
  11. String patchQuery = "MATCH (e:Entity) WHERE id(e) = %d WITH e CALL graph.versioner.patch(e) YIELD node RETURN node";
  12. StatementResult result = session.run(String.format(patchQuery, entityA.id()));
  13. // Then
  14. Assertions.assertThat(session.run(String.format("MATCH (a:Entity)-[:CURRENT]->(:State)-[:testType]->(:R)-[:FOR]->(b:Entity) WHERE id(a) = %d AND id(b) = %d RETURN a", entityA.id(), entityB.id())))
  15. .hasSize(1);
  16. }
  17. }

代码示例来源:origin: Wolfgang-Schuetzelhofer/jcypher

  1. private Entity getPropertiesObject(long id, int rowIndex, ElemType typ) {
  2. Record rec = this.records.get(rowIndex);
  3. List<Pair<String, Value>> flds = rec.fields();
  4. for (Pair<String, Value> pair : flds) {
  5. if (typ == ElemType.NODE && pair.value() instanceof NodeValue) {
  6. Node nd = pair.value().asNode();
  7. if (nd.id() == id)
  8. return nd;
  9. } else if (typ == ElemType.RELATION && pair.value() instanceof RelationshipValue) {
  10. Relationship rel = pair.value().asRelationship();
  11. if (rel.id() == id)
  12. return rel;
  13. }
  14. }
  15. // element with id may not have been loaded
  16. return this.reloaded.getEntity(id, typ);
  17. }

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

  1. @Test
  2. public void shouldNotCreateTheRelationshipIfSourceIsNotAnEntity() throws Throwable {
  3. try (Driver driver = GraphDatabase
  4. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  5. // Given
  6. Node entityA = session.run("CREATE (e:Entity) RETURN e").single().get("e").asNode(); //Not an entity because missing states and R
  7. Node entityB = initEntity(session);
  8. String testType = "testType";
  9. // When
  10. String query = "MATCH (a:Entity), (b:Entity) WHERE id(a) = %d AND id(b) = %d WITH a, b CALL graph.versioner.relationship.create(a, b, '%s') YIELD relationship RETURN relationship";
  11. assertThat(session.run(String.format(query, entityA.id(), entityB.id(), testType)));
  12. Throwable thrown = catchThrowable(() -> session.run(String.format(query, entityA.id(), entityB.id(), testType)));
  13. //Then
  14. assertThat(thrown).hasMessageContaining("The given node is not a Versioner Core Entity");
  15. }
  16. }

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

  1. @Test
  2. public void shouldNotCreateTheRelationshipIfDestinationIsNotAnEntity() throws Throwable {
  3. try (Driver driver = GraphDatabase
  4. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  5. // Given
  6. Node entityA = initEntity(session);
  7. Node entityB = session.run("CREATE (e:Entity) RETURN e").single().get("e").asNode(); //Not an entity because missing states and R
  8. String testType = "testType";
  9. // When
  10. String query = "MATCH (a:Entity), (b:Entity) WHERE id(a) = %d AND id(b) = %d WITH a, b CALL graph.versioner.relationship.create(a, b, '%s') YIELD relationship RETURN relationship";
  11. assertThat(session.run(String.format(query, entityA.id(), entityB.id(), testType)));
  12. Throwable thrown = catchThrowable(() -> session.run(String.format(query, entityA.id(), entityB.id(), testType)));
  13. //Then
  14. assertThat(thrown).hasMessageContaining("The given node is not a Versioner Core Entity");
  15. }
  16. }

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

  1. @Test
  2. public void shouldCreateTheRelationshipInANewCurrentStatePreservingTheOldOne() {
  3. try (Driver driver = GraphDatabase
  4. .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  5. // Given
  6. Node entityA = initEntity(session);
  7. Node entityB = initEntity(session);
  8. String testType = "testType";
  9. Long entityACurrentId = session.run(String.format("MATCH (e:Entity)-[:CURRENT]->(s:State) WHERE id(e) = %d RETURN s", entityA.id())).single().get("s").asNode().id();
  10. // When
  11. String query = "MATCH (a:Entity), (b:Entity) WHERE id(a) = %d AND id(b) = %d WITH a, b CALL graph.versioner.relationship.create(a, b, '%s') YIELD relationship RETURN relationship";
  12. Relationship relationship = session.run(String.format(query, entityA.id(), entityB.id(), testType)).single().get("relationship").asRelationship();
  13. // Then
  14. String querySourceStates = "MATCH (:R)<-[r:%s]-(s1:State)-[:PREVIOUS]->(s2:State) WHERE id(r) = %d RETURN s1, s2";
  15. StatementResult result = session.run(String.format(querySourceStates, testType, relationship.id()));
  16. assertThat(result)
  17. .hasSize(1)
  18. .allMatch(r -> r.get("s1").asNode().id() != r.get("s2").asNode().id() && r.get("s2").asNode().id() == entityACurrentId);
  19. }
  20. }

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

  1. @Test
  2. public void originalIds() throws ExecutionException, InterruptedException {
  3. String uri = "//localhost:" + gremlinServer.getPort();
  4. String uuid = "ef8b80c9-f8f9-40b6-bad2-ee4757d5bb33";
  5. gremlinServer.gremlinClient().submit(format("g.addV('VertexWithStringId').property(id, '%s')", uuid)).all().get();
  6. // freshReadmeSnippet: originalIds
  7. Config config = Config.build()
  8. .withTranslation(TranslatorFlavor.gremlinServer())
  9. .ignoreIds()
  10. .toConfig();
  11. Driver driver = GremlinDatabase.driver(uri, config);
  12. try (Session session = driver.session()) {
  13. StatementResult getOriginal = session.run("MATCH (n:VertexWithStringId) RETURN id(n) as id");
  14. Object originalId = getOriginal.single().get("id").asObject();
  15. assertThat(originalId).isEqualTo(uuid); // ef8b80c9-f8f9-40b6-bad2-ee4757d5bb33
  16. StatementResult result = session.run("MATCH (n) WHERE id(n) = $originalId RETURN n", singletonMap("originalId", originalId));
  17. Node n = result.single().get("n").asNode();
  18. assertThat(n.id()).isEqualTo(-1); // -1
  19. }
  20. // freshReadmeSnippet: originalIds
  21. }
  22. }

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

  1. @Test
  2. public void shouldCreateAnRNodeConnectedToTheEntity() throws Throwable {
  3. try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
  4. StatementResult result = session.run("CALL graph.versioner.init('Entity')");
  5. StatementResult rPath = session.run("MATCH rPath = (:R)-[:FOR]->(:Entity) RETURN rPath");
  6. Assertions.assertThat(result.single().get("node").asNode().id()).isEqualTo(0L);
  7. Assertions.assertThat(rPath)
  8. .hasSize(1)
  9. .allMatch(path -> path.get("rPath").asPath().length() == 1);
  10. }
  11. }
  12. }

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

  1. @Test
  2. public void shouldCreateAnEntityAndAStateNodeWithoutPropsIfEmptyMapIsPassed() 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')");
  8. StatementResult stateResult = session.run("MATCH (s:State) RETURN s");
  9. StatementResult currentResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN id(e) as id");
  10. Node state = stateResult.single().get("s").asNode();
  11. // Then
  12. assertThat(result.single().get("node").asNode().id(), equalTo(0L));
  13. assertThat(state.id(), equalTo(1L));
  14. assertThat(currentResult.single().get("id").asLong(), equalTo(0L));
  15. }
  16. }

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

  1. @Test
  2. public void ignoreIds() throws ExecutionException, InterruptedException {
  3. gremlinServer.gremlinClient().submit("g.addV('stringId1').property(id, 'string1')").all().get();
  4. gremlinServer.gremlinClient().submit("g.addV('stringId1').property(id, 'string2')").all().get();
  5. // freshReadmeSnippet: ignoreIds
  6. Config config = Config.build()
  7. .ignoreIds()
  8. .toConfig();
  9. // freshReadmeSnippet: ignoreIds
  10. Driver driver = GremlinDatabase.driver("//localhost:" + gremlinServer.getPort(), config);
  11. try (Session session = driver.session()) {
  12. StatementResult result = session.run("MATCH (n:stringId1) RETURN n");
  13. assertThat(result.list())
  14. .extracting(r -> r.get("n").asNode().id())
  15. .containsExactly(-1L, -1L);
  16. }
  17. }

相关文章