type Handler
Responsible for converting between JAVA types and JDBC types, TypeHandler interface methods fall into two categories:
- void setParameter (): responsible for translating JAVA type JDBC type
- T getResult (): responsible for the data from a JDBC type to type JAVA
Abstract class BaseTypeHandler to provide Mybatis, the main achievement of its subclasses to achieve.
TypeHandler type conversion for performing a single column and a single parameter value.
Type Trades Register
//记录JdbcType与TypeHandler之间的关系,前者是个枚举
private final Map<JdbcType, TypeHandler<?>> JDBC_TYPE_HANDLER_MAP = new EnumMap<JdbcType, TypeHandler<?>>(JdbcType.class);
//记录JAVA类型与向指定JDBC类型转换时的关系,如String可以转换为char、varchar等类型,所以存在一对多
private final Map<Type, Map<JdbcType, TypeHandler<?>>> TYPE_HANDLER_MAP = new ConcurrentHashMap<Type, Map<JdbcType, TypeHandler<?>>>();
//所有TypeHandler类型以及对应对象
private final Map<Class<?>, TypeHandler<?>> ALL_TYPE_HANDLERS_MAP = new HashMap<Class<?>, TypeHandler<?>>();
//空TypeHandler集合标识
private static final Map<JdbcType, TypeHandler<?>> NULL_TYPE_HANDLER_MAP = Collections.emptyMap();
Overloaded by a plurality of register () method as an object in the set register typeHandler;
by a plurality overloaded getTypeHandler () acquired from the object corresponding to the four TypeHandler set;
TYpeAliasRegister
Provides classes alias registration and management functions, use TYPE_ALIEASES field ( Map<String,Class<?>>
type) manage the relationship between the alias and type java, use registerAlias () to complete the registration