EntityFetchGroup union = flatUnionFetchGroups(fetchGroupInObject, fetchGroupInClone, false);// this method is not called for aggregates setObjectFetchGroup(workingClone, union, uow); if (workingClone != backupClone) { setObjectFetchGroup(backupClone, union, uow); refreshFetchGroupIntoClones(partialObject, workingClone, backupClone, fetchGroupInObject, fetchGroupInClone, uow); } else {//no refresh is enforced revertDataIntoUnfetchedAttributesOfClones(partialObject, workingClone, backupClone, fetchGroupInObject, fetchGroupInClone, uow);
/** * Lookup the FetchGroup to use given a name and a flag taking into * consideration descriptor inheritance to ensure parent descriptors are * searched for named and default FetchGroup. This is used to determine the * FetchGroup to use in a query's prepare. */ public FetchGroup getFetchGroup(String groupName, boolean useDefault) { FetchGroup fg = null; if (groupName != null) { fg = getFetchGroup(groupName); } // Process default using hierarchy if (fg == null && useDefault) { fg = getDefaultFetchGroup(); } return fg; }
protected void initNonReferenceEntityFetchGroup() { 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); } } } this.addMinimalFetchGroup(nonReferenceFetchGroup); this.nonReferenceEntityFetchGroup = getEntityFetchGroup(nonReferenceFetchGroup); }
/** * INTERNAL: * Copy fetch group reference from the source object to the target */ public void copyFetchGroupInto(Object source, Object target, AbstractSession session) { if (isPartialObject(source)) { setObjectFetchGroup(target, ((FetchGroupTracker)source)._persistence_getFetchGroup(), session); } }
/** * INTERNAL: * Union the fetch group of the domain object with the new fetch group. */ public void unionFetchGroupIntoObject(Object source, FetchGroup newFetchGroup, AbstractSession session) { setObjectFetchGroup(source, unionFetchGroups(((FetchGroupTracker)source)._persistence_getFetchGroup(), newFetchGroup), session); }
/** * INTERNAL: * Cascade discover and persist new objects during commit. * It may raise exceptions as described in the EJB3 specification */ public void cascadeDiscoverAndPersistUnregisteredNewObjects(Object object, Map newObjects, Map unregisteredExistingObjects, Map visitedObjects, UnitOfWorkImpl uow, Set cascadeErrors) { // PERF: Only process relationships. if (!this.isSimple) { List<DatabaseMapping> mappings = this.relationshipMappings; int size = mappings.size(); FetchGroupManager fetchGroupManager = descriptor.getFetchGroupManager(); // Only cascade fetched mappings. if ((fetchGroupManager != null) && fetchGroupManager.isPartialObject(object)) { for (int index = 0; index < size; index++) { DatabaseMapping mapping = mappings.get(index); if (fetchGroupManager.isAttributeFetched(object, mapping.getAttributeName())) { mapping.cascadeDiscoverAndPersistUnregisteredNewObjects(object, newObjects, unregisteredExistingObjects, visitedObjects, uow, cascadeErrors); } } } else { for (int index = 0; index < size; index++) { DatabaseMapping mapping = mappings.get(index); mapping.cascadeDiscoverAndPersistUnregisteredNewObjects(object, newObjects, unregisteredExistingObjects, visitedObjects, uow, cascadeErrors); } } } }
/** * Clean up the cached object data and only revert the fetch group data back to the cached object. */ private void revertFetchGroupData(Object domainObject, ClassDescriptor concreteDescriptor, CacheKey cacheKey, ObjectBuildingQuery query, JoinedAttributeManager joinManager, AbstractRecord databaseRow, AbstractSession session, boolean targetIsProtected) { FetchGroup fetchGroup = query.getExecutionFetchGroup(concreteDescriptor); FetchGroupManager fetchGroupManager = concreteDescriptor.getFetchGroupManager(); //the cached object is either invalidated, or staled as the version is newer, or a refresh is explicitly set on the query. //clean all data of the cache object. fetchGroupManager.reset(domainObject); //set fetch group reference to the cached object fetchGroupManager.setObjectFetchGroup(domainObject, fetchGroupManager.getEntityFetchGroup(fetchGroup), session); // Bug 276362 - set the CacheKey's read time (to re-validate the CacheKey) before buildAttributesIntoObject is called cacheKey.setReadTime(query.getExecutionTime()); //read in the fetch group data only concreteDescriptor.getObjectBuilder().buildAttributesIntoObject(domainObject, cacheKey, databaseRow, query, joinManager, fetchGroup, false, session); //set refresh on fetch group fetchGroupManager.setRefreshOnFetchGroupToObject(domainObject, (query.shouldRefreshIdentityMapResult() || concreteDescriptor.shouldAlwaysRefreshCache())); //set query id to prevent infinite recursion on refresh object cascade all cacheKey.setLastUpdatedQueryId(query.getQueryId()); //register the object into the IM and set the write lock object if applied. if (concreteDescriptor.usesOptimisticLocking()) { OptimisticLockingPolicy policy = concreteDescriptor.getOptimisticLockingPolicy(); cacheKey.setWriteLockValue(policy.getValueToPutInCache(databaseRow, session)); } }
if (!(Helper.classImplementsInterface(getDescriptor().getJavaClass(), ClassConstants.FetchGroupTracker_class))) { while(it.hasNext()) { FetchGroup fetchGroup = it.next(); prepareAndVerify(fetchGroup); getEntityFetchGroup(fetchGroup); ClassDescriptor parent = current.getInheritancePolicy().getParentDescriptor(); if (parent.hasFetchGroupManager()) { this.defaultFetchGroup = parent.getFetchGroupManager().getDefaultFetchGroup(); if(this.defaultFetchGroup != null) { return; for (DatabaseMapping mapping : getDescriptor().getMappings()) { if (mapping.isForeignReferenceMapping() || (!mapping.isLazy())) { defaultCandidate.addAttribute(mapping.getAttributeName()); prepareAndVerify(this.defaultFetchGroup); this.defaultEntityFetchGroup = getEntityFetchGroup(this.defaultFetchGroup); initNonReferenceEntityFetchGroup();
(new FetchGroupManager()).setObjectFetchGroup(persistenceWeavedRest, fetchGroup, null);
boolean isUnionFetchGroups = false; if (wasAClone && fetchGroupManager != null && fetchGroupManager.isPartialObject(workingClone) && (!fetchGroupManager.isObjectValidForFetchGroup(workingClone, fetchGroupManager.getEntityFetchGroup(fetchGroup)))) { if (!fetchGroupManager.isObjectValidForFetchGroup(workingClone, fetchGroupManager.getEntityFetchGroup(fetchGroup))) { isARefresh = true; isUnionFetchGroups = true; if (isUnionFetchGroups && fetchGroupManager.isPartialObject(workingClone)) { fetchGroupManager.unionEntityFetchGroupIntoObject(workingClone, fetchGroupManager.getEntityFetchGroup(query.getExecutionFetchGroup(this.descriptor)), unitOfWork, false); } else { fetchGroupManager.setObjectFetchGroup(workingClone, query.getExecutionFetchGroup(this.descriptor), unitOfWork); fetchGroupManager.setObjectFetchGroup(workingClone, query.getExecutionFetchGroup(this.descriptor), unitOfWork);
FetchGroup fetchGroup = fetchGroupManager.getObjectFetchGroup(original); if (fetchGroup != null) { if (!fetchGroup.getAttributeNames().containsAll(copyGroup.getAttributeNames())) { existingEntityFetchGroup = fetchGroupManager.getObjectEntityFetchGroup(copy); EntityFetchGroup copyGroupEntityFetchGroup = fetchGroupManager.getEntityFetchGroup(attributesToCopy); if(copyGroupEntityFetchGroup == null) { if(!existingEntityFetchGroup.getAttributeNames().containsAll(attributesToCopy)) { newEntityFetchGroup = fetchGroupManager.flatUnionFetchGroups(existingEntityFetchGroup, copyGroupEntityFetchGroup, false); shouldAssignNewEntityFetchGroup = true; fetchGroupManager.setObjectFetchGroup(copy, newEntityFetchGroup, null); FetchGroupManager referenceFetchGroupManager = referenceDescriptor.getFetchGroupManager(); if(referenceFetchGroupManager != null) { EntityFetchGroup nonReferenceEntityFetchGroup = referenceFetchGroupManager.getNonReferenceEntityFetchGroup(copyGroup.shouldResetPrimaryKey(), copyGroup.shouldResetVersion()); if(nonReferenceEntityFetchGroup != null) { mappingCopyGroup = nonReferenceEntityFetchGroup.toCopyGroup();
boolean isARefresh = query.shouldRefreshIdentityMapResult() || (query.isLockQuery() && (!wasAClone || !query.isClonePessimisticLocked(workingClone, unitOfWork))); if (wasAClone && fetchGroupManager != null && (fetchGroupManager.isPartialObject(workingClone) && (!fetchGroupManager.isObjectValidForFetchGroup(workingClone, fetchGroupManager.getEntityFetchGroup(fetchGroup))))) { isARefresh = true; fetchGroupManager.setObjectFetchGroup(workingClone, query.getExecutionFetchGroup(this.descriptor), unitOfWork); if (wasAnOriginal) { fetchGroupManager.setObjectFetchGroup(workingClone, fetchGroupManager.getObjectFetchGroup(original), unitOfWork); } else { fetchGroupManager.setObjectFetchGroup(workingClone, query.getExecutionFetchGroup(this.descriptor), unitOfWork);
FetchGroup union = unionFetchGroups(fetchGroupInObject, fetchGroupInClone); setObjectFetchGroup(workingClone, union, uow); if (workingClone != backupClone) { setObjectFetchGroup(backupClone, union, uow); refreshFetchGroupIntoClones(partialObject, workingClone, backupClone, fetchGroupInObject, fetchGroupInClone, uow); } else {//no refresh is enforced revertDataIntoUnfetchedAttributesOfClones(partialObject, workingClone, backupClone, fetchGroupInObject, fetchGroupInClone, uow);
/** * INTERNAL: * Add mandatory attributes to fetch group, create entityFetchGroup. */ public void prepareFetchGroup() throws QueryException { FetchGroupManager fetchGroupManager = this.descriptor.getFetchGroupManager(); if (fetchGroupManager != null) { if (this.fetchGroup == null) { if (this.fetchGroupName != null) { this.fetchGroup = fetchGroupManager.getFetchGroup(this.fetchGroupName); } else if (this.shouldUseDefaultFetchGroup) { this.fetchGroup = this.descriptor.getFetchGroupManager().getDefaultFetchGroup(); } } if (this.fetchGroup != null) { if (hasPartialAttributeExpressions()) { //fetch group does not work with partial attribute reading throw QueryException.fetchGroupNotSupportOnPartialAttributeReading(); } // currently SOP is incompatible with fetch groups setShouldUseSerializedObjectPolicy(false); this.descriptor.getFetchGroupManager().prepareAndVerify(this.fetchGroup); } } else { // FetchGroupManager is null if (this.fetchGroup != null || this.fetchGroupName != null) { throw QueryException.fetchGroupValidOnlyIfFetchGroupManagerInDescriptor(getDescriptor().getJavaClassName(), getName()); } } }
/** * Clean up the cached object data and only revert the fetch group data back to the cached object. */ private void revertFetchGroupData(Object domainObject, ClassDescriptor concreteDescriptor, CacheKey cacheKey, ObjectBuildingQuery query, JoinedAttributeManager joinManager, AbstractRecord databaseRow, AbstractSession session) { //the cached object is either invalidated, or staled as the version is newer, or a refresh is explicitly set on the query. //clean all data of the cache object. concreteDescriptor.getFetchGroupManager().reset(domainObject); //set fetch group reference to the cached object concreteDescriptor.getFetchGroupManager().setObjectFetchGroup(domainObject, query.getFetchGroup(), session); // Bug 276362 - set the CacheKey's read time (to re-validate the CacheKey) before buildAttributesIntoObject is called cacheKey.setReadTime(query.getExecutionTime()); //read in the fetch group data only concreteDescriptor.getObjectBuilder().buildAttributesIntoObject(domainObject, databaseRow, query, joinManager, false); //set refresh on fetch group concreteDescriptor.getFetchGroupManager().setRefreshOnFetchGroupToObject(domainObject, (query.shouldRefreshIdentityMapResult() || concreteDescriptor.shouldAlwaysRefreshCache())); //set query id to prevent infinite recursion on refresh object cascade all cacheKey.setLastUpdatedQueryId(query.getQueryId()); //register the object into the IM and set the write lock object if applied. if (concreteDescriptor.usesOptimisticLocking()) { OptimisticLockingPolicy policy = concreteDescriptor.getOptimisticLockingPolicy(); cacheKey.setWriteLockValue(policy.getValueToPutInCache(databaseRow, session)); } }
protected void addFetchGroupManagerLine(NonreflectiveMethodDefinition method, ClassDescriptor descriptor) { if (descriptor.getFetchGroupManager() == null) { return; } method.addLine("//Fetch groups"); method.addLine("descriptor.setFetchGroupManager(new FetchGroupManager());"); Map namedFetchGroups = descriptor.getFetchGroupManager().getFetchGroups(); if (descriptor.getFetchGroupManager().getDefaultFetchGroup() != null) { String defaultFetchGroupIdentifier = descriptor.getFetchGroupManager().getDefaultFetchGroup().getName() + "FetchGroup"; method.addLine(""); method.addLine("//Default fetch group -- " + defaultFetchGroupIdentifier); method.addLine("descriptor.getFetchGroupManager().setDefaultFetchGroup(" + defaultFetchGroupIdentifier + ");"); } if (namedFetchGroups.isEmpty()) { return; } for (Iterator namedFetchGroupIter = namedFetchGroups.values().iterator(); namedFetchGroupIter.hasNext();) { FetchGroup namedFetchGroup = (FetchGroup)namedFetchGroupIter.next(); String fetchGroupIdentifier = namedFetchGroup.getName() + "FetchGroup"; method.addLine(""); method.addLine("//Named fetch group -- " + fetchGroupIdentifier); addFetchGroupLines(method, namedFetchGroup, fetchGroupIdentifier); method.addLine("descriptor.getFetchGroupManager().addFetchGroup(" + fetchGroupIdentifier + ");"); } }
FetchGroup sourceFetchGroup = this.descriptor.getFetchGroupManager().getObjectFetchGroup(source); FetchGroup targetFetchGroup = this.descriptor.getFetchGroupManager().getObjectFetchGroup(target); if(targetFetchGroup != null) { if(!targetFetchGroup.isSupersetOf(sourceFetchGroup)) { this.descriptor.getFetchGroupManager().setObjectFetchGroup(target, sourceFetchGroup, targetSession);
boolean isARefresh = query.shouldRefreshIdentityMapResult() || (query.isLockQuery() && (!wasAClone || !query.isClonePessimisticLocked(workingClone, unitOfWork))); if (wasAClone && descriptor.hasFetchGroupManager() && (descriptor.getFetchGroupManager().isPartialObject(workingClone) && (!descriptor.getFetchGroupManager().isObjectValidForFetchGroup(workingClone, query.getFetchGroup())))) { isARefresh = true; this.descriptor.getFetchGroupManager().setObjectFetchGroup(workingClone, query.getFetchGroup(), unitOfWork); this.descriptor.getFetchGroupManager().setObjectFetchGroup(workingClone, query.getFetchGroup(), unitOfWork);
return getNonReferenceEntityFetchGroup(); for (DatabaseMapping mapping : getDescriptor().getMappings()) { if(!mapping.isForeignReferenceMapping()) { String name = mapping.getAttributeName(); return getEntityFetchGroup(nonReferenceFetchGroup);
this.entityFetchGroups = new ConcurrentHashMap(); if (!(Helper.classImplementsInterface(getDescriptor().getJavaClass(), ClassConstants.FetchGroupTracker_class))) { session.getIntegrityChecker().handleError(DescriptorException.needToImplementFetchGroupTracker(getDescriptor().getJavaClass(), getDescriptor())); for (DatabaseMapping mapping : getDescriptor().getMappings()) { String name = mapping.getAttributeName(); if(mapping.isPrimaryKeyMapping()) { if (parentManager != null) { this.idEntityFetchGroup = parentManager.getIdEntityFetchGroup(); } else { this.idEntityFetchGroup = getEntityFetchGroup(this.minimalFetchGroup); DatabaseMapping lockMapping = getDescriptor().getObjectBuilder().getMappingForField(lockField); if (lockMapping != null) { String attributeName = lockMapping.getAttributeName(); getEntityFetchGroup(this.minimalFetchGroup);