Package org.jdbi.v3.core.mapper.reflect
Class ReflectionMappers
- java.lang.Object
-
- org.jdbi.v3.core.mapper.reflect.ReflectionMappers
-
- All Implemented Interfaces:
JdbiConfig<ReflectionMappers>
public class ReflectionMappers extends java.lang.Object implements JdbiConfig<ReflectionMappers>
Configuration class for reflective mappers.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.UnaryOperator<java.lang.String>caseChangeprivate java.util.List<ColumnNameMatcher>columnNameMatchersprivate java.util.function.Consumer<java.lang.reflect.AccessibleObject>makeAccessibleprivate booleanstrictMatching
-
Constructor Summary
Constructors Modifier Constructor Description ReflectionMappers()Create a default configuration that attempts case insensitive and snake_case matching for names.privateReflectionMappers(ReflectionMappers that)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ReflectionMapperscreateCopy()Returns a copy of this configuration object.ReflectionMappersdisableAccessibleObjectStrategy()Set the strategy Jdbi uses for Java accessibility rules to a no-op.java.util.function.UnaryOperator<java.lang.String>getCaseChange()Case change strategy for the database column names.java.util.List<ColumnNameMatcher>getColumnNameMatchers()Returns the registered column name mappers.booleanisStrictMatching()Returns whether strict column name matching is enabled.<T extends java.lang.reflect.AccessibleObject>
TmakeAccessible(T accessibleObject)Use the accessibility strategy to potentially make a reflective operation accessible.ReflectionMapperssetAccessibleObjectStrategy(java.util.function.Consumer<java.lang.reflect.AccessibleObject> makeAccessible)Set the strategy Jdbi uses for Java accessibility rules.ReflectionMapperssetCaseChange(java.util.function.UnaryOperator<java.lang.String> caseChange)Sets the case change strategy for the database column names.ReflectionMapperssetColumnNameMatchers(java.util.List<ColumnNameMatcher> columnNameMatchers)Replace all column name matchers with the given list.ReflectionMapperssetStrictMatching(boolean strictMatching)Throw an IllegalArgumentException if a the set of fields doesn't match to columns exactly.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jdbi.v3.core.config.JdbiConfig
setRegistry
-
-
-
-
Field Detail
-
columnNameMatchers
private java.util.List<ColumnNameMatcher> columnNameMatchers
-
strictMatching
private boolean strictMatching
-
caseChange
private java.util.function.UnaryOperator<java.lang.String> caseChange
-
makeAccessible
private java.util.function.Consumer<java.lang.reflect.AccessibleObject> makeAccessible
-
-
Constructor Detail
-
ReflectionMappers
public ReflectionMappers()
Create a default configuration that attempts case insensitive and snake_case matching for names.
-
ReflectionMappers
private ReflectionMappers(ReflectionMappers that)
-
-
Method Detail
-
getColumnNameMatchers
public java.util.List<ColumnNameMatcher> getColumnNameMatchers()
Returns the registered column name mappers.- Returns:
- the registered column name mappers.
-
setColumnNameMatchers
public ReflectionMappers setColumnNameMatchers(java.util.List<ColumnNameMatcher> columnNameMatchers)
Replace all column name matchers with the given list.- Parameters:
columnNameMatchers- the column name matchers to use- Returns:
- this
-
isStrictMatching
public boolean isStrictMatching()
Returns whether strict column name matching is enabled.- Returns:
- True if strict column name matching is enabled.
-
setStrictMatching
public ReflectionMappers setStrictMatching(boolean strictMatching)
Throw an IllegalArgumentException if a the set of fields doesn't match to columns exactly. Reflection mappers with prefixes will only check those columns that begin with the mapper's prefix.- Parameters:
strictMatching- whether to enable strict matching- Returns:
- this
-
getCaseChange
public java.util.function.UnaryOperator<java.lang.String> getCaseChange()
Case change strategy for the database column names. By default, the row names are lowercased using the system locale.- Returns:
- The current case change strategy.
- See Also:
CaseStrategy
-
setCaseChange
public ReflectionMappers setCaseChange(java.util.function.UnaryOperator<java.lang.String> caseChange)
Sets the case change strategy for the database column names. By default, the row names are lowercased using the system locale.- Parameters:
caseChange- The strategy to use. Must not be null.- See Also:
CaseStrategy
-
setAccessibleObjectStrategy
@Alpha public ReflectionMappers setAccessibleObjectStrategy(java.util.function.Consumer<java.lang.reflect.AccessibleObject> makeAccessible)
Set the strategy Jdbi uses for Java accessibility rules. The legacy default is to callsetAccessible(true)in certain cases when we try to use a Constructor, Method, or Field. In the future, this default will be changed to a no-op, to better interact with the Java module system.- Parameters:
makeAccessible- AConsumerinstance that implements the strategy.- See Also:
AccessibleObjectStrategy
-
disableAccessibleObjectStrategy
@Alpha public ReflectionMappers disableAccessibleObjectStrategy()
Set the strategy Jdbi uses for Java accessibility rules to a no-op.
-
makeAccessible
@Alpha public <T extends java.lang.reflect.AccessibleObject> T makeAccessible(T accessibleObject)
Use the accessibility strategy to potentially make a reflective operation accessible.
-
createCopy
public ReflectionMappers createCopy()
Description copied from interface:JdbiConfigReturns a copy of this configuration object. Changes to the copy should not modify the original, and vice-versa.- Specified by:
createCopyin interfaceJdbiConfig<ReflectionMappers>- Returns:
- a copy of this configuration object.
-
-