public final class JdbcMapperFactory extends Object
JdbcMapperFactory is not Thread-Safe but the mappers are. It is strongly advised to instantiate one mapper per class for the life of your application.
You can instantiate dynamic mapper which will use the ResultSetMetaData to figure out the list of the columns or a static one using a builder.
// create a dynamic mapper targeting MyClass
JdbcMapperFactory
.newInstance()
.newMapper(MyClass.class);
// create a static mapper targeting MyClass
JdbcMapperFactory
.newInstance()
.newBuilder(MyClass.class)
.addMapping("id")
.addMapping("field1")
.addMapping("field2")
.mapper();
| Modifier and Type | Method and Description |
|---|---|
JdbcMapperFactory |
addAlias(String key,
String value)
Associate an alias on the column key to rename to value.
|
JdbcMapperFactory |
addAliases(Map<String,String> aliases)
Associate the aliases value to the column key.
|
JdbcMapperFactory |
addColumnDefinition(Predicate<? super JdbcColumnKey> predicate,
FieldMapperColumnDefinition<JdbcColumnKey,ResultSet> columnDefinition)
Associate the specified columnDefinition to the column matching the predicate.
|
JdbcMapperFactory |
addColumnDefinition(String key,
FieldMapperColumnDefinition<JdbcColumnKey,ResultSet> columnDefinition)
Associate the specified columnDefinition to the specified column.
|
JdbcMapperFactory |
addCustomFieldMapper(String key,
FieldMapper<ResultSet,?> fieldMapper)
Associate the specified FieldMapper for the specified column.
|
JdbcMapperFactory |
addCustomGetter(String key,
Getter<ResultSet,?> getter)
Associate the specified Getter for the specified column.
|
JdbcMapperFactory |
addKeys(String... columns)
Mark the specified columns as keys.
|
JdbcMapperFactory |
asmMapperNbFieldsLimit(int asmMapperNbFieldsLimit)
change the number of fields threshold after which an asm mapper is not generated.
|
JdbcMapperFactory |
disableAsm(boolean disableAsm) |
JdbcMapperFactory |
failOnAsm(boolean b) |
JdbcMapperFactory |
fieldMapperErrorHandler(FieldMapperErrorHandler<JdbcColumnKey> fieldMapperErrorHandler)
the FieldMapperErrorHandler is called when a error occurred when mapping a field from the source to the target.
|
JdbcMapperFactory |
getterFactory(GetterFactory<ResultSet,JdbcColumnKey> getterFactory)
Override the default implementation of the GetterFactory used to get access to value from the ResultSet.
|
JdbcMapperFactory |
ignorePropertyNotFound()
Change the mapperBuilderErrorHandler to an IgnoreMapperBuilderErrorHandler.
|
JdbcMapperFactory |
mapperBuilderErrorHandler(MapperBuilderErrorHandler mapperBuilderErrorHandler)
Set the new MapperBuilderErrorHandler.
|
<T> JdbcMapperBuilder<T> |
newBuilder(Class<T> target)
Will create a instance of JdbcMapperBuilder on the specified target class.
|
<T> JdbcMapperBuilder<T> |
newBuilder(Type target)
Will create a instance of JdbcMapperBuilder on the specified type.
|
<T> JdbcMapperBuilder<T> |
newBuilder(TypeReference<T> target)
Will create a instance of JdbcMapperBuilder on the type T specified by the typeReference.
|
<T> DiscriminatorJdbcBuilder<T> |
newDiscriminator(String column)
Create a discriminator builder based on the specified column
|
static JdbcMapperFactory |
newInstance()
instantiate a new JdbcMapperFactory
|
<T> JdbcMapper<T> |
newMapper(Class<T> target)
Will create a DynamicMapper on the specified target class.
|
<T> JdbcMapper<T> |
newMapper(Class<T> target,
ResultSetMetaData metaData)
Will create a instance of JdbcMapper based on the specified metadata and the target class.
|
<T> JdbcMapper<T> |
newMapper(Type target)
Will create a DynamicMapper on the specified type.
|
<T> JdbcMapper<T> |
newMapper(TypeReference<T> target)
Will create a DynamicMapper on the type specified by the TypeReference.
|
JdbcMapperFactory |
propertyNameMatcherFactory(PropertyNameMatcherFactory propertyNameMatcherFactory)
Override the default PropertyNameMatcherFactory with the specified factory.
|
JdbcMapperFactory |
reflectionService(ReflectionService reflectionService)
Override the default implementation of the ReflectionService.
|
RowHandlerErrorHandler |
rowHandlerErrorHandler() |
JdbcMapperFactory |
rowHandlerErrorHandler(RowHandlerErrorHandler rowHandlerErrorHandler)
the RowHandlerErrorHandler is called when an exception is thrown by the RowHandler in the forEach call.
|
JdbcMapperFactory |
useAsm(boolean useAsm) |
public static JdbcMapperFactory newInstance()
public JdbcMapperFactory fieldMapperErrorHandler(FieldMapperErrorHandler<JdbcColumnKey> fieldMapperErrorHandler)
fieldMapperErrorHandler - the new FieldMapperErrorHandlerpublic JdbcMapperFactory ignorePropertyNotFound()
public JdbcMapperFactory mapperBuilderErrorHandler(MapperBuilderErrorHandler mapperBuilderErrorHandler)
mapperBuilderErrorHandler - the MapperBuilderErrorHandlerpublic JdbcMapperFactory rowHandlerErrorHandler(RowHandlerErrorHandler rowHandlerErrorHandler)
rowHandlerErrorHandler - the new RowHandlerErrorHandlerpublic JdbcMapperFactory useAsm(boolean useAsm)
useAsm - false if you want to disable asm generation of Mappers, Getter and Setter. This would be active by default if asm is present in a compatible version.public JdbcMapperFactory disableAsm(boolean disableAsm)
disableAsm - true if you want to disable asm for generation and to resolve constructor parameter names.public JdbcMapperFactory getterFactory(GetterFactory<ResultSet,JdbcColumnKey> getterFactory)
getterFactory - the getterFactorypublic JdbcMapperFactory reflectionService(ReflectionService reflectionService)
reflectionService - the overriding instancepublic <T> JdbcMapper<T> newMapper(Class<T> target, ResultSetMetaData metaData) throws SQLException
T - the mapper target typetarget - the target class of the mappermetaData - the metadata to create the mapper fromSQLException - if an error occurs getting the metaDatapublic <T> JdbcMapperBuilder<T> newBuilder(Class<T> target)
T - the mapper target typetarget - the target classpublic <T> JdbcMapperBuilder<T> newBuilder(TypeReference<T> target)
T - the mapper target typetarget - the typeReferencepublic <T> JdbcMapperBuilder<T> newBuilder(Type target)
T - the mapper target typetarget - the typepublic <T> JdbcMapper<T> newMapper(Class<T> target)
T - the mapper target typetarget - the classpublic <T> JdbcMapper<T> newMapper(TypeReference<T> target)
T - the mapper target typetarget - the TypeReferencepublic <T> JdbcMapper<T> newMapper(Type target)
T - the mapper target typetarget - the typepublic JdbcMapperFactory addAlias(String key, String value)
key - the column to renamevalue - then name to rename topublic JdbcMapperFactory addCustomFieldMapper(String key, FieldMapper<ResultSet,?> fieldMapper)
key - the columnfieldMapper - the fieldMapperpublic JdbcMapperFactory addCustomGetter(String key, Getter<ResultSet,?> getter)
key - the columngetter - the getterpublic JdbcMapperFactory addColumnDefinition(String key, FieldMapperColumnDefinition<JdbcColumnKey,ResultSet> columnDefinition)
key - the columncolumnDefinition - the columnDefinitionpublic JdbcMapperFactory addColumnDefinition(Predicate<? super JdbcColumnKey> predicate, FieldMapperColumnDefinition<JdbcColumnKey,ResultSet> columnDefinition)
predicate - the column predicatecolumnDefinition - the columnDefinitionpublic JdbcMapperFactory propertyNameMatcherFactory(PropertyNameMatcherFactory propertyNameMatcherFactory)
propertyNameMatcherFactory - the factorypublic JdbcMapperFactory addAliases(Map<String,String> aliases)
aliases - the key value pairpublic JdbcMapperFactory failOnAsm(boolean b)
b - true if we want the builder to fail on asm generation failurepublic JdbcMapperFactory asmMapperNbFieldsLimit(int asmMapperNbFieldsLimit)
the default value is calculated from the benchmark results, currently 240.
asmMapperNbFieldsLimit - the limit after which it does not use asm for the mapper.public JdbcMapperFactory addKeys(String... columns)
columns - the columnspublic <T> DiscriminatorJdbcBuilder<T> newDiscriminator(String column)
T - the root type of the mappercolumn - the discriminator columnpublic RowHandlerErrorHandler rowHandlerErrorHandler()
Copyright © 2015. All rights reserved.