private boolean hasKey( PropertyCursor propertyCursor, int key ) { while ( propertyCursor.next() ) { if ( propertyCursor.propertyKey() == key ) { return true; } } return false; }
@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; }
@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; }
@Override public Iterable<String> getPropertyKeys() { KernelTransaction transaction = spi.kernelTransaction(); List<String> keys = new ArrayList<>(); try { RelationshipScanCursor relationships = transaction.ambientRelationshipCursor(); PropertyCursor properties = transaction.ambientPropertyCursor(); singleRelationship( transaction, relationships ); TokenRead token = transaction.tokenRead(); relationships.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; }
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; }
@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; }
@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; }
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 ) ); }
@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 boolean hasProperty( String key ) { if ( null == key ) { return false; } KernelTransaction transaction = safeAcquireTransaction(); int propertyKey = transaction.tokenRead().propertyKey( key ); if ( propertyKey == TokenRead.NO_TOKEN ) { return false; } PropertyCursor properties = transaction.ambientPropertyCursor(); transaction.dataRead().graphProperties( properties ); while ( properties.next() ) { if ( propertyKey == properties.propertyKey() ) { return true; } } return false; }
@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; }
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; }
@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" ) ) ); } }
@Override public boolean hasProperty( String key ) { if ( null == key ) { return false; } KernelTransaction transaction = spi.kernelTransaction(); int propertyKey = transaction.tokenRead().propertyKey( key ); if ( propertyKey == TokenRead.NO_TOKEN ) { return false; } RelationshipScanCursor relationships = transaction.ambientRelationshipCursor(); PropertyCursor properties = transaction.ambientPropertyCursor(); singleRelationship( transaction, relationships ); relationships.properties( properties ); while ( properties.next() ) { if ( propertyKey == properties.propertyKey() ) { return true; } } return false; }
@Override public boolean hasProperty( String key ) { if ( null == key ) { return false; } KernelTransaction transaction = safeAcquireTransaction(); int propertyKey = transaction.tokenRead().propertyKey( key ); if ( propertyKey == TokenRead.NO_TOKEN ) { return false; } NodeCursor nodes = transaction.ambientNodeCursor(); PropertyCursor properties = transaction.ambientPropertyCursor(); singleNode( transaction, nodes ); nodes.properties( properties ); while ( properties.next() ) { if ( propertyKey == properties.propertyKey() ) { return true; } } return false; }
@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() ); } }
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; } } }