/** * Adds this receiver as one of the included fetch groups of the given * parent. * The parent fetch group will include this receiver as a side-effect of * this call. * * @see #includes(String, boolean) * @see #addDeclaredInclude(String) * * @return true if given parent is a new addition. false othrwise. * @since 1.1.0 */ public boolean addContainedBy(FetchGroup parent) { parent.addDeclaredInclude(this.getName()); if (_containedBy==null) _containedBy = new HashSet<String>(); return _containedBy.add(parent.getName()); }
/** * Copy state from the given fetch group. */ void copy(FetchGroup fg) { if (fg._includes != null) { for (String included : fg._includes) { addDeclaredInclude(included); } } if (fg._containedBy != null) { this._containedBy = new HashSet<String>(fg._containedBy); } if (fg._depths != null) { for (Map.Entry<FieldMetaData,Number> entry : fg._depths.entrySet()) { setRecursionDepth(entry.getKey(), entry.getValue().intValue()); } } if (fg._postLoad != null) { _postLoad = fg._postLoad; } }
public Division findDivChildren(Integer id) { Division result = null; FetchGroup group = new FetchGroup("divChildren"); group.addAttribute("_id"); group.addAttribute("_children"); Query q = em.createQuery("Select d from Division d where d.id = :id").setParameter("id", id); q.setHint(QueryHints.FETCH_GROUP, group); result = q.getSingleResult() return (result); }
fg.setPostLoad(true); for (String s : group.fetchGroups()) { fg.addDeclaredInclude(s); String[] includedFetchGropNames = fg.getDeclaredIncludes(); for (String includedFectchGroupName:includedFetchGropNames) { org.apache.openjpa.meta.FetchGroup child = if (child == null) throw new UserException(_loc.get("missing-included-fg", meta.getDescribedType().getName(), fg.getName(), includedFectchGroupName)); child.addContainedBy(fg);
/** * Set a field's fetch group. */ private static void parseFetchAttribute(ClassMetaData meta, org.apache.openjpa.meta.FetchGroup fg, FetchAttributeImpl attr) { FieldMetaData field = meta.getDeclaredField(attr.name()); if (field == null || field.getManagement() != FieldMetaData.MANAGE_PERSISTENT) throw new MetaDataException(_loc.get("bad-fg-field", fg.getName(), meta, attr.name())); field.setInFetchGroup(fg.getName(), true); Set<String> parentFetchGroups = fg.getContainedBy(); for (Object parentFetchGroup : parentFetchGroups) field.setInFetchGroup(parentFetchGroup.toString(), true); if (attr.recursionDepth() != Integer.MIN_VALUE) fg.setRecursionDepth(field, attr.recursionDepth()); }
/** * Remove a declared fetch group. */ public boolean removeDeclaredFetchGroup(FetchGroup fg) { if (fg == null) return false; if (_fgMap.remove(fg.getName()) != null) { _fgs = null; _customFGs = null; return true; } return false; }
/** * Recursion depth for the given field. This is the depth of relations of * the same class as this one we can fetch through the given field. */ public int getRecursionDepth(FieldMetaData fm) { Number depth = findRecursionDepth(fm); return (depth == null) ? RECURSION_DEPTH_DEFAULT : depth.intValue(); }
/** * Adds fetch group of the given name, or returns existing instance. * * @param name a non-null, non-empty name. Must be unique within this * receiver's scope. The super class <em>may</em> have a group with * the same name. */ public FetchGroup addDeclaredFetchGroup(String name) { if (StringUtils.isEmpty(name)) throw new MetaDataException(_loc.get("empty-fg-name", this)); if (_fgMap == null) _fgMap = new HashMap<String,FetchGroup>(); FetchGroup fg = _fgMap.get(name); if (fg == null) { fg = new FetchGroup(this, name); _fgMap.put(name, fg); _fgs = null; _customFGs = null; } return fg; }
if (fm.isInDefaultFetchGroup()) max = meta.getFetchGroup(FetchGroup.NAME_DEFAULT). getRecursionDepth(fm); String[] groups = fm.getCustomFetchGroups(); int cur; cur = meta.getFetchGroup(groups[i]).getRecursionDepth(fm); if (cur == FetchGroup.DEPTH_INFINITE || cur > max) max = cur;
fg.setPostLoad(true); for (String s : group.fetchGroups()) { fg.addDeclaredInclude(s); String[] includedFetchGropNames = fg.getDeclaredIncludes(); for (String includedFectchGroupName:includedFetchGropNames) { org.apache.openjpa.meta.FetchGroup child = if (child == null) throw new UserException(_loc.get("missing-included-fg", meta.getDescribedType().getName(), fg.getName(), includedFectchGroupName)); child.addContainedBy(fg);
/** * Set a field's fetch group. */ private void parseFetchAttribute(ClassMetaData meta, org.apache.openjpa.meta.FetchGroup fg, FetchAttribute attr) { FieldMetaData field = meta.getDeclaredField(attr.name()); if (field == null || field.getManagement() != FieldMetaData.MANAGE_PERSISTENT) throw new MetaDataException(_loc.get("bad-fg-field", fg.getName(), meta, attr.name())); field.setInFetchGroup(fg.getName(), true); Set parentFetchGroups = fg.getContainedBy(); for (Object parentFetchGroup:parentFetchGroups) field.setInFetchGroup(parentFetchGroup.toString(), true); if (attr.recursionDepth() != Integer.MIN_VALUE) fg.setRecursionDepth(field, attr.recursionDepth()); }
/** * Remove a declared fetch group. */ public boolean removeDeclaredFetchGroup(FetchGroup fg) { if (fg == null) return false; if (_fgMap.remove(fg.getName()) != null) { _fgs = null; _customFGs = null; return true; } return false; }
/** * Recursion depth for the given field. This is the depth of relations of * the same class as this one we can fetch through the given field. */ public int getRecursionDepth(FieldMetaData fm) { Number depth = findRecursionDepth(fm); return (depth == null) ? RECURSION_DEPTH_DEFAULT : depth.intValue(); }
/** * Adds fetch group of the given name, or returns existing instance. * * @param name a non-null, non-empty name. Must be unique within this * receiver's scope. The super class <em>may</em> have a group with * the same name. */ public FetchGroup addDeclaredFetchGroup(String name) { if (StringUtils.isEmpty(name)) throw new MetaDataException(_loc.get("empty-fg-name", this)); if (_fgMap == null) _fgMap = new HashMap(); FetchGroup fg = (FetchGroup) _fgMap.get(name); if (fg == null) { fg = new FetchGroup(this, name); _fgMap.put(name, fg); _fgs = null; _customFGs = null; } return fg; }
if (fm.isInDefaultFetchGroup()) max = meta.getFetchGroup(FetchGroup.NAME_DEFAULT). getRecursionDepth(fm); String[] groups = fm.getCustomFetchGroups(); int cur; cur = meta.getFetchGroup(groups[i]).getRecursionDepth(fm); if (cur == FetchGroup.DEPTH_INFINITE || cur > max) max = cur;
fg.setPostLoad(true); for (String s : group.fetchGroups()) { fg.addDeclaredInclude(s); String[] includedFetchGropNames = fg.getDeclaredIncludes(); for (String includedFectchGroupName:includedFetchGropNames) { org.apache.openjpa.meta.FetchGroup child = if (child == null) throw new UserException(_loc.get("missing-included-fg", meta.getDescribedType().getName(), fg.getName(), includedFectchGroupName)); child.addContainedBy(fg);
/** * Set a field's fetch group. */ private static void parseFetchAttribute(ClassMetaData meta, org.apache.openjpa.meta.FetchGroup fg, FetchAttributeImpl attr) { FieldMetaData field = meta.getDeclaredField(attr.name()); if (field == null || field.getManagement() != FieldMetaData.MANAGE_PERSISTENT) throw new MetaDataException(_loc.get("bad-fg-field", fg.getName(), meta, attr.name())); field.setInFetchGroup(fg.getName(), true); Set<String> parentFetchGroups = fg.getContainedBy(); for (Object parentFetchGroup : parentFetchGroups) field.setInFetchGroup(parentFetchGroup.toString(), true); if (attr.recursionDepth() != Integer.MIN_VALUE) fg.setRecursionDepth(field, attr.recursionDepth()); }
/** * Adds this receiver as one of the included fetch groups of the given * parent. * The parent fetch group will include this receiver as a side-effect of * this call. * * @see #includes(String, boolean) * @see #addDeclaredInclude(String) * * @return true if given parent is a new addition. false othrwise. * @since 1.1.0 */ public boolean addContainedBy(FetchGroup parent) { parent.addDeclaredInclude(this.getName()); if (_containedBy==null) _containedBy = new HashSet<String>(); return _containedBy.add(parent.getName()); }