@Override public List<I_M_HU_Assignment> retrieveIncludedHUAssignments(final I_M_HU_Assignment assignment) { final IQueryBL queryBL = Services.get(IQueryBL.class); final IQueryBuilder<I_M_HU_Assignment> queryBuilder = queryBL.createQueryBuilder(I_M_HU_Assignment.class, assignment); queryBuilder // references same record.. .addEqualsFilter(I_M_HU_Assignment.COLUMN_AD_Table_ID, assignment.getAD_Table_ID()) .addEqualsFilter(I_M_HU_Assignment.COLUMN_Record_ID, assignment.getRecord_ID()) // ..and same toplevel-HU.. .addEqualsFilter(I_M_HU_Assignment.COLUMN_M_HU_ID, assignment.getM_HU_ID()); // ..but additionally references one of the HU's components (TU or LU) final ICompositeQueryFilter<I_M_HU_Assignment> subFilter = queryBL.createCompositeQueryFilter(I_M_HU_Assignment.class); subFilter .setJoinOr() .addNotEqualsFilter(I_M_HU_Assignment.COLUMN_M_LU_HU_ID, null) .addNotEqualsFilter(I_M_HU_Assignment.COLUMN_M_TU_HU_ID, null); queryBuilder.filter(subFilter); // return queryBuilder.create().list(I_M_HU_Assignment.class); }
@Override public <T> List<T> retrieveModelsForHU( final I_M_HU hu, final Class<T> clazz, final boolean topLevel) { final IQueryBL queryBL = Services.get(IQueryBL.class); final int tableId = InterfaceWrapperHelper.getTableId(clazz); final String keyColumnName = InterfaceWrapperHelper.getKeyColumnName(clazz); final IQueryBuilder<I_M_HU_Assignment> huAssigmentQueryBuilder = queryBL .createQueryBuilder(I_M_HU_Assignment.class, hu) .addOnlyContextClientOrSystem() .addOnlyActiveRecordsFilter() .addEqualsFilter(I_M_HU_Assignment.COLUMN_AD_Table_ID, tableId); if (topLevel) { huAssigmentQueryBuilder.addEqualsFilter(I_M_HU_Assignment.COLUMN_M_HU_ID, hu.getM_HU_ID()); applyCommonTopLevelFilters(huAssigmentQueryBuilder, tableId); } else { final ICompositeQueryFilter<I_M_HU_Assignment> filter = queryBL .createCompositeQueryFilter(I_M_HU_Assignment.class) .setJoinOr() .addEqualsFilter(I_M_HU_Assignment.COLUMN_M_LU_HU_ID, hu.getM_HU_ID()) .addEqualsFilter(I_M_HU_Assignment.COLUMN_M_TU_HU_ID, hu.getM_HU_ID()) .addEqualsFilter(I_M_HU_Assignment.COLUMN_VHU_ID, hu.getM_HU_ID()); huAssigmentQueryBuilder.filter(filter); } final IQuery<I_M_HU_Assignment> huAssigmentQuery = huAssigmentQueryBuilder.create(); // @formatter:off return queryBL .createQueryBuilder(clazz, hu) .addOnlyContextClientOrSystem() .addOnlyActiveRecordsFilter() .addInSubQueryFilter( keyColumnName, I_M_HU_Assignment.COLUMNNAME_Record_ID, huAssigmentQuery) .orderBy() .addColumn(InterfaceWrapperHelper.getKeyColumnName(clazz)) .endOrderBy() .create() .list(clazz); // @formatter:on }