// Path: src/main/java/com/elong/pb/newdda/client/constants/ThreadPoolConstants.java
// public class ThreadPoolConstants {
// 
//     public final static int CORE_SIZE = Runtime.getRuntime().availableProcessors();
// 
// 
// 
// }
// 
// Path: src/main/java/com/elong/pb/newdda/client/executor/wrapper/StatementExecutorWrapper.java
// public class StatementExecutorWrapper {
// 
//     private final Statement statement;
// 
//     private final SqlExecutionUnit sqlExecutionUnit;
// 
//     public StatementExecutorWrapper(final Statement statement, final SqlExecutionUnit sqlExecutionUnit) {
//         this.statement = statement;
//         this.sqlExecutionUnit = sqlExecutionUnit;
//     }
// 
//     //==================================================get method start ==================================================
// 
//     public Statement getStatement() {
//         return statement;
//     }
// 
//     public SqlExecutionUnit getSqlExecutionUnit() {
//         return sqlExecutionUnit;
//     }
// 
//     //==================================================get method end ==================================================
// 
// }
// 
// 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  =====================================================
// 
// }


import com.elong.pb.newdda.client.constants.ThreadPoolConstants;
import com.elong.pb.newdda.client.executor.wrapper.StatementExecutorWrapper;
import com.elong.pb.newdda.client.router.SqlExecutionUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
package com.elong.pb.newdda.client.executor;



public class StatementExecutor {

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

    //防止多线程环境下,数据没有flush到主内存
    private final Object flushLock = new Object();

    //是否抛出异常
    private final static boolean THROW_EXCEPTION = true;

    //定义线程池
    private final List<StatementExecutorWrapper> statementExecutorWrappers = new ArrayList<StatementExecutorWrapper>();

    private final static int MAX_SIZE = ThreadPoolConstants.CORE_SIZE * 2 + 1;

    private final static int KEEP_ALIVE_TIME = 600;

    private final static int EXECUTE_MAX_TIME = 10;

    private static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
// Path: src/main/java/com/elong/pb/newdda/client/constants/ThreadPoolConstants.java
// public class ThreadPoolConstants {
// 
//     public final static int CORE_SIZE = Runtime.getRuntime().availableProcessors();
// 
// 
// 
// }
// 
// Path: src/main/java/com/elong/pb/newdda/client/executor/wrapper/StatementExecutorWrapper.java
// public class StatementExecutorWrapper {
// 
//     private final Statement statement;
// 
//     private final SqlExecutionUnit sqlExecutionUnit;
// 
//     public StatementExecutorWrapper(final Statement statement, final SqlExecutionUnit sqlExecutionUnit) {
//         this.statement = statement;
//         this.sqlExecutionUnit = sqlExecutionUnit;
//     }
// 
//     //==================================================get method start ==================================================
// 
//     public Statement getStatement() {
//         return statement;
//     }
// 
//     public SqlExecutionUnit getSqlExecutionUnit() {
//         return sqlExecutionUnit;
//     }
// 
//     //==================================================get method end ==================================================
// 
// }
// 
// 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/executor/StatementExecutor.java
import com.elong.pb.newdda.client.constants.ThreadPoolConstants;
import com.elong.pb.newdda.client.executor.wrapper.StatementExecutorWrapper;
import com.elong.pb.newdda.client.router.SqlExecutionUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

package com.elong.pb.newdda.client.executor;



public class StatementExecutor {

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

    //防止多线程环境下,数据没有flush到主内存
    private final Object flushLock = new Object();

    //是否抛出异常
    private final static boolean THROW_EXCEPTION = true;

    //定义线程池
    private final List<StatementExecutorWrapper> statementExecutorWrappers = new ArrayList<StatementExecutorWrapper>();

    private final static int MAX_SIZE = ThreadPoolConstants.CORE_SIZE * 2 + 1;

    private final static int KEEP_ALIVE_TIME = 600;

    private final static int EXECUTE_MAX_TIME = 10;

    private static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
            ThreadPoolConstants.CORE_SIZE,