本文整理了Java中org.neo4j.internal.kernel.api.Write.graphSetProperty()
方法的一些代码示例,展示了Write.graphSetProperty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Write.graphSetProperty()
方法的具体详情如下:
包路径:org.neo4j.internal.kernel.api.Write
类名称:Write
方法名:graphSetProperty
[英]Set a property on the graph
[中]在图形上设置属性
代码示例来源:origin: neo4j/neo4j
@Override
public void setProperty( String key, Object value )
{
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() )
{
transaction.dataWrite().graphSetProperty( propertyKeyId, Values.of( value, false ) );
}
catch ( InvalidTransactionTypeKernelException e )
{
throw new ConstraintViolationException( e.getMessage(), e );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldNotWriteWhenSettingPropertyToSameValue() throws Exception
{
// Given
int prop;
Value theValue = stringValue( "The Value" );
try ( Transaction tx = beginTransaction() )
{
prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" );
tx.dataWrite().graphSetProperty( prop, theValue );
tx.success();
}
// When
Transaction tx = beginTransaction();
assertThat( tx.dataWrite().graphSetProperty( prop, theValue ), equalTo( theValue ) );
tx.success();
assertThat( tx.closeTransaction(), equalTo( Transaction.READ_ONLY ) );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldBeAbleToWriteNewGraphProperty() 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 ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
{
assertThat( testSupport.graphProperties().getProperty( "prop" ), equalTo( "hello" ) );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldBeAbleToReplaceExistingGraphProperty() 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().graphSetProperty( prop, stringValue( "good bye" ) ), equalTo( stringValue("hello") ) );
tx.success();
}
try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
{
assertThat( testSupport.graphProperties().getProperty( "prop" ), equalTo( "good bye" ) );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldSeeNewGraphPropertyInTransaction() throws Exception
{
try ( Transaction tx = beginTransaction();
PropertyCursor cursor = tx.cursors().allocatePropertyCursor() )
{
int prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" );
assertThat( tx.dataWrite().graphSetProperty( prop, stringValue( "hello" ) ), equalTo( NO_VALUE ) );
tx.dataRead().graphProperties( cursor );
assertTrue( cursor.next() );
assertThat( cursor.propertyKey(), equalTo( prop ) );
assertThat( cursor.propertyValue(), equalTo( stringValue( "hello" ) ) );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldSeeUpdatedGraphPropertyInTransaction() 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().graphSetProperty( prop, stringValue( "good bye" ) ),
equalTo( stringValue( "hello" ) ) );
tx.dataRead().graphProperties( cursor );
assertTrue( cursor.next() );
assertThat( cursor.propertyKey(), equalTo( prop ) );
assertThat( cursor.propertyValue(), equalTo( stringValue( "good bye" ) ) );
assertFalse( cursor.next() );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldBeAbleToReadExistingGraphProperties() throws Exception
{
int prop1, prop2, prop3;
try ( Transaction tx = beginTransaction() )
{
prop1 = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop1" );
prop2 = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop2" );
prop3 = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop3" );
tx.dataWrite().graphSetProperty( prop1, stringValue( "hello" ) );
tx.dataWrite().graphSetProperty( prop2, stringValue( "world" ) );
tx.dataWrite().graphSetProperty( prop3, stringValue( "etc" ) );
tx.success();
}
try ( Transaction tx = beginTransaction();
PropertyCursor cursor = tx.cursors().allocatePropertyCursor() )
{
tx.dataRead().graphProperties( cursor );
assertTrue( cursor.next() );
assertThat( cursor.propertyKey(), equalTo( prop1 ) );
assertThat( cursor.propertyValue(), equalTo( stringValue( "hello" ) ) );
assertTrue( cursor.next() );
assertThat( cursor.propertyKey(), equalTo( prop2 ) );
assertThat( cursor.propertyValue(), equalTo( stringValue( "world" ) ) );
assertTrue( cursor.next() );
assertThat( cursor.propertyKey(), equalTo( prop3 ) );
assertThat( cursor.propertyValue(), equalTo( stringValue( "etc" ) ) );
assertFalse( cursor.next() );
}
}
代码示例来源:origin: neo4j/neo4j
@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" ) );
}
}
代码示例来源:origin: neo4j/neo4j
@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() );
}
}
代码示例来源:origin: org.neo4j/neo4j-kernel
@Override
public void setProperty( String key, Object value )
{
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() )
{
transaction.dataWrite().graphSetProperty( propertyKeyId, Values.of( value, false ) );
}
catch ( InvalidTransactionTypeKernelException e )
{
throw new ConstraintViolationException( e.getMessage(), e );
}
}
内容来源于网络,如有侵权,请联系作者删除!