Example usage for org.apache.ibatis.mapping ResultMapping.Builder typeHandler

List of usage examples for org.apache.ibatis.mapping ResultMapping.Builder typeHandler

Introduction

In this page you can find the example usage for org.apache.ibatis.mapping ResultMapping.Builder typeHandler.

Prototype

TypeHandler typeHandler

To view the source code for org.apache.ibatis.mapping ResultMapping.Builder typeHandler.

Click Source Link

Usage

From source file:com.hand.hap.mybatis.entity.EntityTable.java

License:Open Source License

/**
 * ??resultMap//from   w w  w  . ja v a 2  s . c o m
 *
 * @param configuration
 * @return
 */
public ResultMap getResultMap(Configuration configuration) {
    if (this.resultMap != null) {
        return this.resultMap;
    }
    if (entityClassColumns == null || entityClassColumns.size() == 0) {
        return null;
    }
    List<ResultMapping> resultMappings = new ArrayList<ResultMapping>();
    for (EntityColumn entityColumn : entityClassColumns) {
        ResultMapping.Builder builder = new ResultMapping.Builder(configuration, entityColumn.getProperty(),
                entityColumn.getColumn(), entityColumn.getJavaType());
        if (entityColumn.getJdbcType() != null) {
            builder.jdbcType(entityColumn.getJdbcType());
        }
        if (entityColumn.getTypeHandler() != null) {
            try {
                builder.typeHandler(entityColumn.getTypeHandler().newInstance());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        List<ResultFlag> flags = new ArrayList<ResultFlag>();
        if (entityColumn.isId()) {
            flags.add(ResultFlag.ID);
        }
        builder.flags(flags);
        resultMappings.add(builder.build());
    }
    ResultMap.Builder builder = new ResultMap.Builder(configuration, "BaseMapperResultMap", this.entityClass,
            resultMappings, true);
    this.resultMap = builder.build();
    return this.resultMap;
}

From source file:com.sinotopia.mybatis.mapper.entity.EntityTable.java

License:Open Source License

/**
 * ??resultMap//from   w w  w.  ja  v  a 2s  .  co  m
 *
 * @param configuration
 * @return
 */
public ResultMap getResultMap(Configuration configuration) {
    if (this.resultMap != null) {
        return this.resultMap;
    }
    if (entityClassColumns == null || entityClassColumns.size() == 0) {
        return null;
    }
    List<ResultMapping> resultMappings = new ArrayList<ResultMapping>();
    for (EntityColumn entityColumn : entityClassColumns) {
        String column = entityColumn.getColumn();
        //?
        Matcher matcher = DELIMITER.matcher(column);
        if (matcher.find()) {
            column = matcher.group(1);
        }
        ResultMapping.Builder builder = new ResultMapping.Builder(configuration, entityColumn.getProperty(),
                column, entityColumn.getJavaType());
        if (entityColumn.getJdbcType() != null) {
            builder.jdbcType(entityColumn.getJdbcType());
        }
        if (entityColumn.getTypeHandler() != null) {
            try {
                builder.typeHandler(entityColumn.getTypeHandler().newInstance());
            } catch (Exception e) {
                throw new MapperException(e);
            }
        }
        List<ResultFlag> flags = new ArrayList<ResultFlag>();
        if (entityColumn.isId()) {
            flags.add(ResultFlag.ID);
        }
        builder.flags(flags);
        resultMappings.add(builder.build());
    }
    ResultMap.Builder builder = new ResultMap.Builder(configuration, "BaseMapperResultMap", this.entityClass,
            resultMappings, true);
    this.resultMap = builder.build();
    return this.resultMap;
}

From source file:org.mybatisorm.annotation.handler.TableHandler.java

License:Apache License

public List<ResultMapping> getResultMappingList(Configuration configuration) {
    List<ResultMapping> list = new ArrayList<ResultMapping>();
    for (Field field : getColumnFields()) {
        String columnName = ColumnAnnotation.getName(field);

        if (!"".equals(columnName)) {
            ResultMapping.Builder builder = new ResultMapping.Builder(configuration, field.getName(),
                    columnName, field.getType());
            // add typeHandler
            if (field.isAnnotationPresent(TypeHandler.class)) {
                TypeHandler typeHandlerAnnotation = field.getAnnotation(TypeHandler.class);
                // if (logger.isDebugEnabled()) logger.debug("add typeHandler [" + typeHandlerAnnotation.value().getName() + "] for " + columnName + ":" + typeHandlerAnnotation.jdbcType());
                builder.typeHandler(BeanUtils.instantiate(typeHandlerAnnotation.value()))
                        .jdbcType(typeHandlerAnnotation.jdbcType());

            }// ww w .j a v a2 s.  c  o  m
            list.add(builder.build());
        }
    }
    return list;
}

From source file:tk.mybatis.mapper.entity.EntityTable.java

License:Open Source License

/**
 * ??resultMap//from ww w .ja  v  a2 s . c  om
 *
 * @param configuration
 * @return
 */
public ResultMap getResultMap(Configuration configuration) {
    if (this.resultMap != null) {
        return this.resultMap;
    }
    if (entityClassColumns == null || entityClassColumns.size() == 0) {
        return null;
    }
    List<ResultMapping> resultMappings = new ArrayList<ResultMapping>();
    for (EntityColumn entityColumn : entityClassColumns) {
        ResultMapping.Builder builder = new ResultMapping.Builder(configuration, entityColumn.getProperty(),
                entityColumn.getColumn(), entityColumn.getJavaType());
        if (entityColumn.getJdbcType() != null) {
            builder.jdbcType(entityColumn.getJdbcType());
        }
        if (entityColumn.getTypeHandler() != null) {
            try {
                builder.typeHandler(entityColumn.getTypeHandler().newInstance());
            } catch (Exception e) {
                throw new MapperException(e);
            }
        }
        List<ResultFlag> flags = new ArrayList<ResultFlag>();
        if (entityColumn.isId()) {
            flags.add(ResultFlag.ID);
        }
        builder.flags(flags);
        resultMappings.add(builder.build());
    }
    ResultMap.Builder builder = new ResultMap.Builder(configuration, "BaseMapperResultMap", this.entityClass,
            resultMappings, true);
    this.resultMap = builder.build();
    return this.resultMap;
}