org.sfm.querydsl.QueryDslMapperBuilder Maven / Gradle / Ivy
package org.sfm.querydsl;
import com.mysema.query.Tuple;
import com.mysema.query.types.Expression;
import com.mysema.query.types.Path;
import org.sfm.map.Mapper;
import org.sfm.map.MapperBuildingException;
import org.sfm.map.MapperConfig;
import org.sfm.map.mapper.FieldMapperMapperBuilder;
import org.sfm.map.mapper.KeyFactory;
import org.sfm.map.mapper.MapperSource;
import org.sfm.map.column.FieldMapperColumnDefinition;
import org.sfm.map.context.MappingContextFactoryBuilder;
import org.sfm.map.mapper.MapperSourceImpl;
import org.sfm.reflect.ReflectionService;
import org.sfm.reflect.meta.ClassMeta;
import java.lang.reflect.Type;
public final class QueryDslMapperBuilder {
public static final MapperSource FIELD_MAPPER_SOURCE =
new MapperSourceImpl(Tuple.class, new TupleGetterFactory());
private static final KeyFactory KEY_FACTORY = new KeyFactory() {
@Override
public TupleElementKey newKey(String name, int i) {
return new TupleElementKey(name, i);
}
} ;
private final FieldMapperMapperBuilder fieldMapperMapperBuilder;
public QueryDslMapperBuilder(final Type target) throws MapperBuildingException {
this(target, ReflectionService.newInstance());
}
@SuppressWarnings("unchecked")
public QueryDslMapperBuilder(final Type target, ReflectionService reflectService) throws MapperBuildingException {
this(reflectService.getClassMeta(target), new QueryDslMappingContextFactoryBuilder());
}
public QueryDslMapperBuilder(final ClassMeta classMeta, MappingContextFactoryBuilder parentBuilder) throws MapperBuildingException {
fieldMapperMapperBuilder =
new FieldMapperMapperBuilder(
FIELD_MAPPER_SOURCE,
classMeta,
MapperConfig.fieldMapperConfig(),
parentBuilder, KEY_FACTORY);
}
public QueryDslMapperBuilder addMapping(Expression> expression, int i) {
fieldMapperMapperBuilder.addMapping(new TupleElementKey(expression, i), FieldMapperColumnDefinition.identity());
return this;
}
public Mapper mapper() {
return fieldMapperMapperBuilder.mapper();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy