org.simpleflatmapper.jdbc.spring.JdbcTemplateMapperFactory Maven / Gradle / Ivy
package org.simpleflatmapper.jdbc.spring;
import org.simpleflatmapper.jdbc.*;
import org.simpleflatmapper.map.MapperBuildingException;
import org.simpleflatmapper.map.getter.ContextualGetterFactoryAdapter;
import org.simpleflatmapper.map.mapper.AbstractColumnNameDiscriminatorMapperFactory;
import org.simpleflatmapper.map.mapper.AbstractMapperFactory;
import org.simpleflatmapper.map.property.FieldMapperColumnDefinition;
import org.simpleflatmapper.map.mapper.FieldMapperColumnDefinitionProviderImpl;
import org.simpleflatmapper.util.TypeReference;
import javax.sql.DataSource;
import java.lang.reflect.Type;
import java.sql.ResultSet;
public final class JdbcTemplateMapperFactory extends AbstractColumnNameDiscriminatorMapperFactory {
private JdbcTemplateMapperFactory(AbstractMapperFactory config) {
super(config, NameBasedResultSetGetterFactory.INSTANCE);
}
private JdbcTemplateMapperFactory() {
super(new FieldMapperColumnDefinitionProviderImpl(),
FieldMapperColumnDefinition.identity(),
NameBasedResultSetGetterFactory.INSTANCE,
new ContextualGetterFactoryAdapter(ResultSetGetterFactory.INSTANCE));
}
public static JdbcTemplateMapperFactory newInstance() {
return new JdbcTemplateMapperFactory();
}
public static JdbcTemplateMapperFactory newInstance(AbstractMapperFactory config) {
return new JdbcTemplateMapperFactory(config);
}
public RowMapperImpl newRowMapper(Class target)
throws MapperBuildingException {
return newRowMapper((Type)target);
}
public RowMapperImpl newRowMapper(TypeReference target)
throws MapperBuildingException {
return newRowMapper(target.getType());
}
public RowMapperImpl newRowMapper(Type target)
throws MapperBuildingException {
return new RowMapperImpl(this.newJdbcMapper(target));
}
public JdbcMapper newJdbcMapper(Type target) {
return JdbcMapperFactory.newInstance(this).newMapper(target);
}
public PreparedStatementCallbackImpl newPreparedStatementCallback(Class target)
throws MapperBuildingException {
return newPreparedStatementCallback((Type)target);
}
public PreparedStatementCallbackImpl newPreparedStatementCallback(Type target)
throws MapperBuildingException {
return new PreparedStatementCallbackImpl(this.newJdbcMapper(target));
}
public PreparedStatementCallbackImpl newPreparedStatementCallback(TypeReference target)
throws MapperBuildingException {
return newPreparedStatementCallback(target.getType());
}
public ResultSetExtractorImpl newResultSetExtractor(Class target)
throws MapperBuildingException {
return newResultSetExtractor((Type)target);
}
public ResultSetExtractorImpl newResultSetExtractor(Type target)
throws MapperBuildingException {
return new ResultSetExtractorImpl(this.newJdbcMapper(target));
}
public ResultSetExtractorImpl newResultSetExtractor(TypeReference target)
throws MapperBuildingException {
return newResultSetExtractor(target.getType());
}
public SqlParameterSourceFactory newSqlParameterSourceFactory(Class target) {
return newSqlParameterSourceFactory((Type)target);
}
public SqlParameterSourceFactory newSqlParameterSourceFactory(Type target) {
return new SqlParameterSourceFactory(new DynamicPlaceHolderValueGetterSource(this.getClassMeta(target), mapperConfig(target)));
}
public SqlParameterSourceFactory newSqlParameterSourceFactory(TypeReference target) {
return newSqlParameterSourceFactory(target.getType());
}
public SqlParameterSourceFactory newSqlParameterSourceFactory(Class target, String sql) {
return newSqlParameterSourceFactory((Type)target, sql);
}
public SqlParameterSourceFactory newSqlParameterSourceFactory(Type target, String sql) {
SqlParameterSourceBuilder builder = new SqlParameterSourceBuilder(this.getClassMeta(target), mapperConfig(target));
return builder.buildFactory(sql);
}
public SqlParameterSourceFactory newSqlParameterSourceFactory(TypeReference target, String sql) {
return newSqlParameterSourceFactory(target.getType(), sql);
}
public JdbcTemplateCrudDSL crud(Type target, Type keyTarget) {
return new JdbcTemplateCrudDSL(this, target, keyTarget);
}
public JdbcTemplateCrudDSL crud(Class target, Class keyTarget) {
return crud((Type)target, (Type)keyTarget);
}
public MappingSqlQuery mappingSqlQuery(Type target, DataSource ds, String sql) {
return new MappingSqlQuery(ds, sql, this.newJdbcMapper(target));
}
}