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() + ");");
}
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;
}
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);
}
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);
}
}
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;
}
Aggregations