// Path: src/main/java/com/elong/pb/newdda/client/jdbc/ShardingResultSets.java
// public class ShardingResultSets {
// 
//     private final List<ResultSet> resultSets;
// 
//     private ResultSetOperateType resultSetOperateType;
// 
//     public ShardingResultSets(final List<ResultSet> resultSets) throws SQLException {
//         this.resultSets = filterResultSets(resultSets);
//         this.resultSetOperateType = generateType();
//     }
// 
//     private List<ResultSet> filterResultSets(final List<ResultSet> resultSets) throws SQLException {
//         List<ResultSet> result = new ArrayList<ResultSet>(resultSets.size());
//         for (ResultSet each : resultSets) {
//             if (each.next()) {
//                 result.add(new WrapperResultSet(each));
//             }
//         }
//         return result;
//     }
// 
//     private ResultSetOperateType generateType() {
//         if (this.resultSets.isEmpty()) {
//             return ResultSetOperateType.EMPTY;
//         } else if (1 == this.resultSets.size()) {
//             return ResultSetOperateType.SINGLE;
//         } else {
//             return ResultSetOperateType.MULTIPLE;
//         }
//     }
// 
//     enum ResultSetOperateType {
//         EMPTY, SINGLE, MULTIPLE
//     }
// 
//     //===============================================================get set method start =========================================================================
// 
//     public List<ResultSet> getResultSets() {
//         return resultSets;
//     }
// 
//     public ResultSetOperateType getResultSetOperateType() {
//         return resultSetOperateType;
//     }
// 
//     //===============================================================get set method end  =========================================================================
// 
// }
// 
// Path: src/main/java/com/elong/pb/newdda/client/router/result/merge/resultset/IteratorReducerResultSet.java
// public final class IteratorReducerResultSet extends AbstractDelegateResultSet {
//     
//     private int resultSetIndex = 1;
//     
//     public IteratorReducerResultSet(final ResultSetMergeContext resultSetMergeContext) throws SQLException {
//         super(resultSetMergeContext.getShardingResultSets().getResultSets());
//     }
//     
//     @Override
//     protected boolean firstNext() throws SQLException {
//         return processCurrent();
//     }
//     
//     @Override
//     protected boolean afterFirstNext() throws SQLException {
//         return processCurrent() || (!isOutOfIndex() && processNext());
//     }
//     
//     private boolean processCurrent() throws SQLException {
//         return getDelegate().next();
//     }
//     
//     private boolean isOutOfIndex() {
//         return resultSetIndex >= getResultSets().size();
//     }
//     
//     private boolean processNext() throws SQLException {
//         ResultSet resultSet = getResultSets().get(resultSetIndex++);
//         setDelegate(resultSet);
//         return resultSet.next();
//     }
// 
// }


import com.elong.pb.newdda.client.jdbc.ShardingResultSets;
import com.elong.pb.newdda.client.router.result.merge.resultset.IteratorReducerResultSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
package com.elong.pb.newdda.client.router.result.merge;



/**
 * Created by zhangyong on 2016/9/16.
 */
public class ResultSetFactory {

    private final static Logger logger = LoggerFactory.getLogger(ResultSetFactory.class);

    public static ResultSet getResultSet(final List<ResultSet> resultSets, final MergeContext mergeContext) throws SQLException {
        //无结果集
        if (resultSets == null) {
            return null;
        }
        //单个结果集
        else if (resultSets.size() == 1) {
            return resultSets.get(0);
        }
        //多个结果集
        else {
// Path: src/main/java/com/elong/pb/newdda/client/jdbc/ShardingResultSets.java
// public class ShardingResultSets {
// 
//     private final List<ResultSet> resultSets;
// 
//     private ResultSetOperateType resultSetOperateType;
// 
//     public ShardingResultSets(final List<ResultSet> resultSets) throws SQLException {
//         this.resultSets = filterResultSets(resultSets);
//         this.resultSetOperateType = generateType();
//     }
// 
//     private List<ResultSet> filterResultSets(final List<ResultSet> resultSets) throws SQLException {
//         List<ResultSet> result = new ArrayList<ResultSet>(resultSets.size());
//         for (ResultSet each : resultSets) {
//             if (each.next()) {
//                 result.add(new WrapperResultSet(each));
//             }
//         }
//         return result;
//     }
// 
//     private ResultSetOperateType generateType() {
//         if (this.resultSets.isEmpty()) {
//             return ResultSetOperateType.EMPTY;
//         } else if (1 == this.resultSets.size()) {
//             return ResultSetOperateType.SINGLE;
//         } else {
//             return ResultSetOperateType.MULTIPLE;
//         }
//     }
// 
//     enum ResultSetOperateType {
//         EMPTY, SINGLE, MULTIPLE
//     }
// 
//     //===============================================================get set method start =========================================================================
// 
//     public List<ResultSet> getResultSets() {
//         return resultSets;
//     }
// 
//     public ResultSetOperateType getResultSetOperateType() {
//         return resultSetOperateType;
//     }
// 
//     //===============================================================get set method end  =========================================================================
// 
// }
// 
// Path: src/main/java/com/elong/pb/newdda/client/router/result/merge/resultset/IteratorReducerResultSet.java
// public final class IteratorReducerResultSet extends AbstractDelegateResultSet {
//     
//     private int resultSetIndex = 1;
//     
//     public IteratorReducerResultSet(final ResultSetMergeContext resultSetMergeContext) throws SQLException {
//         super(resultSetMergeContext.getShardingResultSets().getResultSets());
//     }
//     
//     @Override
//     protected boolean firstNext() throws SQLException {
//         return processCurrent();
//     }
//     
//     @Override
//     protected boolean afterFirstNext() throws SQLException {
//         return processCurrent() || (!isOutOfIndex() && processNext());
//     }
//     
//     private boolean processCurrent() throws SQLException {
//         return getDelegate().next();
//     }
//     
//     private boolean isOutOfIndex() {
//         return resultSetIndex >= getResultSets().size();
//     }
//     
//     private boolean processNext() throws SQLException {
//         ResultSet resultSet = getResultSets().get(resultSetIndex++);
//         setDelegate(resultSet);
//         return resultSet.next();
//     }
// 
// }


// Path: src/main/java/com/elong/pb/newdda/client/router/result/merge/ResultSetFactory.java
import com.elong.pb.newdda.client.jdbc.ShardingResultSets;
import com.elong.pb.newdda.client.router.result.merge.resultset.IteratorReducerResultSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

package com.elong.pb.newdda.client.router.result.merge;



/**
 * Created by zhangyong on 2016/9/16.
 */
public class ResultSetFactory {

    private final static Logger logger = LoggerFactory.getLogger(ResultSetFactory.class);

    public static ResultSet getResultSet(final List<ResultSet> resultSets, final MergeContext mergeContext) throws SQLException {
        //无结果集
        if (resultSets == null) {
            return null;
        }
        //单个结果集
        else if (resultSets.size() == 1) {
            return resultSets.get(0);
        }
        //多个结果集
        else {
            ShardingResultSets shardingResultSets = new ShardingResultSets(resultSets);