public ClosableIterator findAssociation()

in neo4j/src/main/java/org/hibernate/ogm/datastore/neo4j/remote/bolt/dialect/impl/BoltNeo4jEntityQueries.java [285:337]


	public ClosableIterator<RemoteNeo4jAssociationPropertiesRow> findAssociation(Transaction tx, Object[] columnValues, String role, AssociationKeyMetadata associationKeyMetadata) {
		// Find the target node
		String queryForAssociation = getFindAssociationQuery( role, associationKeyMetadata );

		// Find the embedded properties of the target node
		String queryForEmbedded = getFindAssociationTargetEmbeddedValues( role, associationKeyMetadata );

		// Execute the queries
		Map<String, Object> params = params( columnValues );

		Statement associationStatement = new Statement( queryForAssociation, params );
		StatementResult associationResult = tx.run( associationStatement );

		Statement embeddedStatement = new Statement( queryForEmbedded, params );
		StatementResult embeddedResult = tx.run( embeddedStatement );

		List<RemoteNeo4jAssociationPropertiesRow> responseRows = new ArrayList<>();
		Record embeddedRecord = null;
		while ( associationResult.hasNext() ) {
			Record record = associationResult.next();
			Object idTarget = record.get( 0 );
			Map<String, Object> ownerNode = record.get( ENTITY_ALIAS ).asMap();
			Map<String, Object> targetNode = new HashMap<>( record.get( "target" ).asMap() );
			Map<String, Object> rel = record.get( "r" ).asMap();

			while ( embeddedResult.hasNext() || embeddedRecord != null ) {
				if ( embeddedRecord == null ) {
					embeddedRecord = embeddedResult.next();
				}
				Object embeddedOwnerId = embeddedRecord.get( 0 );
				if ( embeddedOwnerId.equals( idTarget ) ) {
					addTargetEmbeddedProperties( targetNode, embeddedRecord );
					if ( embeddedResult.hasNext() ) {
						embeddedRecord = embeddedResult.next();
					}
					else {
						embeddedRecord = null;
					}
				}
				else {
					break;
				}
			}

			RemoteNeo4jAssociationPropertiesRow associationPropertiesRow = new RemoteNeo4jAssociationPropertiesRow( rel, ownerNode, targetNode );
			responseRows.add( associationPropertiesRow );
		}
		if ( responseRows.isEmpty() ) {
			return EMPTY_RELATIONSHIPS;
		}
		return new ClosableIteratorAdapter<>( responseRows.iterator() );

	}