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

org.sfm.querydsl.QueryDslMapperBuilder 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 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;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy