@Override public Object removeProperty( String key ) { KernelTransaction transaction = spi.kernelTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); return transaction.dataWrite().relationshipRemoveProperty( id, propertyKeyId ).asObjectCopy(); } catch ( EntityNotFoundException e ) { throw new NotFoundException( e ); } catch ( IllegalTokenNameException e ) { throw new IllegalArgumentException( format( "Invalid property key '%s'.", key ), e ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( AutoIndexingKernelException e ) { throw new IllegalStateException( "Auto indexing encountered a failure while removing property: " + e.getMessage(), e ); } }
assertThat( tx.dataWrite().relationshipRemoveProperty( relationshipId, token ), equalTo( intValue( 42 ) ) ); assertThat( tx.dataWrite().relationshipRemoveProperty( relationshipId, token ), equalTo( NO_VALUE ) ); tx.success();
@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(); } }
@Test public void shouldRemoveNonExistingPropertyFromRelationship() 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 proxy = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) ); relationshipId = proxy.getId(); tx.success(); } // When try ( Transaction tx = beginTransaction() ) { int token = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().relationshipRemoveProperty( relationshipId, token ), equalTo( NO_VALUE ) ); tx.success(); } // Then try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertFalse( graphDb.getRelationshipById( relationshipId ).hasProperty( "prop" ) ); } }
@Test public void shouldRemovePropertyFromRelationship() 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 proxy = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) ); relationshipId = proxy.getId(); proxy.setProperty( propertyKey, 42 ); tx.success(); } // When try ( Transaction tx = beginTransaction() ) { int token = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().relationshipRemoveProperty( relationshipId, token ), equalTo( intValue( 42 ) ) ); tx.success(); } // Then try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertFalse( graphDb.getRelationshipById( relationshipId ).hasProperty( "prop" ) ); } }
@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(); }
tx.dataWrite().relationshipRemoveProperty( relationship, prop1 ); assertTrue( hasProperties( cursor, tx ) ); tx.dataWrite().relationshipRemoveProperty( relationship, prop2 ); assertTrue( hasProperties( cursor, tx ) ); tx.dataWrite().relationshipRemoveProperty( relationship, prop3 ); assertFalse( hasProperties( cursor, tx ) );
assertEquals( tx.dataWrite().relationshipRemoveProperty( relationshipId, propToken ), stringValue( "hello" ) ); assertEquals( tx.dataWrite().relationshipSetProperty( relationshipId, propToken, stringValue( "world" ) ),
assertEquals( tx.dataWrite().relationshipRemoveProperty( relationshipId, propToken ), stringValue( "hello" ) ); try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor();
@Override public Object removeProperty( String key ) { KernelTransaction transaction = spi.kernelTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); return transaction.dataWrite().relationshipRemoveProperty( id, propertyKeyId ).asObjectCopy(); } catch ( EntityNotFoundException e ) { throw new NotFoundException( e ); } catch ( IllegalTokenNameException e ) { throw new IllegalArgumentException( format( "Invalid property key '%s'.", key ), e ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( AutoIndexingKernelException e ) { throw new IllegalStateException( "Auto indexing encountered a failure while removing property: " + e.getMessage(), e ); } }