Search in sources :

Example 1 with MethodBasedFieldTransformation

use of org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation in project eclipselink by eclipse-ee4j.

the class ProjectClassGenerator method addTransformationMappingLines.

protected void addTransformationMappingLines(NonreflectiveMethodDefinition method, String mappingName, TransformationMapping mapping) {
    if (!mapping.isWriteOnly()) {
        if (mapping.getAttributeMethodName() != null) {
            method.addLine(mappingName + ".setAttributeTransformation(\"" + mapping.getAttributeMethodName() + "\");");
        } else {
            method.addLine(mappingName + ".setAttributeTransformer(new " + mapping.getAttributeTransformerClassName() + "());");
        }
    }
    Iterator<FieldTransformation> fieldTransformations = mapping.getFieldTransformations().iterator();
    while (fieldTransformations.hasNext()) {
        FieldTransformation trans = fieldTransformations.next();
        String fieldName = trans.getFieldName();
        if (trans instanceof MethodBasedFieldTransformation) {
            String methodName = ((MethodBasedFieldTransformation) trans).getMethodName();
            method.addLine(mappingName + ".addFieldTransformation(\"" + fieldName + "\", \"" + methodName + "\");");
        } else {
            String transformerClass = ((TransformerBasedFieldTransformation) trans).getTransformerClassName();
            method.addLine(mappingName + ".addFieldTransformer(\"" + fieldName + "\", new " + transformerClass + "());");
        }
    }
    IndirectionPolicy policy = mapping.getIndirectionPolicy();
    if (policy instanceof ContainerIndirectionPolicy) {
        String containerClassName = ((ContainerIndirectionPolicy) policy).getContainerClassName();
        method.addLine(mappingName + ".useContainerIndirection(" + containerClassName + ".class);");
    } else if (policy instanceof BasicIndirectionPolicy) {
        method.addLine(mappingName + ".useBasicIndirection();");
    }
    method.addLine(mappingName + ".setIsMutable(" + mapping.isMutable() + ");");
}
Also used : TransformerBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation) MethodBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation) ContainerIndirectionPolicy(org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy) ProxyIndirectionPolicy(org.eclipse.persistence.internal.indirection.ProxyIndirectionPolicy) ContainerIndirectionPolicy(org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy) NoIndirectionPolicy(org.eclipse.persistence.internal.indirection.NoIndirectionPolicy) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) InMemoryQueryIndirectionPolicy(org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy) IndirectionPolicy(org.eclipse.persistence.internal.indirection.IndirectionPolicy) BasicIndirectionPolicy(org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy) BasicIndirectionPolicy(org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy) TransformerBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation) FieldTransformation(org.eclipse.persistence.internal.descriptors.FieldTransformation) MethodBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation)

Example 2 with MethodBasedFieldTransformation

use of org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation in project eclipselink by eclipse-ee4j.

the class AbstractTransformationMapping method getFieldNameToMethodNameAssociations.

/**
 * INTERNAL:
 * Needed for backwards compatibility
 */
public Vector getFieldNameToMethodNameAssociations() {
    Vector associations = new Vector();
    for (Iterator<FieldTransformation> source = getFieldTransformations().iterator(); source.hasNext(); ) {
        FieldTransformation tf = source.next();
        if (tf instanceof MethodBasedFieldTransformation) {
            Association ass = new Association();
            ass.setKey(tf.getField().getQualifiedName());
            ass.setValue(((MethodBasedFieldTransformation) tf).getMethodName());
            associations.addElement(ass);
        }
    }
    return associations;
}
Also used : Association(org.eclipse.persistence.mappings.Association) MethodBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation) Vector(java.util.Vector) TransformerBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation) FieldTransformation(org.eclipse.persistence.internal.descriptors.FieldTransformation) MethodBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation)

Example 3 with MethodBasedFieldTransformation

use of org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation in project eclipselink by eclipse-ee4j.

the class AbstractTransformationMapping method addFieldTransformation.

/**
 * PUBLIC:
 * Add the field and the name of the method
 * that returns the value to be placed in said field
 * when the object is written to the database.
 * The method may take zero arguments, or it may
 * take a single argument of type
 * <code>org.eclipse.persistence.sessions.Session</code>.
 */
public void addFieldTransformation(DatabaseField field, String methodName) {
    MethodBasedFieldTransformation transformation = new MethodBasedFieldTransformation();
    transformation.setField(field);
    transformation.setMethodName(methodName);
    getFieldTransformations().add(transformation);
}
Also used : MethodBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation)

Example 4 with MethodBasedFieldTransformation

use of org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation in project eclipselink by eclipse-ee4j.

the class AbstractTransformationMapping method setFieldNameToMethodNameAssociations.

/**
 * INTERNAL:
 * needed for backwards compatibility
 */
public void setFieldNameToMethodNameAssociations(Vector associations) {
    setFieldTransformations(org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(associations.size()));
    for (Iterator source = associations.iterator(); source.hasNext(); ) {
        Association ass = (Association) source.next();
        MethodBasedFieldTransformation tf = new MethodBasedFieldTransformation();
        tf.setField(new DatabaseField((String) ass.getKey()));
        tf.setMethodName((String) ass.getValue());
        getFieldTransformations().add(tf);
    }
}
Also used : Association(org.eclipse.persistence.mappings.Association) MethodBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) Iterator(java.util.Iterator) DescriptorIterator(org.eclipse.persistence.internal.descriptors.DescriptorIterator)

Example 5 with MethodBasedFieldTransformation

use of org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation in project eclipselink by eclipse-ee4j.

the class AbstractTransformationMapping method getFieldNameToMethodNames.

/**
 * INTERNAL:
 * Required for reverse compatibility and test cases:
 * @return a hash table containing the fieldName and their respective method names
 */
public Hashtable getFieldNameToMethodNames() {
    Hashtable table = new Hashtable(getFieldTransformations().size());
    Iterator<FieldTransformation> transformations = getFieldTransformations().iterator();
    while (transformations.hasNext()) {
        FieldTransformation transformation = transformations.next();
        if (transformation instanceof MethodBasedFieldTransformation) {
            table.put(transformation.getField().getQualifiedName(), ((MethodBasedFieldTransformation) transformation).getMethodName());
        }
    }
    return table;
}
Also used : MethodBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation) Hashtable(java.util.Hashtable) TransformerBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation) FieldTransformation(org.eclipse.persistence.internal.descriptors.FieldTransformation) MethodBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation)

Aggregations

MethodBasedFieldTransformation (org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation)6 FieldTransformation (org.eclipse.persistence.internal.descriptors.FieldTransformation)4 TransformerBasedFieldTransformation (org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation)4 Association (org.eclipse.persistence.mappings.Association)2 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 Vector (java.util.Vector)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 ProxyIndirectionPolicy (org.eclipse.persistence.internal.indirection.ProxyIndirectionPolicy)1 TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 InMemoryQueryIndirectionPolicy (org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy)1 Session (org.eclipse.persistence.sessions.Session)1 ServerSession (org.eclipse.persistence.sessions.server.ServerSession)1