Skip to content

Commit

Permalink
Support removing graph property
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Mar 1, 2018
1 parent 220edf4 commit 2f74c49
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,29 @@ public void shouldBeAbleToReplaceExistingGraphProperty() throws Exception
}
}

@Test
public void shouldBeAbleToRemoveExistingGraphProperty() throws Exception
{
int prop;
try ( Transaction tx = session.beginTransaction() )
{
prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" );
assertThat( tx.dataWrite().graphSetProperty( prop, stringValue( "hello" ) ), equalTo( NO_VALUE ) );
tx.success();
}

try ( Transaction tx = session.beginTransaction() )
{
assertThat( tx.dataWrite().graphRemoveProperty( prop ), equalTo( stringValue("hello") ) );
tx.success();
}

try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
{
assertFalse( graphProperties().hasProperty( "prop" ) );
}
}

@Test
public void shouldBeAbleToReadExistingGraphProperties() throws Exception
{
Expand Down Expand Up @@ -150,5 +173,26 @@ public void shouldSeeUpdatedGraphPropertyInTransaction() throws Exception
}
}

@Test
public void shouldNotSeeURemovedGraphPropertyInTransaction() throws Exception
{
int prop;
try ( Transaction tx = session.beginTransaction() )
{
prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" );
assertThat( tx.dataWrite().graphSetProperty( prop, stringValue( "hello" ) ), equalTo( NO_VALUE ) );
tx.success();
}

try ( Transaction tx = session.beginTransaction();
PropertyCursor cursor = cursors.allocatePropertyCursor() )
{
assertThat( tx.dataWrite().graphRemoveProperty( prop ), equalTo( stringValue( "hello" ) ) );

tx.dataRead().graphProperties( cursor );
assertFalse( cursor.next() );
}
}

protected abstract PropertyContainer graphProperties();
}
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,14 @@ public Value graphSetProperty( int propertyKey, Value value )
@Override
public Value graphRemoveProperty( int propertyKey )
{
ktx.locks().optimistic().acquireExclusive( ktx.lockTracer(), ResourceTypes.GRAPH_PROPS, ResourceTypes.graphPropertyResource() );
ktx.assertOpen();
throw new UnsupportedOperationException();
Value existingValue = readGraphProperty( propertyKey );
if ( existingValue != Values.NO_VALUE )
{
ktx.txState().graphDoRemoveProperty( propertyKey, existingValue );
}
return existingValue;
}

@Override
Expand Down

0 comments on commit 2f74c49

Please sign in to comment.