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; }
private void setProperty( long nodeId, int propertyId, Object value ) throws KernelException { transaction.dataWrite().nodeSetProperty( nodeId, propertyId, Values.of( value ) ); }
private void createNodeWithProperty( Transaction tx, int propId1 ) throws KernelException { long node = tx.dataWrite().nodeCreate(); tx.dataWrite().nodeSetProperty( node, propId1, Values.intValue( 42 ) ); }
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; }
@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 ) ); }
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; }
@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 ); }
@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" ); }
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; }
@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" ); }
@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(); }
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 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(); }
@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(); }
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; }
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; }
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; }
@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 ); }
@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() ); } }