Search in sources :

Example 61 with ContainerPolicy

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

the class InterfacePolicy method selectAllObjectsUsingMultipleTableSubclassRead.

/**
 * INTERNAL:
 * Select all objects for an interface descriptor.
 * This is accomplished by selecting for all of the concrete classes and then merging the objects.
 */
public Object selectAllObjectsUsingMultipleTableSubclassRead(ReadAllQuery query) throws DatabaseException {
    ContainerPolicy containerPolicy = query.getContainerPolicy();
    Object objects = containerPolicy.containerInstance();
    if (query.shouldIncludeData()) {
        ComplexQueryResult result = new ComplexQueryResult();
        result.setResult(objects);
        result.setData(new ArrayList());
        objects = result;
    }
    int size = this.childDescriptors.size();
    for (int index = 0; index < size; index++) {
        ClassDescriptor descriptor = this.childDescriptors.get(index);
        objects = containerPolicy.concatenateContainers(objects, descriptor.getInterfacePolicy().selectAllObjects(query), query.getSession());
    }
    return objects;
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) ArrayList(java.util.ArrayList) ComplexQueryResult(org.eclipse.persistence.queries.ComplexQueryResult)

Example 62 with ContainerPolicy

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

the class ContainerCloningTest method test.

@Override
public void test() {
    ContainerPolicy cp = new CollectionContainerPolicy();
    cp.setContainerClass(ClassConstants.ArrayList_class);
    Collection<Employee> originalC = java.util.Arrays.asList(new Employee());
    Collection cloneC = (Collection) cp.cloneFor(originalC);
    cp = new MapContainerPolicy();
    cp.setContainerClass(java.util.WeakHashMap.class);
    Map originalM = new java.util.WeakHashMap();
    originalM.put(1, 2);
    Map cloneM = (Map) cp.cloneFor(originalM);
    if ((originalC == cloneC) || (originalC.size() != cloneC.size())) {
        throw new TestErrorException("Cloned Collections are not copies.");
    }
    if ((originalM == cloneM) || (originalM.size() != cloneM.size())) {
        throw new TestErrorException("Cloned Maps are not copies.");
    }
    if (!originalC.iterator().next().equals(cloneC.iterator().next())) {
        throw new TestErrorException("Cloned Collections are not the same.");
    }
    if (!originalM.get(1).equals(cloneM.get(1))) {
        throw new TestErrorException("Cloned Maps are not the same.");
    }
}
Also used : CollectionContainerPolicy(org.eclipse.persistence.internal.queries.CollectionContainerPolicy) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) MapContainerPolicy(org.eclipse.persistence.internal.queries.MapContainerPolicy) CollectionContainerPolicy(org.eclipse.persistence.internal.queries.CollectionContainerPolicy) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) MapContainerPolicy(org.eclipse.persistence.internal.queries.MapContainerPolicy) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) Collection(java.util.Collection) Map(java.util.Map)

Example 63 with ContainerPolicy

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

the class ProjectXMLSortedCollectionMapping method verify.

@Override
protected void verify() {
    if (exception != null) {
        throw new TestErrorException("There is problem when read project back from project.xml", exception);
    }
    ClassDescriptor readBackDescriptor = readBackProject.getDescriptors().get(Employee.class);
    DatabaseMapping readBackMapping = readBackDescriptor.getMappingForAttributeName("projects");
    CollectionMapping collectionMapping = (CollectionMapping) readBackMapping;
    ContainerPolicy containerPolciy = collectionMapping.getContainerPolicy();
    if (containerPolciy.isCollectionPolicy()) {
        Class<?> conatinerClass = containerPolciy.getContainerClass();
        Class<?> comparatorClass = ((SortedCollectionContainerPolicy) containerPolciy).getComparatorClass();
        if (!conatinerClass.equals(TreeSet.class)) {
            throw new TestErrorException("The container class read was not equal to the conatiner class set originally, which expected as the java.util.TreeSet class. ");
        }
        if (!comparatorClass.equals(ProjectXMLSortedCollectionMapping.ProjectComparator.class)) {
            throw new TestErrorException("The comparator class read was not equal to the comparator class set originally, which expected as the ProjectXMLCollectionMappingUseSortedClassNameTest.ProjectComparator class. ");
        }
    } else {
        throw new TestErrorException("The container policy expect to set as SortedCollectionContainerPolicy.");
    }
}
Also used : SortedCollectionContainerPolicy(org.eclipse.persistence.internal.queries.SortedCollectionContainerPolicy) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) SortedCollectionContainerPolicy(org.eclipse.persistence.internal.queries.SortedCollectionContainerPolicy) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) TreeSet(java.util.TreeSet) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping)

Example 64 with ContainerPolicy

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

the class EISOneToManyMappingHelper method compareAttributeValuesWithOrder.

/**
 * Compare the attributes. Return true if they are alike.
 * The order of the elements is significant.
 */
private boolean compareAttributeValuesWithOrder(Object collection1, Object collection2, AbstractSession session) {
    ContainerPolicy cp = this.getContainerPolicy();
    Object iter1 = cp.iteratorFor(collection1);
    Object iter2 = cp.iteratorFor(collection2);
    while (cp.hasNext(iter1)) {
        if (!this.compareElements(cp.next(iter1, session), cp.next(iter2, session), session)) {
            return false;
        }
    }
    return true;
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy)

Example 65 with ContainerPolicy

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

the class EISOneToManyMappingHelper method compareAttributeValuesForChangeWithoutOrder.

/**
 * Build and return the change record that results
 * from comparing the two collection attributes.
 * Ignore the order of the elements.
 */
private ChangeRecord compareAttributeValuesForChangeWithoutOrder(Object cloneCollection, Object backupCollection, ObjectChangeSet owner, AbstractSession session) {
    ContainerPolicy cp = this.getContainerPolicy();
    // "clone" it so we can clear out the slots
    List backupVector = cp.vectorFor(backupCollection, session);
    EISCollectionChangeRecord changeRecord = new EISCollectionChangeRecord(owner, this.getAttributeName(), this.getDatabaseMapping());
    for (Object cloneIter = cp.iteratorFor(cloneCollection); cp.hasNext(cloneIter); ) {
        Object cloneElement = cp.next(cloneIter, session);
        boolean found = false;
        for (int i = 0; i < backupVector.size(); i++) {
            if (this.compareElementsForChange(cloneElement, backupVector.get(i), session)) {
                // the clone element was found in the backup collection
                found = true;
                // clear out the matching backup element
                backupVector.set(i, XXX);
                if (this.mapKeyHasChanged(cloneElement, session)) {
                    changeRecord.addChangedMapKeyChangeSet(this.buildChangeSet(cloneElement, owner, session));
                }
                // matching backup element found - skip the rest of them
                break;
            }
        }
        if (!found) {
            // the clone element was not found, so it must have been added
            changeRecord.addAddedChangeSet(this.buildChangeSet(cloneElement, owner, session));
        }
    }
    for (int i = 0; i < backupVector.size(); i++) {
        Object backupElement = backupVector.get(i);
        if (backupElement != XXX) {
            // the backup element was not in the clone collection, so it must have been removed
            changeRecord.addRemovedChangeSet(this.buildChangeSet(backupElement, owner, session));
        }
    }
    if (changeRecord.hasChanges()) {
        return changeRecord;
    } else {
        return null;
    }
}
Also used : EISCollectionChangeRecord(org.eclipse.persistence.eis.EISCollectionChangeRecord) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) List(java.util.List)

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