/** * INTERNAL: * Return if the query has an non-default fetch group defined for itself. */ protected boolean hasNonDefaultFetchGroup() { return this.descriptor.hasFetchGroupManager() && ((this.fetchGroup != null) || (this.fetchGroupName != null) || (!this.shouldUseDefaultFetchGroup)); } }
/** * INTERNAL: * Return if the query has an non-default fetch group defined for itself. */ protected boolean hasNonDefaultFetchGroup() { return this.descriptor.hasFetchGroupManager() && ((this.fetchGroup != null) || (this.fetchGroupName != null) || (!this.shouldUseDefaultFetchGroup && (this.descriptor.getFetchGroupManager().getDefaultFetchGroup() != null))); } }
/** * INTERNAL: * Return if the query has an non-default fetch group defined for itself. */ protected boolean hasNonDefaultFetchGroup() { return this.descriptor.hasFetchGroupManager() && ((this.fetchGroup != null) || (this.fetchGroupName != null) || (!this.shouldUseDefaultFetchGroup && (this.descriptor.getFetchGroupManager().getDefaultFetchGroup() != null))); } }
/** * INTERNAL: * * Return the default fetch group on the descriptor. * All read object and read all queries will use the default fetch group if * no fetch group is explicitly defined for the query. */ public FetchGroup getDefaultFetchGroup() { if (!hasFetchGroupManager()) { //fetch group manager is not set, therefore no default fetch group. return null; } return getFetchGroupManager().getDefaultFetchGroup(); }
/** * INTERNAL: * * Return the default fetch group on the descriptor. * All read object and read all queries will use the default fetch group if * no fetch group is explicitly defined for the query. */ public FetchGroup getDefaultFetchGroup() { if (!hasFetchGroupManager()) { //fetch group manager is not set, therefore no default fetch group. return null; } return getFetchGroupManager().getDefaultFetchGroup(); }
/** * INTERNAL: * * Return the default fetch group on the descriptor. * All read object and read all queries will use the default fetch group if * no fetch group is explicitly defined for the query. */ public FetchGroup getDefaultFetchGroup() { if (!hasFetchGroupManager()) { //fetch group manager is not set, therefore no default fetch group. return null; } return getFetchGroupManager().getDefaultFetchGroup(); }
@Override public String toString() { String str = super.toString(); if(this.fetchGroup != null) { str += '\n' + this.fetchGroup.toString(); } else if(this.fetchGroupName != null) { str += '\n' + "FetchGroup(" + this.fetchGroupName + ")"; } else if(this.shouldUseDefaultFetchGroup) { if(this.descriptor != null && this.descriptor.hasFetchGroupManager()) { FetchGroup defaultFetchGroup = descriptor.getFetchGroupManager().getDefaultFetchGroup(); if(defaultFetchGroup != null) { str += '\n' + "Default " + defaultFetchGroup.toString(); } } } return str; }
@Override public String toString() { String str = super.toString(); if(this.fetchGroup != null) { str += '\n' + this.fetchGroup.toString(); } else if(this.fetchGroupName != null) { str += '\n' + "FetchGroup(" + this.fetchGroupName + ")"; } else if(this.shouldUseDefaultFetchGroup) { if(this.descriptor != null && this.descriptor.hasFetchGroupManager()) { FetchGroup defaultFetchGroup = descriptor.getFetchGroupManager().getDefaultFetchGroup(); if(defaultFetchGroup != null) { str += '\n' + "Default " + defaultFetchGroup.toString(); } } } return str; }
/** * INTERNAL: * Ensure the change set is populated for cache coordination. */ public void ensureChanges() { if (this.isNew && ((this.changes == null) || this.changes.isEmpty())) { AbstractSession unitOfWork = this.unitOfWorkChangeSet.getSession(); // Full change set is only required for cache coordination, not remote. if (!unitOfWork.isRemoteUnitOfWork()) { ClassDescriptor descriptor = getDescriptor(); if ((unitOfWork != null) && (descriptor != null)) { FetchGroup fetchGroup = null; if(descriptor.hasFetchGroupManager()) { fetchGroup = descriptor.getFetchGroupManager().getObjectFetchGroup(this.cloneObject); } List mappings = descriptor.getMappings(); int mappingsSize = mappings.size(); for (int index = 0; index < mappingsSize; index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); if (fetchGroup == null || fetchGroup.containsAttributeInternal(mapping.getAttributeName())) { addChange(mapping.compareForChange(this.cloneObject, this.cloneObject, this, unitOfWork)); } } } } } }
/** * Returns the backup clone of the specified object. This is called only from unit of work. * The clone sent as parameter is always a working copy from the unit of work. */ public Object buildBackupClone(Object clone, UnitOfWorkImpl unitOfWork) { // The copy policy builds clone . ClassDescriptor descriptor = this.descriptor; Object backup = descriptor.getCopyPolicy().buildClone(clone, unitOfWork); // PERF: Avoid synchronized enumerator as is concurrency bottleneck. List mappings = getCloningMappings(); int size = mappings.size(); if (descriptor.hasFetchGroupManager() && descriptor.getFetchGroupManager().isPartialObject(clone)) { FetchGroupManager fetchGroupManager = descriptor.getFetchGroupManager(); for (int index = 0; index < size; index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); if (fetchGroupManager.isAttributeFetched(clone, mapping.getAttributeName())) { mapping.buildBackupClone(clone, backup, unitOfWork); } } } else { for (int index = 0; index < size; index++) { ((DatabaseMapping)mappings.get(index)).buildBackupClone(clone, backup, unitOfWork); } } return backup; }
/** * Returns the backup clone of the specified object. This is called only from unit of work. * The clone sent as parameter is always a working copy from the unit of work. */ public Object buildBackupClone(Object clone, UnitOfWorkImpl unitOfWork) { // The copy policy builds clone . ClassDescriptor descriptor = this.descriptor; Object backup = descriptor.getCopyPolicy().buildClone(clone, unitOfWork); // PERF: Avoid synchronized enumerator as is concurrency bottleneck. List mappings = getCloningMappings(); int size = mappings.size(); if (descriptor.hasFetchGroupManager() && descriptor.getFetchGroupManager().isPartialObject(clone)) { FetchGroupManager fetchGroupManager = descriptor.getFetchGroupManager(); for (int index = 0; index < size; index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); if (fetchGroupManager.isAttributeFetched(clone, mapping.getAttributeName())) { mapping.buildBackupClone(clone, backup, unitOfWork); } } } else { for (int index = 0; index < size; index++) { ((DatabaseMapping)mappings.get(index)).buildBackupClone(clone, backup, unitOfWork); } } return backup; }
/** * Determine the load state of a given persistent attribute of an entity * belonging to the persistence unit. * * @param entity * containing the attribute * @param attributeName * name of attribute whose load state is to be determined * @return false if entity's state has not been loaded or if the attribute * state has not been loaded, otherwise true */ public static Boolean isLoaded(Object entity, String attributeName, AbstractSession session) { ClassDescriptor descriptor = session.getDescriptor(entity); if (descriptor == null) { return null; } if (descriptor.hasFetchGroupManager()){ if (!descriptor.getFetchGroupManager().isAttributeFetched(entity, attributeName)){ return false; } } DatabaseMapping mapping = descriptor.getMappingForAttributeName(attributeName); if (mapping == null) { return null; } return isLoaded(entity, attributeName, mapping); }
/** * Ensure the change set is populated for cache coordination. * * @param session current database session * @param changeSet change set to populate * @param descriptor class (relational) descriptor related to the change set */ private void ensureChanges(final AbstractSession session, final ObjectChangeSet changeSet, final ClassDescriptor descriptor) { FetchGroup fetchGroup = null; if (descriptor.hasFetchGroupManager()) { fetchGroup = descriptor.getFetchGroupManager().getObjectFetchGroup(changeSet.cloneObject); } for (DatabaseMapping mapping : descriptor.getMappings()) { if (fetchGroup == null || fetchGroup.containsAttributeInternal(mapping.getAttributeName())) { changeSet.addChange(mapping.compareForChange(changeSet.cloneObject, changeSet.cloneObject, changeSet, session)); } } }
/** * Clones the attributes of the specified object. This is called only from unit of work. * The domainObject sent as parameter is always a copy from the parent of unit of work. */ public void populateAttributesForClone(Object original, CacheKey cacheKey, Object clone, Integer refreshCascade, AbstractSession cloningSession) { List mappings = getCloningMappings(); int size = mappings.size(); if (this.descriptor.hasFetchGroupManager() && this.descriptor.getFetchGroupManager().isPartialObject(original)) { FetchGroupManager fetchGroupManager = this.descriptor.getFetchGroupManager(); for (int index = 0; index < size; index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); if (fetchGroupManager.isAttributeFetched(original, mapping.getAttributeName())) { mapping.buildClone(original, cacheKey, clone, refreshCascade, cloningSession); } } } else { for (int index = 0; index < size; index++) { ((DatabaseMapping)mappings.get(index)).buildClone(original, cacheKey, clone, refreshCascade, cloningSession); } } // PERF: Avoid events if no listeners. if (this.descriptor.getEventManager().hasAnyEventListeners()) { DescriptorEvent event = new DescriptorEvent(clone); event.setSession(cloningSession); event.setOriginalObject(original); event.setDescriptor(descriptor); event.setEventCode(DescriptorEventManager.PostCloneEvent); cloningSession.deferEvent(event); } }
/** * Clones the attributes of the specified object. This is called only from unit of work. * The domainObject sent as parameter is always a copy from the parent of unit of work. */ public void populateAttributesForClone(Object original, Object clone, UnitOfWorkImpl unitOfWork) { List mappings = getCloningMappings(); int size = mappings.size(); if (this.descriptor.hasFetchGroupManager() && this.descriptor.getFetchGroupManager().isPartialObject(original)) { FetchGroupManager fetchGroupManager = this.descriptor.getFetchGroupManager(); for (int index = 0; index < size; index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); if (fetchGroupManager.isAttributeFetched(original, mapping.getAttributeName())) { mapping.buildClone(original, clone, unitOfWork); } } } else { for (int index = 0; index < size; index++) { ((DatabaseMapping)mappings.get(index)).buildClone(original, clone, unitOfWork); } } // PERF: Avoid events if no listeners. if (this.descriptor.getEventManager().hasAnyEventListeners()) { DescriptorEvent event = new DescriptorEvent(clone); event.setSession(unitOfWork); event.setOriginalObject(original); event.setEventCode(DescriptorEventManager.PostCloneEvent); this.descriptor.getEventManager().executeEvent(event); } }
/** * INTERNAL: * Build and return a clone of the attribute. */ protected Object buildClonePart(Object attributeValue, Object clone, CacheKey parentCacheKey, Integer refreshCascade, AbstractSession cloningSession, boolean isNewObject) { if (attributeValue == null) { return null; } if (cloningSession.isUnitOfWork() && isNewObject) { // only true if cloningSession is UOW as this signature only exists in this mapping. ((UnitOfWorkImpl)cloningSession).addNewAggregate(attributeValue); } // Do not clone for read-only. if (cloningSession.isUnitOfWork() && cloningSession.isClassReadOnly(attributeValue.getClass())){ return attributeValue; } ObjectBuilder aggregateObjectBuilder = getObjectBuilder(attributeValue, cloningSession); // bug 2612602 as we are building the working copy make sure that we call to correct clone method. Object clonedAttributeValue = aggregateObjectBuilder.instantiateWorkingCopyClone(attributeValue, cloningSession); aggregateObjectBuilder.populateAttributesForClone(attributeValue, parentCacheKey, clonedAttributeValue, refreshCascade, cloningSession); //also clone the fetch group reference if applied if (aggregateObjectBuilder.getDescriptor().hasFetchGroupManager()) { aggregateObjectBuilder.getDescriptor().getFetchGroupManager().copyAggregateFetchGroupInto(attributeValue, clonedAttributeValue, clone, cloningSession); } return clonedAttributeValue; }
List mappings = getCloningMappings(); int size = mappings.size(); if (this.descriptor.hasFetchGroupManager() && this.descriptor.getFetchGroupManager().isPartialObject(original)) { FetchGroupManager fetchGroupManager = this.descriptor.getFetchGroupManager(); for (int index = 0; index < size; index++) {
/** * INTERNAL: * Build and return a clone of the attribute. */ protected Object buildClonePart(Object attributeValue, Object clone, CacheKey parentCacheKey, Integer refreshCascade, AbstractSession cloningSession, boolean isNewObject) { if (attributeValue == null) { return null; } if (cloningSession.isUnitOfWork() && isNewObject) { // only true if cloningSession is UOW as this signature only exists in this mapping. ((UnitOfWorkImpl)cloningSession).addNewAggregate(attributeValue); } // Do not clone for read-only. if (cloningSession.isUnitOfWork() && cloningSession.isClassReadOnly(attributeValue.getClass())){ return attributeValue; } ObjectBuilder aggregateObjectBuilder = getObjectBuilder(attributeValue, cloningSession); // bug 2612602 as we are building the working copy make sure that we call to correct clone method. Object clonedAttributeValue = aggregateObjectBuilder.instantiateWorkingCopyClone(attributeValue, cloningSession); aggregateObjectBuilder.populateAttributesForClone(attributeValue, parentCacheKey, clonedAttributeValue, refreshCascade, cloningSession); //also clone the fetch group reference if applied if (aggregateObjectBuilder.getDescriptor().hasFetchGroupManager()) { aggregateObjectBuilder.getDescriptor().getFetchGroupManager().copyAggregateFetchGroupInto(attributeValue, clonedAttributeValue, clone, cloningSession); } return clonedAttributeValue; }
if (this.getDescriptor().hasFetchGroupManager() && FetchGroupTracker.class.isAssignableFrom(clonedDescriptor.getJavaClass())){ if (clonedDescriptor.getFetchGroupManager() == null) { clonedDescriptor.setFetchGroupManager(new FetchGroupManager());
if (parent.hasFetchGroupManager()) { fg = parent.getFetchGroupManager().getFetchGroup(groupName);