// Path: src/main/java/com/elong/pb/newdda/client/router/SqlExecutionUnit.java
// public class SqlExecutionUnit {
// 
//     private final String dataSource;
// 
//     private String sql;
// 
//     private SqlAppender sqlAppender;
// 
//     public SqlExecutionUnit(final String dataSource, final SqlAppender sqlAppender) {
//         this.dataSource = dataSource;
//         this.sqlAppender = sqlAppender.cloneBuilder();
//         this.sql = sqlAppender.toSQL();
//     }
// 
//     @Override
//     public int hashCode() {
//         final int prime = 31;
//         int result = 1;
//         result = prime * result + (this.dataSource == null ? 0 : this.dataSource.hashCode());
//         result = prime * result + (this.sql == null ? 0 : this.sql.hashCode());
//         return result;
//     }
// 
//     @Override
//     public String toString() {
//         StringBuilder builder = new StringBuilder();
//         builder.append("route sql to db: [").append(dataSource).append("] sql:[").append(sql).append("]");
//         return builder.toString();
//     }
// 
//     //====================================================set get method start ====================================================
// 
//     public void setSql(String sql) {
//         this.sql = sql;
//     }
// 
//     public String getDataSource() {
//         return dataSource;
//     }
// 
//     public String getSql() {
//         return sql;
//     }
// 
//     //====================================================set get method end  =====================================================
// 
// }
// 
// Path: src/main/java/com/elong/pb/newdda/client/router/rule/Algorithm.java
// public interface Algorithm {
// 
//      AlgorithmResult doAlgorithm(ShardingValue shardingValue);
// 
// }
// 
// Path: src/main/java/com/elong/pb/newdda/client/router/rule/AlgorithmResult.java
// public class AlgorithmResult {
// 
//     //命中数据源
//     private String targetDataSource;
// 
//     //逻辑表名
//     private String logicTable;
// 
//     //目标表名
//     private String targetTableName;
// 
//     public String getTargetDataSource() {
//         return targetDataSource;
//     }
// 
//     public void setTargetDataSource(String targetDataSource) {
//         this.targetDataSource = targetDataSource;
//     }
// 
//     public String getLogicTable() {
//         return logicTable;
//     }
// 
//     public void setLogicTable(String logicTable) {
//         this.logicTable = logicTable;
//     }
// 
//     public String getTargetTableName() {
//         return targetTableName;
//     }
// 
//     public void setTargetTableName(String targetTableName) {
//         this.targetTableName = targetTableName;
//     }
// 
// }
// 
// Path: src/main/java/com/elong/pb/newdda/client/router/rule/ShardingKey.java
// public class ShardingKey {
// 
//     //表名
//     private String tableName;
// 
//     //分区字段
//     private String shardingColumn;
// 
//     public String getTableName() {
//         return tableName;
//     }
// 
//     public void setTableName(String tableName) {
//         this.tableName = tableName;
//     }
// 
//     public String getShardingColumn() {
//         return shardingColumn;
//     }
// 
//     public void setShardingColumn(String shardingColumn) {
//         this.shardingColumn = shardingColumn;
//     }
// 
// }
// 
// Path: src/main/java/com/elong/pb/newdda/client/router/rule/ShardingRule.java
// public class ShardingRule {
// 
//     //默认mysql数据类型也可以配置
//     private DatabaseType databaseType = DatabaseType.MySQL;
// 
//     private DataSourceContainer dataSourceContainer;
// 
//     private Algorithm algorithm;
// 
//     private List<ShardingKey> shardingKey;
// 
//     //======================================================================get  set method start ======================================================================
//     public DatabaseType getDatabaseType() {
//         return databaseType;
//     }
// 
//     public void setDatabaseType(DatabaseType databaseType) {
//         this.databaseType = databaseType;
//     }
// 
//     public List<ShardingKey> getShardingKey() {
//         return shardingKey;
//     }
// 
//     public void setShardingKey(List<ShardingKey> shardingKey) {
//         this.shardingKey = shardingKey;
//     }
// 
//     public Algorithm getAlgorithm() {
//         return algorithm;
//     }
// 
//     public void setAlgorithm(Algorithm algorithm) {
//         this.algorithm = algorithm;
//     }
// 
//     public DataSourceContainer getDataSourceContainer() {
//         return dataSourceContainer;
//     }
// 
//     public void setDataSourceContainer(DataSourceContainer dataSourceContainer) {
//         this.dataSourceContainer = dataSourceContainer;
//     }
// 
// //======================================================================get  set method end =======================================================================
// 
// }


