use of org.eclipse.persistence.mappings.converters.ConverterClass in project eclipselink by eclipse-ee4j.
the class ConverterAccessor method process.
/**
* INTERNAL:
* Process this converter for the given mapping.
*/
public void process(DatabaseMapping mapping, boolean isForMapKey, String attributeName, boolean disableConversion) {
ConverterClass converterClass = new ConverterClass(getJavaClassName(), isForMapKey, fieldClassification.getName(), disableConversion);
converterClass.setSession(getProject().getSession());
if (mapping.isDirectMapMapping() && isForMapKey) {
((DirectMapMapping) mapping).setKeyConverter(converterClass);
} else if (mapping.isDirectCollectionMapping()) {
((DirectCollectionMapping) mapping).setValueConverter(converterClass);
} else if (mapping.isDirectToFieldMapping()) {
((AbstractDirectMapping) mapping).setConverter(converterClass);
} else if (mapping.isAggregateObjectMapping()) {
((AggregateObjectMapping) mapping).addConverter(converterClass, attributeName);
} else if (mapping.isAggregateCollectionMapping()) {
((AggregateCollectionMapping) mapping).addConverter(converterClass, attributeName);
}
}
use of org.eclipse.persistence.mappings.converters.ConverterClass in project eclipselink by eclipse-ee4j.
the class ConverterTestSuite method testAutoApplyConverter.
/**
* Test that an attribute picks up an auto apply converter.
*/
public void testAutoApplyConverter() {
ServerSession session = getPersistenceUnitServerSession();
ClassDescriptor employeeDescriptor = session.getDescriptor(Employee.class);
DirectToFieldMapping salaryMapping = (DirectToFieldMapping) employeeDescriptor.getMappingForAttributeName("salary");
assertNotNull("Salary mapping did not have the auto apply converter", salaryMapping.getConverter());
DirectToFieldMapping previousSalaryMapping = (DirectToFieldMapping) employeeDescriptor.getMappingForAttributeName("previousSalary");
assertNull("Salary mapping did not have the auto apply converter", previousSalaryMapping.getConverter());
ClassDescriptor runnerDescriptor = session.getDescriptor(Runner.class);
DirectToFieldMapping tagsMapping = (DirectToFieldMapping) runnerDescriptor.getMappingForAttributeName("tags");
assertTrue("Tags mapping did not have a converter", tagsMapping.hasConverter());
assertTrue("Serials mappings did not have a SerializedObjectConverter", tagsMapping.getConverter() instanceof ConverterClass);
DirectToFieldMapping serialsMapping = (DirectToFieldMapping) runnerDescriptor.getMappingForAttributeName("serials");
assertTrue("Serials mapping did not have a converter", serialsMapping.hasConverter());
assertTrue("Serials mappings did not have a SerializedObjectConverter", serialsMapping.getConverter() instanceof SerializedObjectConverter);
}
use of org.eclipse.persistence.mappings.converters.ConverterClass in project eclipselink by eclipse-ee4j.
the class ConverterTestSuite method testAutoApplyConverter.
/**
* Test that an attribute picks up an auto apply converter.
*/
public void testAutoApplyConverter() {
ServerSession session = getPersistenceUnitServerSession();
ClassDescriptor employeeDescriptor = session.getDescriptor(Employee.class);
DirectToFieldMapping salaryMapping = (DirectToFieldMapping) employeeDescriptor.getMappingForAttributeName("salary");
assertNotNull("Salary mapping did not have the auto apply converter", salaryMapping.getConverter());
DirectToFieldMapping previousSalaryMapping = (DirectToFieldMapping) employeeDescriptor.getMappingForAttributeName("previousSalary");
assertNull("Salary mapping did not have the auto apply converter", previousSalaryMapping.getConverter());
ClassDescriptor runnerDescriptor = session.getDescriptor(Runner.class);
DirectToFieldMapping tagsMapping = (DirectToFieldMapping) runnerDescriptor.getMappingForAttributeName("tags");
assertTrue("Tags mapping did not have a converter", tagsMapping.hasConverter());
assertTrue("Serials mappings did not have a SerializedObjectConverter", tagsMapping.getConverter() instanceof ConverterClass);
DirectToFieldMapping serialsMapping = (DirectToFieldMapping) runnerDescriptor.getMappingForAttributeName("serials");
assertTrue("Serials mapping did not have a converter", serialsMapping.hasConverter());
assertTrue("Serials mappings did not have a SerializedObjectConverter", serialsMapping.getConverter() instanceof SerializedObjectConverter);
}
Aggregations