org.neo4j.internal.kernel.api.Write类的使用及代码示例

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

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

Write介绍

[英]Defines the write operations of the Kernel API.
[中]定义内核API的写操作。

代码示例

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

private long createNodeWithValues( Value value1, Value value2 ) throws KernelException
{
  Write write = dataWriteInNewTransaction();
  long nodeId = write.nodeCreate();
  write.nodeAddLabel( nodeId, labelId );
  write.nodeSetProperty( nodeId, propertyId1, value1 );
  write.nodeSetProperty( nodeId, propertyId2, value2 );
  commit();
  return nodeId;
}

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

@Test
public void shouldHandleMultipleNodeDeletions() throws Exception
{
  long nodeId;
  try ( Transaction tx = beginTransaction() )
  {
    nodeId = tx.dataWrite().nodeCreate();
    tx.success();
  }
  try ( Transaction tx = beginTransaction() )
  {
    assertTrue( tx.dataWrite().nodeDelete( nodeId ) );
    assertFalse( tx.dataWrite().nodeDelete( nodeId ) );
    tx.success();
  }
}

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

private long createNode( Write write, int... labels ) throws KernelException
  {
    long nodeId = write.nodeCreate();
    for ( int label : labels )
    {
      write.nodeAddLabel( nodeId, label );
    }
    return nodeId;
  }
}

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

private void createRelationship( RelationshipDirection direction, long start, int type, Write write )
      throws EntityNotFoundException
  {
    switch ( direction )
    {
    case OUT:
      write.relationshipCreate( start, type, write.nodeCreate() );
      break;
    case IN:
      write.relationshipCreate( write.nodeCreate(), type, start );
      break;
    case LOOP:
      write.relationshipCreate( start, type, start );
      break;
    default:
      throw new IllegalStateException( "Checkstyle, you win again!" );
    }
  }
}

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

tx.dataWrite().relationshipCreate( tx.dataWrite().nodeCreate(), type, start.id );
    tx.dataWrite().relationshipCreate( tx.dataWrite().nodeCreate(), type, start.id );
    break;
  case OUTGOING:
    tx.dataWrite().relationshipCreate( start.id, type, tx.dataWrite().nodeCreate() );
    tx.dataWrite().relationshipCreate( start.id, type, tx.dataWrite().nodeCreate() );
    break;
  case BOTH:
    tx.dataWrite().relationshipCreate( start.id, type, start.id );
    tx.dataWrite().relationshipCreate( start.id, type, start.id );
    break;
  default:
    throw new IllegalStateException( "Oh ye be cursed, foul checkstyle!" );
  tx.dataWrite().relationshipDelete( head.id );
  expectedCounts.put( kv.getKey(), rs.size() + 1 );
tx.dataWrite().relationshipCreate( tx.dataWrite().nodeCreate(), newType, start.id );
tx.dataWrite().relationshipCreate( start.id, newType, tx.dataWrite().nodeCreate() );
tx.dataWrite().relationshipCreate( start.id, newType, start.id );

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

try ( Transaction tx = beginTransaction() )
  node = tx.dataWrite().nodeCreate();
  prop1 = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop1" );
  prop2 = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop2" );
  prop3 = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop3" );
  tx.dataWrite().nodeSetProperty( node, prop1, longValue( 1 ) );
  tx.dataWrite().nodeSetProperty( node, prop2, longValue( 2 ) );
  tx.dataWrite().nodeSetProperty( node, prop3, longValue( 3 ) );
  tx.success();
    tx.dataWrite().nodeRemoveProperty( node, prop1 );
    assertTrue( hasProperties( cursor, props ) );
    tx.dataWrite().nodeRemoveProperty( node, prop2 );
    assertTrue( hasProperties( cursor, props ) );
    tx.dataWrite().nodeRemoveProperty( node, prop3 );
    assertFalse( hasProperties( cursor, props ) );

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

