@Override public void setShouldLoadAll(boolean shouldLoad) { wrappedFetchGroup.setShouldLoadAll(shouldLoad); }
/** * Configure this group to also act as a {@link LoadGroup} the same as * {@link #setShouldLoad(boolean)}. Additionally this method will apply the * provided boolean value to all nested groups already added. * * @see #setShouldLoad(boolean) to only configure this grup without * effecting existing nested groups. */ public void setShouldLoadAll(boolean shouldLoad) { this.setShouldLoad(shouldLoad); if(this.hasItems()) { Iterator<Map.Entry<String, AttributeItem>> it = getItems().entrySet().iterator(); while(it.hasNext()) { Map.Entry<String, AttributeItem> entry = it.next(); FetchGroup group = (FetchGroup)entry.getValue().getGroup(); if(group != null) { group.setShouldLoadAll(shouldLoad); } } } }
/** * Configure this group to also act as a {@link LoadGroup} the same as * {@link #setShouldLoad(boolean)}. Additionally this method will apply the * provided boolean value to all nested groups already added. * * @see #setShouldLoad(boolean) to only configure this grup without * effecting existing nested groups. */ public void setShouldLoadAll(boolean shouldLoad) { this.setShouldLoad(shouldLoad); if(this.hasItems()) { Iterator<Map.Entry<String, AttributeItem>> it = getItems().entrySet().iterator(); while(it.hasNext()) { Map.Entry<String, AttributeItem> entry = it.next(); FetchGroup group = (FetchGroup)entry.getValue().getGroup(); if(group != null) { group.setShouldLoadAll(shouldLoad); } } } }
private void applyView(JpaQuery query, String queryString, AttributeGroup attrGroup, View view, boolean singleResultExpected) { boolean useFetchGroup = attrGroup instanceof FetchGroup; FetchGroupDescription description = calculateFetchGroup(queryString, view, singleResultExpected, useFetchGroup); if (attrGroup instanceof FetchGroup) ((FetchGroup) attrGroup).setShouldLoadAll(true); if (log.isTraceEnabled()) log.trace((useFetchGroup ? "Fetch" : "Load") + " group for " + view + ":\n" + description.getAttributes().stream().collect(Collectors.joining("\n"))); for (String attribute : description.getAttributes()) { attrGroup.addAttribute(attribute); } MetaClass metaClass = metadata.getClassNN(view.getEntityClass()); if (!metadataTools.isCacheable(metaClass)) { query.setHint(useFetchGroup ? QueryHints.FETCH_GROUP : QueryHints.LOAD_GROUP, attrGroup); } if (log.isDebugEnabled()) { String fetchModes = description.getHints().entrySet().stream() .map(e -> e.getKey() + "=" + (e.getValue().equals(QueryHints.LEFT_FETCH) ? "JOIN" : "BATCH")) .collect(Collectors.joining(", ")); log.debug("Fetch modes for " + view + ": " + (fetchModes.equals("") ? "<none>" : fetchModes)); } for (Map.Entry<String, String> entry : description.getHints().entrySet()) { query.setHint(entry.getValue(), entry.getKey()); } if (description.hasBatches()) { query.setHint(QueryHints.BATCH_TYPE, "IN"); } }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isObjectLevelReadQuery()) { FetchGroup fetchGroup = ((ObjectLevelReadQuery)query).getFetchGroup(); if (fetchGroup == null) { fetchGroup = new FetchGroup(); ((ObjectLevelReadQuery)query).setFetchGroup(fetchGroup); } fetchGroup.setShouldLoadAll((Boolean)valueToApply); } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isObjectLevelReadQuery()) { if(valueToApply != null) { if (valueToApply instanceof String){ AttributeGroup eg = activeSession.getAttributeGroups().get(valueToApply); if (eg != null){ FetchGroup fg = eg.toFetchGroup(); fg.setShouldLoadAll(true); ((ObjectLevelReadQuery)query).setFetchGroup(fg); }else{ throw new IllegalArgumentException(ExceptionLocalization.buildMessage("no_entity_graph_of_name", new Object[]{valueToApply})); } }else if (valueToApply instanceof EntityGraphImpl){ FetchGroup fg = ((EntityGraphImpl)valueToApply).getAttributeGroup().toFetchGroup(); fg.setShouldLoadAll(true); ((ObjectLevelReadQuery)query).setFetchGroup(fg); }else{ throw new IllegalArgumentException(ExceptionLocalization.buildMessage("not_usable_passed_to_entitygraph_hint", new Object[]{QueryHints.JPA_FETCH_GRAPH, valueToApply})); } } else { ((ObjectLevelReadQuery)query).setFetchGroup(null); } } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }