Search in sources :

Example 6 with FieldTransformation

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);
            }
        }
    }
}
Also used : TransformerBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation) MethodBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation) TransformerBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation) FieldTransformation(org.eclipse.persistence.internal.descriptors.FieldTransformation) MethodBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation) ServerSession(org.eclipse.persistence.sessions.server.ServerSession) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession) Session(org.eclipse.persistence.sessions.Session)

Aggregations

FieldTransformation (org.eclipse.persistence.internal.descriptors.FieldTransformation)6 MethodBasedFieldTransformation (org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation)6 TransformerBasedFieldTransformation (org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation)6 PrivilegedActionException (java.security.PrivilegedActionException)2 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Vector (java.util.Vector)1 ConversionException (org.eclipse.persistence.exceptions.ConversionException)1 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)1 DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)1 ValidationException (org.eclipse.persistence.exceptions.ValidationException)1 DatabasePlatform (org.eclipse.persistence.internal.databaseaccess.DatabasePlatform)1 FieldTypeDefinition (org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition)1 DescriptorIterator (org.eclipse.persistence.internal.descriptors.DescriptorIterator)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 BasicIndirectionPolicy (org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy)1 ContainerIndirectionPolicy (org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy)1 IndirectionPolicy (org.eclipse.persistence.internal.indirection.IndirectionPolicy)1 NoIndirectionPolicy (org.eclipse.persistence.internal.indirection.NoIndirectionPolicy)1