paulk-asert opened a new pull request, #318:
URL: https://github.com/apache/openjpa/pull/318

   [OPENJPA-3092](https://issues.apache.org/jira/browse/OPENJPA-3092): Criteria 
API set operations (`CriteriaBuilder.union`, `unionAll`, `intersect`, `except`) 
built their compound `QueryExpressions` in 
`CriteriaSelectImpl.getQueryExpressions()` without projections and with 
`DISTINCT_AUTO`, as the JPQL builder did before OPENJPA-3091:
   
   - a union of `CriteriaQuery<String>` operands returned `Object[]` rows of 
length 1;
   - `cb.construct(...)` and tuple operands were not packed, e.g. `Object[]` 
rows in place of the constructed class;
   - once projections are copied, `DISTINCT_AUTO` would turn on in-memory 
duplicate removal and `UNION ALL` would lose rows.
   
   Changes:
   1. Move the handling OPENJPA-3091 added to 
`JPQLExpressionBuilder.evalSetOperatorExpressions()` into a helper, 
`QueryExpressions.useResultOfFirstSetOperand()`. It copies the projections, 
aliases, clauses, result class and result shape of the first (leftmost) operand 
onto the compound and sets `distinct` to `DISTINCT_FALSE`.
   2. Call it from both `JPQLExpressionBuilder` and `CriteriaSelectImpl`. The 
JPQL behaviour is unchanged.
   
   `QueryExpressions.isAggregate()` and the prepared query SQL cache exclusion 
from OPENJPA-3091 already apply to criteria set operations, since they look at 
the compound's `setOperationType`.
   
   Testing:
   - New `TestCriteriaSetOperations`, which clears and seeds its own `CompUser` 
rows (as `TestSelectionParameters` does), executes each set operation twice and 
checks the values:
     - `scalarResults`: `union`, `unionAll` (keeping duplicates), `intersect` 
and `except` over `CriteriaQuery<String>`;
     - `nestedSetOperation`: an `except` whose left operand is a `unionAll`;
     - `multiselectResults`: `Object[]` rows;
     - `constructedResults`: `cb.construct(...)` operands yield the constructed 
class;
     - `constructedAmongSeveralSelections`: a constructor that is one of 
several selections yields `[dto, value]` rows;
     - `tupleResults`: tuple operands yield `Tuple` rows.
   - Without the fix, `scalarResults`, `nestedSetOperation` and 
`constructedResults` fail. Removing any one line of the helper makes at least 
one test fail.
   - `TestEntityManagerFactoryTCK.selected()` unwrapped single-element 
`Object[]` rows, with a comment noting that set operations pack them that way. 
It now expects the projected values themselves.
   - The existing smoke tests in `TestTypesafeCriteria` (`criteriaUnion` and 
others) are left as they are. Their class shares its tables with other test 
classes and deliberately does not seed rows, so the value checks live in the 
new class instead.
   - The full test suites of openjpa-kernel, openjpa-jdbc, openjpa-persistence 
and openjpa-persistence-jdbc pass on the default test database (4,701 tests), 
as do the RAT checks.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to