/** * INTERNAL: * Allow the mapping the do any further batch preparation. */ protected void postPrepareNestedBatchQuery(ReadQuery batchQuery, ReadAllQuery query) { // Force a distinct to filter out m-1 duplicates. if (!query.isDistinctComputed()) { ((ObjectLevelReadQuery)batchQuery).useDistinct(); } if(this.mechanism != null) { ReadAllQuery mappingBatchQuery = (ReadAllQuery)batchQuery; mappingBatchQuery.setShouldIncludeData(true); for (Enumeration relationFieldsEnum = this.mechanism.getSourceRelationKeyFields().elements(); relationFieldsEnum.hasMoreElements();) { mappingBatchQuery.getAdditionalFields().add(mappingBatchQuery.getExpressionBuilder().getTable(this.mechanism.getRelationTable()).getField((DatabaseField)relationFieldsEnum.nextElement())); } } }
void visitAbstractSelectClause(AbstractSelectClause expression) { // DISTINCT if (expression.hasDistinct()) { CountFunctionVisitor visitor = new CountFunctionVisitor(); expression.accept(visitor); if (!visitor.hasCountFunction) { query.useDistinct(); } } // Indicate on the query if "return null if primary key null". // This means we want nulls returned if we expect an outer join // True: SELECT employee.address FROM ..... // Simple 1:1 // True: SELECT a.b.c.d FROM ..... // where a->b, b->c and c->d are all 1:1. // False: SELECT OBJECT(employee) FROM ..... // simple SELECT // False: SELECT phoneNumber.areaCode FROM ..... // direct-to-field OneToOneSelectedVisitor visitor = new OneToOneSelectedVisitor(); expression.accept(visitor); query.setShouldBuildNullForNullPk(visitor.oneToOneSelected); // Now visit the select expression expression.getSelectExpression().accept(this); }
void visitAbstractSelectClause(AbstractSelectClause expression) { // DISTINCT if (expression.hasDistinct()) { CountFunctionVisitor visitor = new CountFunctionVisitor(); expression.accept(visitor); if (!visitor.hasCountFunction) { query.useDistinct(); } } // Indicate on the query if "return null if primary key null". // This means we want nulls returned if we expect an outer join // True: SELECT employee.address FROM ..... // Simple 1:1 // True: SELECT a.b.c.d FROM ..... // where a->b, b->c and c->d are all 1:1. // False: SELECT OBJECT(employee) FROM ..... // simple SELECT // False: SELECT phoneNumber.areaCode FROM ..... // direct-to-field OneToOneSelectedVisitor visitor = new OneToOneSelectedVisitor(); expression.accept(visitor); query.setShouldBuildNullForNullPk(visitor.oneToOneSelected); // Now visit the select expression expression.getSelectExpression().accept(this); }
/** * INTERNAL: * Allow the mapping the do any further batch preparation. */ @Override protected void postPrepareNestedBatchQuery(ReadQuery batchQuery, ObjectLevelReadQuery query) { super.postPrepareNestedBatchQuery(batchQuery, query); // Force a distinct to filter out m-1 duplicates. // Only set if really a m-1, not a 1-1 if (!this.isOneToOneRelationship && ((ObjectLevelReadQuery)batchQuery).getBatchFetchPolicy().isJOIN()) { if (!((ObjectLevelReadQuery)batchQuery).isDistinctComputed() && (batchQuery.getSession().getPlatform().isLobCompatibleWithDistinct() || !Helper.hasLob(batchQuery.getDescriptor().getSelectionFields((ObjectLevelReadQuery)batchQuery)))) { ((ObjectLevelReadQuery)batchQuery).useDistinct(); } } if (this.mechanism != null) { this.mechanism.postPrepareNestedBatchQuery(batchQuery, query); } }
/** * INTERNAL: * Allow the mapping the do any further batch preparation. */ @Override protected void postPrepareNestedBatchQuery(ReadQuery batchQuery, ObjectLevelReadQuery query) { super.postPrepareNestedBatchQuery(batchQuery, query); // Force a distinct to filter out m-1 duplicates. // Only set if really a m-1, not a 1-1 if (!this.isOneToOneRelationship && ((ObjectLevelReadQuery)batchQuery).getBatchFetchPolicy().isJOIN()) { if (!((ObjectLevelReadQuery)batchQuery).isDistinctComputed() && (batchQuery.getSession().getPlatform().isLobCompatibleWithDistinct() || !Helper.hasLob(batchQuery.getDescriptor().getSelectionFields((ObjectLevelReadQuery)batchQuery)))) { ((ObjectLevelReadQuery)batchQuery).useDistinct(); } } if (this.mechanism != null) { this.mechanism.postPrepareNestedBatchQuery(batchQuery, query); } }