// 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/util/IdGenerator.java
// public class IdGenerator {
// 
//     //总的分区数
//     private final static int SHARDING_NUM = ShardingConstants.SHARDING_LENGTH;
// 
//     //最大机器id 1023 也就是 1111111111
//     private final static int MAX_WORKER_ID = SHARDING_NUM - 1;
// 
//     //最大序号
//     private final static int MAX_SEQ = 4095;
// 
//     private final static long WORKERID_BITS = 10L;
// 
//     private final static long SEQUENCE_BITS = 12L;
// 
//     private final static long TIMESTAMP_LEFTSHIFT = SEQUENCE_BITS + WORKERID_BITS;
// 
//     private final static long WORKERID_SHIFT = SEQUENCE_BITS;
// 
//     public static long getUniqueId(int workerId , int seqId) {
//         if(workerId > MAX_WORKER_ID || workerId < 0) {
//             throw new IllegalArgumentException("workerId is not Illegal");
//         }
//         if(seqId > MAX_SEQ || seqId < 0) {
//             throw new IllegalArgumentException("seqId is not Illegal ");
//         }
//         //时间戳
//         long timestamp = System.currentTimeMillis();
//         //机器编号
//         return  (timestamp << TIMESTAMP_LEFTSHIFT) | (workerId << WORKERID_SHIFT) | seqId;
//     }
// 
// }


import com.elong.pb.newdda.client.router.rule.ShardingRule;
import com.elong.pb.newdda.client.util.IdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import java.sql.*;
    }

    @Test
    public void testUpdatePrepareStatement() throws SQLException {
        Connection shardingConnection = shardingDataSource.getConnection();
        PreparedStatement statement = null;
        String sql = "update test set user_name = ? ,update_time = now() where user_id = ?";
        try {
            statement = null;
            statement = shardingConnection.prepareStatement(sql);
            statement.setString(1, "zhangyong17");
            statement.setInt(2, 1);
            int updateRow = statement.executeUpdate();
            System.out.println("updateRow=" + updateRow);
        } finally {
            if (statement != null) {
                statement.close();
            }
            if (shardingConnection != null) {
                shardingConnection.close();
            }
        }
    }

    @Test
    public void testInsertStatement() throws SQLException {
        Connection shardingConnection = shardingDataSource.getConnection();
        Statement statement = null;
        int workerId = 1012;
        int seq = 19;
// 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/util/IdGenerator.java
// public class IdGenerator {
// 
//     //总的分区数
//     private final static int SHARDING_NUM = ShardingConstants.SHARDING_LENGTH;
// 
//     //最大机器id 1023 也就是 1111111111
//     private final static int MAX_WORKER_ID = SHARDING_NUM - 1;
// 
//     //最大序号
//     private final static int MAX_SEQ = 4095;
// 
//     private final static long WORKERID_BITS = 10L;
// 
//     private final static long SEQUENCE_BITS = 12L;
// 
//     private final static long TIMESTAMP_LEFTSHIFT = SEQUENCE_BITS + WORKERID_BITS;
// 
//     private final static long WORKERID_SHIFT = SEQUENCE_BITS;
// 
//     public static long getUniqueId(int workerId , int seqId) {
//         if(workerId > MAX_WORKER_ID || workerId < 0) {
//             throw new IllegalArgumentException("workerId is not Illegal");
//         }
//         if(seqId > MAX_SEQ || seqId < 0) {
//             throw new IllegalArgumentException("seqId is not Illegal ");
//         }
//         //时间戳
//         long timestamp = System.currentTimeMillis();
//         //机器编号
//         return  (timestamp << TIMESTAMP_LEFTSHIFT) | (workerId << WORKERID_SHIFT) | seqId;
//     }
// 
// }


// Path: src/test/java/com/elong/pb/newdda/client/datasource/ShardingDataSourceUnitTest.java
import com.elong.pb.newdda.client.router.rule.ShardingRule;
import com.elong.pb.newdda.client.util.IdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import java.sql.*;

    }

    @Test
    public void testUpdatePrepareStatement() throws SQLException {
        Connection shardingConnection = shardingDataSource.getConnection();
        PreparedStatement statement = null;
        String sql = "update test set user_name = ? ,update_time = now() where user_id = ?";
        try {
            statement = null;
            statement = shardingConnection.prepareStatement(sql);
            statement.setString(1, "zhangyong17");
            statement.setInt(2, 1);
            int updateRow = statement.executeUpdate();
            System.out.println("updateRow=" + updateRow);
        } finally {
            if (statement != null) {
                statement.close();
            }
            if (shardingConnection != null) {
                shardingConnection.close();
            }
        }
    }

    @Test
    public void testInsertStatement() throws SQLException {
        Connection shardingConnection = shardingDataSource.getConnection();
        Statement statement = null;
        int workerId = 1012;
        int seq = 19;
        Long userId = IdGenerator.getUniqueId(workerId, seq);