/** * 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; }
MutableIntSet propertyIds = IntSets.mutable.empty(); while ( propertyCursor.next() ) int propertyKey = propertyCursor.propertyKey(); Value currentValue = propertyCursor.propertyValue(); Pair<Integer,Integer> key = Pair.of( typeId, propertyKey ); updateValueTypeInMapping( currentValue, key, relMappings.relationshipTypeIdANDPropertyTypeIdToValueType ); propertyCursor.close();
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() ); } }
private boolean hasKey( PropertyCursor propertyCursor, int key ) { while ( propertyCursor.next() ) { if ( propertyCursor.propertyKey() == key ) { return true; } } return false; }
private boolean acceptByStoreFiltering( long reference, int storeLookups, Value[] values ) { // Initialize the property cursor scan read.singleNode( reference, node ); if ( !node.next() ) { // This node doesn't exist, therefore it cannot be accepted property.close(); return false; } node.properties( property ); while ( storeLookups > 0 && property.next() ) { for ( int i = 0; i < filters.length; i++ ) { IndexQuery filter = filters[i]; if ( filter != null && (values == null || values[i] == NO_VALUE) && property.propertyKey() == filter.propertyKeyId() ) { if ( !filter.acceptsValueAt( property ) ) { return false; } storeLookups--; } } } return storeLookups == 0; }
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(); } }
private boolean hasProperties( NodeCursor node, PropertyCursor props ) { node.properties( props ); return props.next(); }
@Test public void propertyTypeShouldBeTxStateAware() throws Exception { // Given long node; try ( Transaction tx = beginTransaction() ) { node = tx.dataWrite().nodeCreate(); tx.success(); } // Then try ( Transaction tx = beginTransaction() ) { try ( NodeCursor nodes = tx.cursors().allocateNodeCursor(); PropertyCursor properties = tx.cursors().allocatePropertyCursor() ) { tx.dataRead().singleNode( node, nodes ); assertTrue( nodes.next() ); assertFalse( hasProperties( nodes, properties ) ); int prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ); tx.dataWrite().nodeSetProperty( node, prop, stringValue( "foo" ) ); nodes.properties( properties ); assertTrue( properties.next() ); assertThat( properties.propertyType(), equalTo( ValueGroup.TEXT ) ); } } }
public boolean acceptsValueAt( PropertyCursor property ) { return acceptsValue( property.propertyValue() ); }
@Override public Iterable<String> getPropertyKeys() { KernelTransaction transaction = safeAcquireTransaction(); List<String> keys = new ArrayList<>(); try { PropertyCursor properties = transaction.ambientPropertyCursor(); TokenRead token = transaction.tokenRead(); transaction.dataRead().graphProperties( properties ); while ( properties.next() ) { keys.add( token.propertyKeyName( properties.propertyKey() ) ); } } catch ( PropertyKeyIdNotFoundKernelException e ) { throw new IllegalStateException( "Property key retrieved through kernel API should exist.", e ); } return keys; }
private boolean acceptByStoreFiltering( long reference, int storeLookups, Value[] values ) { // Initialize the property cursor scan read.singleNode( reference, node ); if ( !node.next() ) { // This node doesn't exist, therefore it cannot be accepted property.close(); return false; } node.properties( property ); while ( storeLookups > 0 && property.next() ) { for ( int i = 0; i < filters.length; i++ ) { IndexQuery filter = filters[i]; if ( filter != null && (values == null || values[i] == NO_VALUE) && property.propertyKey() == filter.propertyKeyId() ) { if ( !filter.acceptsValueAt( property ) ) { return false; } storeLookups--; } } } return storeLookups == 0; }
while ( props.next() ) values.add( props.propertyValue().asObject() );
private boolean hasProperties( NodeCursor cursor, PropertyCursor props ) { cursor.properties( props ); return props.next(); }
@Test public void propertyTypeShouldBeTxStateAware() throws Exception { // Given long relationship; try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); int token = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ); relationship = write.relationshipCreate( write.nodeCreate(), token, write.nodeCreate() ); tx.success(); } // Then try ( Transaction tx = beginTransaction() ) { try ( RelationshipScanCursor relationships = tx.cursors().allocateRelationshipScanCursor(); PropertyCursor properties = tx.cursors().allocatePropertyCursor() ) { tx.dataRead().singleRelationship( relationship, relationships ); assertTrue( relationships.next() ); assertFalse( hasProperties( relationships, tx ) ); int prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ); tx.dataWrite().relationshipSetProperty( relationship, prop, stringValue( "foo" ) ); relationships.properties( properties ); assertTrue( properties.next() ); assertThat( properties.propertyType(), equalTo( ValueGroup.TEXT ) ); } } }
public boolean acceptsValueAt( PropertyCursor property ) { return acceptsValue( property.propertyValue() ); }
/** * 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 Iterable<String> getPropertyKeys() { KernelTransaction transaction = safeAcquireTransaction(); List<String> keys = new ArrayList<>(); try { NodeCursor nodes = transaction.ambientNodeCursor(); PropertyCursor properties = transaction.ambientPropertyCursor(); singleNode( transaction, nodes ); TokenRead token = transaction.tokenRead(); nodes.properties( properties ); while ( properties.next() ) { keys.add( token.propertyKeyName( properties.propertyKey() ) ); } } catch ( PropertyKeyIdNotFoundKernelException e ) { throw new IllegalStateException( "Property key retrieved through kernel API should exist.", e ); } return keys; }
MutableIntSet propertyIds = IntSets.mutable.empty(); while ( propertyCursor.next() ) Value currentValue = propertyCursor.propertyValue(); int propertyKeyId = propertyCursor.propertyKey(); Pair<SortedLabels,Integer> key = Pair.of( labels, propertyKeyId ); updateValueTypeInMapping( currentValue, key, nodeMappings.labelSetANDNodePropertyKeyIdToValueType ); propertyCursor.close();
private boolean hasProperties( RelationshipScanCursor cursor, Transaction tx ) { try ( PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor() ) { cursor.properties( propertyCursor ); return propertyCursor.next(); } }
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; }