Example usage for org.apache.ibatis.mapping ResultMapping getColumn

List of usage examples for org.apache.ibatis.mapping ResultMapping getColumn

Introduction

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

Prototype

public String getColumn() 

Source Link

Usage

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.");
    }/*from w w  w.  ja v  a 2s.  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.playersun.jbf.common.persistence.search.SearchableSqlBuilder.java

License:Apache License

/**
 * ??ResultMappingcolumn/* ww w  . j av  a2  s  .co  m*/
 * ?column??parentIdcolumnparent_id
 * @param prop
 * @param resultMappings
 * @return
 */
private String findInResultMapping(String prop, List<ResultMapping> resultMappings) {
    for (ResultMapping rsm : resultMappings) {
        if (prop.equals(rsm.getProperty())) {
            return rsm.getColumn();
        }
    }
    return prop;
}

From source file:das.orm.ORMBackendConnector.java

License:Apache License

public List<BeanPropertyMapping> getBeanPropertiesMapping(Class<?> beanClass) {
    log.trace(">>> getBeanPropertiesMapping()");
    List<BeanPropertyMapping> DAOprops = new ArrayList<BeanPropertyMapping>();
    Configuration conf = getConfiguration();
    if (conf != null) {
        ///*from  w ww  . jav  a 2 s  .  c o m*/
        //checkDAOMapperClass(mapperClass, dao);
        Collection<ResultMap> rmc = conf.getResultMaps();
        //log.debug("ResultMaps size="+rmc.size());
        Iterator<ResultMap> rmci = rmc.iterator();
        while (rmci.hasNext()) {
            ResultMap rm = rmci.next();
            // ID=com.example.server.dao.UserMapper.UserMap, Type=com.example.server.dao.UserDTO
            log.debug("ResultMap ID=" + rm.getId() + ", Type=" + rm.getType().getName());
            // ?, ??   ResultMap ??   beanClass
            if (isCompatibleMap(rm, beanClass)) {
                List<ResultMapping> r = rm.getResultMappings();
                Iterator<ResultMapping> i2 = r.iterator();
                while (i2.hasNext()) {
                    ResultMapping r2 = i2.next();
                    // ? ?? (?)  . 
                    //  ?  ?? ? ? ??   
                    DAOprops.add(new BeanPropertyMapping(r2.getProperty(), r2.getColumn(), r2.getJavaType(),
                            r2.getFlags(), r2.getNotNullColumns()));
                    StringBuilder s = new StringBuilder();
                    s.append("Column=").append(r2.getColumn());
                    s.append(", Property=").append(r2.getProperty());
                    s.append(", JavaType=").append(r2.getJavaType());
                    s.append(", Flags=[");
                    List<ResultFlag> flags = r2.getFlags();
                    for (ResultFlag rf : flags) {
                        s.append(rf.name()).append(", ");
                    }
                    s.append("]");
                    s.append(", NotNullColumns=[");
                    Set<String> nncs = r2.getNotNullColumns();
                    for (String nnc : nncs) {
                        s.append(nnc).append(", ");
                    }
                    s.append("]");
                    log.debug(s.toString());
                }
                break; //    ?? , ? 
            }
        }
    }
    return DAOprops;
}

From source file:fxapp01.orm.ORMBackendConnector.java

License:Apache License

public List<BeanPropertyMapping> getBeanPropertiesMapping(Class beanClass) {
    log.trace(">>> getDAOProperties()");
    List<BeanPropertyMapping> DAOprops = new ArrayList<>();
    Configuration conf = getConfiguration();
    if (conf != null) {
        ////ww w  . jav a2s.  c  o  m
        //checkDAOMapperClass(mapperClass, dao);
        Collection<ResultMap> rmc = conf.getResultMaps();
        //log.debug("ResultMaps size="+rmc.size());
        Iterator<ResultMap> rmci = rmc.iterator();
        while (rmci.hasNext()) {
            ResultMap rm = rmci.next();
            // ID=com.example.server.dao.UserMapper.UserMap, Type=com.example.server.dao.UserDTO
            log.debug("ResultMap ID=" + rm.getId() + ", Type=" + rm.getType().getName());
            // ?, ??   ResultMap ??   beanClass
            if (isCompatibleMap(rm, beanClass)) {
                List<ResultMapping> r = rm.getResultMappings();
                Iterator<ResultMapping> i2 = r.iterator();
                while (i2.hasNext()) {
                    ResultMapping r2 = i2.next();
                    // ? ?? (?)  . 
                    //  ?  ?? ? ? ??   
                    DAOprops.add(new BeanPropertyMapping(r2.getProperty(), r2.getColumn(), r2.getJavaType()));
                    log.debug("Column=" + r2.getColumn() + ", Property=" + r2.getProperty() + ", JavaType="
                            + r2.getJavaType());
                }
                break; //    ?? , ? 
            }
        }
    }
    return DAOprops;
}

From source file:org.molasdin.wbase.batis.support.BasicBatisEngine.java

License:Apache License

@Override
public String columnByProperty(String property, String resultMap) {
    ResultMap map = null;//  w w w  .j a  v a2 s. co m
    map = session.getConfiguration().getResultMap(resultMap);
    if (property.contains(".")) {
        String[] parts = property.split("\\.");
        property = parts[parts.length - 1];
        for (int i = 0; i < parts.length - 1; i++) {
            resultMap = resultMapNameFromProp(parts[i], map);
            if (resultMap == null) {
                throw new IllegalArgumentException(
                        String.format("Can not find result map for property: %s", parts[i]));
            }
            map = session.getConfiguration().getResultMap(resultMap);
        }
    } else {
        map = session.getConfiguration().getResultMap(resultMap);
    }

    if (property.startsWith("$")) {
        Integer number = Integer.parseInt(property.replace("$", ""));
        ResultMapping mapping = map.getConstructorResultMappings().get(number);
        return mapping.getColumn();
    }
    for (ResultMapping mapping : map.getPropertyResultMappings()) {
        if (mapping.getProperty().equals(property)) {
            return mapping.getColumn();
        }
    }
    throw new IllegalArgumentException(String.format("Can not find property: %s", property));
}