Search in sources :

Example 16 with CollectionMapping

use of org.eclipse.persistence.mappings.CollectionMapping in project eclipselink by eclipse-ee4j.

the class ProjectClassGeneratorOrderByQueryKeysTest method setup.

/**
 * Setup what we want written out.
 */
@Override
public void setup() {
    CollectionMapping mapping = (CollectionMapping) project.getDescriptor(org.eclipse.persistence.testing.models.employee.domain.Employee.class).getMappingForAttributeName(ATTRIBUTE_NAME);
    // Add the new order by query keys to the mapping
    mapping.addAscendingOrdering("ascending1");
    mapping.addDescendingOrdering("descending1");
    mapping.addAscendingOrdering("ascending2");
    mapping.addDescendingOrdering("descending2");
}
Also used : CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping)

Example 17 with CollectionMapping

use of org.eclipse.persistence.mappings.CollectionMapping in project eclipselink by eclipse-ee4j.

the class ProjectXMLSortedCollectionMapping method test.

@Override
public void test() {
    try {
        Project writeToProject = new EmployeeProject();
        ClassDescriptor descriptorToModify = writeToProject.getDescriptors().get(Employee.class);
        DatabaseMapping mappingToModify = descriptorToModify.getMappingForAttributeName("projects");
        if (mappingToModify.isForeignReferenceMapping()) {
            if (mappingToModify.isCollectionMapping()) {
                CollectionMapping collectionMapping = (CollectionMapping) mappingToModify;
                collectionMapping.useSortedSetClassName(TreeSet.class.getName(), getComparator().getName());
            }
        } else {
            throw new Exception("The test must have sorted collection mapping specified in the class descriptor in order to test.");
        }
        // Write out the project with changes and read back in again.
        XMLProjectWriter.write(TEMP_FILE, writeToProject);
        readBackProject = XMLProjectReader.read(TEMP_FILE, getClass().getClassLoader());
    } catch (Exception e) {
        exception = e;
    }
}
Also used : Project(org.eclipse.persistence.sessions.Project) EmployeeProject(org.eclipse.persistence.testing.models.employee.relational.EmployeeProject) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) TreeSet(java.util.TreeSet) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) EmployeeProject(org.eclipse.persistence.testing.models.employee.relational.EmployeeProject) CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException)

Example 18 with CollectionMapping

use of org.eclipse.persistence.mappings.CollectionMapping 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 19 with CollectionMapping

use of org.eclipse.persistence.mappings.CollectionMapping in project eclipselink by eclipse-ee4j.

the class UseCollectionClassOnMappingTest method setup.

@Override
protected void setup() {
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    descriptorToModify = project.getDescriptors().get(Employee.class);
    mappingToModify = descriptorToModify.getMappingForAttributeName("projects");
    if (mappingToModify.isForeignReferenceMapping()) {
        if (mappingToModify.isCollectionMapping()) {
            CollectionMapping collectionMapping = (CollectionMapping) mappingToModify;
            collectionMapping.getContainerPolicy().setContainerClass(Employee.class);
        }
    }
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping)

Example 20 with CollectionMapping

use of org.eclipse.persistence.mappings.CollectionMapping in project eclipselink by eclipse-ee4j.

the class MappedKeyMapContainerPolicy method processAdditionalWritableMapKeyFields.

/**
 * INTERNAL:
 * This method is used to check the key mapping to ensure that it does not write to
 * a field that is written by another mapping.  There are two possibilities:
 *
 * 1. The conflicting mapping has already been processed.  In that case, we add MultipleWritableMappings
 * exception to the integrity checker right away
 * 2. There are no conflicting mappings.  In that case, we store the list of fields that this mapping
 * has processed on the descriptor for the target so they can be checked as the descriptor initializes.
 */
@Override
public void processAdditionalWritableMapKeyFields(AbstractSession session) {
    if (!((DatabaseMapping) getKeyMapping()).isReadOnly() && (this.valueMapping instanceof CollectionMapping)) {
        CollectionMapping mapping = (CollectionMapping) valueMapping;
        Iterator<DatabaseField> i = getIdentityFieldsForMapKey().iterator();
        while (i.hasNext()) {
            DatabaseField field = i.next();
            if (mapping.getReferenceDescriptor().getObjectBuilder().getMappingsByField().containsKey(field) || mapping.getReferenceDescriptor().getAdditionalWritableMapKeyFields().contains(field)) {
                session.getIntegrityChecker().handleError(DescriptorException.multipleWriteMappingsForField(field.toString(), mapping));
            } else {
                mapping.getReferenceDescriptor().getAdditionalWritableMapKeyFields().add(field);
            }
        }
    }
}
Also used : DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping)

Aggregations

CollectionMapping (org.eclipse.persistence.mappings.CollectionMapping)27 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)11 DirectCollectionMapping (org.eclipse.persistence.mappings.DirectCollectionMapping)6 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)4 Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)4 Expression (org.eclipse.persistence.expressions.Expression)3 AggregateCollectionMapping (org.eclipse.persistence.mappings.AggregateCollectionMapping)3 EntityManager (jakarta.persistence.EntityManager)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 TreeSet (java.util.TreeSet)2 EISCompositeCollectionMapping (org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping)2 EISOneToManyMapping (org.eclipse.persistence.eis.mappings.EISOneToManyMapping)2 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)2 TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)2 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)2 MapContainerPolicy (org.eclipse.persistence.internal.queries.MapContainerPolicy)2 ForeignReferenceMapping (org.eclipse.persistence.mappings.ForeignReferenceMapping)2 ManyToManyMapping (org.eclipse.persistence.mappings.ManyToManyMapping)2