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

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

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

Write.nodeRemoveLabel介绍

[英]Remove a label from a node
[中]从节点中删除标签

代码示例

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

@Test
public void shouldNotFindNodeWithRemovedLabelInRangeSearch() throws Exception
{
  // Given
  boolean needsValues = indexProvidesStringValues();
  int label = token.nodeLabel( "Node" );
  int prop = token.propertyKey( "prop" );
  IndexReference index = schemaRead.index( label, prop );
  try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction();
     NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() )
  {
    // when
    tx.dataWrite().nodeRemoveLabel( strOne, label );
    tx.dataWrite().nodeRemoveLabel( strThree1, label );
    tx.dataWrite().nodeRemoveLabel( strThree2, label );
    tx.dataWrite().nodeRemoveLabel( strThree3, label );
    tx.dataRead().nodeIndexSeek( index, node, IndexOrder.NONE, needsValues, IndexQuery.range( prop, "one", true, "three", true ) );
    // then
    assertFalse( node.next() );
  }
}

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

@Override
public void removeLabel( Label label )
{
  KernelTransaction transaction = spi.kernelTransaction();
  try ( Statement ignore = transaction.acquireStatement() )
  {
    int labelId = transaction.tokenRead().nodeLabel( label.name() );
    if ( labelId != TokenRead.NO_TOKEN )
    {
      transaction.dataWrite().nodeRemoveLabel( getId(), labelId );
    }
  }
  catch ( EntityNotFoundException e )
  {
    throw new NotFoundException( "No node with id " + getId() + " found.", e );
  }
  catch ( KernelException e )
  {
    throw new ConstraintViolationException( e.getMessage(), e );
  }
}

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

@Test
public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_RemoveLabel() throws Exception
{
  // given
  long node = createNodeWithLabelAndProps( label, aValues );
  // when
  newTransaction();
  transaction.dataWrite().nodeRemoveLabel( node, label );
  long newNode = createLabeledNode( label );
  setProperties( newNode, aValues );
  // then does not fail
  commit();
}

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

@Test
public void shouldNotSeeNodeThatHasItsLabelRemovedInTransaction() throws Exception
{
  long nodeID = createNode();
  try ( Transaction ignore = graphDatabaseAPI.beginTx() )
  {
    KernelTransaction ktx = ktx();
    ktx.dataWrite().nodeRemoveLabel( nodeID, LABEL_ID );
    try ( NodeValueIndexCursor cursor = seek( ktx ) )
    {
      assertFalse( cursor.next() );
    }
  }
}

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

@Test
public void shouldRemoveLabel() throws Exception
{
  long nodeId = createNodeWithLabel( labelName );
  try ( Transaction tx = beginTransaction() )
  {
    int labelId = tx.token().labelGetOrCreateForName( labelName );
    assertTrue( tx.dataWrite().nodeRemoveLabel( nodeId, labelId ) );
    tx.success();
  }
  assertNoLabels( nodeId );
}

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

@Test
public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_RemoveLabel() throws Exception
{
  // given
  long node = constrainedNode( "Label1", "key1", "value1" );
  Transaction transaction = newTransaction( AnonymousContext.writeToken() );
  // when
  int label = transaction.tokenWrite().labelGetOrCreateForName( "Label1" );
  transaction.dataWrite().nodeRemoveLabel( node, label );
  createLabeledNode( transaction, "Label1", "key1", "value1" );
  commit();
}

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

@Test
public void shouldRemoveLabelOnce() throws Exception
{
  int labelId;
  long nodeId = createNodeWithLabel( labelName );
  try ( Transaction tx = beginTransaction() )
  {
    labelId = tx.token().labelGetOrCreateForName( labelName );
    assertTrue( tx.dataWrite().nodeRemoveLabel( nodeId, labelId ) );
    tx.success();
  }
  try ( Transaction tx = beginTransaction() )
  {
    labelId = tx.token().labelGetOrCreateForName( labelName );
    assertFalse( tx.dataWrite().nodeRemoveLabel( nodeId, labelId ) );
    tx.success();
  }
  assertNoLabels( nodeId );
}

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

@Ignore
public void shouldNotFindNodeWithRemovedLabelInConjunctionLabelScan() 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[1] );
    tx.dataRead().nodeLabelIntersectionScan( cursor, node.labels );
    // then
    assertFalse( cursor.next() );
  }
}

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

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

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

@Test
public void shouldNotCountRemovedLabelsFromTxState() throws Exception
{
  // Given
  Node node1 = createNode( "label" );
  Node node2 = createNode( "label" );
  try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction() )
  {
    // when
    tx.dataWrite().nodeRemoveLabel( node2.node, node2.labels[0] );
    long countTxState = tx.dataRead().countsForNode( node1.labels[0] );
    long countNoTxState = tx.dataRead().countsForNodeWithoutTxState( node1.labels[0] );
    // then
    assertEquals( 1, countTxState );
    assertEquals( 2, countNoTxState );
  }
}

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

