All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sfm.querydsl.TupleFieldMapperFactory Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 1.10.3
Show newest version
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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy