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

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

Introduction

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

Prototype

public String getId() 

Source Link

Usage

From source file:com.baomidou.mybatisplus.MybatisXMLMapperBuilder.java

License:Apache License

private String processNestedResultMappings(XNode context, List<ResultMapping> resultMappings) throws Exception {
    if ("association".equals(context.getName()) || "collection".equals(context.getName())
            || "case".equals(context.getName())) {
        if (context.getStringAttribute("select") == null) {
            ResultMap resultMap = resultMapElement(context, resultMappings);
            return resultMap.getId();
        }/*from   w w  w .  jav  a 2  s  . c o m*/
    }
    return null;
}

From source file:com.create.mybatis.repository.support.MyBatisMapperProvider.java

License:Apache License

public <T> T getMapper(final Class<T> domainClass) {
    T mapper = null;/*from  w ww . j a  v  a  2s .co  m*/
    for (final ResultMap resultMap : sqlSessionTemplate.getConfiguration().getResultMaps()) {
        if (resultMap.getType().equals(domainClass)) {
            mapper = getMapperForResultMapId(resultMap.getId());
            if (mapper != null)
                break;
        }
    }
    return mapper;
}

From source file:com.dmm.framework.basedb.apache.ibatis.session.Configuration.java

License:Apache License

public void addResultMap(ResultMap rm) {
    resultMaps.put(rm.getId(), rm);
    checkLocallyForDiscriminatedNestedResultMaps(rm);
    checkGloballyForDiscriminatedNestedResultMaps(rm);
}

From source file:com.dmm.framework.basedb.apache.ibatis.session.Configuration.java

License:Apache License

protected void checkGloballyForDiscriminatedNestedResultMaps(ResultMap rm) {
    if (rm.hasNestedResultMaps()) {
        for (Map.Entry<String, ResultMap> entry : resultMaps.entrySet()) {
            Object value = entry.getValue();
            if (value instanceof ResultMap) {
                ResultMap entryResultMap = (ResultMap) value;
                if (!entryResultMap.hasNestedResultMaps() && entryResultMap.getDiscriminator() != null) {
                    Collection<String> discriminatedResultMapNames = entryResultMap.getDiscriminator()
                            .getDiscriminatorMap().values();
                    if (discriminatedResultMapNames.contains(rm.getId())) {
                        entryResultMap.forceNestedResultMaps();
                    }/*from  w  w  w.  j  a  v  a2s  .  c o  m*/
                }
            }
        }
    }
}

From source file:com.github.abel533.mapper.MapperHelper.java

License:Open Source License

/**
 * ?Key?/*from ww w . jav  a 2s .c  om*/
 *
 * @param result
 * @param ms
 */
public void cameHumpMap(Object result, MappedStatement ms) {
    ResultMap resultMap = ms.getResultMaps().get(0);
    Class<?> type = resultMap.getType();
    //?typeMap,???resultMap,???
    if (result instanceof List && ((List) result).size() > 0 && Map.class.isAssignableFrom(type)
            && !resultMap.hasNestedQueries() && !resultMap.hasNestedResultMaps()) {
        List resultList = (List) result;
        //1.resultType
        if (resultMap.getId().endsWith("-Inline")) {
            for (Object re : resultList) {
                processMap((Map) re);
            }
        } else {//2.resultMap
            for (Object re : resultList) {
                processMap((Map) re, resultMap.getResultMappings());
            }
        }
    }
}

From source file:com.sxj.mybatis.orm.builder.GenericStatementBuilder.java

License:Open Source License

private void buildMultiGet(String statementId, String collection) {
    Integer fetchSize = null;//from w w w  .j a  va  2s  . co m
    Integer timeout = null;
    Class<?> resultType = entityClass;
    //~~~~~~~~~~~~~~~~~~~~~~~
    boolean flushCache = true;
    boolean useCache = false;
    boolean resultOrdered = false;
    KeyGenerator keyGenerator = new NoKeyGenerator();

    SqlSource sqlSource = new DynamicSqlSource(configuration, getMultiGetSql(collection));

    String resultMap = null;
    Iterator<String> resultMapNames = configuration.getResultMapNames().iterator();
    while (resultMapNames.hasNext()) {
        String name = resultMapNames.next();
        ResultMap temp = configuration.getResultMap(name);
        if (temp.getType().equals(entityClass)) {
            resultMap = temp.getId();
            break;
        }
    }
    assistant.addMappedStatement(statementId, sqlSource, StatementType.PREPARED, SqlCommandType.SELECT,
            fetchSize, timeout, null, idField.getType(), resultMap, resultType, null, flushCache, useCache,
            resultOrdered, keyGenerator, null, null, databaseId, lang);
}

From source file:com.sxj.mybatis.orm.builder.GenericStatementBuilder.java

License:Open Source License

private void buildSelect(String statementId) {
    Integer fetchSize = null;/* w w  w  . ja v  a2  s  .c  o  m*/
    Integer timeout = entity.timeout() == -1 ? null : entity.timeout();
    Class<?> resultType = entityClass;

    //~~~~~~~~~~~~~~~~~
    boolean flushCache = entity.flushCache();
    boolean useCache = entity.useCache();
    boolean resultOrdered = false;
    KeyGenerator keyGenerator = new NoKeyGenerator();

    List<SqlNode> contents = new ArrayList<SqlNode>();
    contents.add(this.getGetSql());

    SqlSource sqlSource = new DynamicSqlSource(configuration, new MixedSqlNode(contents));
    String resultMap = null;
    Iterator<String> resultMapNames = configuration.getResultMapNames().iterator();
    while (resultMapNames.hasNext()) {
        String name = resultMapNames.next();
        ResultMap temp = configuration.getResultMap(name);
        if (temp.getType().equals(entityClass)) {
            resultMap = temp.getId();
            break;
        }
    }
    assistant.addMappedStatement(statementId, sqlSource, StatementType.PREPARED, SqlCommandType.SELECT,
            fetchSize, timeout, null, idField.getType(), resultMap, resultType, null, flushCache, useCache,
            resultOrdered, keyGenerator, null, null, databaseId, lang);
}

From source file:com.yunmel.syncretic.core.CameHumpInterceptor.java

License:Apache License

public Object intercept(Invocation invocation) throws Throwable {
    // ??//  w w w .  j  a v a 2 s.co  m
    Object result = invocation.proceed();
    MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
    ResultMap resultMap = mappedStatement.getResultMaps().get(0);
    Class<?> type = resultMap.getType();
    // ?typeMap,???resultMap,???
    if (((List) result).size() > 0 && Map.class.isAssignableFrom(type) && !resultMap.hasNestedQueries()
            && !resultMap.hasNestedResultMaps()) {
        List resultList = (List) result;
        // 1.resultType
        if (resultMap.getId().endsWith(RESULT_TYPE)) {
            for (Object re : resultList) {
                if (re == null)
                    continue;
                processMap((Map) re);
            }
        } else {// 2.resultMap
            for (Object re : resultList) {
                processMap((Map) re, resultMap.getResultMappings());
            }
        }
    }
    return result;
}

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  ww  w  . j av  a  2  s . com
        //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) {
        ////from   ww w  .  j  a  v  a2s .c om
        //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;
}