public void removeLabelFromNode( long nodeId, String labelName ) throws NodeNotFoundException { node( nodeId ).removeLabel( label( labelName ) ); }
private void removeLabels( Node node, Label... labels ) { try ( Transaction tx = db.beginTx() ) { for ( Label label : labels ) { node.removeLabel( label ); } tx.success(); } }
private void removeLabels( Node node, Label... labels ) { try ( Transaction tx = dbRule.beginTx() ) { for ( Label label : labels ) { node.removeLabel( label ); } tx.success(); } }
public void remove( Node node, String label ) { node.removeLabel( label( label ) ); put( removed, node, label ); }
@Test public void shouldHandleUpdateRemovalOfLabelConcurrentlyWithIndexDrop() throws Throwable { shouldHandleIndexDropConcurrentlyWithOperation( nodeId -> db.getNodeById( nodeId ).removeLabel( LABEL ) ); }
public void setLabelsOnNode( long nodeId, Collection<String> labels ) throws NodeNotFoundException, BadInputException { Node node = node( nodeId ); try { // Remove current labels for ( Label label : node.getLabels() ) { node.removeLabel( label ); } // Add new labels for ( String labelName : labels ) { node.addLabel( label( labelName ) ); } } catch ( org.neo4j.graphdb.ConstraintViolationException e ) { throw new BadInputException( "Unable to add label, see nested exception.", e ); } }
private void removeLabelFromExistingNode( List<Pair<Long,Label[]>> nodesInStore ) { Pair<Long,Label[]> existingNode; Node node; do { int targetIndex = random.nextInt( nodesInStore.size() ); existingNode = nodesInStore.get( targetIndex ); node = db.getNodeById( existingNode.first() ); } while ( existingNode.other().length == 0 ); node.removeLabel( existingNode.other()[0] ); }
private void removeLabels( long nodeId, int startLabelIndex, int count ) { try ( Transaction tx = dbRule.beginTx() ) { Node node = dbRule.getNodeById( nodeId ); int endLabelIndex = startLabelIndex + count; for ( int i = startLabelIndex; i < endLabelIndex; i++ ) { node.removeLabel( labelWithIndex( i ) ); } tx.success(); } }
@Override void perform( Graph graph, ExpectedTransactionData expectations ) { Node node = graph.randomNode(); if ( node != null ) { Label label = graph.randomLabel(); if ( node.hasLabel( label ) ) { node.removeLabel( label ); expectations.removedLabel( node, label ); debug( node + " " + label ); } } } },
@Test public void removingCommittedLabel() { // Given GraphDatabaseService graphDatabase = dbRule.getGraphDatabaseAPI(); Label label = Labels.MY_LABEL; Node myNode = createNode( graphDatabase, label ); // When try ( Transaction tx = graphDatabase.beginTx() ) { myNode.removeLabel( label ); tx.success(); } // Then assertThat( myNode, not( inTx( graphDatabase, hasLabel( label ) ) ) ); }
@Test public void removingNonExistentLabel() { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); Label label = Labels.MY_LABEL; // When Node myNode; try ( Transaction tx = beansAPI.beginTx() ) { myNode = beansAPI.createNode(); myNode.removeLabel( label ); tx.success(); } // THEN assertThat( myNode, not( inTx( beansAPI, hasLabel( label ) ) ) ); }
@Test public void removingExistingLabelFromUnlabeledNode() { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); Label label = Labels.MY_LABEL; createNode( beansAPI, label ); Node myNode = createNode( beansAPI ); // When try ( Transaction tx = beansAPI.beginTx() ) { myNode.removeLabel( label ); tx.success(); } // THEN assertThat( myNode, not( inTx( beansAPI, hasLabel( label ) ) ) ); }
@Test public void removingLabelDoesNotBreakPreviouslyCreatedLabelsIterator() { // GIVEN GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); Label label1 = label( "A" ); Label label2 = label( "B" ); try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( label1, label2 ); for ( Label next : node.getLabels() ) { node.removeLabel( next ); } tx.success(); } }
@Test public void removingUncommittedLabel() { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); Label label = Labels.MY_LABEL; // When Node myNode; try ( Transaction tx = beansAPI.beginTx() ) { myNode = beansAPI.createNode(); myNode.addLabel( label ); myNode.removeLabel( label ); // THEN assertFalse( myNode.hasLabel( label ) ); tx.success(); } }
@Test public void shouldIdentifyTransactionWithNetZeroChangesAsReadOnly() { // GIVEN a transaction that has seen some changes, where all those changes result in a net 0 change set // a good way of producing such state is to add a label to an existing node, and then remove it. GraphDatabaseAPI db = dbr.getGraphDatabaseAPI(); TransactionIdStore txIdStore = db.getDependencyResolver().resolveDependency( TransactionIdStore.class ); long startTxId = txIdStore.getLastCommittedTransactionId(); Node node = createEmptyNode( db ); try ( Transaction tx = db.beginTx() ) { node.addLabel( TestLabels.LABEL_ONE ); node.removeLabel( TestLabels.LABEL_ONE ); tx.success(); } // WHEN closing that transaction // THEN it should not have been committed assertEquals( "Expected last txId to be what it started at + 2 (1 for the empty node, and one for the label)", startTxId + 2, txIdStore.getLastCommittedTransactionId() ); }
@Test public void queryResultsMustNotIncludeNodesWithRemovedIndexedLabels() { db = createDatabase(); try ( Transaction tx = db.beginTx() ) { createSimpleNodesIndex(); tx.success(); } long nodeId; try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( LABEL ); node.setProperty( PROP, "value" ); nodeId = node.getId(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.getNodeById( nodeId ).removeLabel( LABEL ); assertQueryFindsIds( db, true, "nodes", "nodes" ); tx.success(); } }
@Test public void shouldDetectNoChangesInCommitsAlsoForTheIndexes() { // GIVEN a transaction that has seen some changes, where all those changes result in a net 0 change set // a good way of producing such state is to add a label to an existing node, and then remove it. GraphDatabaseAPI db = dbr.getGraphDatabaseAPI(); TransactionIdStore txIdStore = db.getDependencyResolver().resolveDependency( TransactionIdStore.class ); long startTxId = txIdStore.getLastCommittedTransactionId(); Node node = createEmptyNode( db ); Index<Node> index = createNodeIndex( db ); try ( Transaction tx = db.beginTx() ) { node.addLabel( TestLabels.LABEL_ONE ); node.removeLabel( TestLabels.LABEL_ONE ); index.add( node, "key", "value" ); index.remove( node, "key", "value" ); tx.success(); } // WHEN closing that transaction // THEN it should not have been committed assertEquals( "Expected last txId to be what it started at + 3 " + "(1 for the empty node, 1 for index, and one for the label)", startTxId + 3, txIdStore.getLastCommittedTransactionId() ); }
@Test public void getNodesWithLabelsWithTxAddsAndRemoves() { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); Node node1 = createNode( beansAPI, Labels.MY_LABEL, Labels.MY_OTHER_LABEL ); Node node2 = createNode( beansAPI, Labels.MY_LABEL, Labels.MY_OTHER_LABEL ); // WHEN Node node3; Set<Node> nodesWithMyLabel; Set<Node> nodesWithMyOtherLabel; try ( Transaction tx = beansAPI.beginTx() ) { node3 = beansAPI.createNode( Labels.MY_LABEL ); node2.removeLabel( Labels.MY_LABEL ); // extracted here to be asserted below nodesWithMyLabel = asSet( beansAPI.findNodes( Labels.MY_LABEL ) ); nodesWithMyOtherLabel = asSet( beansAPI.findNodes( Labels.MY_OTHER_LABEL ) ); tx.success(); } // THEN assertEquals( asSet( node1, node3 ), nodesWithMyLabel ); assertEquals( asSet( node1, node2 ), nodesWithMyOtherLabel ); }
@Test public void shouldUpdateRelationshipWithLabelCountsWhenRemovingLabelAndDeletingRelationship() { // given Node foo; try ( Transaction tx = db.beginTx() ) { foo = db.createNode( label( "Foo" ) ); Node bar = db.createNode( label( "Bar" ) ); foo.createRelationshipTo( bar, withName( "BAZ" ) ); tx.success(); } long before = numberOfRelationshipsMatching( label( "Foo" ), withName( "BAZ" ), null ); // when try ( Transaction tx = db.beginTx() ) { for ( Relationship relationship : foo.getRelationships() ) { relationship.delete(); } foo.removeLabel( label("Foo")); tx.success(); } long after = numberOfRelationshipsMatching( label( "Foo" ), withName( "BAZ" ), null ); // then assertEquals( before - 1, after ); }
@Test public void shouldMaintainCountsOnLabelRemove() { // given Node foo; Node bar; try ( Transaction tx = db.beginTx() ) { foo = db.createNode( label( "Foo" ) ); bar = db.createNode( label( "Bar" ) ); foo.createRelationshipTo( bar, withName( "KNOWS" ) ); tx.success(); } // when try ( Transaction tx = db.beginTx() ) { foo.removeLabel( label( "Foo" ) ); tx.success(); } // then numberOfRelationshipsMatching( label( "Foo" ), withName( "KNOWS" ), null ).shouldBe( 0 ); numberOfRelationshipsMatching( null, withName( "KNOWS" ), label( "Foo" ) ).shouldBe( 0 ); numberOfRelationshipsMatching( null, withName( "KNOWS" ), label( "Bar" ) ).shouldBe( 1 ); numberOfRelationshipsMatching( label( "Bar" ), withName( "KNOWS" ), null ).shouldBe( 0 ); }