Example usage for org.apache.ibatis.session SqlSession selectMap

List of usage examples for org.apache.ibatis.session SqlSession selectMap

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSession selectMap.

Prototype

<K, V> Map<K, V> selectMap(String statement, String mapKey);

Source Link

Document

The selectMap is a special case in that it is designed to convert a list of results into a Map based on one of the properties in the resulting objects.

Usage

From source file:com.baidu.oped.apm.plugin.mybatis.SqlSessionTestBase.java

License:Apache License

protected final void testAndVerifySelectMap() throws Exception {
    // Given//www. ja v  a2  s  . c  o m
    final String selectMapId = "selectListId";
    SqlSession sqlSession = getSqlSession();
    // When
    sqlSession.selectMap(selectMapId, "key");
    sqlSession.selectMap(selectMapId, new Object(), "key");
    sqlSession.selectMap(selectMapId, new Object(), "key", RowBounds.DEFAULT);
    // Then
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    Method selectMap1 = sqlSession.getClass().getDeclaredMethod("selectMap", String.class, String.class);
    Method selectMap2 = sqlSession.getClass().getDeclaredMethod("selectMap", String.class, Object.class,
            String.class);
    Method selectMap3 = sqlSession.getClass().getDeclaredMethod("selectMap", String.class, Object.class,
            String.class, RowBounds.class);
    verifier.verifyTrace(event("MYBATIS", selectMap1, Expectations.cachedArgs(selectMapId)));
    verifier.verifyTrace(event("MYBATIS", selectMap2, Expectations.cachedArgs(selectMapId)));
    verifier.verifyTrace(event("MYBATIS", selectMap3, Expectations.cachedArgs(selectMapId)));
}

From source file:net.hasor.db.orm.mybatis3.SqlExecutorTemplate.java

License:Apache License

public <K, V> Map<K, V> selectMap(final String statement, final String mapKey) throws SQLException {
    return this.execute(new SqlSessionCallback<Map<K, V>>() {
        public Map<K, V> doSqlSession(SqlSession sqlSession) {
            return sqlSession.selectMap(statement, mapKey);
        }//w w w . j  a  v a 2 s  .com
    });
}