org.neo4j.graphdb.Node.getId()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(204)

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

Node.getId介绍

[英]Returns the unique id of this node. Ids are garbage collected over time so they are only guaranteed to be unique during a specific time span: if the node is deleted, it's likely that a new node at some point will get the old id. Note: This makes node ids brittle as public APIs.
[中]返回此节点的唯一id。id会随着时间的推移被垃圾收集,因此它们只能在特定的时间跨度内被保证是唯一的:如果节点被删除,很可能新节点在某个时候会获得旧id。注意:这使得节点id作为公共API变得脆弱。

代码示例

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

  1. private long initWithNode( GraphDatabaseService db )
  2. {
  3. try ( Transaction tx = db.beginTx() )
  4. {
  5. Node theNode = db.createNode();
  6. long id = theNode.getId();
  7. tx.success();
  8. return id;
  9. }
  10. }

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

  1. private long nodeWithNoLabel( GraphDatabaseService graphDb, Object value )
  2. {
  3. Node node = graphDb.createNode();
  4. node.setProperty( "prop", value );
  5. return node.getId();
  6. }

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

  1. @Test
  2. public void testFromSimpleGraph()
  3. {
  4. final Node n0 = gdb.createNode();
  5. final Node n1 = gdb.createNode();
  6. n1.setProperty( "name", "Node1" );
  7. final Relationship relationship = n0.createRelationshipTo( n1, RelationshipType.withName( "REL" ) );
  8. relationship.setProperty( "related", true );
  9. final SubGraph graph = DatabaseSubGraph.from( gdb );
  10. assertEquals( "create (_" + n0.getId() + ")" + lineSeparator() +
  11. "create (_" + n1.getId() + " {`name`:\"Node1\"})" + lineSeparator() +
  12. "create (_" + n0.getId() + ")-[:`REL` {`related`:true}]->(_" + n1.getId() + ")" +
  13. lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) );
  14. }
  15. }

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

  1. @Test
  2. public void shouldReuseExcessBatchIdsWhichWerentUsedBeforeClose() throws Exception
  3. {
  4. // given
  5. Node firstNode;
  6. try ( Transaction tx = db.beginTx() )
  7. {
  8. firstNode = db.createNode();
  9. tx.success();
  10. }
  11. // when
  12. db.restartDatabase();
  13. Node secondNode;
  14. try ( Transaction tx = db.beginTx() )
  15. {
  16. secondNode = db.createNode();
  17. tx.success();
  18. }
  19. // then
  20. assertEquals( firstNode.getId() + 1, secondNode.getId() );
  21. }
  22. }

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

  1. @Test
  2. public void shouldIterateThroughNodesInReverse()
  3. {
  4. // given
  5. Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );
  6. Iterator<Node> iterator = path.reverseNodes().iterator();
  7. Node node;
  8. // then
  9. assertTrue( iterator.hasNext() );
  10. assertThat( node = iterator.next(), instanceOf( Node.class ) );
  11. assertEquals( 3, node.getId() );
  12. assertTrue( iterator.hasNext() );
  13. assertThat( node = iterator.next(), instanceOf( Node.class ) );
  14. assertEquals( 2, node.getId() );
  15. assertTrue( iterator.hasNext() );
  16. assertThat( node = iterator.next(), instanceOf( Node.class ) );
  17. assertEquals( 1, node.getId() );
  18. assertFalse( iterator.hasNext() );
  19. }

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

  1. @Test
  2. public void mixingBeansApiWithKernelAPI() throws Exception
  3. {
  4. // 1: Start your transactions through the Beans API
  5. Transaction transaction = db.beginTx();
  6. // 2: Get a hold of a KernelAPI transaction this way:
  7. KernelTransaction ktx = statementContextSupplier.getKernelTransactionBoundToThisThread( true );
  8. // 3: Now you can interact through both the statement context and the kernel API to manipulate the
  9. // same transaction.
  10. Node node = db.createNode();
  11. int labelId = ktx.tokenWrite().labelGetOrCreateForName( "labello" );
  12. ktx.dataWrite().nodeAddLabel( node.getId(), labelId );
  13. // 4: Commit through the beans API
  14. transaction.success();
  15. transaction.close();
  16. }

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

  1. @Test
  2. public void populatingConstraintMustAcceptDatasetThatGetsUpdatedWithUniqueEntries() throws Exception
  3. {
  4. // Given
  5. givenUniqueDataset();
  6. // When
  7. Future<?> createConstraintTransaction = applyChangesToPopulatingUpdater(
  8. d.getId(), a.getId(), setProperty( d, "d1" ) );
  9. // Then observe that our constraint was created successfully:
  10. createConstraintTransaction.get();
  11. // Future.get() will throw an ExecutionException, if the Runnable threw an exception.
  12. }

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

  1. @Test
  2. public void shouldCreateNode() throws Exception
  3. {
  4. long node;
  5. try ( Transaction tx = beginTransaction() )
  6. {
  7. node = tx.dataWrite().nodeCreate();
  8. tx.success();
  9. }
  10. try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
  11. {
  12. assertEquals( node, graphDb.getNodeById( node ).getId() );
  13. }
  14. }

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

  1. @Test
  2. public void shouldIncludeNodesCreatedInSameTxInIndexSeek()
  3. {
  4. // GIVEN
  5. createNodes( db, LABEL, nonMatching[0], nonMatching[1] );
  6. MutableLongSet expected = createNodes( db, LABEL, values );
  7. // WHEN
  8. MutableLongSet found = new LongHashSet();
  9. try ( Transaction tx = db.beginTx() )
  10. {
  11. expected.add( createNode( db, propertyMap( keys, values ), LABEL ).getId() );
  12. createNode( db, propertyMap( keys, nonMatching[2] ), LABEL );
  13. collectNodes( found, indexSeek.findNodes( keys, values, db ) );
  14. }
  15. // THEN
  16. assertThat( found, equalTo( expected ) );
  17. }

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

  1. @Test
  2. public void indexHitsFromQueryingRemovedDoesNotReturnNegativeCount()
  3. {
  4. Index<Node> index = nodeIndex( LuceneIndexImplementation.EXACT_CONFIG );
  5. Node theNode = graphDb.createNode();
  6. index.remove( theNode );
  7. try ( IndexHits<Node> hits = index.query( "someRandomKey", theNode.getId() ) )
  8. {
  9. assertTrue( hits.size() >= 0 );
  10. }
  11. }

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

  1. private void assertReadNode( String propValue, long expectedNodeId )
  2. {
  3. try ( Transaction tx = db.beginTx() )
  4. {
  5. Node node = db.findNode( LABEL_ONE, propKey, propValue );
  6. assertNotNull( node );
  7. assertEquals( "node id", expectedNodeId, node.getId() );
  8. tx.success();
  9. }
  10. }
  11. }

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

  1. private void verifyIds( EmbeddedProxySPI actions, long relationshipId, long nodeId1, int typeId, long nodeId2 )
  2. {
  3. RelationshipProxy proxy = new RelationshipProxy( actions, relationshipId, nodeId1, typeId, nodeId2 );
  4. assertEquals( relationshipId, proxy.getId() );
  5. // our mock above is known to return RelationshipTypeToken
  6. assertEquals( nodeId1, proxy.getStartNode().getId() );
  7. assertEquals( nodeId1, proxy.getStartNodeId() );
  8. assertEquals( nodeId2, proxy.getEndNode().getId() );
  9. assertEquals( nodeId2, proxy.getEndNodeId() );
  10. assertEquals( nodeId2, proxy.getOtherNode( nodeWithId( nodeId1 ) ).getId() );
  11. assertEquals( nodeId2, proxy.getOtherNodeId( nodeId1 ) );
  12. assertEquals( nodeId1, proxy.getOtherNode( nodeWithId( nodeId2 ) ).getId() );
  13. assertEquals( nodeId1, proxy.getOtherNodeId( nodeId2 ) );
  14. }

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

  1. private long createNode( Map<String, Object> properties, Label... labels )
  2. {
  3. try ( org.neo4j.graphdb.Transaction tx = db.beginTx() )
  4. {
  5. Node node = db.createNode( labels );
  6. for ( Map.Entry<String,Object> property : properties.entrySet() )
  7. {
  8. node.setProperty( property.getKey(), property.getValue() );
  9. }
  10. tx.success();
  11. return node.getId();
  12. }
  13. }

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

  1. public MutableLongSet createNodes( GraphDatabaseService db, Label label, Object[]... propertyValueTuples )
  2. {
  3. MutableLongSet expected = new LongHashSet();
  4. try ( Transaction tx = db.beginTx() )
  5. {
  6. for ( Object[] valueTuple : propertyValueTuples )
  7. {
  8. expected.add( createNode( db, propertyMap( keys, valueTuple ), label ).getId() );
  9. }
  10. tx.success();
  11. }
  12. return expected;
  13. }

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

  1. private long createNode()
  2. {
  3. long node;
  4. try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() )
  5. {
  6. node = graphDb.createNode().getId();
  7. ctx.success();
  8. }
  9. return node;
  10. }

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

  1. @Test
  2. public void testFromSimpleCypherResult()
  3. {
  4. Node n = gdb.createNode();
  5. final ExecutionResult result = result( "node", n );
  6. final SubGraph graph = CypherResultSubGraph.from( result, gdb, false );
  7. assertEquals( "create (_" + n.getId() + ")" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) );
  8. }

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

  1. @Test
  2. public void shouldPrintCypherEsqueRelationshipToString()
  3. {
  4. // GIVEN
  5. Node start;
  6. Node end;
  7. RelationshipType type = RelationshipType.withName( "NICE" );
  8. Relationship relationship;
  9. try ( Transaction tx = db.beginTx() )
  10. {
  11. // GIVEN
  12. start = db.createNode();
  13. end = db.createNode();
  14. relationship = start.createRelationshipTo( end, type );
  15. tx.success();
  16. // WHEN
  17. String toString = relationship.toString();
  18. // THEN
  19. assertEquals( "(" + start.getId() + ")-[" + type + "," + relationship.getId() + "]->(" + end.getId() + ")",
  20. toString );
  21. }
  22. }

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

  1. @Test
  2. public void shouldIterateThroughNodes()
  3. {
  4. // given
  5. Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );
  6. Iterator<Node> iterator = path.nodes().iterator();
  7. Node node;
  8. // then
  9. assertTrue( iterator.hasNext() );
  10. assertThat( node = iterator.next(), instanceOf( Node.class ) );
  11. assertEquals( 1, node.getId() );
  12. assertTrue( iterator.hasNext() );
  13. assertThat( node = iterator.next(), instanceOf( Node.class ) );
  14. assertEquals( 2, node.getId() );
  15. assertTrue( iterator.hasNext() );
  16. assertThat( node = iterator.next(), instanceOf( Node.class ) );
  17. assertEquals( 3, node.getId() );
  18. assertFalse( iterator.hasNext() );
  19. }

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

  1. @Test
  2. public void queryResultsMustIncludeNodesAddedInThisTransaction()
  3. {
  4. db = createDatabase();
  5. try ( Transaction tx = db.beginTx() )
  6. {
  7. createSimpleNodesIndex();
  8. tx.success();
  9. }
  10. awaitIndexesOnline();
  11. try ( Transaction tx = db.beginTx() )
  12. {
  13. Node node = db.createNode( LABEL );
  14. node.setProperty( PROP, "value" );
  15. assertQueryFindsIds( db, true, "nodes", "value", newSetWith( node.getId() ) );
  16. tx.success();
  17. }
  18. }

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

  1. @Test
  2. public void canAcquireReadLock()
  3. {
  4. // when
  5. placeboTx.acquireReadLock( resource );
  6. // then
  7. verify( locks ).acquireSharedNodeLock( resource.getId() );
  8. }

相关文章