org.sfm.querydsl.QueryDslMapperBuilder 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 com.mysema.query.types.Expression;
import org.sfm.map.FieldMapper;
import org.sfm.map.Mapper;
import org.sfm.map.MapperBuildingException;
import org.sfm.map.MappingContextFactoryBuilder;
import org.sfm.map.impl.*;
import org.sfm.reflect.Instantiator;
import org.sfm.reflect.ReflectionService;
import org.sfm.reflect.meta.ClassMeta;
import org.sfm.tuples.Tuple2;
import java.lang.reflect.Type;
public final class QueryDslMapperBuilder
extends AbstractFieldMapperMapperBuilder {
public QueryDslMapperBuilder(final Type target) throws MapperBuildingException {
this(target, ReflectionService.newInstance());
}
@SuppressWarnings("unchecked")
public QueryDslMapperBuilder(final Type target, ReflectionService reflectService) throws MapperBuildingException {
this(reflectService.getRootClassMeta(target), new QueryDslMappingContextFactoryBuilder());
}
public QueryDslMapperBuilder(final ClassMeta classMeta, MappingContextFactoryBuilder parentBuilder) throws MapperBuildingException {
super(Tuple.class, classMeta, new TupleGetterFactory(),
new TupleFieldMapperFactory(new TupleGetterFactory()),
new IdentityFieldMapperColumnDefinitionProvider(),
new DefaultPropertyNameMatcherFactory(), new RethrowMapperBuilderErrorHandler(), parentBuilder);
}
@Override
public Mapper mapper() {
Tuple2[], Instantiator> constructorFieldMappersAndInstantiator = getConstructorFieldMappersAndInstantiator();
return new MapperImpl(fields(),
constructorFieldMappersAndInstantiator.first(),
constructorFieldMappersAndInstantiator.second(),
mappingContextFactoryBuilder.newFactory());
}
@Override
protected AbstractFieldMapperMapperBuilder newSubBuilder(
Type type, ClassMeta classMeta, MappingContextFactoryBuilder mappingContextFactoryBuilder) {
return new QueryDslMapperBuilder(classMeta, mappingContextFactoryBuilder);
}
public QueryDslMapperBuilder addMapping(Expression> expression, int i) {
_addMapping(new TupleElementKey(expression, i), FieldMapperColumnDefinition.identity());
return this;
}
}