@Override public Map<?, ?> selectMap( final String statementName, final Object parameterObject, final String mapKey, final RowBounds rowBounds) { if (isSqlAuditorBehaviorEnabled()) { getSqlAuditor() .audit( statementName, getSqlByStatementName(statementName, parameterObject), parameterObject); } if (isPartitioningBehaviorEnabled()) { SortedMap<String, DataSource> dsMap = lookupDataSourcesByRouter(statementName, parameterObject); if (dsMap != null && !dsMap.isEmpty()) { SqlSessionCallback action = new SqlSessionCallback<Map<?, ?>>() { @Override public Map<?, ?> doInSession(SqlSession sqlSession) { return sqlSession.selectMap(statementName, parameterObject, mapKey, rowBounds); } }; if (dsMap.size() == 1) { return (Map<?, ?>) executeWith(dsMap.get(dsMap.firstKey()), action); } else { List<Object> results = executeInConcurrency(action, dsMap); Map<?, ?> retVal = Maps.newHashMap(); if (results != null && !results.isEmpty()) { for (int i = 0; i < results.size(); i++) { retVal.putAll((Map) results.get(i)); } } return retVal; } } } return super.selectMap(statementName, parameterObject, mapKey, rowBounds); }
protected List<Object> executeInConcurrency( SqlSessionCallback action, SortedMap<String, DataSource> dsMap) { List<ConcurrentShardRequest> requests = Lists.newArrayList(); for (Map.Entry<String, DataSource> entry : dsMap.entrySet()) { ConcurrentShardRequest request = new ConcurrentShardRequest(); request.setAction(action); request.setDataSource(entry.getValue()); request.setExecutor(dataSourceSpecificExecutors.get(entry.getKey())); requests.add(request); } return getConcurrentShardRequestProcessor().process(requests); }