Search in sources :

Example 26 with FetchGroupManager

use of org.eclipse.persistence.descriptors.FetchGroupManager in project eclipselink by eclipse-ee4j.

the class FetchGroupMetadata method process.

/**
 * INTERNAL:
 */
public void process(ClassAccessor accessor) {
    MetadataDescriptor descriptor = accessor.getDescriptor();
    FetchGroupManager fetchGroupManager;
    if (descriptor.getClassDescriptor().hasFetchGroupManager()) {
        fetchGroupManager = descriptor.getClassDescriptor().getFetchGroupManager();
    } else {
        fetchGroupManager = new FetchGroupManager();
        descriptor.getClassDescriptor().setFetchGroupManager(fetchGroupManager);
    }
    if (fetchGroupManager.hasFetchGroup(m_name)) {
        // We must be adding a fetch group from a mapped superclass.
        // Entity fetch groups are added first followed by those from
        // mapped superclasses. So if one already exists we need to ignore
        // it.
        getLogger().logConfigMessage(MetadataLogger.IGNORE_MAPPED_SUPERCLASS_FETCH_GROUP, descriptor.getJavaClass(), accessor.getJavaClass(), m_name);
    } else {
        FetchGroup fetchGroup = new FetchGroup();
        // Process the name of the fetch group.
        fetchGroup.setName(m_name);
        // Process all the attributes of the fetch group.
        for (FetchAttributeMetadata fetchAttribute : m_fetchAttributes) {
            fetchGroup.addAttribute(fetchAttribute.getName());
        }
        fetchGroupManager.addFetchGroup(fetchGroup);
    }
}
Also used : FetchGroupManager(org.eclipse.persistence.descriptors.FetchGroupManager) MetadataDescriptor(org.eclipse.persistence.internal.jpa.metadata.MetadataDescriptor) FetchGroup(org.eclipse.persistence.queries.FetchGroup)

Example 27 with FetchGroupManager

use of org.eclipse.persistence.descriptors.FetchGroupManager in project eclipselink by eclipse-ee4j.

the class PersistenceContext method wrap.

/**
 * Make adjustments to an unmarshalled entity based on what is found in the weaved fields
 */
protected Object wrap(Object entity) {
    if ((entity != null) && (PersistenceWeavedRest.class.isAssignableFrom(entity.getClass()))) {
        if (!doesExist(null, entity)) {
            return entity;
        }
        ClassDescriptor descriptor = getJAXBDescriptorForClass(entity.getClass());
        if (entity instanceof FetchGroupTracker) {
            FetchGroup fetchGroup = new FetchGroup();
            for (DatabaseMapping mapping : descriptor.getMappings()) {
                if (!(mapping instanceof XMLInverseReferenceMapping)) {
                    fetchGroup.addAttribute(mapping.getAttributeName());
                }
            }
            (new FetchGroupManager()).setObjectFetchGroup(entity, fetchGroup, null);
            ((FetchGroupTracker) entity)._persistence_setSession(JpaHelper.getDatabaseSession(getEmf()));
        } else if (descriptor.hasRelationships()) {
            for (DatabaseMapping mapping : descriptor.getMappings()) {
                if (mapping instanceof XMLInverseReferenceMapping) {
                    // we require Fetch groups to handle relationships
                    JPARSLogger.error(getSessionLog(), "weaving_required_for_relationships", new Object[] {});
                    throw JPARSException.invalidConfiguration();
                }
            }
        }
    }
    return entity;
}
Also used : FetchGroupTracker(org.eclipse.persistence.queries.FetchGroupTracker) FetchGroupManager(org.eclipse.persistence.descriptors.FetchGroupManager) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) FetchGroup(org.eclipse.persistence.queries.FetchGroup) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Aggregations

FetchGroupManager (org.eclipse.persistence.descriptors.FetchGroupManager)27 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)13 FetchGroup (org.eclipse.persistence.queries.FetchGroup)12 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)8 EntityFetchGroup (org.eclipse.persistence.internal.queries.EntityFetchGroup)8 InvalidObject (org.eclipse.persistence.internal.helper.InvalidObject)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 DynamicEntity (org.eclipse.persistence.dynamic.DynamicEntity)4 CacheKey (org.eclipse.persistence.internal.identitymaps.CacheKey)4 PersistenceResource (org.eclipse.persistence.jpa.rs.resources.unversioned.PersistenceResource)4 Test (org.junit.Test)4 FetchGroupTracker (org.eclipse.persistence.queries.FetchGroupTracker)3 ArrayList (java.util.ArrayList)2 Vector (java.util.Vector)2 DescriptorEvent (org.eclipse.persistence.descriptors.DescriptorEvent)2 XMLInverseReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping)2 ObjectLevelReadQuery (org.eclipse.persistence.queries.ObjectLevelReadQuery)2 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)2 JAXBException (jakarta.xml.bind.JAXBException)1