/** * 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: * 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); } } } }
for (int index = 0; index < size; index++) { DatabaseMapping mapping = mappings.get(index); if (fetchGroupManager.isAttributeFetched(object, mapping.getAttributeName())) { mapping.cascadeRegisterNewIfRequired(object, uow, visitedObjects);
for (int index = 0; index < size; index++) { DatabaseMapping mapping = mappings.get(index); if (fetchGroupManager.isAttributeFetched(object, mapping.getAttributeName())) { mapping.cascadeRegisterNewIfRequired(object, uow, visitedObjects);
/** * 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; }
/** * 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); }
/** * 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); } }
/** * 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); } }
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);
/** * @return false for any lazily loaded property of root object being validated */ public boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) { boolean reachable = true; String attributeName = null; if (isRootObjectPath(pathToTraversableObject)) { attributeName = traversableProperty.getName(); //Refer to section 4.2 of Bean Validation spec for more details about Path.Node DatabaseMapping mapping = getMappingForAttributeName(attributeName); if(mapping != null) { if(mapping.isForeignReferenceMapping()) { // For lazy relationships check whether it is instantiated if(mapping.isLazy()) { Object attributeValue = mapping.getAttributeAccessor().getAttributeValueFromObject(traversableObject); reachable = ((ForeignReferenceMapping)mapping).getIndirectionPolicy().objectIsInstantiatedOrChanged(attributeValue); } } else { // For lazy non relationship attributes, check whether it is fetched FetchGroupManager fetchGroupManager = descriptor.getFetchGroupManager(); if (fetchGroupManager != null) { reachable = fetchGroupManager.isAttributeFetched(traversableObject, attributeName); } } } } return reachable; }
DatabaseMapping mapping = (DatabaseMapping)mappings.next(); if (!isPartialObject || (fetchGroupManager.isAttributeFetched(objectForClone, mapping.getAttributeName()))) {
DatabaseMapping mapping = (DatabaseMapping)mappings.next(); if (!isPartialObject || (fetchGroupManager.isAttributeFetched(objectForClone, mapping.getAttributeName()))) {
DatabaseMapping mapping = (DatabaseMapping)mappings.next(); if (!isPartialObject || (fetchGroupManager.isAttributeFetched(objectForClone, mapping.getAttributeName()))) {