org.neo4j.internal.kernel.api.Write.relationshipSetProperty()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(13.0k)|赞(0)|评价(0)|浏览(90)

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

Write.relationshipSetProperty介绍

[英]Set a property on a relationship
[中]设置关系的属性

代码示例

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

transaction.dataWrite().relationshipSetProperty( id, propertyKeyId, Values.of( value, false ) );

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

private void createRelationship( long startNode, String type, long endNode, List<String> propKeys, List<Value> propValues ) throws Throwable
{
  assert type != null && !type.equals( "" );
  assert propKeys.size() == propValues.size();
  Transaction transaction = newTransaction( AnonymousContext.writeToken() );
  int typeId = transaction.tokenWrite().relationshipTypeGetOrCreateForName( type );
  long relId = transaction.dataWrite().relationshipCreate( startNode, typeId, endNode );
  for ( int i = 0; i < propKeys.size(); i++ )
  {
    String propKeyName = propKeys.get( i );
    Value propValue = propValues.get( i );
    int propKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( propKeyName );
    transaction.dataWrite().relationshipSetProperty( relId, propKeyId, propValue );
  }
  commit();
}

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

@Test
public void shouldUpdatePropertyToRelationshipInTransaction() throws Exception
{
  // Given
  long  relationshipId;
  String propertyKey = "prop";
  try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() )
  {
    Node node1 = graphDb.createNode();
    Node node2 = graphDb.createNode();
    relationshipId = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) ).getId();
    tx.success();
  }
  // When
  try ( Transaction tx = beginTransaction() )
  {
    int token = tx.token().propertyKeyGetOrCreateForName( propertyKey );
    assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, token, stringValue( "hello" ) ), equalTo( NO_VALUE ) );
    assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, token, stringValue( "world" ) ), equalTo( stringValue( "hello" ) ) );
    assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, token, intValue( 1337 ) ), equalTo( stringValue( "world" ) ) );
    tx.success();
  }
  // Then
  try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
  {
    assertThat( graphDb.getRelationshipById( relationshipId ).getProperty( "prop" ), equalTo( 1337 ) );
  }
}

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

@Parameterized.Parameters( name = "{0}" )
public static Collection<Object[]> parameters()
{
  // Some samples of operations that should react to transaction killing. Not exhaustive.
  return Arrays.asList(
      operation( "nodeExists", ( read, write, schema ) -> read.nodeExists( 0 ) ),
      operation( "singleRelationship", ( read, write, schema ) -> read.singleRelationship( 0, null ) ),
      operation( "nodeCreate", ( read, write, schema ) -> write.nodeCreate() ),
      operation( "relationshipSetProperty", ( read, write, schema ) -> write.relationshipSetProperty( 0, 2, Values.longValue( 42 ) ) ),
      operation( "indexesGetAll", ( read, write, schema ) -> schema.indexesGetAll() ) );
}

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

@Test
  public void shouldNotWriteWhenSettingPropertyToSameValue() throws Exception
  {
    // Given
    long relationshipId;
    String propertyKey = "prop";
    Value theValue = stringValue( "The Value" );

    try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() )
    {
      Node node1 = graphDb.createNode();
      Node node2 = graphDb.createNode();

      Relationship r = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) );

      r.setProperty( propertyKey, theValue.asObject() );
      relationshipId = r.getId();
      ctx.success();
    }

    // When
    Transaction tx = beginTransaction();
    int property = tx.token().propertyKeyGetOrCreateForName( propertyKey );
    assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, property, theValue ), equalTo( theValue ) );
    tx.success();

    assertThat( tx.closeTransaction(), equalTo( Transaction.READ_ONLY ) );
  }
}

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

@Test
public void shouldAddPropertyToRelationship() throws Exception
{
  // Given
  long  relationshipId;
  String propertyKey = "prop";
  try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() )
  {
    Node node1 = graphDb.createNode();
    Node node2 = graphDb.createNode();
    relationshipId = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) ).getId();
    tx.success();
  }
  // When
  try ( Transaction tx = beginTransaction() )
  {
    int token = tx.token().propertyKeyGetOrCreateForName( propertyKey );
    assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, token, stringValue( "hello" ) ), equalTo( NO_VALUE ) );
    tx.success();
  }
  // Then
  try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
  {
    assertThat( graphDb.getRelationshipById( relationshipId ).getProperty( "prop" ), equalTo( "hello" ) );
  }
}

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

