Search in sources :

Example 1 with EnumTypeHandler

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;
}
Also used : Enumerated(com.qiuyj.mybatis.annotation.Enumerated) PropertyColumnMapping(com.qiuyj.mybatis.PropertyColumnMapping) EnumOrdinalTypeHandler(org.apache.ibatis.type.EnumOrdinalTypeHandler) EnumOrdinalTypeHandler(org.apache.ibatis.type.EnumOrdinalTypeHandler) EnumTypeHandler(org.apache.ibatis.type.EnumTypeHandler) TypeHandler(org.apache.ibatis.type.TypeHandler) EnumTypeHandler(org.apache.ibatis.type.EnumTypeHandler)

Aggregations

PropertyColumnMapping (com.qiuyj.mybatis.PropertyColumnMapping)1 Enumerated (com.qiuyj.mybatis.annotation.Enumerated)1 EnumOrdinalTypeHandler (org.apache.ibatis.type.EnumOrdinalTypeHandler)1 EnumTypeHandler (org.apache.ibatis.type.EnumTypeHandler)1 TypeHandler (org.apache.ibatis.type.TypeHandler)1