Search in sources :

Example 1 with TransformationMapping

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

the class AggregateProject method amendJobDescriptor.

/**
 * The field types must be set in an amendment as the XML format does not support types.
 */
public static void amendJobDescriptor(ClassDescriptor descriptor) {
    TransformationMapping transformationmapping = (TransformationMapping) descriptor.getMappingForAttributeName("normalHours");
    transformationmapping.getFieldTransformations().clear();
    DatabaseField field = new DatabaseField("WORKER.END_TIME");
    field.setType(java.sql.Time.class);
    transformationmapping.addFieldTransformation(field, "getEndTime");
    field = new DatabaseField("WORKER.START_TIME");
    field.setType(java.sql.Time.class);
    transformationmapping.addFieldTransformation(field, "getStartTime");
}
Also used : TransformationMapping(org.eclipse.persistence.mappings.TransformationMapping) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField)

Example 2 with TransformationMapping

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

the class IllegalArgumentWhileInvokingAttributeMethodTest method setup.

@Override
protected void setup() {
    descriptor = new RelationalDescriptor();
    descriptor.setJavaClass(IllegalArgumentWhileInvokingAttributeMethodTest.class);
    descriptor.addTableName("EMPLOYEE");
    mapping = new TransformationMapping();
    mapping.setAttributeName("normalHours");
    mapping.setAttributeTransformation("invalidMethod");
    descriptor.addMapping(mapping);
    mapping.initialize((AbstractSession) getSession());
    row = new DatabaseRecord();
    expectedException = DescriptorException.illegalArgumentWhileInvokingAttributeMethod(mapping, new Exception());
}
Also used : RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) TransformationMapping(org.eclipse.persistence.mappings.TransformationMapping) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException)

Example 3 with TransformationMapping

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

the class SecurityWhileConvertingToMethodTest method setup.

@Override
protected void setup() {
    super.setup();
    expectedException = DescriptorException.securityWhileConvertingToMethod("getStartTime", mapping, new Exception());
    mapping = new TransformationMapping();
    mapping.setAttributeName("normalHours");
    mapping.setAttributeTransformation("buildNormalHours");
    mapping.addFieldTransformation("EMPLOYEE.START_TIME", "getStartTime");
    mapping.addFieldTransformation("EMPLOYEE.END_TIME", "getEndTime");
    // the following three lines ensure that the mapping is not isWriteOnly();
    mapping.setAttributeName(null);
    mapping.getAttributeAccessor().setAttributeName(null);
    mapping.setAttributeTransformation(null);
    mapping.setDescriptor(getTestDescriptor());
}
Also used : TransformationMapping(org.eclipse.persistence.mappings.TransformationMapping) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException)

Example 4 with TransformationMapping

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

the class SecurityOnInitializingAttributeMethodTest method setup.

@Override
protected void setup() {
    super.setup();
    expectedException = DescriptorException.securityOnInitializingAttributeMethod("buildNormalHours", mapping, new Exception());
    mapping = new TransformationMapping();
    mapping.setAttributeName("normalHours");
    // 
    mapping.setAttributeTransformation("buildNormalHours");
    // 
    mapping.addFieldTransformation("EMPLOYEE.START_TIME", "getStartTime");
    // 
    mapping.addFieldTransformation("EMPLOYEE.END_TIME", "getEndTime");
    mapping.setDescriptor(getTestDescriptor());
}
Also used : TransformationMapping(org.eclipse.persistence.mappings.TransformationMapping) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException)

Example 5 with TransformationMapping

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

the class TargetInvocationWhileInvokingAttributeMethodTest method setup.

@Override
protected void setup() {
    descriptor = new RelationalDescriptor();
    descriptor.setJavaClass(TargetInvocationWhileInvokingAttributeMethodTest.class);
    descriptor.addTableName("EMPLOYEE");
    mapping = new TransformationMapping();
    mapping.setAttributeName("normalHours");
    mapping.setAttributeTransformation("invalidMethod");
    descriptor.addMapping(mapping);
    mapping.initialize((AbstractSession) getSession());
    row = new DatabaseRecord();
    expectedException = DescriptorException.targetInvocationWhileInvokingAttributeMethod(mapping, new Exception());
}
Also used : RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) TransformationMapping(org.eclipse.persistence.mappings.TransformationMapping) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException)

Aggregations

TransformationMapping (org.eclipse.persistence.mappings.TransformationMapping)19 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)13 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)10 DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)5 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)5 OneToManyMapping (org.eclipse.persistence.mappings.OneToManyMapping)5 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)4 Vector (java.util.Vector)2 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)2 DirectCollectionMapping (org.eclipse.persistence.mappings.DirectCollectionMapping)2 ObjectTypeConverter (org.eclipse.persistence.mappings.converters.ObjectTypeConverter)2 DatabaseRecord (org.eclipse.persistence.sessions.DatabaseRecord)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 VersionLockingPolicy (org.eclipse.persistence.descriptors.VersionLockingPolicy)1 WriteTransformerMetadata (org.eclipse.persistence.internal.jpa.metadata.transformers.WriteTransformerMetadata)1 AggregateObjectMapping (org.eclipse.persistence.mappings.AggregateObjectMapping)1 ManyToManyMapping (org.eclipse.persistence.mappings.ManyToManyMapping)1 SerializedObjectConverter (org.eclipse.persistence.mappings.converters.SerializedObjectConverter)1 TypeConversionConverter (org.eclipse.persistence.mappings.converters.TypeConversionConverter)1