@Test
public void shouldUpdatePropertyToRelationship() throws Exception
{
  // Given
  long  relationshipId;
  String propertyKey = "prop";
  try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() )
  {
    Node node1 = graphDb.createNode();
    Node node2 = graphDb.createNode();
    Relationship r = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) );
    r.setProperty( propertyKey, 42  );
    relationshipId = r.getId();
    tx.success();
  }
  // When
  try ( Transaction tx = beginTransaction() )
  {
    int token = tx.token().propertyKeyGetOrCreateForName( propertyKey );
    assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, token, stringValue( "hello" ) ),
        equalTo( intValue( 42 ) ) );
    tx.success();
  }
  // Then
  try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
  {
    assertThat( graphDb.getRelationshipById( relationshipId ).getProperty( "prop" ), equalTo( "hello" ) );
  }
}

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

@Test
  public void shouldBeAbleToRemoveResetAndTwiceRemovePropertyOnRelationship() throws Exception
  {
    // given
    Transaction transaction = newTransaction( AnonymousContext.writeToken() );
    int prop = transaction.tokenWrite().propertyKeyGetOrCreateForName( "foo" );
    int type = transaction.tokenWrite().relationshipTypeGetOrCreateForName( "RELATED" );

    long startNodeId = transaction.dataWrite().nodeCreate();
    long endNodeId = transaction.dataWrite().nodeCreate();
    long rel = transaction.dataWrite().relationshipCreate( startNodeId, type, endNodeId );
    transaction.dataWrite().relationshipSetProperty( rel, prop, Values.of( "bar" ) );

    commit();

    // when
    Write write = dataWriteInNewTransaction();
    write.relationshipRemoveProperty( rel, prop );
    write.relationshipSetProperty( rel, prop, Values.of( "bar" ) );
    write.relationshipRemoveProperty( rel, prop );
    write.relationshipRemoveProperty( rel, prop );

    commit();

    // then
    transaction = newTransaction();
    assertThat( relationshipGetProperty(transaction, rel, prop ), equalTo( Values.NO_VALUE ) );
    commit();
  }
}

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

@Test
public void shouldNotAllowModifyingPropertiesOnDeletedRelationship() throws Exception
{
  // given
  Transaction transaction = newTransaction( AnonymousContext.writeToken() );
  int prop1 = transaction.tokenWrite().propertyKeyGetOrCreateForName( "prop1" );
  int type = transaction.tokenWrite().relationshipTypeGetOrCreateForName( "RELATED" );
  long startNodeId = transaction.dataWrite().nodeCreate();
  long endNodeId = transaction.dataWrite().nodeCreate();
  long rel = transaction.dataWrite().relationshipCreate( startNodeId, type, endNodeId );
  transaction.dataWrite().relationshipSetProperty( rel, prop1, Values.stringValue( "As" ) );
  transaction.dataWrite().relationshipDelete( rel );
  // When
  try
  {
    transaction.dataWrite().relationshipRemoveProperty( rel, prop1 );
    fail( "Should have failed." );
  }
  catch ( EntityNotFoundException e )
  {
    assertThat( e.getMessage(), equalTo( "Unable to load RELATIONSHIP with id " + rel + "." ) );
  }
  commit();
}

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

@Test
public void propertyTypeShouldBeTxStateAware() throws Exception
{
  // Given
  long relationship;
  try ( Transaction tx = beginTransaction() )
  {
    Write write = tx.dataWrite();
    int token = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" );
    relationship = write.relationshipCreate( write.nodeCreate(), token, write.nodeCreate() );
    tx.success();
  }
  // Then
  try ( Transaction tx = beginTransaction() )
  {
    try ( RelationshipScanCursor relationships = tx.cursors().allocateRelationshipScanCursor();
       PropertyCursor properties = tx.cursors().allocatePropertyCursor() )
    {
      tx.dataRead().singleRelationship( relationship, relationships );
      assertTrue( relationships.next() );
      assertFalse( hasProperties( relationships, tx ) );
      int prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" );
      tx.dataWrite().relationshipSetProperty( relationship, prop, stringValue( "foo" ) );
      relationships.properties( properties );
      assertTrue( properties.next() );
      assertThat( properties.propertyType(), equalTo( ValueGroup.TEXT ) );
    }
  }
}

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

tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ), write.nodeCreate() );
propToken1 = tx.token().propertyKeyGetOrCreateForName( propKey1 );
assertEquals( write.relationshipSetProperty( relationshipId, propToken1, stringValue( "hello" ) ),
    NO_VALUE );
