org.sfm.querydsl.TupleFieldMapperFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simpleFlatMapper Show documentation
Show all versions of simpleFlatMapper Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.sfm.querydsl;
import com.mysema.query.Tuple;
import org.sfm.map.FieldMapper;
import org.sfm.map.FieldMapperErrorHandler;
import org.sfm.map.GetterFactory;
import org.sfm.map.MapperBuilderErrorHandler;
import org.sfm.map.impl.*;
import org.sfm.map.impl.fieldmapper.FieldMapperImpl;
import org.sfm.reflect.Getter;
import org.sfm.reflect.Setter;
import java.lang.reflect.Type;
public final class TupleFieldMapperFactory implements FieldMapperFactory> {
private final GetterFactory getterFactory;
public TupleFieldMapperFactory(GetterFactory getterFactory) {
this.getterFactory = getterFactory;
}
@Override
public FieldMapper newFieldMapper(PropertyMapping> propertyMapping, FieldMapperErrorHandler errorHandler,
MapperBuilderErrorHandler mappingErrorHandler) {
final Type propertyType = propertyMapping.getPropertyMeta().getType();
final Setter setter = propertyMapping.getPropertyMeta().getSetter();
final TupleElementKey key = propertyMapping.getColumnKey();
Getter getter = getterFactory.newGetter(propertyType, key);
if (getter == null) {
mappingErrorHandler.getterNotFound("Could not find getter for " + key + " type " + propertyType);
}
FieldMapper fm = new FieldMapperImpl(getter, setter);
if (errorHandler != null) {
fm = new FieldErrorHandlerMapper(key, fm, errorHandler);
}
return fm;
}
}