Search in sources :

Example 11 with TransformerBasedFieldTransformation

use of org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation 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

TransformerBasedFieldTransformation (org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation)11 Field (java.lang.reflect.Field)5 ObjectPersistenceWorkbenchXMLProject (org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject)5 ConstantTransformer (org.eclipse.persistence.mappings.transformers.ConstantTransformer)5 XMLTransformationMapping (org.eclipse.persistence.oxm.mappings.XMLTransformationMapping)5 Project (org.eclipse.persistence.sessions.Project)5 FieldTransformation (org.eclipse.persistence.internal.descriptors.FieldTransformation)4 MethodBasedFieldTransformation (org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation)4 StringReader (java.io.StringReader)2 PrivilegedActionException (java.security.PrivilegedActionException)2 SQLException (java.sql.SQLException)2 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)2 XMLContext (org.eclipse.persistence.oxm.XMLContext)2 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)2 BeforeClass (org.junit.BeforeClass)2 Document (org.w3c.dom.Document)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Statement (java.sql.Statement)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1