use of org.eclipse.persistence.internal.descriptors.FieldTransformation in project eclipselink by eclipse-ee4j.
the class DefaultTableGenerator method resetTransformedFieldType.
/**
* Reset the transformation mapping field types
*/
protected void resetTransformedFieldType(TransformationMapping mapping) {
Iterator<FieldTransformation> transIter = mapping.getFieldTransformations().iterator();
while (transIter.hasNext()) {
FieldTransformation transformation = transIter.next();
if (transformation instanceof MethodBasedFieldTransformation) {
MethodBasedFieldTransformation methodTransformation = (MethodBasedFieldTransformation) transformation;
try {
Class<?> returnType = Helper.getDeclaredMethod(mapping.getDescriptor().getJavaClass(), methodTransformation.getMethodName(), null).getReturnType();
getFieldDefFromDBField(methodTransformation.getField()).setType(returnType);
} catch (NoSuchMethodException ex) {
// For some reason, the method type could not be retrieved,
// use the default java.lang.String type
}
} else {
// Must be a TransformerBasedFieldTransformation
TransformerBasedFieldTransformation classTransformation = (TransformerBasedFieldTransformation) transformation;
String methodName = "buildFieldValue";
Class<?>[] params = new Class<?>[] { Object.class, String.class, Session.class };
try {
Class<?> returnType = Helper.getDeclaredMethod(classTransformation.getTransformerClass(), methodName, params).getReturnType();
if (returnType.equals(Object.class)) {
// an exception.
throw ValidationException.missingFieldTypeForDDLGenerationOfClassTransformation(mapping.getDescriptor(), mapping.getAttributeName(), methodName);
}
getFieldDefFromDBField(classTransformation.getField()).setType(returnType);
} catch (NoSuchMethodException ex) {
// Did the interface method change? Throw an exception.
throw ValidationException.missingTransformerMethodForDDLGenerationOfClassTransformation(mapping.getDescriptor(), mapping.getAttributeName(), methodName);
}
}
}
}
Aggregations