@Override public Object removeProperty( String key ) { KernelTransaction transaction = safeAcquireTransaction(); int propertyKeyId; try { propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); } catch ( IllegalTokenNameException e ) { throw new IllegalArgumentException( format( "Invalid property key '%s'.", key ), e ); } try ( Statement ignore = transaction.acquireStatement() ) { return transaction.dataWrite().graphRemoveProperty( propertyKeyId ).asObjectCopy(); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } }
@Test public void shouldNotSeeRemovedGraphPropertyInTransaction() throws Exception { int prop; try ( Transaction tx = beginTransaction() ) { prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ); assertThat( tx.dataWrite().graphSetProperty( prop, stringValue( "hello" ) ), equalTo( NO_VALUE ) ); tx.success(); } try ( Transaction tx = beginTransaction(); PropertyCursor cursor = tx.cursors().allocatePropertyCursor() ) { assertThat( tx.dataWrite().graphRemoveProperty( prop ), equalTo( stringValue( "hello" ) ) ); tx.dataRead().graphProperties( cursor ); assertFalse( cursor.next() ); } }
@Test public void shouldBeAbleToRemoveExistingGraphProperty() throws Exception { int prop; try ( Transaction tx = beginTransaction() ) { prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ); assertThat( tx.dataWrite().graphSetProperty( prop, stringValue( "hello" ) ), equalTo( NO_VALUE ) ); tx.success(); } try ( Transaction tx = beginTransaction() ) { assertThat( tx.dataWrite().graphRemoveProperty( prop ), equalTo( stringValue("hello") ) ); tx.success(); } try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertFalse( testSupport.graphProperties().hasProperty( "prop" ) ); } }
@Override public Object removeProperty( String key ) { KernelTransaction transaction = safeAcquireTransaction(); int propertyKeyId; try { propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); } catch ( IllegalTokenNameException e ) { throw new IllegalArgumentException( format( "Invalid property key '%s'.", key ), e ); } try ( Statement ignore = transaction.acquireStatement() ) { return transaction.dataWrite().graphRemoveProperty( propertyKeyId ).asObjectCopy(); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } }