Search in sources :

Example 76 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.

the class ObjectBuilder method buildObjectsFromCursorInto.

/**
 * Return a container which contains the instances of the receivers javaClass.
 * Set the fields of the instance to the values stored in the database rows.
 */
public Object buildObjectsFromCursorInto(ReadAllQuery query, List databaseRows, Object domainObjects) {
    AbstractSession session = query.getSession();
    session.startOperationProfile(SessionProfiler.ObjectBuilding, query, SessionProfiler.ALL);
    try {
        InheritancePolicy inheritancePolicy = null;
        if (this.descriptor.hasInheritance()) {
            inheritancePolicy = this.descriptor.getInheritancePolicy();
        }
        boolean isUnitOfWork = session.isUnitOfWork();
        boolean shouldCacheQueryResults = query.shouldCacheQueryResults();
        boolean shouldUseWrapperPolicy = query.shouldUseWrapperPolicy();
        // PERF: Avoid lazy init of join manager if no joining.
        JoinedAttributeManager joinManager = null;
        if (query.hasJoining()) {
            joinManager = query.getJoinedAttributeManager();
        }
        ContainerPolicy policy = query.getContainerPolicy();
        if (policy.shouldAddAll()) {
            List domainObjectsIn = new ArrayList();
            List<AbstractRecord> databaseRowsIn = new ArrayList();
            for (Enumeration iterator = ((Vector) databaseRows).elements(); iterator.hasMoreElements(); ) {
                AbstractRecord databaseRow = (AbstractRecord) iterator.nextElement();
                // PERF: 1-m joining nulls out duplicate rows.
                if (databaseRow != null) {
                    domainObjectsIn.add(buildObject(query, databaseRow, joinManager, session, this.descriptor, inheritancePolicy, isUnitOfWork, shouldCacheQueryResults, shouldUseWrapperPolicy));
                    databaseRowsIn.add(databaseRow);
                }
            }
            policy.addAll(domainObjectsIn, domainObjects, session, databaseRowsIn, query, null, true);
        } else {
            boolean quickAdd = (domainObjects instanceof Collection) && !this.hasWrapperPolicy;
            for (Enumeration iterator = ((Vector) databaseRows).elements(); iterator.hasMoreElements(); ) {
                AbstractRecord databaseRow = (AbstractRecord) iterator.nextElement();
                // PERF: 1-m joining nulls out duplicate rows.
                if (databaseRow != null) {
                    Object domainObject = buildObject(query, databaseRow, joinManager, session, this.descriptor, inheritancePolicy, isUnitOfWork, shouldCacheQueryResults, shouldUseWrapperPolicy);
                    if (quickAdd) {
                        ((Collection) domainObjects).add(domainObject);
                    } else {
                        policy.addInto(domainObject, domainObjects, session, databaseRow, query, null, true);
                    }
                }
            }
        }
    } finally {
        session.endOperationProfile(SessionProfiler.ObjectBuilding, query, SessionProfiler.ALL);
    }
    return domainObjects;
}
Also used : Enumeration(java.util.Enumeration) JoinedAttributeManager(org.eclipse.persistence.internal.queries.JoinedAttributeManager) ArrayList(java.util.ArrayList) AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) InheritancePolicy(org.eclipse.persistence.descriptors.InheritancePolicy) Collection(java.util.Collection) ThreadCursoredList(org.eclipse.persistence.internal.helper.ThreadCursoredList) ArrayList(java.util.ArrayList) List(java.util.List) InvalidObject(org.eclipse.persistence.internal.helper.InvalidObject) Vector(java.util.Vector) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 77 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.

the class WriteLockManager method traverseRelatedLocks.

/**
 * INTERNAL:
 * Traverse the object and acquire locks on all related objects.
 */
public CacheKey traverseRelatedLocks(Object objectForClone, Map lockedObjects, Map refreshedObjects, ClassDescriptor descriptor, AbstractSession cloningSession) {
    // If all mappings have indirection short-circuit.
    if (descriptor.shouldAcquireCascadedLocks()) {
        FetchGroupManager fetchGroupManager = descriptor.getFetchGroupManager();
        boolean isPartialObject = (fetchGroupManager != null) && fetchGroupManager.isPartialObject(objectForClone);
        for (Iterator<DatabaseMapping> mappings = descriptor.getLockableMappings().iterator(); mappings.hasNext(); ) {
            DatabaseMapping mapping = mappings.next();
            // Only cascade fetched mappings.
            if (!isPartialObject || (fetchGroupManager.isAttributeFetched(objectForClone, mapping.getAttributeName()))) {
                // any mapping in this list must not have indirection.
                Object objectToLock = mapping.getAttributeValueFromObject(objectForClone);
                if (mapping.isCollectionMapping()) {
                    // Ignore null, means empty.
                    if (objectToLock != null) {
                        ContainerPolicy cp = mapping.getContainerPolicy();
                        Object iterator = cp.iteratorFor(objectToLock);
                        while (cp.hasNext(iterator)) {
                            Object object = cp.next(iterator, cloningSession);
                            if (mapping.getReferenceDescriptor().hasWrapperPolicy()) {
                                object = mapping.getReferenceDescriptor().getWrapperPolicy().unwrapObject(object, cloningSession);
                            }
                            CacheKey toWaitOn = checkAndLockObject(object, lockedObjects, refreshedObjects, mapping, cloningSession);
                            if (toWaitOn != null) {
                                return toWaitOn;
                            }
                        }
                    }
                } else {
                    if (mapping.getReferenceDescriptor().hasWrapperPolicy()) {
                        objectToLock = mapping.getReferenceDescriptor().getWrapperPolicy().unwrapObject(objectToLock, cloningSession);
                    }
                    CacheKey toWaitOn = checkAndLockObject(objectToLock, lockedObjects, refreshedObjects, mapping, cloningSession);
                    if (toWaitOn != null) {
                        return toWaitOn;
                    }
                }
            }
        }
    }
    return null;
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) FetchGroupManager(org.eclipse.persistence.descriptors.FetchGroupManager) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) CacheKey(org.eclipse.persistence.internal.identitymaps.CacheKey)

