|
@@ -1,150 +0,0 @@
|
|
|
-package org.geek.szbay.assistant.bigdata;
|
|
|
-
|
|
|
-import java.sql.Connection;
|
|
|
-import java.util.Date;
|
|
|
-
|
|
|
-import java.sql.DriverManager;
|
|
|
-import java.sql.Statement;
|
|
|
-
|
|
|
-
|
|
|
- * @author wutianbin
|
|
|
- * @Time:2017年5月30日 上午8:58:56
|
|
|
- * @version 1.0
|
|
|
- */
|
|
|
-public class BigDataBuilder {
|
|
|
- private static final String DB_URL ="jdbc:mysql://123.56.3.131/wutb?useEncodingUnicode=true&zeroDateTimeBehavior=convertToNull&characterEncoding=utf-8&useOldAliasMetadataBehavior=true&allowMultiQueries=true";
|
|
|
- private static final String DB_NAME = "root";
|
|
|
- private static final String DB_PASS = "Hjlytour2017";
|
|
|
- private static final String DB_DRIVER ="com.mysql.jdbc.Driver";
|
|
|
- @SuppressWarnings("unused")
|
|
|
- private static final String DB_SCHEMA = "wutb";
|
|
|
-
|
|
|
- private Connection initDB() {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- Connection con = null;
|
|
|
-
|
|
|
- try {
|
|
|
- Class.forName(DB_DRIVER);
|
|
|
- con = DriverManager.getConnection(DB_URL,DB_NAME,DB_PASS);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return con;
|
|
|
- }
|
|
|
-
|
|
|
- public void generate(int totalNumber, int perNumber, int beginId) {
|
|
|
- Connection con = initDB();
|
|
|
- if (con == null) {
|
|
|
- System.out.println("Connection is null.");
|
|
|
- return ;
|
|
|
- }
|
|
|
-
|
|
|
- long total_msec_insert = 0;
|
|
|
- long total_msec_update = 0;
|
|
|
-
|
|
|
- long per_msec_insert = 0;
|
|
|
- long per_msec_update = 0;
|
|
|
-
|
|
|
- long insert_msec = 0;
|
|
|
- long update_msec = 0;
|
|
|
-
|
|
|
- System.out.println("begin...");
|
|
|
- for(int i = 0; i < totalNumber; i++) {
|
|
|
- int num = i + 1;
|
|
|
- insert_msec = insertIntoOrder(con, beginId + num);
|
|
|
- update_msec = updateIntoOrder(con, beginId + num);
|
|
|
- total_msec_insert = total_msec_insert + insert_msec;
|
|
|
- total_msec_update = total_msec_update + update_msec;
|
|
|
-
|
|
|
- per_msec_insert = per_msec_insert + insert_msec;
|
|
|
- per_msec_update = per_msec_update + update_msec;
|
|
|
-
|
|
|
- if (num % perNumber == 0) {
|
|
|
- insertIntoCalc(con, num, total_msec_insert, total_msec_update,
|
|
|
- per_msec_insert, per_msec_update,
|
|
|
- total_msec_insert/num, total_msec_update/num,
|
|
|
- per_msec_insert/perNumber, per_msec_update/perNumber);
|
|
|
- per_msec_insert = 0;
|
|
|
- per_msec_update = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- System.out.println("");
|
|
|
- System.out.println("end.");
|
|
|
- }
|
|
|
-
|
|
|
- private long updateIntoOrder(Connection con, Integer id) {
|
|
|
- String sql = "UPDATE `wutb`.`pay_order` SET `pay_no` = ?, `qrcode` = ? "
|
|
|
- + " WHERE `id` = ? ";
|
|
|
- java.sql.PreparedStatement updateStat = null;
|
|
|
- try {
|
|
|
- updateStat = con.prepareStatement(sql);
|
|
|
- updateStat.setString(1, "pay_order value");
|
|
|
- updateStat.setString(2, "qrcode value");
|
|
|
- updateStat.setInt(3, id);
|
|
|
- updateStat.executeUpdate();
|
|
|
- long msec = (new Date()).getTime();
|
|
|
- updateStat.executeUpdate();
|
|
|
- return (new Date()).getTime() - msec;
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println(sql);
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- private long insertIntoOrder(Connection con, Integer id) {
|
|
|
- String sql = "INSERT INTO `wutb`.`pay_order` (`merchant_id`, `app_identity`, `order_no`, `client_ip`) "
|
|
|
- + "VALUES(?, ?, ?, ?)";
|
|
|
- java.sql.PreparedStatement updateStat = null;
|
|
|
- try {
|
|
|
- updateStat = con.prepareStatement(sql);
|
|
|
- updateStat.setInt(1, id);
|
|
|
- updateStat.setString(2, "app_identity");
|
|
|
- updateStat.setInt(3, id);
|
|
|
- updateStat.setString(4, "127.0.0.1");
|
|
|
- updateStat.executeUpdate();
|
|
|
- long msec = (new Date()).getTime();
|
|
|
- updateStat.executeUpdate();
|
|
|
- return (new Date()).getTime() - msec;
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println(sql);
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- private long insertIntoCalc(Connection con, Integer num,
|
|
|
- Long total_msec_insert, Long total_msec_update,
|
|
|
- Long per_msec_insert, Long per_msec_update,
|
|
|
- Long total_avg_insert, Long total_avg_update,
|
|
|
- Long per_avg_insert, Long per_avg_update) {
|
|
|
- String sql = "INSERT INTO `wutb`.`calc_rec`"
|
|
|
- + "(`rec_number`,`insert_msec_total`,`update_msec_total`,`insert_msec`,`update_msec`,"
|
|
|
- + "`insert_avg_total`,`update_avg_total`,`insert_avg`,`update_avg`)"
|
|
|
- + "VALUES(%d,%d,%d,%d,%d,"
|
|
|
- + "%d,%d,%d,%d)";
|
|
|
- sql = String.format(sql, num, total_msec_insert, total_msec_update, per_msec_insert, per_msec_update,
|
|
|
- total_avg_insert, total_avg_update, per_avg_insert, per_avg_update);
|
|
|
-
|
|
|
- System.out.print(".");
|
|
|
-
|
|
|
- Statement stat = null;
|
|
|
- try {
|
|
|
- stat = con.createStatement();
|
|
|
- stat.execute(sql);
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println(sql);
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- public static void main(String[] args) {
|
|
|
- BigDataBuilder builder = new BigDataBuilder();
|
|
|
- builder.generate(1000, 100, 8003000);
|
|
|
-
|
|
|
- }
|
|
|
-}
|