Search in sources :

Example 1 with ConverterClass

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);
    }
}
Also used : AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping) AggregateCollectionMapping(org.eclipse.persistence.mappings.AggregateCollectionMapping) ConverterClass(org.eclipse.persistence.mappings.converters.ConverterClass) DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping)

Example 2 with ConverterClass

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);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ServerSession(org.eclipse.persistence.sessions.server.ServerSession) SerializedObjectConverter(org.eclipse.persistence.mappings.converters.SerializedObjectConverter) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ConverterClass(org.eclipse.persistence.mappings.converters.ConverterClass)

Example 3 with ConverterClass

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);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ServerSession(org.eclipse.persistence.sessions.server.ServerSession) SerializedObjectConverter(org.eclipse.persistence.mappings.converters.SerializedObjectConverter) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ConverterClass(org.eclipse.persistence.mappings.converters.ConverterClass)

Aggregations

ConverterClass (org.eclipse.persistence.mappings.converters.ConverterClass)3 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)2 SerializedObjectConverter (org.eclipse.persistence.mappings.converters.SerializedObjectConverter)2 ServerSession (org.eclipse.persistence.sessions.server.ServerSession)2 AggregateCollectionMapping (org.eclipse.persistence.mappings.AggregateCollectionMapping)1 DirectMapMapping (org.eclipse.persistence.mappings.DirectMapMapping)1 AbstractDirectMapping (org.eclipse.persistence.mappings.foundation.AbstractDirectMapping)1