private void indexRelationship( long id ) { if ( !visitingNodes ) { read.singleRelationship( id, relationshipCursor ); if ( relationshipCursor.next() && schema.isAffected( new long[]{relationshipCursor.type()} ) ) { relationshipCursor.properties( propertyCursor ); indexProperties( id ); } } }
@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; }
PropertyCursor propertyCursor = transaction.ambientPropertyCursor(); singleRelationship( transaction, relationships ); relationships.properties( propertyCursor ); int propertiesToFind = itemsToReturn; while ( propertiesToFind > 0 && propertyCursor.next() )
/** * 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; }
private boolean hasProperties( RelationshipScanCursor cursor, Transaction tx ) { try ( PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor() ) { cursor.properties( propertyCursor ); return propertyCursor.next(); } }
PropertyCursor properties = transaction.ambientPropertyCursor(); singleRelationship( transaction, relationships ); relationships.properties( properties ); while ( properties.next() )
@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 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; }
relationshipScanCursor.properties( propertyCursor ); MutableIntSet propertyIds = IntSets.mutable.empty();
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; } } }
@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 ) ); } } }
assertTrue( "should access relationship", relationship.next() ); relationship.properties( property );
assertTrue( "should access relationship", relationship.next() ); relationship.properties( property ); assertTrue( property.next() ); assertEquals( propToken, property.propertyKey() );
assertTrue( "should access relationship", relationship.next() ); relationship.properties( property );
assertTrue( "should access relationship", relationship.next() ); relationship.properties( property ); assertTrue( property.next() ); assertEquals( propToken, property.propertyKey() );
assertTrue( "should access relationship", relationship.next() ); relationship.properties( property ); assertFalse( "should not find any properties", property.next() ); assertFalse( "should only find one relationship", relationship.next() );
@Override public void validateRelationshipPropertyExistenceConstraint( RelationshipScanCursor relationshipCursor, PropertyCursor propertyCursor, RelationTypeSchemaDescriptor descriptor ) throws CreateConstraintFailureException { while ( relationshipCursor.next() ) { relationshipCursor.properties( propertyCursor ); for ( int propertyKey : descriptor.getPropertyIds() ) { if ( relationshipCursor.type() == descriptor.getRelTypeId() && !hasProperty( propertyCursor, propertyKey ) ) { throw createConstraintFailure( new RelationshipPropertyExistenceException( descriptor, VERIFICATION, relationshipCursor.relationshipReference() ) ); } } } }
static void visitWeight( Read readOp, CursorFactory cursors, int sourceGraphId, int targetGraphId, WeightMap weights, long relationshipId) { // TODO: make access to rel properties better try (RelationshipScanCursor scanCursor = cursors.allocateRelationshipScanCursor(); PropertyCursor pc = cursors.allocatePropertyCursor()) { readOp.singleRelationship(relationshipId, scanCursor); while (scanCursor.next()) { scanCursor.properties(pc); double weight = ReadHelper.readProperty(pc, weights.propertyId(), weights.defaultValue()); if (weight != weights.defaultValue()) { long relId = RawValues.combineIntInt(sourceGraphId, targetGraphId); weights.put(relId, weight); } } } }
static void visitUndirectedWeight( Read readOp, CursorFactory cursors, int sourceGraphId, int targetGraphId, WeightMap weights, long relationshipId) { // TODO: make access to rel properties better try (RelationshipScanCursor scanCursor = cursors.allocateRelationshipScanCursor(); PropertyCursor pc = cursors.allocatePropertyCursor()) { readOp.singleRelationship(relationshipId, scanCursor); while (scanCursor.next()) { scanCursor.properties(pc); double weight = ReadHelper.readProperty(pc, weights.propertyId(), weights.defaultValue()); if (weight != weights.defaultValue()) { long relId = RawValues.combineIntInt(sourceGraphId, targetGraphId); weights.put(relId, weight); relId = RawValues.combineIntInt(targetGraphId, sourceGraphId); weights.put(relId, weight); } } } }