@Ignore
public void shouldFindNodeWithOneRemovedLabelInDisjunctionLabelScan() 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[1] );
    tx.dataRead().nodeLabelUnionScan( cursor, node.labels );
    // then
    assertTrue( cursor.next() );
    assertEquals( node.node, cursor.nodeReference() );
  }
}

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

@Test
public void shouldNotFindDNodeWithRemovedLabelInIndexSeek() throws Exception
{
  // Given
  boolean needsValues = false;
  int label = token.nodeLabel( "Node" );
  int prop = token.propertyKey( "prop" );
  IndexReference index = schemaRead.index( label, prop );
  try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction();
     NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() )
  {
    // when
    tx.dataWrite().nodeRemoveLabel( strOne, label );
    tx.dataRead().nodeIndexSeek( index, node, IndexOrder.NONE, needsValues, IndexQuery.exact( prop, "one" ) );
    // then
    assertFalse( node.next() );
  }
}

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

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

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

@Test
public void shouldNotFindNodeWithRemovedLabelInPrefixSearch() throws Exception
{
  // Given
  boolean needsValues = indexProvidesStringValues();
  int label = token.nodeLabel( "Node" );
  int prop = token.propertyKey( "prop" );
  IndexReference index = schemaRead.index( label, prop );
  try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction();
     NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() )
  {
    // when
    tx.dataWrite().nodeRemoveLabel( strOne, label );
    tx.dataRead().nodeIndexSeek( index, node, IndexOrder.NONE, needsValues, IndexQuery.stringPrefix( prop, stringValue( "on" )) );
    // then
    assertFalse( node.next() );
  }
}

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

@Test
public void shouldNotFindNodeWithRemovedLabelInCompositeIndex() throws Exception
{
  // Given
  boolean needsValues = false;
  int label = token.nodeLabel( "Person" );
  int firstName = token.propertyKey( "firstname" );
  int surname = token.propertyKey( "surname" );
  IndexReference index = schemaRead.index( label, firstName, surname );
  try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction();
     NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() )
  {
    // when
    tx.dataWrite().nodeRemoveLabel( joeDalton, label );
    tx.dataRead().nodeIndexSeek( index, node, IndexOrder.NONE, needsValues, IndexQuery.exact( firstName, "Joe" ),
        IndexQuery.exact( surname, "Dalton" ) );
    // then
    assertFalse( node.next() );
  }
}

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

@Test
public void shouldFindSwappedNodeInIndexSeek() throws Exception
{
  // Given
  boolean needsValues = false;
  int label = token.nodeLabel( "Node" );
  int prop = token.propertyKey( "prop" );
  IndexReference index = schemaRead.index( label, prop );
  try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction();
     NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() )
  {
    // when
    tx.dataWrite().nodeRemoveLabel( strOne, label );
    tx.dataWrite().nodeAddLabel( strOneNoLabel, label );
    tx.dataRead().nodeIndexSeek( index, node, IndexOrder.NONE, needsValues, IndexQuery.exact( prop, "one" ) );
    // then
    assertTrue( node.next() );
    assertEquals( strOneNoLabel, node.nodeReference() );
  }
}

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

@Test
public void shouldFindSwappedNodeInPrefixSearch() throws Exception
{
  // Given
  boolean needsValues = indexProvidesStringValues();
  int label = token.nodeLabel( "Node" );
  int prop = token.propertyKey( "prop" );
  IndexReference index = schemaRead.index( label, prop );
  try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction();
     NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() )
  {
    // when
    tx.dataWrite().nodeRemoveLabel( strOne, label );
    tx.dataWrite().nodeAddLabel( strOneNoLabel, label );
    tx.dataRead().nodeIndexSeek( index, node, IndexOrder.NONE, needsValues, IndexQuery.stringPrefix( prop, stringValue( "on" )) );
    // then
    assertTrue( node.next() );
    assertEquals( strOneNoLabel, node.nodeReference() );
  }
}

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

@Test
public void shouldFindSwappedNodeInRangeSearch() throws Exception
{
  // Given
  boolean needsValues = indexProvidesStringValues();
  int label = token.nodeLabel( "Node" );
  int prop = token.propertyKey( "prop" );
  IndexReference index = schemaRead.index( label, prop );
  try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction();
     NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() )
  {
    // when
    tx.dataWrite().nodeRemoveLabel( strOne, label );
    tx.dataWrite().nodeAddLabel( strOneNoLabel, label );
    tx.dataRead().nodeIndexSeek( index, node, IndexOrder.NONE, needsValues, IndexQuery.range( prop, "one", true, "ones", true ) );
    // then
    assertTrue( node.next() );
    assertEquals( strOneNoLabel, node.nodeReference() );
    assertFalse( node.next() );
  }
}

相关文章