private boolean hasProperties( NodeCursor node, PropertyCursor props ) { node.properties( props ); return props.next(); }
private boolean hasProperties( NodeCursor cursor, PropertyCursor props ) { cursor.properties( props ); return props.next(); }
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; }
@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; }
@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; }
private boolean hasProperties( RelationshipScanCursor cursor, Transaction tx ) { try ( PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor() ) { cursor.properties( propertyCursor ); return propertyCursor.next(); } }
@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; }
@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 = 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; }
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() ); } }
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() ); } }
@Test public void shouldNotSeeRemovedGraphPropertyInTransaction() 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().graphRemoveProperty( prop ), equalTo( stringValue( "hello" ) ) ); tx.dataRead().graphProperties( cursor ); assertFalse( cursor.next() ); } }
@Test public void shouldNotAccessNonExistentProperties() { // given try ( NodeCursor node = cursors.allocateNodeCursor(); PropertyCursor props = cursors.allocatePropertyCursor() ) { // when read.singleNode( bare, node ); assertTrue( "node by reference", node.next() ); assertFalse( "no properties", hasProperties( node, props ) ); node.properties( props ); assertFalse( "no properties by direct method", props.next() ); read.nodeProperties( node.nodeReference(), node.propertiesReference(), props ); assertFalse( "no properties via property ref", props.next() ); assertFalse( "only one node", node.next() ); } }