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

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

Introduction

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

Prototype

public List<ResultMapping> getPropertyResultMappings() 

Source Link

Usage

From source file:com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.java

License:Apache License

public Object queryForObject(String id, Object parameterObject, Object userObject) throws SQLException {
    Object systemObject = queryForObject(id, parameterObject);
    if (systemObject != null && userObject != null) {
        MappedStatement ms = configuration.getMappedStatement(id);
        for (ResultMap rm : ms.getResultMaps()) {
            for (ResultMapping mapping : rm.getPropertyResultMappings()) {
                MetaObject metaUserObject = SystemMetaObject.forObject(userObject);
                MetaObject metaSystemObject = SystemMetaObject.forObject(systemObject);
                String propName = mapping.getProperty();
                if (propName != null) {
                    metaUserObject.setValue(propName, metaSystemObject.getValue(propName));
                }/*from  w w  w.java2 s .  c o m*/
            }
        }
    }
    return userObject;
}

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]));
            }/*from   w w w  . ja va  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));
}