Skip to content

Commit

Permalink
Fix for ReportQuery not fetching relationships with BatchFetch.IN (ec…
Browse files Browse the repository at this point in the history
…lipse-ee4j#2303)

(cherry picked from commit d7114a0)
  • Loading branch information
Sheikah45 committed Nov 22, 2024
1 parent fc24a51 commit 1cd3cfb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,12 @@ public Object executeDatabaseQuery() throws DatabaseException {
return getDescriptor().getInterfacePolicy().selectAllObjectsUsingMultipleTableSubclassRead(this);
}

return buildObjects(getQueryMechanism().selectAllReportQueryRows());
List<AbstractRecord> rows = getQueryMechanism().selectAllReportQueryRows();
if ((this.batchFetchPolicy != null) && this.batchFetchPolicy.isIN()) {
this.batchFetchPolicy.setDataResults(rows);
}

return buildObjects((Vector) rows);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020 IBM Corporation. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -239,9 +239,26 @@ protected Object processItem(ReportQuery query, AbstractRecord row, Vector toMan
AbstractRecord subRow = row;
// Check if at the start of the row, then avoid building a subRow.
if (itemIndex > 0) {
Vector trimedFields = new NonSynchronizedSubVector(row.getFields(), itemIndex, rowSize);
Vector trimedValues = new NonSynchronizedSubVector(row.getValues(), itemIndex, rowSize);
subRow = new DatabaseRecord(trimedFields, trimedValues);
BatchFetchPolicy batchFetchPolicy = query.getBatchFetchPolicy();
if (batchFetchPolicy != null && batchFetchPolicy.isIN()) {

List<AbstractRecord> subRows = new ArrayList(toManyData.size());
for (AbstractRecord parentRow : (Vector<AbstractRecord>) toManyData) {
Vector<DatabaseField> trimedParentFields = new NonSynchronizedSubVector<>(parentRow.getFields(), itemIndex, rowSize);
Vector trimedParentValues = new NonSynchronizedSubVector<>(parentRow.getValues(), itemIndex, rowSize);
subRows.add(new DatabaseRecord(trimedParentFields, trimedParentValues));
}

for (DatabaseMapping subMapping : descriptor.getMappings()) {
batchFetchPolicy.setDataResults(subMapping, subRows);
}

subRow = subRows.get(toManyData.indexOf(row));
} else {
Vector trimedFields = new NonSynchronizedSubVector(row.getFields(), itemIndex, rowSize);
Vector trimedValues = new NonSynchronizedSubVector(row.getValues(), itemIndex, rowSize);
subRow = new DatabaseRecord(trimedFields, trimedValues);
}
}
if (mapping != null && mapping.isAggregateObjectMapping()){
value = ((AggregateObjectMapping)mapping).buildAggregateFromRow(subRow, null, null, joinManager, query, false, query.getSession(), true);
Expand Down

0 comments on commit 1cd3cfb

Please sign in to comment.