@Alias("jsonMapHandler") @MappedTypes({Map.class}) @MappedJdbcTypes({JdbcType.VARCHAR, JdbcType.CLOB}) @Slf4j public class JsonMapHandler extends BaseTypeHandler<Map<String, Object>> {
@Override public JobState getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { return valueOf(super.getNullableResult(cs, columnIndex)); }
@Override public Long getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { return valueOf(super.getNullableResult(cs, columnIndex)); }
} else if (parameterObject == null) { value = null; } else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) { value = parameterObject; } else { typeHandler.setParameter(ps, i + 1, value, jdbcType); } catch (TypeException | SQLException e) { throw new TypeException("Could not set parameters for mapping: " + parameterMapping + ". Cause: " + e, e);
public void initMybatisTypeHandlers(Configuration configuration) { configuration.getTypeHandlerRegistry().register(VariableType.class, JdbcType.VARCHAR, new IbatisVariableTypeHandler()); }
void loadAlias(String alias, Class dtoClass) { conf.getTypeAliasRegistry().registerAlias(alias, dtoClass); }
/** * 实例化TypeHandler * @param javaTypeClass * @param typeHandlerClass * @return */ @SuppressWarnings("unchecked") public <T> TypeHandler<T> getInstance(Class<?> javaTypeClass, Class<?> typeHandlerClass) { if (javaTypeClass != null) { try { Constructor<?> c = typeHandlerClass.getConstructor(Class.class); return (TypeHandler<T>) c.newInstance(javaTypeClass); } catch (NoSuchMethodException ignored) { // ignored } catch (Exception e) { throw new TypeException("Failed invoking constructor for handler " + typeHandlerClass, e); } } try { Constructor<?> c = typeHandlerClass.getConstructor(); return (TypeHandler<T>) c.newInstance(); } catch (Exception e) { throw new TypeException("Unable to find a usable constructor for " + typeHandlerClass, e); } }
@Getter @Setter @AllArgsConstructor @MappedJdbcTypes({JdbcType.NUMERIC, JdbcType.TINYINT, JdbcType.INTEGER, JdbcType.BIGINT}) static class EnumDictArrayHandler<T extends Enum & EnumDict> implements TypeHandler<Object[]> {
sb.append(this.jdbcType.toString());
@Override public int hashCode() { int result = table != null ? table.hashCode() : 0; result = 31 * result + (property != null ? property.hashCode() : 0); result = 31 * result + (column != null ? column.hashCode() : 0); result = 31 * result + (javaType != null ? javaType.hashCode() : 0); result = 31 * result + (jdbcType != null ? jdbcType.hashCode() : 0); result = 31 * result + (typeHandler != null ? typeHandler.hashCode() : 0); result = 31 * result + (id ? 1 : 0); result = 31 * result + (identity ? 1 : 0); result = 31 * result + (generator != null ? generator.hashCode() : 0); result = 31 * result + (orderBy != null ? orderBy.hashCode() : 0); return result; }
@Alias("jsonSetHandler") @MappedTypes({Set.class}) @MappedJdbcTypes({JdbcType.VARCHAR, JdbcType.CLOB}) @Slf4j public class JsonSetHandler extends BaseTypeHandler<Set> {
private void typeHandlerElement(XNode parent) { if (parent != null) { for (XNode child : parent.getChildren()) { if ("package".equals(child.getName())) { String typeHandlerPackage = child.getStringAttribute("name"); typeHandlerRegistry.register(typeHandlerPackage); } else { String javaTypeName = child.getStringAttribute("javaType"); String jdbcTypeName = child.getStringAttribute("jdbcType"); String handlerTypeName = child.getStringAttribute("handler"); Class<?> javaTypeClass = resolveClass(javaTypeName); JdbcType jdbcType = resolveJdbcType(jdbcTypeName); Class<?> typeHandlerClass = resolveClass(handlerTypeName); if (javaTypeClass != null) { if (jdbcType == null) { typeHandlerRegistry.register(javaTypeClass, typeHandlerClass); } else { typeHandlerRegistry.register(javaTypeClass, jdbcType, typeHandlerClass); } } else { typeHandlerRegistry.register(typeHandlerClass); } } } } }
/** * 实例化TypeHandler * @param javaTypeClass * @param typeHandlerClass * @return */ @SuppressWarnings("unchecked") public <T> TypeHandler<T> getInstance(Class<?> javaTypeClass, Class<?> typeHandlerClass) { if (javaTypeClass != null) { try { Constructor<?> c = typeHandlerClass.getConstructor(Class.class); return (TypeHandler<T>) c.newInstance(javaTypeClass); } catch (NoSuchMethodException ignored) { // ignored } catch (Exception e) { throw new TypeException("Failed invoking constructor for handler " + typeHandlerClass, e); } } try { Constructor<?> c = typeHandlerClass.getConstructor(); return (TypeHandler<T>) c.newInstance(); } catch (Exception e) { throw new TypeException("Unable to find a usable constructor for " + typeHandlerClass, e); } }
@Getter @Setter @AllArgsConstructor @MappedJdbcTypes({JdbcType.VARCHAR, JdbcType.BIT, JdbcType.BOOLEAN, JdbcType.NUMERIC, JdbcType.TINYINT, JdbcType.INTEGER,
@Override public int hashCode() { int result = table != null ? table.hashCode() : 0; result = 31 * result + (property != null ? property.hashCode() : 0); result = 31 * result + (column != null ? column.hashCode() : 0); result = 31 * result + (javaType != null ? javaType.hashCode() : 0); result = 31 * result + (jdbcType != null ? jdbcType.hashCode() : 0); result = 31 * result + (typeHandler != null ? typeHandler.hashCode() : 0); result = 31 * result + (id ? 1 : 0); result = 31 * result + (identity ? 1 : 0); result = 31 * result + (generator != null ? generator.hashCode() : 0); result = 31 * result + (orderBy != null ? orderBy.hashCode() : 0); return result; }
@Override public JobState getNullableResult(ResultSet rs, String columnName) throws SQLException { return valueOf(super.getNullableResult(rs, columnName)); }
@Override public Long getNullableResult(ResultSet rs, String columnName) throws SQLException { return valueOf(super.getNullableResult(rs, columnName)); }
@Alias("jsonArrayHandler") @MappedTypes({List.class}) @MappedJdbcTypes({JdbcType.VARCHAR, JdbcType.CLOB}) @Slf4j public class JsonArrayHandler extends BaseTypeHandler<List<Object>> {
@Override public JobState getNullableResult(ResultSet rs, int columnIndex) throws SQLException { return valueOf(super.getNullableResult(rs, columnIndex)); }
@Override public Long getNullableResult(ResultSet rs, int columnIndex) throws SQLException { return valueOf(super.getNullableResult(rs, columnIndex)); }