本文整理了Java中org.neo4j.driver.v1.types.Node.id()
方法的一些代码示例,展示了Node.id()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.id()
方法的具体详情如下:
包路径:org.neo4j.driver.v1.types.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: neo4j/neo4j-ogm
public long nodeId(Object node) {
return ((Node) node).id();
}
代码示例来源:origin: org.neo4j/neo4j-ogm-bolt-driver
public long nodeId(Object node) {
return ((Node) node).id();
}
代码示例来源:origin: org.neo4j.driver/neo4j-java-driver
@Override
public String toString()
{
return String.format( relationship.startNodeId() == start.id() ?
"(%s)-[%s:%s]->(%s)" : "(%s)<-[%s:%s]-(%s)",
start.id(), relationship.id(), relationship.type(), end.id() );
}
}
代码示例来源:origin: org.neo4j.driver/neo4j-java-driver
private static boolean isEndpoint( Node node, Relationship relationship )
{
return node.id() == relationship.startNodeId() || node.id() == relationship.endNodeId();
}
代码示例来源:origin: net.iot-solutions.graphdb/jcypher
@SuppressWarnings("unchecked")
@Override
public long gePathtNodeIdAt(PathInfo pathInfo, int index) {
Object obj = pathInfo.getContentObject();
List<Node> nodes = null;
if (obj instanceof List<?>)
nodes = (List<Node>) obj;
else if (obj instanceof Path) {
nodes = new ArrayList<Node>();
Iterator<Node> it = ((Path)obj).nodes().iterator();
while(it.hasNext())
nodes.add(it.next());
pathInfo.setContentObject(nodes);
}
return nodes.get(index).id();
}
代码示例来源:origin: Wolfgang-Schuetzelhofer/jcypher
@SuppressWarnings("unchecked")
@Override
public long gePathtNodeIdAt(PathInfo pathInfo, int index) {
Object obj = pathInfo.getContentObject();
List<Node> nodes = null;
if (obj instanceof List<?>)
nodes = (List<Node>) obj;
else if (obj instanceof Path) {
nodes = new ArrayList<Node>();
Iterator<Node> it = ((Path)obj).nodes().iterator();
while(it.hasNext())
nodes.add(it.next());
pathInfo.setContentObject(nodes);
}
return nodes.get(index).id();
}
代码示例来源:origin: neueda/jetbrains-plugin-graph-database-support
public Neo4jBoltNode(Node value) {
this.id = String.valueOf(value.id());
this.types = Iterables.asList(value.labels());
this.propertyContainer = new Neo4jBoltPropertyContainer(value.asMap());
}
代码示例来源:origin: neo4j/cypher-shell
@Nonnull
default String pathAsString(@Nonnull Path path) {
List<String> list = new ArrayList<>(path.length());
Node lastTraversed = path.start();
if (lastTraversed != null) {
list.add(nodeAsString(lastTraversed));
for (Path.Segment segment : path) {
Relationship relationship = segment.relationship();
if (relationship.startNodeId() == lastTraversed.id()) {
list.add("-" + relationshipAsString(relationship) + "->");
} else {
list.add("<-" + relationshipAsString(relationship) + "-");
}
list.add(nodeAsString(segment.end()));
lastTraversed = segment.end();
}
}
return list.stream().collect(Collectors.joining());
}
代码示例来源:origin: net.iot-solutions.graphdb/jcypher
public static ElementInfo fromRecordValue(Value val) {
if (val instanceof ListValue)
return ElementInfo.fromRecordValue(((ListValue)val).get(0));
ElementInfo ret = null;
if (val != null) {
String typName = val.type().name(); // NODE, RELATIONSHIP, NULL
if ("NODE".equals(typName)) {
ret = new ElementInfo();
ret.isNull = false;
ret.id = val.asNode().id();
ret.type = ElemType.NODE;
} else if ("RELATIONSHIP".equals(typName)) {
ret = new ElementInfo();
ret.isNull = false;
ret.id = val.asRelationship().id();
ret.type = ElemType.RELATION;
} else if ("NULL".equals(typName))
ret = ElementInfo.nullElement();
}
return ret;
}
代码示例来源: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: h-omer/neo4j-versioner-core
@Test
public void shouldMaintainTheRelationshipsFromTheCurrentState() throws Throwable {
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
Node entityA = initEntity(session);
Node entityB = initEntity(session);
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)";
session.run(String.format(createEntityRelationshipQuery, entityA.id(), entityB.id()));
// When
String patchQuery = "MATCH (e:Entity) WHERE id(e) = %d WITH e CALL graph.versioner.patch(e) YIELD node RETURN node";
StatementResult result = session.run(String.format(patchQuery, entityA.id()));
// Then
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())))
.hasSize(1);
}
}
代码示例来源: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: h-omer/neo4j-versioner-core
@Test
public void shouldNotCreateTheRelationshipIfSourceIsNotAnEntity() throws Throwable {
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
Node entityA = session.run("CREATE (e:Entity) RETURN e").single().get("e").asNode(); //Not an entity because missing states and R
Node entityB = initEntity(session);
String testType = "testType";
// When
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";
assertThat(session.run(String.format(query, entityA.id(), entityB.id(), testType)));
Throwable thrown = catchThrowable(() -> session.run(String.format(query, entityA.id(), entityB.id(), testType)));
//Then
assertThat(thrown).hasMessageContaining("The given node is not a Versioner Core Entity");
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldNotCreateTheRelationshipIfDestinationIsNotAnEntity() throws Throwable {
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
Node entityA = initEntity(session);
Node entityB = session.run("CREATE (e:Entity) RETURN e").single().get("e").asNode(); //Not an entity because missing states and R
String testType = "testType";
// When
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";
assertThat(session.run(String.format(query, entityA.id(), entityB.id(), testType)));
Throwable thrown = catchThrowable(() -> session.run(String.format(query, entityA.id(), entityB.id(), testType)));
//Then
assertThat(thrown).hasMessageContaining("The given node is not a Versioner Core Entity");
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldCreateTheRelationshipInANewCurrentStatePreservingTheOldOne() {
try (Driver driver = GraphDatabase
.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
// Given
Node entityA = initEntity(session);
Node entityB = initEntity(session);
String testType = "testType";
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();
// When
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";
Relationship relationship = session.run(String.format(query, entityA.id(), entityB.id(), testType)).single().get("relationship").asRelationship();
// Then
String querySourceStates = "MATCH (:R)<-[r:%s]-(s1:State)-[:PREVIOUS]->(s2:State) WHERE id(r) = %d RETURN s1, s2";
StatementResult result = session.run(String.format(querySourceStates, testType, relationship.id()));
assertThat(result)
.hasSize(1)
.allMatch(r -> r.get("s1").asNode().id() != r.get("s2").asNode().id() && r.get("s2").asNode().id() == entityACurrentId);
}
}
代码示例来源:origin: opencypher/cypher-for-gremlin
@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
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldCreateAnRNodeConnectedToTheEntity() throws Throwable {
try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {
StatementResult result = session.run("CALL graph.versioner.init('Entity')");
StatementResult rPath = session.run("MATCH rPath = (:R)-[:FOR]->(:Entity) RETURN rPath");
Assertions.assertThat(result.single().get("node").asNode().id()).isEqualTo(0L);
Assertions.assertThat(rPath)
.hasSize(1)
.allMatch(path -> path.get("rPath").asPath().length() == 1);
}
}
}
代码示例来源:origin: h-omer/neo4j-versioner-core
@Test
public void shouldCreateAnEntityAndAStateNodeWithoutPropsIfEmptyMapIsPassed() 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')");
StatementResult stateResult = session.run("MATCH (s:State) RETURN s");
StatementResult currentResult = session.run("MATCH (e:Entity)-[:CURRENT]->(s:State) RETURN id(e) as id");
Node state = stateResult.single().get("s").asNode();
// Then
assertThat(result.single().get("node").asNode().id(), equalTo(0L));
assertThat(state.id(), equalTo(1L));
assertThat(currentResult.single().get("id").asLong(), equalTo(0L));
}
}
代码示例来源:origin: opencypher/cypher-for-gremlin
@Test
public void ignoreIds() throws ExecutionException, InterruptedException {
gremlinServer.gremlinClient().submit("g.addV('stringId1').property(id, 'string1')").all().get();
gremlinServer.gremlinClient().submit("g.addV('stringId1').property(id, 'string2')").all().get();
// freshReadmeSnippet: ignoreIds
Config config = Config.build()
.ignoreIds()
.toConfig();
// freshReadmeSnippet: ignoreIds
Driver driver = GremlinDatabase.driver("//localhost:" + gremlinServer.getPort(), config);
try (Session session = driver.session()) {
StatementResult result = session.run("MATCH (n:stringId1) RETURN n");
assertThat(result.list())
.extracting(r -> r.get("n").asNode().id())
.containsExactly(-1L, -1L);
}
}
内容来源于网络,如有侵权,请联系作者删除!