use of org.apache.ibatis.type.EnumTypeHandler in project qiuyj-code by qiuyuanjun.
the class EnumTypeConditionChecker method doCheck.
@Override
@SuppressWarnings("unchecked")
public ReturnValue doCheck(Field field, SqlInfo sqlInfo, ReturnValue preRv) {
Enumerated enumerated = AnnotationUtils.findAnnotation(field, Enumerated.class);
if (Objects.isNull(enumerated)) {
if (Objects.isNull(preRv.fieldMethod)) {
try {
preRv.fieldMethod = ReflectionUtils.getDeclaredMethod(sqlInfo.getBeanType(), fieldToGetterName(field));
} catch (Exception e) {
// ignore
}
}
if (Objects.nonNull(preRv.fieldMethod)) {
enumerated = AnnotationUtils.findAnnotation(preRv.fieldMethod, Enumerated.class);
}
}
if (Objects.nonNull(enumerated)) {
Class<?> type = getFieldJavaType(field);
if (type.isEnum()) {
PropertyColumnMapping enumMapping = sqlInfo.getPropertyColumnMappingByPropertyName(field.getName());
TypeHandler enumTypeHandlerType = enumerated.type() == Enumerated.ValueType.ORDINAL ? new EnumOrdinalTypeHandler(type) : new EnumTypeHandler(type);
enumMapping.setTypeHandler(enumTypeHandlerType);
enumMapping.setJdbcType(enumerated.jdbcType());
sqlInfo.setHasEnumField();
}
}
preRv.intValue = ConditionChecker.CONTINUE_EXECUTION;
return preRv;
}
Aggregations