public ClosableIterator findAssociation()

in neo4j/src/main/java/org/hibernate/ogm/datastore/neo4j/remote/http/dialect/impl/HttpNeo4jEntityQueries.java [373:422]


	public ClosableIterator<RemoteNeo4jAssociationPropertiesRow> findAssociation(HttpNeo4jClient executionEngine, Long txId, 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 );
		Statements statements = new Statements();
		statements.addStatement( queryForAssociation, params, Statement.AS_ROW );
		statements.addStatement( queryForEmbedded, params, Statement.AS_ROW );
		List<StatementResult> response = executeQuery( executionEngine, txId, statements );

		if ( response != null ) {
			List<Row> data = response.get( 0 ).getData();
			List<Row> embeddedNodes = response.get( 1 ).getData();
			int embeddedNodesIndex = 0;
			List<RemoteNeo4jAssociationPropertiesRow> responseRows = new ArrayList<>( data.size() );
			for ( int i = 0; i < data.size(); i++ ) {
				String idTarget = String.valueOf( data.get( i ).getRow().get( 0 ) );

				// Read the properties of the owner, the target and the relationship that joins them
				Map<String, Object> rel = (Map<String, Object>) data.get( i ).getRow().get( 1 );
				Map<String, Object> ownerNode = (Map<String, Object>) data.get( i ).getRow().get( 2 );
				Map<String, Object> targetNode = (Map<String, Object>) data.get( i ).getRow().get( 3 );

				// Read the embedded column and add them to the target node
				while ( embeddedNodesIndex < embeddedNodes.size() ) {
					Row row = embeddedNodes.get( embeddedNodesIndex );
					String embeddedOwnerId = row.getRow().get( 0 ).toString();
					if ( embeddedOwnerId.equals( idTarget ) ) {
						addTargetEmbeddedProperties( targetNode, row );
						embeddedNodesIndex++;
					}
					else {
						break;
					}
				}
				RemoteNeo4jAssociationPropertiesRow associationPropertiesRow = new RemoteNeo4jAssociationPropertiesRow( rel, ownerNode, targetNode );
				responseRows.add( associationPropertiesRow );
			}
			if ( responseRows.isEmpty() ) {
				return EMPTY_RELATIONSHIPS;
			}
			return new ClosableIteratorAdapter<>( responseRows.iterator() );
		}
		return EMPTY_RELATIONSHIPS;
	}