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