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;
}
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.");
}
}
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.");
}
}
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;
}
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;
}
}
Aggregations