tx.success();
assertEquals( tx.dataWrite().relationshipSetProperty( relationshipId, propToken2, stringValue( "world" ) ),
    NO_VALUE );

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

prop2 = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop2" );
prop3 = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop3" );
tx.dataWrite().relationshipSetProperty( relationship, prop1, longValue( 1 ) );
tx.dataWrite().relationshipSetProperty( relationship, prop2, longValue( 2 ) );
tx.dataWrite().relationshipSetProperty( relationship, prop3, longValue( 3 ) );
tx.success();

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

tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ), write.nodeCreate() );
propToken = tx.token().propertyKeyGetOrCreateForName( propKey );
assertEquals( write.relationshipSetProperty( relationshipId, propToken, stringValue( "hello" ) ),
    NO_VALUE );
tx.success();
assertEquals( tx.dataWrite().relationshipSetProperty( relationshipId, propToken, stringValue( "world" ) ),
    stringValue( "hello" ) );
try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor();

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

tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ), write.nodeCreate() );
propToken = tx.token().propertyKeyGetOrCreateForName( propKey );
assertEquals( write.relationshipSetProperty( relationshipId, propToken, stringValue( "hello" ) ),
    NO_VALUE );
tx.success();
assertEquals( tx.dataWrite().relationshipSetProperty( relationshipId, propToken, stringValue( "world" ) ),
    NO_VALUE );
try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor();

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

@Test
public void hasPropertiesShouldSeeNewlyCreatedPropertiesOnNewlyCreatedRelationship() throws Exception
{
  try ( Transaction tx = beginTransaction() )
  {
    Write write = tx.dataWrite();
    int token = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" );
    long relationship = write.relationshipCreate( write.nodeCreate(), token, write.nodeCreate() );
    try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor() )
    {
      tx.dataRead().singleRelationship( relationship, cursor );
      assertTrue( cursor.next() );
      assertFalse( hasProperties( cursor, tx ) );
      tx.dataWrite().relationshipSetProperty( relationship,
          tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ),
          stringValue( "foo" ) );
      assertTrue( hasProperties( cursor, tx ) );
    }
  }
}

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

assertEquals( tx.dataWrite().relationshipSetProperty( relationshipId, propToken, stringValue( "hello" ) ),
    NO_VALUE );

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

@Test
public void hasPropertiesShouldSeeNewlyCreatedProperties() throws Exception
{
  // Given
  long relationship;
  try ( Transaction tx = beginTransaction() )
  {
    Write write = tx.dataWrite();
    int token = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" );
    relationship = write.relationshipCreate( write.nodeCreate(),
        token,
        write.nodeCreate() );
    tx.success();
  }
  // Then
  try ( Transaction tx = beginTransaction() )
  {
    try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor() )
    {
      tx.dataRead().singleRelationship( relationship, cursor );
      assertTrue( cursor.next() );
      assertFalse( hasProperties( cursor, tx ) );
      tx.dataWrite().relationshipSetProperty( relationship,
          tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ),
          stringValue( "foo" ) );
      assertTrue( hasProperties( cursor, tx ) );
    }
  }
}

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

int prop1 = tx.token().propertyKeyGetOrCreateForName( propKey1 );
int prop2 = tx.token().propertyKeyGetOrCreateForName( propKey2 );
assertEquals( tx.dataWrite().relationshipSetProperty( r, prop1, stringValue( "hello" ) ), NO_VALUE );
assertEquals( tx.dataWrite().relationshipSetProperty( r, prop2, stringValue( "world" ) ), NO_VALUE );

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

tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ), write.nodeCreate() );
propToken = tx.token().propertyKeyGetOrCreateForName( propKey );
assertEquals( write.relationshipSetProperty( relationshipId, propToken, stringValue( "hello" ) ),
    NO_VALUE );
tx.success();

代码示例来源:origin: neo4j-contrib/neo4j-graph-algorithms

private void export(SimilarityResult similarityResult) {
  applyInTransaction(statement -> {
    long node1 = similarityResult.item1;
    long node2 = similarityResult.item2;
    try {
      long relationshipId = statement.dataWrite().relationshipCreate(node1, relationshipTypeId, node2);
      statement.dataWrite().relationshipSetProperty(
          relationshipId, propertyId, Values.doubleValue(similarityResult.similarity));
    } catch (KernelException e) {
      ExceptionUtil.throwKernelException(e);
    }
    return null;
  });
}

相关文章