Example 78 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.

the class CacheBasedValueHolder method getValue.

/**
 * Process against the UOW and attempt to load a local copy before going to the shared cache
 * If null is returned then the calling UOW will instantiate as normal.
 */
@Override
@SuppressWarnings({ "unchecked" })
public T getValue(UnitOfWorkImpl uow) {
    if (this.references != null && this.references.length != 0) {
        if (mapping.isCollectionMapping()) {
            Collection<Object> result = uow.getIdentityMapAccessorInstance().getAllFromIdentityMapWithEntityPK(this.references, this.mapping.getReferenceDescriptor()).values();
            if (result.size() == references.length) {
                ContainerPolicy cp = mapping.getContainerPolicy();
                Object container = cp.containerInstance(result.size());
                for (Object object : result) {
                    cp.addInto(object, container, uow);
                }
                return (T) container;
            }
        } else {
            return (T) uow.getIdentityMapAccessorInstance().getFromIdentityMap(this.references[0], this.mapping.getReferenceClass());
        }
    }
    return null;
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy)

Example 79 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.

the class AggregateCollectionMapping method cascadePerformRemovePrivateOwnedObjectFromChangeSetIfRequired.

/**
 * INTERNAL:
 * Cascade perform removal of orphaned private owned objects from the UnitOfWorkChangeSet
 */
@Override
public void cascadePerformRemovePrivateOwnedObjectFromChangeSetIfRequired(Object object, UnitOfWorkImpl uow, Map visitedObjects) {
    // if the object is not instantiated, do not instantiate or cascade
    Object attributeValue = getAttributeValueFromObject(object);
    if (attributeValue != null && getIndirectionPolicy().objectIsInstantiated(attributeValue)) {
        Object cloneObjectCollection = getRealCollectionAttributeValueFromObject(object, uow);
        ContainerPolicy cp = getContainerPolicy();
        for (Object cloneIter = cp.iteratorFor(cloneObjectCollection); cp.hasNext(cloneIter); ) {
            Object referencedObject = cp.next(cloneIter, uow);
            if (referencedObject != null && !visitedObjects.containsKey(referencedObject)) {
                visitedObjects.put(referencedObject, referencedObject);
                ObjectBuilder builder = getReferenceDescriptor(referencedObject.getClass(), uow).getObjectBuilder();
                builder.cascadePerformRemovePrivateOwnedObjectFromChangeSet(referencedObject, uow, visitedObjects);
            }
        }
    }
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) ObjectBuilder(org.eclipse.persistence.internal.descriptors.ObjectBuilder)

Example 80 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.

the class AggregateCollectionMapping method verifyDeleteForUpdate.

/**
 * Verifying deletes make sure that all the records privately owned by this mapping are
 * actually removed. If such records are found than those are all read and removed one
 * by one taking their privately owned parts into account.
 */
protected void verifyDeleteForUpdate(DeleteObjectQuery query) throws DatabaseException, OptimisticLockException {
    Object objects = readPrivateOwnedForObject(query);
    // Delete all these object one by one.
    ContainerPolicy cp = getContainerPolicy();
    for (Object iter = cp.iteratorFor(objects); cp.hasNext(iter); ) {
        query.getSession().deleteObject(cp.next(iter, query.getSession()));
    }
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy)

Aggregations

ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)119 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)28 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)17 XMLRecord (org.eclipse.persistence.oxm.record.XMLRecord)17 List (java.util.List)14 Vector (java.util.Vector)14 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)14 XMLField (org.eclipse.persistence.oxm.XMLField)14 ArrayList (java.util.ArrayList)13 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)13 Collection (java.util.Collection)12 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)10 CollectionContainerPolicy (org.eclipse.persistence.internal.queries.CollectionContainerPolicy)9 InstanceVariableAttributeAccessor (org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor)8 MethodAttributeAccessor (org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor)8 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)8 HashMap (java.util.HashMap)7 VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)7 CustomAccessorAttributeAccessor (org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor)7 JAXBSetMethodAttributeAccessor (org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor)7