private long createNode( Write write, int... labels ) throws KernelException { long nodeId = write.nodeCreate(); for ( int label : labels ) { write.nodeAddLabel( nodeId, label ); } return nodeId; } }
private void addLabel( long nodeId, int labelId ) throws KernelException { transaction.dataWrite().nodeAddLabel( nodeId, labelId ); }
private long createLabeledNode( int labelId ) throws KernelException { long node = transaction.dataWrite().nodeCreate(); transaction.dataWrite().nodeAddLabel( node, labelId ); return node; }
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; }
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; }
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; }
@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 ); } }
@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"} ) ) ); }
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 ); }
@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(); }
@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(); }
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 ); }
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 ); } }
@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 ); }
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; }
@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 ); }
@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(); }
@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 ); } }
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; }
@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() ); } }