import com.elong.pb.newdda.client.router.SqlExecutionUnit;
import com.elong.pb.newdda.client.router.result.router.*;
import com.elong.pb.newdda.client.router.rule.Algorithm;
import com.elong.pb.newdda.client.router.rule.AlgorithmResult;
import com.elong.pb.newdda.client.router.rule.ShardingKey;
import com.elong.pb.newdda.client.router.rule.ShardingRule;
import java.util.*;
package com.elong.pb.newdda.client.router.action;



/**
 * 分区动作
 * Created by zhangyong on 2016/9/17.
 */
public class DefaultShardingAction implements ShardingAction {

    private ShardingRule shardingRule;

    private ConditionContext conditionContext;

    private Set<String> logicTables;

    private SqlAppender sqlAppender;

    private SqlStatementType sqlStatementType;

    public DefaultShardingAction(final ShardingRule shardingRule, final ConditionContext conditionContext, final Set<String> logicTables, final SqlAppender sqlAppender, final SqlStatementType sqlStatementType) {
        this.shardingRule = shardingRule;
        this.conditionContext = conditionContext;
        this.logicTables = logicTables;
        this.sqlAppender = sqlAppender;
        this.sqlStatementType = sqlStatementType;
    }

    @Override
// Path: src/main/java/com/elong/pb/newdda/client/router/SqlExecutionUnit.java
// public class SqlExecutionUnit {
// 
//     private final String dataSource;
// 
//     private String sql;
// 
//     private SqlAppender sqlAppender;
// 
//     public SqlExecutionUnit(final String dataSource, final SqlAppender sqlAppender) {
//         this.dataSource = dataSource;
//         this.sqlAppender = sqlAppender.cloneBuilder();
//         this.sql = sqlAppender.toSQL();
//     }
// 
//     @Override
//     public int hashCode() {
//         final int prime = 31;
//         int result = 1;
//         result = prime * result + (this.dataSource == null ? 0 : this.dataSource.hashCode());
//         result = prime * result + (this.sql == null ? 0 : this.sql.hashCode());
//         return result;
//     }
// 
//     @Override
//     public String toString() {
//         StringBuilder builder = new StringBuilder();
//         builder.append("route sql to db: [").append(dataSource).append("] sql:[").append(sql).append("]");
//         return builder.toString();
//     }
// 
//     //====================================================set get method start ====================================================
// 
//     public void setSql(String sql) {
//         this.sql = sql;
//     }
// 
//     public String getDataSource() {
//         return dataSource;
//     }
// 
//     public String getSql() {
//         return sql;
//     }
// 
//     //====================================================set get method end  =====================================================
// 
// }
// 
// Path: src/main/java/com/elong/pb/newdda/client/router/rule/Algorithm.java
// public interface Algorithm {
// 
//      AlgorithmResult doAlgorithm(ShardingValue shardingValue);
// 
// }
// 
// Path: src/main/java/com/elong/pb/newdda/client/router/rule/AlgorithmResult.java
// public class AlgorithmResult {
// 
//     //命中数据源
//     private String targetDataSource;
// 
//     //逻辑表名
//     private String logicTable;
// 
//     //目标表名
//     private String targetTableName;
// 
//     public String getTargetDataSource() {
//         return targetDataSource;
//     }
// 
//     public void setTargetDataSource(String targetDataSource) {
//         this.targetDataSource = targetDataSource;
//     }
// 
//     public String getLogicTable() {
//         return logicTable;
//     }
// 
//     public void setLogicTable(String logicTable) {
//         this.logicTable = logicTable;
//     }
// 
//     public String getTargetTableName() {
//         return targetTableName;
//     }
// 
//     public void setTargetTableName(String targetTableName) {
//         this.targetTableName = targetTableName;
//     }
// 
// }
// 
// Path: src/main/java/com/elong/pb/newdda/client/router/rule/ShardingKey.java
// public class ShardingKey {
// 
//     //表名
//     private String tableName;
// 
//     //分区字段
//     private String shardingColumn;
// 
//     public String getTableName() {
//         return tableName;
//     }
// 
//     public void setTableName(String tableName) {
//         this.tableName = tableName;
//     }
// 
//     public String getShardingColumn() {
//         return shardingColumn;
//     }
// 
//     public void setShardingColumn(String shardingColumn) {
//         this.shardingColumn = shardingColumn;
//     }
// 
// }
// 
// Path: src/main/java/com/elong/pb/newdda/client/router/rule/ShardingRule.java
// public class ShardingRule {
// 
//     //默认mysql数据类型也可以配置
//     private DatabaseType databaseType = DatabaseType.MySQL;
// 
//     private DataSourceContainer dataSourceContainer;
// 
//     private Algorithm algorithm;
// 
//     private List<ShardingKey> shardingKey;
// 
//     //======================================================================get  set method start ======================================================================
//     public DatabaseType getDatabaseType() {
//         return databaseType;
//     }
// 
//     public void setDatabaseType(DatabaseType databaseType) {
//         this.databaseType = databaseType;
//     }
// 
//     public List<ShardingKey> getShardingKey() {
//         return shardingKey;
//     }
// 
//     public void setShardingKey(List<ShardingKey> shardingKey) {
//         this.shardingKey = shardingKey;
//     }
// 
//     public Algorithm getAlgorithm() {
//         return algorithm;
//     }
// 
//     public void setAlgorithm(Algorithm algorithm) {
//         this.algorithm = algorithm;
//     }
// 
//     public DataSourceContainer getDataSourceContainer() {
//         return dataSourceContainer;
//     }
// 
//     public void setDataSourceContainer(DataSourceContainer dataSourceContainer) {
//         this.dataSourceContainer = dataSourceContainer;
//     }
// 
// //======================================================================get  set method end =======================================================================
// 
// }


// Path: src/main/java/com/elong/pb/newdda/client/router/action/DefaultShardingAction.java
import com.elong.pb.newdda.client.router.SqlExecutionUnit;
import com.elong.pb.newdda.client.router.result.router.*;
import com.elong.pb.newdda.client.router.rule.Algorithm;
import com.elong.pb.newdda.client.router.rule.AlgorithmResult;
import com.elong.pb.newdda.client.router.rule.ShardingKey;
import com.elong.pb.newdda.client.router.rule.ShardingRule;
import java.util.*;

package com.elong.pb.newdda.client.router.action;



/**
 * 分区动作
 * Created by zhangyong on 2016/9/17.
 */
public class DefaultShardingAction implements ShardingAction {

    private ShardingRule shardingRule;

    private ConditionContext conditionContext;

    private Set<String> logicTables;

    private SqlAppender sqlAppender;

    private SqlStatementType sqlStatementType;

    public DefaultShardingAction(final ShardingRule shardingRule, final ConditionContext conditionContext, final Set<String> logicTables, final SqlAppender sqlAppender, final SqlStatementType sqlStatementType) {
        this.shardingRule = shardingRule;
        this.conditionContext = conditionContext;
        this.logicTables = logicTables;
        this.sqlAppender = sqlAppender;
        this.sqlStatementType = sqlStatementType;
    }

    @Override
    public Collection<SqlExecutionUnit> doSharding() {