private void createNodeWithProperty( Transaction tx, int propId1 ) throws KernelException
{
  long node = tx.dataWrite().nodeCreate();
  tx.dataWrite().nodeSetProperty( node, propId1, Values.intValue( 42 ) );
}

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

private void setProperty( long nodeId, int propertyId, Object value ) throws KernelException
{
  transaction.dataWrite().nodeSetProperty( nodeId, propertyId, Values.of( value ) );
}

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

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 shouldRemoveReSetAndTwiceRemovePropertyOnNode() throws Exception
{
  // given
  long node = createNodeWithProperty( propertyKey, "bar" );
  // when
  try ( Transaction tx = beginTransaction() )
  {
    int prop = tx.token().propertyKeyGetOrCreateForName( propertyKey );
    tx.dataWrite().nodeRemoveProperty( node, prop );
    tx.dataWrite().nodeSetProperty( node, prop, Values.of( "bar" ) );
    tx.dataWrite().nodeRemoveProperty( node, prop );
    tx.dataWrite().nodeRemoveProperty( node, prop );
    tx.success();
  }
  // then
  assertNoProperty( node, propertyKey );
}

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

private void addLabel( long nodeId, int labelId ) throws KernelException
{
  transaction.dataWrite().nodeAddLabel( nodeId, labelId );
}

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

@Test
public void shouldFindSwappedNodeInLabelScan() throws Exception
{
  // Given
  Node node1 = createNode( "label" );
  Node node2 = createNode();
  try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction();
     NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor() )
  {
    // when
    tx.dataWrite().nodeRemoveLabel( node1.node, node1.labels[0] );
    tx.dataWrite().nodeAddLabel( node2.node, node1.labels[0] );
    tx.dataRead().nodeLabelScan( node1.labels[0], cursor );
    // then
    assertTrue( cursor.next() );
    assertEquals( node2.node, cursor.nodeReference() );
  }
}

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

@Ignore
public void shouldNotFindNodeWithAllRemovedLabelsInDisjunctionLabelScan() throws Exception
{
  // Given
  Node node = createNode( "label1", "label2" );
  try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction();
     NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor() )
  {
    // when
    tx.dataWrite().nodeRemoveLabel( node.node, node.labels[0] );
    tx.dataWrite().nodeRemoveLabel( node.node, node.labels[1] );
    tx.dataRead().nodeLabelUnionScan( cursor, node.labels );
    // then
    assertFalse( cursor.next() );
  }
}

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

@Test
public void shouldNotRemoveNodeThatDoesNotExist() throws Exception
{
  long node = 0;
  try ( Transaction tx = beginTransaction() )
  {
    assertFalse( tx.dataWrite().nodeDelete( node ) );
    tx.failure();
  }
  try ( Transaction tx = beginTransaction() )
  {
    assertFalse( tx.dataWrite().nodeDelete( node ) );
    tx.success();
  }
  // should not crash
}

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

@Test
public void txReturnsCorrectIdWhenFailedAndMarkedForTermination() throws Exception
{
  executeDummyTxs( db, 42 );
  org.neo4j.internal.kernel.api.Transaction tx = newTransaction( AUTH_DISABLED );
  tx.dataWrite().nodeCreate();
  tx.failure();
  tx.markForTermination( Status.Transaction.Terminated );
  assertEquals( KernelTransaction.ROLLBACK, tx.closeTransaction() );
  assertFalse( tx.isOpen() );
}

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

@Test
public void shouldDeleteRelationshipAddedInTransaction() throws Exception
{
  long n1, n2;
  try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() )
  {
    n1 = graphDb.createNode().getId();
    n2 = graphDb.createNode().getId();
    tx.success();
  }
  try ( Transaction tx = beginTransaction() )
  {
    int label = tx.token().relationshipTypeGetOrCreateForName( "R" );
    long r = tx.dataWrite().relationshipCreate( n1, label, n2 );
    assertTrue( tx.dataWrite().relationshipDelete( r ) );
    tx.success();
  }
  try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
  {
    assertEquals( 0, graphDb.getNodeById( n1 ).getDegree() );
  }
}

相关文章