Example usage for org.apache.ibatis.mapping ResultMap getConstructorResultMappings

List of usage examples for org.apache.ibatis.mapping ResultMap getConstructorResultMappings

Introduction

In this page you can find the example usage for org.apache.ibatis.mapping ResultMap getConstructorResultMappings.

Prototype

public List<ResultMapping> getConstructorResultMappings() 

Source Link

Usage

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

License:Apache License

@Override
public String columnByProperty(String property, String resultMap) {
    ResultMap map = null;
    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]));
            }/* ww w.ja v  a 2  s.co m*/
            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));
}