コード例 #1
0
  @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);
  }
コード例 #2
0
  @Override
  public Object selectOne(final String statementName, final Object parameterObject) {
    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() {
              @Override
              public Object doInSession(SqlSession sqlSession) {
                return sqlSession.insert(statementName, parameterObject);
              }
            };

        if (dsMap.size() == 1) {
          return executeWith(dsMap.get(dsMap.firstKey()), action);
        } else {
          List<Object> results = executeInConcurrency(action, dsMap);
          if (results != null && !results.isEmpty()) {
            return results.get(0);
          } else {
            return null;
          }
        }
      }
    }

    return super.selectOne(statementName, parameterObject);
  }