/** * Refresh the fetch group data into the working and backup clones. * This is called if refresh is enforced */ private void refreshFetchGroupIntoClones(Object cachedObject, Object workingClone, Object backupClone, FetchGroup fetchGroupInObject, FetchGroup fetchGroupInClone, UnitOfWorkImpl uow) { Vector mappings = descriptor.getMappings(); boolean isObjectPartial = (fetchGroupInObject != null); Set fetchedAttributes = isObjectPartial ? fetchGroupInObject.getAttributes() : null; for (int index = 0; index < mappings.size(); index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); if ((!isObjectPartial) || ((fetchedAttributes != null) && fetchedAttributes.contains(mapping.getAttributeName()))) { //only fill in the unfetched attributes into clones mapping.buildClone(cachedObject, workingClone, uow); mapping.buildClone(workingClone, backupClone, uow); } } }
/** * Revert the clones' unfetched attributes, and leave fetched ones intact. */ private void revertDataIntoUnfetchedAttributesOfClones(Object cachedObject, Object workingClone, Object backupClone, FetchGroup fetchGroupInObject, FetchGroup fetchGroupInClone, UnitOfWorkImpl uow) { //if(fetchGroupInClone == null || fetchGroupInClone.isSupersetOf(fetchGroupInObject)) { if (isObjectValidForFetchGroup(workingClone, fetchGroupInObject)) { //if working clone is fully fetched or it's fetch group is superset of that of the cached object //no reversion is needed, so simply return return; } Vector mappings = descriptor.getMappings(); //fetched attributes list in working clone Set fetchedAttributesClone = fetchGroupInClone.getAttributes(); for (int index = 0; index < mappings.size(); index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); //only revert the attribute which is fetched by the cached object, but not fecthed by the clones. if (isAttributeFetched(cachedObject, mapping.getAttributeName()) && (!fetchedAttributesClone.contains(mapping.getAttributeName()))) { //only fill in the unfetched attributes into clones mapping.buildClone(cachedObject, workingClone, uow); mapping.buildClone(workingClone, backupClone, uow); } } }
/** * 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) { // PERF: Avoid synchronized enumerator as is concurrency bottleneck. List mappings = getCloningMappings(); for (int index = 0; index < mappings.size(); index++) { ((DatabaseMapping)mappings.get(index)).buildClone(original, clone, unitOfWork); } // PERF: Avoid events if no listeners. if (getDescriptor().getEventManager().hasAnyEventListeners()) { oracle.toplink.essentials.descriptors.DescriptorEvent event = new oracle.toplink.essentials.descriptors.DescriptorEvent(clone); event.setSession(unitOfWork); event.setOriginalObject(original); event.setEventCode(DescriptorEventManager.PostCloneEvent); getDescriptor().getEventManager().executeEvent(event); } }