/** * INTERNAL: * Union two fetch groups. */ public FetchGroup unionFetchGroups(FetchGroup first, FetchGroup second) { if ((first == null) || (second == null)) { return null; } //return the superset if applied if (first.isSupersetOf(second)) { return first; } else if (second.isSupersetOf(first)) { return second; } //otherwise, union two fetch groups StringBuffer unionGroupName = new StringBuffer(first.getName()); unionGroupName.append("_"); unionGroupName.append(second.getName()); FetchGroup unionFetchGroup = new FetchGroup(unionGroupName.toString()); unionFetchGroup.addAttributes(first.getAttributes()); unionFetchGroup.addAttributes(second.getAttributes()); return unionFetchGroup; }
public EntityFetchGroup(FetchGroup fetchGroup, String attributeName) { super(fetchGroup.getName() + "+" + attributeName); if(fetchGroup.hasItems()) { Iterator<String> it = fetchGroup.getItems().keySet().iterator(); while(it.hasNext()) { super.addAttribute(it.next(), (AttributeGroup)null); } } super.addAttribute(attributeName, (AttributeGroup)null); }
/** * INTERNAL: * Add primary key and version attributes to the passed fetch group. */ public void addMinimalFetchGroup(FetchGroup fetchGroup) { if (this.minimalFetchGroup == null) { return; } Iterator<String> it = this.minimalFetchGroup.getAttributeNames().iterator(); while(it.hasNext()) { String name = it.next(); if(!fetchGroup.containsAttribute(name)) { fetchGroup.addAttribute(name); } } }
@Override protected FetchGroup newGroup(String name, CoreAttributeGroup parent) { FetchGroup fetchGroup = new FetchGroup(name); if(parent != null) { fetchGroup.setShouldLoad(((FetchGroup)parent).shouldLoad()); } return fetchGroup; }
protected Object constructObjectForId(String entityType, Object id){ FetchGroup fetchGroup = new FetchGroup(); ClassDescriptor descriptor = context.getDescriptor(entityType); List<DatabaseMapping> pkMappings = descriptor.getObjectBuilder().getPrimaryKeyMappings(); for (DatabaseMapping mapping: pkMappings){ fetchGroup.addAttribute(mapping.getAttributeName()); } Map<String, Object> properties = new HashMap<String, Object>(); properties.put(QueryHints.FETCH_GROUP, fetchGroup); properties.put(QueryHints.CACHE_USAGE, CacheUsage.CheckCacheOnly); Object entity = context.find(null, entityType, id, properties); if (entity == null){ return IdHelper.buildObjectShell(context, entityType, id); } return entity; }
return getNonReferenceEntityFetchGroup(); FetchGroup nonReferenceFetchGroup = new FetchGroup(); for (DatabaseMapping mapping : getDescriptor().getMappings()) { if(!mapping.isForeignReferenceMapping()) { String name = mapping.getAttributeName(); if(this.defaultEntityFetchGroup == null || this.defaultEntityFetchGroup.containsAttribute(name)) { nonReferenceFetchGroup.addAttribute(name); for(DatabaseMapping mapping : descriptor.getObjectBuilder().getPrimaryKeyMappings()) { String name = mapping.getAttributeName(); if(!nonReferenceFetchGroup.containsAttribute(name)) { nonReferenceFetchGroup.addAttribute(name); if(mapping.isForeignReferenceMapping()) { String name = mapping.getAttributeName(); if(!nonReferenceFetchGroup.containsAttribute(name)) { nonReferenceFetchGroup.addAttribute(name); String lockAttribute = descriptor.getObjectBuilder().getLockAttribute(); if(lockAttribute != null) { if(!nonReferenceFetchGroup.containsAttribute(lockAttribute)) { nonReferenceFetchGroup.addAttribute(lockAttribute);
/** * 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); } } } }
targetFetchGroup = this.descriptor.getFetchGroupManager().getObjectFetchGroup(target); if(targetFetchGroup != null) { if(!targetFetchGroup.isSupersetOf(sourceFetchGroup)) { targetFetchGroup.onUnfetchedAttribute((FetchGroupTracker)target, null); || (cascadeOnly && mapping.isForeignReferenceMapping()) || (isTargetCloneOfOriginal && mapping.isCloningRequired())) && (sourceFetchGroup == null || sourceFetchGroup.containsAttributeInternal(mapping.getAttributeName()))) { mapping.mergeIntoObject(target, isUnInitialized, source, mergeManager, targetSession);
/** * Return true if the attribute is in the fetch group being tracked. * * @param attribute the attribute * @return true, if successful */ public boolean _persistence_isAttributeFetched(String attribute) { return this.fetchGroup == null || this.fetchGroup.containsAttributeInternal(attribute); }
public EntityFetchGroup(String[] attributeNames) { super(); for(int i=0; i < attributeNames.length; i++) { super.addAttribute(attributeNames[i], (AttributeGroup)null); } }
FetchGroup fetchGroup = new FetchGroup(); fetchGroup.setName(m_name); fetchGroup.addAttribute(fetchAttribute.getName());
protected void addFetchGroupLines(NonreflectiveMethodDefinition method, FetchGroup fetchGroup, String fetchGroupIdentifier) { method.addLine("FetchGroup " + fetchGroupIdentifier + " = new FetchGroup();"); if (!fetchGroup.getName().equals("")) { method.addLine(fetchGroupIdentifier + ".setName(\"" + fetchGroup.getName() + "\");"); } for (String attribute: fetchGroup.getAttributeNames()) { method.addLine(fetchGroupIdentifier + ".addAttribute(\"" + attribute + "\");"); } }
@Override public boolean isSupersetOf(CoreAttributeGroup anotherGroup) { return wrappedFetchGroup.isSupersetOf(anotherGroup); }
/** * INTERNAL: * Union two fetch groups. */ public FetchGroup unionFetchGroups(FetchGroup first, FetchGroup second) { if ((first == null) || (second == null)) { return null; } //return the superset if applied if (first == second || first.isSupersetOf(second)) { return first; } else if (second.isSupersetOf(first)) { return second; } Set<String> unionAttributeNames = new HashSet(); unionAttributeNames.addAll(first.getAttributeNames()); unionAttributeNames.addAll(second.getAttributeNames()); return getEntityFetchGroup(unionAttributeNames); }
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; } }
/** * INTERNAL: * Union two fetch groups as EntityFetchGroups. * Ignores all nested attributes. */ public EntityFetchGroup flatUnionFetchGroups(FetchGroup first, FetchGroup second, boolean shouldClone) { if ((first == null) || (second == null)) { return null; } //return the superset if applied if (first == second) { return getEntityFetchGroup(first); } Set<String> unionAttributeNames = new HashSet(); unionAttributeNames.addAll(first.getAttributeNames()); unionAttributeNames.addAll(second.getAttributeNames()); EntityFetchGroup newGroup = getEntityFetchGroup(unionAttributeNames); if (shouldClone){ newGroup = (EntityFetchGroup) newGroup.clone(); newGroup.setRootEntity(second.getRootEntity()); } return newGroup; }
@Override public String getName() { return wrappedFetchGroup.getName(); }
private static void traverseFetchGroupAttributes(Set<String> set, FetchGroup fetchGroup, String prefix) { for (String attribute : fetchGroup.getAttributeNames()) { FetchGroup group = fetchGroup.getGroup(attribute); if (group != null) { traverseFetchGroupAttributes(set, group, prefix + attribute + "."); } else { set.add(prefix + attribute); } } } }
/** * PUBLIC: * Returns clone of the full fetch group - contains all the attributes, no nesting. * Could be used as a starting point for a new user-defined fetch group. */ public FetchGroup createFullFetchGroup() { return this.fullFetchGroup.clone(); }
@Override public Set<String> getAttributeNames() { return wrappedFetchGroup.getAttributeNames(); }