本文整理了Java中org.neo4j.internal.kernel.api.Write.nodeAddLabel()
方法的一些代码示例,展示了Write.nodeAddLabel()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Write.nodeAddLabel()
方法的具体详情如下:
包路径:org.neo4j.internal.kernel.api.Write
类名称:Write
方法名:nodeAddLabel
[英]Add a label to a node
[中]将标签添加到节点
代码示例来源:origin: neo4j/neo4j
private long createNode( Write write, int... labels ) throws KernelException
{
long nodeId = write.nodeCreate();
for ( int label : labels )
{
write.nodeAddLabel( nodeId, label );
}
return nodeId;
}
}
代码示例来源:origin: neo4j/neo4j
private void addLabel( long nodeId, int labelId ) throws KernelException
{
transaction.dataWrite().nodeAddLabel( nodeId, labelId );
}
代码示例来源:origin: neo4j/neo4j
private long createLabeledNode( int labelId ) throws KernelException
{
long node = transaction.dataWrite().nodeCreate();
transaction.dataWrite().nodeAddLabel( node, labelId );
return node;
}
代码示例来源: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
private long createLabeledNode( Transaction transaction, String label ) throws KernelException
{
long node = transaction.dataWrite().nodeCreate();
int labelId = transaction.tokenWrite().labelGetOrCreateForName( label );
transaction.dataWrite().nodeAddLabel( node, labelId );
return 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
@Test
public void shouldNotAddLabelToNonExistingNode() throws Exception
{
long node = 1337L;
try ( Transaction tx = beginTransaction() )
{
int labelId = tx.token().labelGetOrCreateForName( labelName );
exception.expect( KernelException.class );
tx.dataWrite().nodeAddLabel( node, labelId );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void listAllLabels() throws Throwable
{
// Given
Transaction transaction = newTransaction( AnonymousContext.writeToken() );
long nodeId = transaction.dataWrite().nodeCreate();
int labelId = transaction.tokenWrite().labelGetOrCreateForName( "MyLabel" );
transaction.dataWrite().nodeAddLabel( nodeId, labelId );
commit();
// When
RawIterator<Object[],ProcedureException> stream =
procs().procedureCallRead( procs().procedureGet( procedureName( "db", "labels" ) ).id(), new Object[0] );
// Then
assertThat( asList( stream ), contains( equalTo( new Object[]{"MyLabel"} ) ) );
}
代码示例来源:origin: neo4j/neo4j
public Node createNode( String... labels ) throws Exception
{
long node;
int[] labelIds = new int[labels.length];
try ( Transaction tx = beginTransaction() )
{
Write write = tx.dataWrite();
node = write.nodeCreate();
for ( int i = 0; i < labels.length; i++ )
{
labelIds[i] = tx.tokenWrite().labelGetOrCreateForName( labels[i] );
write.nodeAddLabel( node, labelIds[i] );
}
tx.success();
}
return new Node( node, labelIds );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void createIndexForAnotherLabelWhileHoldingSharedLockOnOtherLabel() throws KernelException
{
TokenWrite tokenWrite = tokenWriteInNewTransaction();
int label2 = tokenWrite.labelGetOrCreateForName( "Label2" );
Write write = dataWriteInNewTransaction();
long nodeId = write.nodeCreate();
write.nodeAddLabel( nodeId, label2 );
schemaWriteInNewTransaction().indexCreate( descriptor );
commit();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldAllowNoopLabelUpdate() throws KernelException
{
// given
long node = constrainedNode( "Label1", "key1", "value1" );
Transaction transaction = newTransaction( AnonymousContext.writeToken() );
// when
int label = transaction.tokenWrite().labelGetOrCreateForName( "Label1" );
transaction.dataWrite().nodeAddLabel( node, label );
// then should not throw exception
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 shouldAddLabelNodeOnce() throws Exception
{
long node = createNodeWithLabel( labelName );
try ( Transaction tx = beginTransaction() )
{
int labelId = tx.token().labelGetOrCreateForName( labelName );
assertFalse( tx.dataWrite().nodeAddLabel( node, labelId ) );
tx.success();
}
assertLabels( node, labelName );
}
代码示例来源: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
@Test
public void shouldAddLabelNode() throws Exception
{
// Given
long node = createNode();
// When
try ( Transaction tx = beginTransaction() )
{
int labelId = tx.token().labelGetOrCreateForName( labelName );
assertTrue( tx.dataWrite().nodeAddLabel( node, labelId ) );
tx.success();
}
// Then
assertLabels( node, labelName );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void mixingBeansApiWithKernelAPI() throws Exception
{
// 1: Start your transactions through the Beans API
Transaction transaction = db.beginTx();
// 2: Get a hold of a KernelAPI transaction this way:
KernelTransaction ktx = statementContextSupplier.getKernelTransactionBoundToThisThread( true );
// 3: Now you can interact through both the statement context and the kernel API to manipulate the
// same transaction.
Node node = db.createNode();
int labelId = ktx.tokenWrite().labelGetOrCreateForName( "labello" );
ktx.dataWrite().nodeAddLabel( node.getId(), labelId );
// 4: Commit through the beans API
transaction.success();
transaction.close();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldCountNewLabelsFromTxState() throws Exception
{
// Given
Node node1 = createNode( "label" );
Node node2 = createNode();
try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction() )
{
// when
tx.dataWrite().nodeAddLabel( node2.node, node1.labels[0] );
long countTxState = tx.dataRead().countsForNode( node1.labels[0] );
long countNoTxState = tx.dataRead().countsForNodeWithoutTxState( node1.labels[0] );
// then
assertEquals( 2, countTxState );
assertEquals( 1, countNoTxState );
}
}
代码示例来源: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
@Ignore
public void shouldFindUpdatedNodeInInConjunctionLabelScan() throws Exception
{
// Given
Node node = createNode("label1");
try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction();
NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor() )
{
// when
int label2 = tx.tokenWrite().labelGetOrCreateForName( "label2" );
tx.dataWrite().nodeAddLabel( node.node, label2 );
tx.dataRead().nodeLabelIntersectionScan( cursor, node.labels[0], label2 );
// then
assertTrue( cursor.next() );
assertEquals( node.node, cursor.nodeReference() );
}
}
内容来源于网络,如有侵权,请联系作者删除!