public boolean acceptsValueAt( PropertyCursor property ) { return acceptsValue( property.propertyValue() ); }
private void indexProperties( long id ) { while ( propertyCursor.next() ) { int propertyKey = propertyCursor.propertyKey(); int index = propKeyToIndex.getIfAbsent( propertyKey, -1 ); if ( index != -1 ) { propertyValues[index] = propertyCursor.propertyValue(); } } if ( modifiedEntityIdsInThisTransaction.add( id ) ) { try { writer.addDocument( documentRepresentingProperties( id, descriptor.propertyNames(), propertyValues ) ); } catch ( IOException e ) { throw new UncheckedIOException( e ); } } Arrays.fill( propertyValues, null ); } }
@Override public Map<String, Object> getAllProperties() { KernelTransaction transaction = safeAcquireTransaction(); Map<String,Object> properties = new HashMap<>(); try { PropertyCursor propertyCursor = transaction.ambientPropertyCursor(); TokenRead token = transaction.tokenRead(); transaction.dataRead().graphProperties( propertyCursor ); while ( propertyCursor.next() ) { properties.put( token.propertyKeyName( propertyCursor.propertyKey() ), propertyCursor.propertyValue().asObjectCopy() ); } } catch ( PropertyKeyIdNotFoundKernelException e ) { throw new IllegalStateException( "Property key retrieved through kernel API should exist.", e ); } return properties; }
/** * Fetches a given property from a node * * @param read The current Read instance * @param nodeCursor The node cursor to use * @param node The id of the node * @param propertyCursor The property cursor to use * @param prop The id of the property to find * @return The value of the given property * @throws EntityNotFoundException If the node cannot be find. */ public static Value nodeGetProperty( Read read, NodeCursor nodeCursor, long node, PropertyCursor propertyCursor, int prop ) throws EntityNotFoundException { if ( prop == StatementConstants.NO_SUCH_PROPERTY_KEY ) { return Values.NO_VALUE; } singleNode( read, nodeCursor, node ); nodeCursor.properties( propertyCursor ); while ( propertyCursor.next() ) { if ( propertyCursor.propertyKey() == prop ) { return propertyCursor.propertyValue(); } } return Values.NO_VALUE; }
/** * Fetches a given property from a relationship * * @param read The current Read instance * @param relationship The node cursor to use * @param node The id of the node * @param propertyCursor The property cursor to use * @param prop The id of the property to find * @return The value of the given property * @throws EntityNotFoundException If the node cannot be find. */ public static Value relationshipGetProperty( Read read, RelationshipScanCursor relationship, long node, PropertyCursor propertyCursor, int prop ) throws EntityNotFoundException { if ( prop == StatementConstants.NO_SUCH_PROPERTY_KEY ) { return Values.NO_VALUE; } singleRelationship( read, relationship, node ); relationship.properties( propertyCursor ); while ( propertyCursor.next() ) { if ( propertyCursor.propertyKey() == prop ) { return propertyCursor.propertyValue(); } } return Values.NO_VALUE; }
@Override public Map<String, Object> getAllProperties() { KernelTransaction transaction = spi.kernelTransaction(); Map<String,Object> properties = new HashMap<>(); try { RelationshipScanCursor relationships = transaction.ambientRelationshipCursor(); PropertyCursor propertyCursor = transaction.ambientPropertyCursor(); TokenRead token = transaction.tokenRead(); singleRelationship( transaction, relationships ); relationships.properties( propertyCursor ); while ( propertyCursor.next() ) { properties.put( token.propertyKeyName( propertyCursor.propertyKey() ), propertyCursor.propertyValue().asObjectCopy() ); } } catch ( PropertyKeyIdNotFoundKernelException e ) { throw new IllegalStateException( "Property key retrieved through kernel API should exist.", e ); } return properties; }
@Override public Map<String,Object> getAllProperties() { KernelTransaction transaction = safeAcquireTransaction(); Map<String,Object> properties = new HashMap<>(); try { NodeCursor nodes = transaction.ambientNodeCursor(); PropertyCursor propertyCursor = transaction.ambientPropertyCursor(); TokenRead token = transaction.tokenRead(); singleNode( transaction, nodes ); nodes.properties( propertyCursor ); while ( propertyCursor.next() ) { properties.put( token.propertyKeyName( propertyCursor.propertyKey() ), propertyCursor.propertyValue().asObjectCopy() ); } } catch ( PropertyKeyIdNotFoundKernelException e ) { throw new IllegalStateException( "Property key retrieved through kernel API should exist.", e ); } return properties; }
private static Value[] getValueTuple( NodeCursor node, PropertyCursor propertyCursor, int changedPropertyKeyId, Value changedValue, int[] indexPropertyIds ) { Value[] values = new Value[indexPropertyIds.length]; node.properties( propertyCursor ); while ( propertyCursor.next() ) { int k = ArrayUtils.indexOf( indexPropertyIds, propertyCursor.propertyKey() ); if ( k >= 0 ) { values[k] = indexPropertyIds[k] == changedPropertyKeyId ? changedValue : propertyCursor.propertyValue(); } } if ( changedPropertyKeyId != NO_SUCH_PROPERTY_KEY ) { int k = ArrayUtils.indexOf( indexPropertyIds, changedPropertyKeyId ); if ( k >= 0 ) { values[k] = changedValue; } } return values; }
@Override public Object getProperty( String key ) { if ( null == key ) { throw new IllegalArgumentException( "(null) property key is not allowed" ); } KernelTransaction transaction = safeAcquireTransaction(); int propertyKey = transaction.tokenRead().propertyKey( key ); if ( propertyKey == TokenRead.NO_TOKEN ) { throw new NotFoundException( format( "No such property, '%s'.", key ) ); } PropertyCursor properties = transaction.ambientPropertyCursor(); transaction.dataRead().graphProperties( properties ); while ( properties.next() ) { if ( propertyKey == properties.propertyKey() ) { Value value = properties.propertyValue(); if ( value == Values.NO_VALUE ) { throw new NotFoundException( format( "No such property, '%s'.", key ) ); } return value.asObjectCopy(); } } throw new NotFoundException( format( "No such property, '%s'.", key ) ); }
Value value = properties.propertyValue(); if ( value == Values.NO_VALUE )
@Override public Object getProperty( String key, Object defaultValue ) { if ( null == key ) { throw new IllegalArgumentException( "(null) property key is not allowed" ); } KernelTransaction transaction = safeAcquireTransaction(); PropertyCursor properties = transaction.ambientPropertyCursor(); int propertyKey = transaction.tokenRead().propertyKey( key ); if ( propertyKey == TokenRead.NO_TOKEN ) { return defaultValue; } transaction.dataRead().graphProperties( properties ); while ( properties.next() ) { if ( propertyKey == properties.propertyKey() ) { Value value = properties.propertyValue(); return value == Values.NO_VALUE ? defaultValue : value.asObjectCopy(); } } return defaultValue; }
@Override public Object getProperty( String key, Object defaultValue ) { if ( null == key ) { throw new IllegalArgumentException( "(null) property key is not allowed" ); } KernelTransaction transaction = spi.kernelTransaction(); RelationshipScanCursor relationships = transaction.ambientRelationshipCursor(); PropertyCursor properties = transaction.ambientPropertyCursor(); int propertyKey = transaction.tokenRead().propertyKey( key ); if ( propertyKey == TokenRead.NO_TOKEN ) { return defaultValue; } singleRelationship( transaction, relationships ); relationships.properties( properties ); while ( properties.next() ) { if ( propertyKey == properties.propertyKey() ) { Value value = properties.propertyValue(); return value == Values.NO_VALUE ? defaultValue : value.asObjectCopy(); } } return defaultValue; }
@Override public Object getProperty( String key, Object defaultValue ) { if ( null == key ) { throw new IllegalArgumentException( "(null) property key is not allowed" ); } KernelTransaction transaction = safeAcquireTransaction(); NodeCursor nodes = transaction.ambientNodeCursor(); PropertyCursor properties = transaction.ambientPropertyCursor(); int propertyKey = transaction.tokenRead().propertyKey( key ); if ( propertyKey == TokenRead.NO_TOKEN ) { return defaultValue; } singleNode( transaction, nodes ); nodes.properties( properties ); while ( properties.next() ) { if ( propertyKey == properties.propertyKey() ) { Value value = properties.propertyValue(); return value == Values.NO_VALUE ? defaultValue : value.asObjectCopy(); } } return defaultValue; }
@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" ) ) ); } }
private Value getPropertyValueFromStore( long nodeReference ) { try ( NodeCursor storeCursor = cursors.allocateNodeCursor(); PropertyCursor propertyCursor = cursors.allocatePropertyCursor() ) { read.singleNode( nodeReference, storeCursor ); storeCursor.next(); storeCursor.properties( propertyCursor ); propertyCursor.next(); return propertyCursor.propertyValue(); } }
@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() ); } }
@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() ); } }
Value relationshipGetProperty( Transaction transaction, long relationship, int property ) { try ( RelationshipScanCursor cursor = transaction.cursors().allocateRelationshipScanCursor(); PropertyCursor properties = transaction.cursors().allocatePropertyCursor() ) { transaction.dataRead().singleRelationship( relationship, cursor ); if ( !cursor.next() ) { return NO_VALUE; } else { cursor.properties( properties ); while ( properties.next() ) { if ( properties.propertyKey() == property ) { return properties.propertyValue(); } } return NO_VALUE; } } }
private void assertAccessSingleProperty( long nodeId, Object expectedValue, ValueGroup expectedValueType ) { // given try ( NodeCursor node = cursors.allocateNodeCursor(); PropertyCursor props = cursors.allocatePropertyCursor() ) { // when read.singleNode( nodeId, node ); assertTrue( "node by reference", node.next() ); assertTrue( "has properties", hasProperties( node, props ) ); node.properties( props ); assertTrue( "has properties by direct method", props.next() ); assertEquals( "correct value", expectedValue, props.propertyValue() ); assertEquals( "correct value type ", expectedValueType, props.propertyType() ); assertFalse( "single property", props.next() ); read.nodeProperties( node.nodeReference(), node.propertiesReference(), props ); assertTrue( "has properties via property ref", props.next() ); assertEquals( "correct value", expectedValue, props.propertyValue() ); assertFalse( "single property", props.next() ); } }
assertEquals( property.propertyValue(), stringValue( "hello" ) ); assertEquals( property.propertyValue(), stringValue( "world" ) );