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

x33g5p2x  于2022-01-28 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(164)

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

Relationship.getId介绍

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

代码示例

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

@Override
  public long id( PropertyContainer entity )
  {
    return ((Relationship) entity).getId();
  }
};

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

@Override
public String getIdentity()
{
  return Long.toString( rel.getId() );
}

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

@Override
long getId( Path source )
{
  return source.lastRelationship().getId();
}

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

@SuppressWarnings( "boxing" )
public IndexedEntityRepresentation( Relationship rel, String key, String value,
    IndexRepresentation indexRepresentation )
{
  this( new RelationshipRepresentation( rel ), rel.getId(), key, value, indexRepresentation );
}

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

public int compareTo( Object rel )
{
  Relationship r = (Relationship) rel;
  return Long.compare( this.getId(), r.getId() );
}

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

@Override
public boolean equals( Object o )
{
  return o instanceof Relationship && this.getId() == ((Relationship) o).getId();
}

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

@Mapping( "metadata" )
public MapRepresentation metadata()
{
  if ( isDeleted() )
  {
    return new MapRepresentation( map( "id", rel.getId(), "deleted", Boolean.TRUE ) );
  }
  else
  {
    return new MapRepresentation( map( "id", rel.getId(), "type", rel.getType().name() ) );
  }
}

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

private static void getRelationshipByIdReadOnly( long index )
  {
    Relationship value = graphDbReadOnly.getRelationshipById( index );
    fail( String.format( "Returned Relationship [0x%x] for index 0x%x (int value: 0x%x)",
        value.getId(), index, (int) index ) );
  }
}

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

private static Relationship mockRelationship( long id, Node start, String type, Node end, Properties properties )
{
  Relationship relationship = mockPropertyContainer( Relationship.class, properties );
  when( relationship.getId() ).thenReturn( id );
  when( relationship.getStartNode() ).thenReturn( start );
  when( relationship.getEndNode() ).thenReturn( end );
  when( relationship.getType() ).thenReturn( RelationshipType.withName( type ) );
  return relationship;
}

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

@Test
public void correctlySaysRelIsDeleted()
{
  // Given
  state.relationshipDoDelete( 1L, 1, 1L, 2L );
  Relationship rel = mock( Relationship.class );
  when( rel.getId() ).thenReturn( 1L );
  ops.withRelationship( 1L, 1L, 1, 2L );
  // When & Then
  assertThat( snapshot().isDeleted( rel ), equalTo( true ) );
}

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

private static Function<Node,StartRelationship> loop( String type )
  {
    return node ->
    {
      RelationshipType relType = withName( type );
      return new StartRelationship(
          node.createRelationshipTo( node, relType ).getId(),
          Direction.BOTH,
          relType );
    };
  }
}

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

@Override
protected long createPropertyContainer()
{
  return db.createNode().createRelationshipTo( db.createNode(), withName( "FOO" ) ).getId();
}

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

long createRelationshipWithProperty( long firstNodeId, long secondNodeId, String propertyKey, Object propertyValue )
{
  Node first = db.getNodeById( firstNodeId );
  Node second = db.getNodeById( secondNodeId );
  Relationship relationship = first.createRelationshipTo( second, RELTYPE );
  relationship.setProperty( propertyKey, propertyValue );
  return relationship.getId();
}

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

private static long createRelationship( GraphDatabaseService db )
{
  long relationshipId;
  try ( Transaction tx = db.beginTx() )
  {
    Node start = db.createNode( Label.label( System.currentTimeMillis() + "" ) );
    Node end = db.createNode( Label.label( System.currentTimeMillis() + "" ) );
    relationshipId = start.createRelationshipTo( end, withName( "KNOWS" ) ).getId();
    tx.success();
  }
  return relationshipId;
}

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

private static Function<Node,StartRelationship> outgoing( String type )
{
  return node ->
  {
    GraphDatabaseService db = node.getGraphDatabase();
    RelationshipType relType = withName( type );
    return new StartRelationship(
        node.createRelationshipTo( db.createNode(), relType ).getId(),
        Direction.OUTGOING,
        relType );
  };
}

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

private static Function<Node,StartRelationship> incoming( String type )
{
  return node ->
  {
    GraphDatabaseService db = node.getGraphDatabase();
    RelationshipType relType = withName( type );
    return new StartRelationship(
        db.createNode().createRelationshipTo( node, relType ).getId(),
        Direction.INCOMING,
        relType );
  };
}

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

private Runnable getById()
{
  return () ->
  {
    dbr.getGraphDatabaseAPI().getNodeById( node.getId() );
    dbr.getGraphDatabaseAPI().getRelationshipById( relationship.getId() );
  };
}

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

private long initWithRel( GraphDatabaseService db )
{
  try ( Transaction tx = db.beginTx() )
  {
    Node node = db.createNode();
    node.setProperty( "a", "prop" );
    Relationship rel = node.createRelationshipTo( db.createNode(), RelationshipType.withName( "T" ) );
    long id = rel.getId();
    tx.success();
    return id;
  }
}

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

@Test
@Title( "Remove properties from a relationship" )
@Graph( nodes = {@NODE( name = "Romeo", setNameProperty = true ),
    @NODE( name = "Juliet", setNameProperty = true )}, relationships = {
    @REL( start = "Romeo", end = "Juliet", type = "LOVES", properties = {
        @PROP( key = "cost", value = "high", type = GraphDescription.PropType.STRING )} )} )
public void shouldReturn204WhenPropertiesAreRemovedFromRelationship()
{
  Relationship loves = getFirstRelationshipFromRomeoNode();
  gen().expectedStatus( Status.NO_CONTENT.getStatusCode() )
      .delete( functionalTestHelper.relationshipPropertiesUri( loves.getId() ) ).entity();
}

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

public long createRelationship( String type, long startNodeId, long endNodeId )
{
  try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.writeToken() ) )
  {
    Node startNode = database.getGraph().getNodeById( startNodeId );
    Node endNode = database.getGraph().getNodeById( endNodeId );
    Relationship relationship = startNode.createRelationshipTo( endNode, RelationshipType.withName( type ) );
    tx.success();
    return relationship.getId();
  }
}

相关文章