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

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

Introduction

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

Prototype

List flags

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

Click Source Link

Usage

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

License:Open Source License

/**
 * ??resultMap//from   w  ww.java2  s. 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) {
        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.ibatis.sqlmap.engine.builder.XmlSqlMapParser.java

License:Apache License

@NodeEvent("/sqlMap/resultMap/result")
public void sqlMapresultMapresult(XNode context) throws Exception {
    String nullValue = context.getStringAttribute("nullValue");
    if (nullValue != null) {
        throw new UnsupportedOperationException("Null value subsitution is not supported by iBATIS 3.");
    }/*w  w  w.ja v a2s .  co  m*/
    String columnIndexProp = context.getStringAttribute("columnIndex");
    if (columnIndexProp != null) {
        throw new UnsupportedOperationException(
                "Numerical column indices are not supported.  Use the column name instead.");
    }

    String propertyName = context.getStringAttribute("property");
    String jdbcType = context.getStringAttribute("jdbcType");
    String javaType = context.getStringAttribute("javaType");
    String columnName = context.getStringAttribute("column");

    String statementName = context.getStringAttribute("select");
    String resultMapName = context.getStringAttribute("resultMap");
    String callback = context.getStringAttribute("typeHandler");

    Class javaClass = null;
    try {
        if (javaType != null && javaType.length() > 0) {
            javaClass = config.getTypeAliasRegistry().resolveAlias(javaType);
        }
    } catch (Exception e) {
        throw new RuntimeException("Error setting java type on result discriminator mapping.  Cause: " + e);
    }
    if (javaClass == null && !Map.class.isAssignableFrom(resultMapBuilder.type())
            && !config.getTypeHandlerRegistry().hasTypeHandler(resultMapBuilder.type())) {
        javaClass = MetaClass.forClass(resultMapBuilder.type()).getSetterType(propertyName);
    }
    if (javaClass == null && statementName != null) {
        javaClass = List.class;
    }

    JdbcType jdbcTypeEnum = null;
    if (jdbcType != null) {
        jdbcTypeEnum = JdbcType.valueOf(jdbcType);
    }

    TypeHandler typeHandler = null;
    if (javaClass != null) {
        typeHandler = config.getTypeHandlerRegistry().getTypeHandler(javaClass, jdbcTypeEnum);
    }
    try {
        if (callback != null && callback.length() > 0) {
            Object o = config.getTypeAliasRegistry().resolveAlias(callback).newInstance();
            if (o instanceof TypeHandlerCallback) {
                typeHandler = new TypeHandlerCallbackAdapter((TypeHandlerCallback) o);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException("Error occurred during custom type handler configuration.  Cause: " + e, e);
    }
    if (typeHandler == null && config.getTypeHandlerRegistry().hasTypeHandler(resultMapBuilder.type())) {
        typeHandler = config.getTypeHandlerRegistry().getTypeHandler(resultMapBuilder.type());
    }

    if (typeHandler == null) {
        Class resultClass = resultMapBuilder.type();
        if (resultClass != null && !Map.class.isAssignableFrom(resultClass)) {
            MetaClass metaResultClass = MetaClass.forClass(resultClass);
            Class resultType = null;
            if (metaResultClass.hasGetter(propertyName)) {
                resultType = metaResultClass.getGetterType(propertyName);
            } else if (metaResultClass.hasSetter(propertyName)) {
                resultType = metaResultClass.getSetterType(propertyName);
            }
            if (resultType != null) {
                typeHandler = config.getTypeHandlerRegistry().getTypeHandler(resultType);
            }
        } else {
            typeHandler = config.getTypeHandlerRegistry().getUnknownTypeHandler();
        }
    }

    List<ResultMapping> composites = parseCompositeColumnName(columnName);
    if (composites.size() > 0) {
        ResultMapping first = composites.get(0);
        columnName = first.getColumn();
    }

    ResultMapping.Builder resultMappingBuilder = new ResultMapping.Builder(config, propertyName, columnName,
            typeHandler);
    resultMappingBuilder.javaType(javaClass);
    resultMappingBuilder.nestedQueryId(statementName);
    resultMappingBuilder.nestedResultMapId(resultMapName);
    resultMappingBuilder.jdbcType(jdbcTypeEnum);
    resultMappingBuilder.composites(composites);
    if (groupByProperties != null && groupByProperties.contains(propertyName)) {
        List<ResultFlag> flags = new ArrayList<ResultFlag>();
        resultMappingBuilder.flags(flags);
    }
    resultMappingList.add(resultMappingBuilder.build());
}

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

License:Open Source License

/**
 * ??resultMap// w w w .j  a  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) {
        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:tk.mybatis.mapper.entity.EntityTable.java

License:Open Source License

/**
 * ??resultMap/*  ww w .ja  v a 2s.  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 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;
}