本文整理了Java中org.neo4j.internal.kernel.api.Write.nodeSetProperty()
方法的一些代码示例,展示了Write.nodeSetProperty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Write.nodeSetProperty()
方法的具体详情如下:
包路径:org.neo4j.internal.kernel.api.Write
类名称:Write
方法名:nodeSetProperty
[英]Set a property on a node
[中]在节点上设置属性
代码示例来源:origin: neo4j/neo4j
private long createNodeWithValues( Value value1, Value value2 ) throws KernelException
{
Write write = dataWriteInNewTransaction();
long nodeId = write.nodeCreate();
write.nodeAddLabel( nodeId, labelId );
write.nodeSetProperty( nodeId, propertyId1, value1 );
write.nodeSetProperty( nodeId, propertyId2, value2 );
commit();
return nodeId;
}
代码示例来源:origin: neo4j/neo4j
private void setProperty( long nodeId, int propertyId, Object value ) throws KernelException
{
transaction.dataWrite().nodeSetProperty( nodeId, propertyId, Values.of( value ) );
}
代码示例来源:origin: neo4j/neo4j
private void createNodeWithProperty( Transaction tx, int propId1 ) throws KernelException
{
long node = tx.dataWrite().nodeCreate();
tx.dataWrite().nodeSetProperty( node, propId1, Values.intValue( 42 ) );
}
代码示例来源:origin: neo4j/neo4j
private long createNodeWithValue( Value value ) throws KernelException
{
Write write = dataWriteInNewTransaction();
long nodeId = write.nodeCreate();
write.nodeAddLabel( nodeId, labelId );
write.nodeSetProperty( nodeId, propertyId1, value );
commit();
return nodeId;
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldNotWriteWhenSettingPropertyToSameValue() throws Exception
{
// Given
Value theValue = stringValue( "The Value" );
long nodeId = createNodeWithProperty( propertyKey, theValue.asObject() );
// When
Transaction tx = beginTransaction();
int property = tx.token().propertyKeyGetOrCreateForName( propertyKey );
assertThat( tx.dataWrite().nodeSetProperty( nodeId, property, theValue ), equalTo( theValue ) );
tx.success();
assertThat( tx.closeTransaction(), equalTo( Transaction.READ_ONLY ) );
}
代码示例来源:origin: neo4j/neo4j
private long createLabeledNode( Transaction transaction, String label, String key, Object value )
throws KernelException
{
long node = createLabeledNode( transaction, label );
int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key );
transaction.dataWrite().nodeSetProperty( node, propertyKeyId, Values.of( value ) );
return node;
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRollbackSetNodeProperty() throws Exception
{
// Given
long node = createNode();
// When
try ( Transaction tx = beginTransaction() )
{
int token = tx.token().propertyKeyGetOrCreateForName( propertyKey );
assertThat( tx.dataWrite().nodeSetProperty( node, token, stringValue( "hello" ) ), equalTo( NO_VALUE ) );
tx.failure();
}
// Then
assertNoProperty( node, propertyKey );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldAddPropertyToNode() throws Exception
{
// Given
long node = createNode();
// When
try ( Transaction tx = beginTransaction() )
{
int token = tx.token().propertyKeyGetOrCreateForName( propertyKey );
assertThat( tx.dataWrite().nodeSetProperty( node, token, stringValue( "hello" ) ), equalTo( NO_VALUE ) );
tx.success();
}
// Then
assertProperty( node, propertyKey, "hello" );
}
代码示例来源:origin: neo4j/neo4j
private long createNode( Transaction transaction, String key, Object value ) throws KernelException
{
long node = transaction.dataWrite().nodeCreate();
int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key );
transaction.dataWrite().nodeSetProperty( node, propertyKeyId, Values.of( value ) );
return node;
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldUpdatePropertyToNode() throws Exception
{
// Given
long node = createNodeWithProperty( propertyKey, 42 );
// When
try ( Transaction tx = beginTransaction() )
{
int token = tx.token().propertyKeyGetOrCreateForName( propertyKey );
assertThat( tx.dataWrite().nodeSetProperty( node, token, stringValue( "hello" ) ),
equalTo( intValue( 42 ) ) );
tx.success();
}
// Then
assertProperty( node, propertyKey, "hello" );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_ChangeProperty() throws Exception
{
// given
long node = createNodeWithLabelAndProps( label, aValues );
// when
newTransaction();
transaction.dataWrite().nodeSetProperty( node, 0, Values.of( "Alive!" ) );
long newNode = createLabeledNode( label );
setProperties( newNode, aValues );
// then does not fail
commit();
}
代码示例来源:origin: neo4j/neo4j
private Pair<Long,Value> nodeWithProp( Transaction tx, Object value ) throws Exception
{
Write write = tx.dataWrite();
long node = write.nodeCreate();
write.nodeAddLabel( node, tx.tokenWrite().labelGetOrCreateForName( "Node" ) );
Value val = Values.of( value );
write.nodeSetProperty( node, tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ), val );
return Pair.of( node, val );
}
代码示例来源:origin: neo4j/neo4j
private Pair<Long,Value> nodeWithProp( Transaction tx, Object value ) throws Exception
{
Write write = tx.dataWrite();
long node = write.nodeCreate();
write.nodeAddLabel( node, tx.tokenWrite().labelGetOrCreateForName( "Node" ) );
Value val = Values.of( value );
write.nodeSetProperty( node, tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ), val );
return Pair.of( node, val );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldAllowNoopPropertyUpdate() throws KernelException
{
// given
long node = constrainedNode( "Label1", "key1", "value1" );
Transaction transaction = newTransaction( AnonymousContext.writeToken() );
// when
int key = transaction.tokenWrite().propertyKeyGetOrCreateForName( "key1" );
transaction.dataWrite().nodeSetProperty( node, key, Values.of( "value1" ) );
// then should not throw exception
commit();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_ChangeProperty() throws Exception
{
// given
long node = constrainedNode( "Label1", "key1", "value1" );
Transaction transaction = newTransaction( AnonymousContext.writeToken() );
// when
int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( "key1" );
transaction.dataWrite().nodeSetProperty( node, propertyKeyId, Values.of( "value2" ) );
createLabeledNode( transaction, "Label1", "key1", "value1" );
commit();
}
代码示例来源:origin: neo4j/neo4j
private long createPersonNode( KernelTransaction ktx, Object value )
throws KernelException
{
int labelId = ktx.tokenWrite().labelGetOrCreateForName( PERSON_LABEL );
int propertyKeyId = ktx.tokenWrite().propertyKeyGetOrCreateForName( NAME_PROPERTY );
long nodeId = ktx.dataWrite().nodeCreate();
ktx.dataWrite().nodeAddLabel( nodeId, labelId );
ktx.dataWrite().nodeSetProperty( nodeId, propertyKeyId, Values.of( value ) );
return nodeId;
}
代码示例来源:origin: neo4j/neo4j
private long createNode()
throws KernelException
{
long nodeID;
try ( Transaction tx = graphDatabaseAPI.beginTx() )
{
KernelTransaction ktx = ktx();
Write write = ktx.dataWrite();
nodeID = write.nodeCreate();
write.nodeAddLabel( nodeID, LABEL_ID );
for ( int propID : index.schema().getPropertyIds() )
{
write.nodeSetProperty( nodeID, propID, Values.intValue( propID ) );
}
tx.success();
}
return nodeID;
}
代码示例来源:origin: neo4j/neo4j
private long constrainedNode( String labelName, String propertyKey, Object propertyValue )
throws KernelException
{
long node;
{
Transaction transaction = newTransaction( AnonymousContext.writeToken() );
int label = transaction.tokenWrite().labelGetOrCreateForName( labelName );
node = transaction.dataWrite().nodeCreate();
transaction.dataWrite().nodeAddLabel( node, label );
int key = transaction.tokenWrite().propertyKeyGetOrCreateForName( propertyKey );
transaction.dataWrite().nodeSetProperty( node, key, Values.of( propertyValue ) );
commit();
}
createConstraint( labelName, propertyKey );
return node;
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRemoveReSetAndTwiceRemovePropertyOnNode() throws Exception
{
// given
long node = createNodeWithProperty( propertyKey, "bar" );
// when
try ( Transaction tx = beginTransaction() )
{
int prop = tx.token().propertyKeyGetOrCreateForName( propertyKey );
tx.dataWrite().nodeRemoveProperty( node, prop );
tx.dataWrite().nodeSetProperty( node, prop, Values.of( "bar" ) );
tx.dataWrite().nodeRemoveProperty( node, prop );
tx.dataWrite().nodeRemoveProperty( node, prop );
tx.success();
}
// then
assertNoProperty( node, propertyKey );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldFindUpdatedNodeInIndexSeek() throws Exception
{
// Given
boolean needsValues = false;
int label = token.nodeLabel( "Node" );
int prop = token.propertyKey( "prop" );
IndexReference index = schemaRead.index( label, prop );
try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction();
NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() )
{
// when
tx.dataWrite().nodeSetProperty( strOne, prop, stringValue( "ett" ) );
tx.dataRead().nodeIndexSeek( index, node, IndexOrder.NONE, needsValues, IndexQuery.exact( prop, "ett" ) );
// then
assertTrue( node.next() );
assertEquals( strOne, node.nodeReference() );
}
}
内容来源于网络,如有侵权,请联系作者删除!