/** * 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: * 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: * 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: * Copy fetch group reference from the source object to the target */ public void copyAggregateFetchGroupInto(Object source, Object target, Object rootEntity, AbstractSession session) { if (isPartialObject(source)) { FetchGroup newGroup = ((FetchGroupTracker)source)._persistence_getFetchGroup().clone(); // must clone because original is linked to orig root newGroup.setRootEntity((FetchGroupTracker) rootEntity); setObjectFetchGroup(target, newGroup, session); } }
/** * INTERNAL: * Copy fetch group reference from the source object to the target */ public void copyAggregateFetchGroupInto(Object source, Object target, Object rootEntity, AbstractSession session) { if (isPartialObject(source)) { FetchGroup newGroup = ((FetchGroupTracker)source)._persistence_getFetchGroup().clone(); // must clone because original is linked to orig root newGroup.setRootEntity((FetchGroupTracker) rootEntity); setObjectFetchGroup(target, newGroup, 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); } } } }
/** * 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); } } } }
/** * INTERNAL: * Return true if the cached object data should be written in clone. * It is used in Fetch Group case when filling in the clone from the cached object. */ public boolean shouldWriteInto(Object cachedObject, Object clone) { if (isPartialObject(clone)) { FetchGroup fetchGroupInSrc = ((FetchGroupTracker)cachedObject)._persistence_getFetchGroup(); FetchGroup fetchGroupInTarg = ((FetchGroupTracker)clone)._persistence_getFetchGroup(); //if the target fetch group is not null (i.e. fully fetched object) or if partially fetched, it's not a superset of that of the source, //or if refresh is required, should always write (either refresh or revert) data from the cache to the clones. return (!((fetchGroupInTarg == null) || fetchGroupInTarg.isSupersetOf(fetchGroupInSrc)) || ((FetchGroupTracker)cachedObject)._persistence_shouldRefreshFetchGroup()); } return false; }
/** * INTERNAL: * This method is used by the UnitOfWork to cascade registration of new objects. * It may raise exceptions as described in the EJB3 specification */ public void cascadeRegisterNewForCreate(Object object, UnitOfWorkImpl uow, Map visitedObjects) { ObjectBuilder builder = this.descriptor.getObjectBuilder(); // PERF: Only process relationships. if (!builder.isSimple()) { List<DatabaseMapping> mappings = builder.getRelationshipMappings(); 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.cascadeRegisterNewIfRequired(object, uow, visitedObjects); } } } else { for (int index = 0; index < size; index++) { DatabaseMapping mapping = mappings.get(index); mapping.cascadeRegisterNewIfRequired(object, uow, visitedObjects); } } } }
/** * 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) { ObjectBuilder builder = this.descriptor.getObjectBuilder(); // PERF: Only process relationships. if (!builder.isSimple()) { List<DatabaseMapping> mappings = builder.getRelationshipMappings(); 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); } } } else { for (int index = 0; index < size; index++) { DatabaseMapping mapping = mappings.get(index); mapping.cascadeDiscoverAndPersistUnregisteredNewObjects(object, newObjects, unregisteredExistingObjects, visitedObjects, uow); } } } }
FetchGroupManager fetchGroupManager = this.descriptor.getFetchGroupManager(); if ((fetchGroupManager != null) && fetchGroupManager.isPartialObject(object)) { for (int index = 0; index < size; index++) { DatabaseMapping mapping = mappings.get(index);
FetchGroupManager fetchGroupManager = this.descriptor.getFetchGroupManager(); if ((fetchGroupManager != null) && fetchGroupManager.isPartialObject(object)) { for (int index = 0; index < size; index++) { DatabaseMapping mapping = mappings.get(index);
/** * 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; }
/** * 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; }
/** * INTERNAL: * Clear the changes in the ObjectChangeListener */ public void clearChanges(Object clone, UnitOfWorkImpl uow, ClassDescriptor descriptor) { ObjectChangeListener listener = (ObjectChangeListener)((ChangeTracker)clone)._persistence_getPropertyChangeListener(); if (listener != null) { listener.clearChanges(); } else { listener = (ObjectChangeListener)setChangeListener(clone, uow, descriptor); } ObjectBuilder builder = descriptor.getObjectBuilder(); // Only relationship mappings need to be reset. if (!builder.isSimple()) { dissableEventProcessing(clone); // Must also ensure the listener has been set on collections and aggregates. FetchGroupManager fetchGroupManager = descriptor.getFetchGroupManager(); boolean isPartialObject = (fetchGroupManager != null) && fetchGroupManager.isPartialObject(clone); List mappings = builder.getRelationshipMappings(); int size = mappings.size(); // Only cascade fetched mappings. for (int index = 0; index < size; index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); if (!isPartialObject || fetchGroupManager.isAttributeFetched(clone, mapping.getAttributeName())) { mapping.setChangeListener(clone, listener, uow); } } enableEventProcessing(clone); } }
/** * INTERNAL: * Clear the changes in the ObjectChangeListener */ public void clearChanges(Object clone, UnitOfWorkImpl uow, ClassDescriptor descriptor, boolean forRefresh) { ObjectChangeListener listener = (ObjectChangeListener)((ChangeTracker)clone)._persistence_getPropertyChangeListener(); if (listener != null) { listener.clearChanges(forRefresh); } else { listener = (ObjectChangeListener)setChangeListener(clone, uow, descriptor); } ObjectBuilder builder = descriptor.getObjectBuilder(); // Only relationship mappings need to be reset. if (!builder.isSimple()) { dissableEventProcessing(clone); // Must also ensure the listener has been set on collections and aggregates. FetchGroupManager fetchGroupManager = descriptor.getFetchGroupManager(); boolean isPartialObject = (fetchGroupManager != null) && fetchGroupManager.isPartialObject(clone); List mappings = builder.getRelationshipMappings(); int size = mappings.size(); // Only cascade fetched mappings. for (int index = 0; index < size; index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); if (!isPartialObject || fetchGroupManager.isAttributeFetched(clone, mapping.getAttributeName())) { mapping.setChangeListener(clone, listener, uow); } } enableEventProcessing(clone); } }
/** * 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); } }
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++) {