├── .gitignore ├── run ├── clean.sh ├── runBenchmark.sh ├── runLoader.sh ├── runSQL.sh ├── sqlTableDrops.mysql ├── sqlTableTruncates ├── sqlTableDrops ├── props.ora ├── props.pg ├── sqlIndexDrops ├── props.mysql ├── sqlExtraCreates.pg ├── sqlIndexCreates.mysql ├── sqlIndexCreates.oracle ├── sqlIndexCreates ├── sqlExtraCreates.ora ├── sqlTableCopies ├── log4j.xml ├── sqlTableCopies.mysql ├── sqlTableCreates.oracle ├── sqlTableCreates └── sqlTableCreates.mysql ├── lib ├── log4j-1.2.17.jar ├── apache-log4j-extras-1.1.jar ├── mysql-connector-java-5.1.35.jar └── postgresql-9.3-1101.jdbc41.jar ├── src ├── pojo │ ├── NewOrder.java │ ├── Item.java │ ├── History.java │ ├── Oorder.java │ ├── Warehouse.java │ ├── District.java │ ├── OrderLine.java │ ├── Stock.java │ └── Customer.java ├── client │ ├── jTPCCConfig.java │ ├── jTPCCUtil.java │ ├── jTPCC.java │ └── jTPCCTerminal.java ├── jdbc │ ├── jdbcIO.java │ └── ExecJDBC.java └── LoadData │ └── LoadData.java ├── HOW-TO-RUN.txt ├── README.md └── README.txt /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | dist 3 | run/log 4 | -------------------------------------------------------------------------------- /run/clean.sh: -------------------------------------------------------------------------------- 1 | rm -rf log/ 2 | 3 | mkdir -p log/archive 4 | 5 | 6 | -------------------------------------------------------------------------------- /lib/log4j-1.2.17.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waterguo/benchmarksql/HEAD/lib/log4j-1.2.17.jar -------------------------------------------------------------------------------- /run/runBenchmark.sh: -------------------------------------------------------------------------------- 1 | myCP=".:../lib/*:../dist/*" 2 | myOPTS="-Dprop=$1" 3 | 4 | java -cp $myCP $myOPTS jTPCC 5 | -------------------------------------------------------------------------------- /lib/apache-log4j-extras-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waterguo/benchmarksql/HEAD/lib/apache-log4j-extras-1.1.jar -------------------------------------------------------------------------------- /lib/mysql-connector-java-5.1.35.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waterguo/benchmarksql/HEAD/lib/mysql-connector-java-5.1.35.jar -------------------------------------------------------------------------------- /lib/postgresql-9.3-1101.jdbc41.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waterguo/benchmarksql/HEAD/lib/postgresql-9.3-1101.jdbc41.jar -------------------------------------------------------------------------------- /run/runLoader.sh: -------------------------------------------------------------------------------- 1 | myCP=".:../lib/*:../dist/*" 2 | myOPTS="-Dprop=$1" 3 | 4 | java -cp ${myCP} $myOPTS LoadData $2 $3 $4 $5 5 | -------------------------------------------------------------------------------- /run/runSQL.sh: -------------------------------------------------------------------------------- 1 | myCP=".:../lib/*:../dist/*" 2 | myOPTS="-Dprop=$1 -DcommandFile=$2" 3 | 4 | java -cp $myCP $myOPTS ExecJDBC 5 | -------------------------------------------------------------------------------- /run/sqlTableDrops.mysql: -------------------------------------------------------------------------------- 1 | 2 | drop table benchmarksql.warehouse; 3 | 4 | drop table benchmarksql.item; 5 | 6 | drop table benchmarksql.stock; 7 | 8 | drop table benchmarksql.district; 9 | 10 | drop table benchmarksql.customer; 11 | 12 | drop table benchmarksql.oorder; 13 | 14 | drop table benchmarksql.order_line; 15 | 16 | drop table benchmarksql.history; 17 | 18 | drop table benchmarksql.new_order; 19 | -------------------------------------------------------------------------------- /run/sqlTableTruncates: -------------------------------------------------------------------------------- 1 | 2 | truncate table benchmarksql.warehouse; 3 | 4 | truncate table benchmarksql.item; 5 | 6 | truncate table benchmarksql.stock; 7 | 8 | truncate table benchmarksql.district; 9 | 10 | truncate table benchmarksql.customer; 11 | 12 | truncate table benchmarksql.history; 13 | 14 | truncate table benchmarksql.oorder; 15 | 16 | truncate table benchmarksql.order_line; 17 | 18 | truncate table benchmarksql.new_order; -------------------------------------------------------------------------------- /run/sqlTableDrops: -------------------------------------------------------------------------------- 1 | 2 | drop table benchmarksql.warehouse; 3 | 4 | drop table benchmarksql.item; 5 | 6 | drop table benchmarksql.stock; 7 | 8 | drop table benchmarksql.district; 9 | 10 | drop table benchmarksql.customer; 11 | 12 | drop table benchmarksql.oorder; 13 | 14 | drop table benchmarksql.order_line; 15 | 16 | drop table benchmarksql.history; 17 | 18 | drop sequence benchmarksql.hist_id_seq; 19 | 20 | drop table benchmarksql.new_order; 21 | -------------------------------------------------------------------------------- /src/pojo/NewOrder.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.Serializable; 3 | 4 | 5 | public class NewOrder implements Serializable { 6 | 7 | public int no_w_id; 8 | public int no_d_id; 9 | public int no_o_id; 10 | 11 | public String toString() 12 | { 13 | return ( 14 | "\n***************** NewOrder ********************" + 15 | "\n* no_w_id = " + no_w_id + 16 | "\n* no_d_id = " + no_d_id + 17 | "\n* no_o_id = " + no_o_id + 18 | "\n**********************************************" 19 | ); 20 | } 21 | 22 | } // end NewOrder -------------------------------------------------------------------------------- /run/props.ora: -------------------------------------------------------------------------------- 1 | driver=oracle.jdbc.driver.OracleDriver 2 | conn=jdbc:oracle:thin:@localhost:1521:XE 3 | user=scott 4 | password=tiger 5 | 6 | 7 | warehouses=1 8 | terminals=1 9 | //To run specified transactions per terminal- runMins must equal zero 10 | runTxnsPerTerminal=10 11 | //To run for specified minutes- runTxnsPerTerminal must equal zero 12 | runMins=0 13 | //Number of total transactions per minute 14 | limitTxnsPerMin=300 15 | 16 | //The following five values must add up to 100 17 | newOrderWeight=45 18 | paymentWeight=43 19 | orderStatusWeight=4 20 | deliveryWeight=4 21 | stockLevelWeight=4 22 | 23 | -------------------------------------------------------------------------------- /run/props.pg: -------------------------------------------------------------------------------- 1 | driver=org.postgresql.Driver 2 | conn=jdbc:postgresql://localhost:5432/postgres 3 | user=postgres 4 | password=password 5 | 6 | warehouses=100 7 | terminals=24 8 | //To run specified transactions per terminal- runMins must equal zero 9 | runTxnsPerTerminal=0 10 | //To run for specified minutes- runTxnsPerTerminal must equal zero 11 | runMins=1 12 | //Number of total transactions per minute 13 | limitTxnsPerMin=0 14 | 15 | 16 | //The following five values must add up to 100 17 | //The default percentages of 45, 43, 4, 4 & 4 match the TPC-C spec 18 | newOrderWeight=45 19 | paymentWeight=43 20 | orderStatusWeight=4 21 | deliveryWeight=4 22 | stockLevelWeight=4 23 | 24 | -------------------------------------------------------------------------------- /src/pojo/Item.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.Serializable; 3 | 4 | 5 | public class Item implements Serializable { 6 | 7 | public int i_id; // PRIMARY KEY 8 | public int i_im_id; 9 | public float i_price; 10 | public String i_name; 11 | public String i_data; 12 | 13 | public String toString() 14 | { 15 | return ( 16 | "\n***************** Item ********************" + 17 | "\n* i_id = " + i_id + 18 | "\n* i_name = " + i_name + 19 | "\n* i_price = " + i_price + 20 | "\n* i_data = " + i_data + 21 | "\n* i_im_id = " + i_im_id + 22 | "\n**********************************************" 23 | ); 24 | } 25 | 26 | } // end Item -------------------------------------------------------------------------------- /run/sqlIndexDrops: -------------------------------------------------------------------------------- 1 | 2 | alter table benchmarksql.warehouse drop constraint pk_warehouse; 3 | 4 | alter table benchmarksql.district drop constraint pk_district; 5 | 6 | alter table benchmarksql.customer drop constraint pk_customer; 7 | drop index ndx_customer_name; 8 | 9 | -- history table has no primary key 10 | -- commit; 11 | 12 | alter table benchmarksql.oorder drop constraint pk_oorder; 13 | drop index ndx_oorder_carrier; 14 | 15 | alter table benchmarksql.new_order drop constraint pk_new_order; 16 | 17 | alter table benchmarksql.order_line drop constraint pk_order_line; 18 | 19 | alter table benchmarksql.stock drop constraint pk_stock; 20 | 21 | alter table benchmarksql.item drop constraint pk_item; -------------------------------------------------------------------------------- /run/props.mysql: -------------------------------------------------------------------------------- 1 | driver=com.mysql.jdbc.Driver 2 | conn=jdbc:mysql://localhost:3306/benchmarksql?useServerPrepStmts=true 3 | user=benchmarksql 4 | password=password 5 | 6 | warehouses=100 7 | terminals=1 8 | //To run specified transactions per terminal- runMins must equal zero 9 | runTxnsPerTerminal=0 10 | //To run for specified minutes- runTxnsPerTerminal must equal zero 11 | runMins=1 12 | //Number of total transactions per minute 13 | limitTxnsPerMin=0 14 | 15 | 16 | //The following five values must add up to 100 17 | //The default percentages of 45, 43, 4, 4 & 4 match the TPC-C spec 18 | newOrderWeight=45 19 | paymentWeight=43 20 | orderStatusWeight=4 21 | deliveryWeight=4 22 | stockLevelWeight=4 23 | 24 | -------------------------------------------------------------------------------- /run/sqlExtraCreates.pg: -------------------------------------------------------------------------------- 1 | -- ---- 2 | -- Extra Schema objects/definitions for PostgreSQL 3 | -- ---- 4 | 5 | -- ---- 6 | -- history.hist_id 7 | -- 8 | -- This is an extra column not present in the TPC-C 9 | -- specs. It is useful for replication systems like 10 | -- Bucardo and Slony-I, which like to have a primary 11 | -- key on a table. It is an auto-increment or serial 12 | -- column type. The definition below is compatible 13 | -- with Oracle 11g, using a sequence and a trigger. 14 | -- ---- 15 | -- Adjust the sequence above the current max(hist_id) 16 | select setval('benchmarksql.hist_id_seq', (select max(hist_id) from benchmarksql.history)); 17 | 18 | -- Make nextval(seq) the default value of the hist_id column. 19 | alter table benchmarksql.history alter column hist_id set default nextval('benchmarksql.hist_id_seq'); 20 | 21 | -- Add a primary key history(hist_id) 22 | alter table benchmarksql.history add primary key (hist_id); 23 | -------------------------------------------------------------------------------- /src/pojo/History.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.Serializable; 3 | 4 | 5 | public class History implements Serializable { 6 | 7 | public int hist_id; 8 | public int h_c_id; 9 | public int h_c_d_id; 10 | public int h_c_w_id; 11 | public int h_d_id; 12 | public int h_w_id; 13 | public long h_date; 14 | public float h_amount; 15 | public String h_data; 16 | 17 | public String toString() 18 | { 19 | return ( 20 | "\n***************** History ********************" + 21 | "\n* h_c_id = " + hist_id + 22 | "\n* h_c_id = " + h_c_id + 23 | "\n* h_c_d_id = " + h_c_d_id + 24 | "\n* h_c_w_id = " + h_c_w_id + 25 | "\n* h_d_id = " + h_d_id + 26 | "\n* h_w_id = " + h_w_id + 27 | "\n* h_date = " + h_date + 28 | "\n* h_amount = " + h_amount + 29 | "\n* h_data = " + h_data + 30 | "\n**********************************************" 31 | ); 32 | } 33 | 34 | } // end History -------------------------------------------------------------------------------- /src/pojo/Oorder.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.Serializable; 3 | 4 | 5 | public class Oorder implements Serializable { 6 | 7 | public int o_id; 8 | public int o_w_id; 9 | public int o_d_id; 10 | public int o_c_id; 11 | public int o_carrier_id; 12 | public int o_ol_cnt; 13 | public int o_all_local; 14 | public long o_entry_d; 15 | 16 | public String toString() 17 | { 18 | java.sql.Timestamp entry_d = new java.sql.Timestamp(o_entry_d); 19 | 20 | return ( 21 | "\n***************** Oorder ********************" + 22 | "\n* o_id = " + o_id + 23 | "\n* o_w_id = " + o_w_id + 24 | "\n* o_d_id = " + o_d_id + 25 | "\n* o_c_id = " + o_c_id + 26 | "\n* o_carrier_id = " + o_carrier_id + 27 | "\n* o_ol_cnt = " + o_ol_cnt + 28 | "\n* o_all_local = " + o_all_local + 29 | "\n* o_entry_d = " + entry_d + 30 | "\n**********************************************" 31 | ); 32 | } 33 | 34 | } // end Oorder -------------------------------------------------------------------------------- /src/pojo/Warehouse.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.Serializable; 3 | 4 | public class Warehouse implements Serializable { 5 | 6 | public int w_id; // PRIMARY KEY 7 | public float w_ytd; 8 | public float w_tax; 9 | public String w_name; 10 | public String w_street_1; 11 | public String w_street_2; 12 | public String w_city; 13 | public String w_state; 14 | public String w_zip; 15 | 16 | public String toString() 17 | { 18 | return ( 19 | "\n***************** Warehouse ********************" + 20 | "\n* w_id = " + w_id + 21 | "\n* w_ytd = " + w_ytd + 22 | "\n* w_tax = " + w_tax + 23 | "\n* w_name = " + w_name + 24 | "\n* w_street_1 = " + w_street_1 + 25 | "\n* w_street_2 = " + w_street_2 + 26 | "\n* w_city = " + w_city + 27 | "\n* w_state = " + w_state + 28 | "\n* w_zip = " + w_zip + 29 | "\n**********************************************" 30 | ); 31 | } 32 | 33 | } // end Warehouse -------------------------------------------------------------------------------- /run/sqlIndexCreates.mysql: -------------------------------------------------------------------------------- 1 | 2 | alter table benchmarksql.warehouse add constraint pk_warehouse 3 | primary key (w_id); 4 | 5 | alter table benchmarksql.district add constraint pk_district 6 | primary key (d_w_id, d_id); 7 | 8 | alter table benchmarksql.customer add constraint pk_customer 9 | primary key (c_w_id, c_d_id, c_id); 10 | 11 | create index ndx_customer_name 12 | on benchmarksql.customer (c_w_id, c_d_id, c_last, c_first); 13 | 14 | alter table benchmarksql.oorder add constraint pk_oorder 15 | primary key (o_w_id, o_d_id, o_id); 16 | 17 | create unique index ndx_oorder_carrier 18 | on benchmarksql.oorder (o_w_id, o_d_id, o_carrier_id, o_id); 19 | 20 | alter table benchmarksql.new_order add constraint pk_new_order 21 | primary key (no_w_id, no_d_id, no_o_id); 22 | 23 | alter table benchmarksql.order_line add constraint pk_order_line 24 | primary key (ol_w_id, ol_d_id, ol_o_id, ol_number); 25 | 26 | alter table benchmarksql.stock add constraint pk_stock 27 | primary key (s_w_id, s_i_id); 28 | 29 | alter table benchmarksql.item add constraint pk_item 30 | primary key (i_id); 31 | 32 | -------------------------------------------------------------------------------- /run/sqlIndexCreates.oracle: -------------------------------------------------------------------------------- 1 | 2 | alter table benchmarksql.warehouse add constraint pk_warehouse 3 | primary key (w_id); 4 | 5 | alter table benchmarksql.district add constraint pk_district 6 | primary key (d_w_id, d_id); 7 | 8 | alter table benchmarksql.customer add constraint pk_customer 9 | primary key (c_w_id, c_d_id, c_id); 10 | 11 | create index ndx_customer_name 12 | on benchmarksql.customer (c_w_id, c_d_id, c_last, c_first); 13 | 14 | alter table benchmarksql.oorder add constraint pk_oorder 15 | primary key (o_w_id, o_d_id, o_id); 16 | 17 | create unique index ndx_oorder_carrier 18 | on benchmarksql.oorder (o_w_id, o_d_id, o_carrier_id, o_id); 19 | 20 | alter table benchmarksql.new_order add constraint pk_new_order 21 | primary key (no_w_id, no_d_id, no_o_id); 22 | 23 | alter table benchmarksql.order_line add constraint pk_order_line 24 | primary key (ol_w_id, ol_d_id, ol_o_id, ol_number); 25 | 26 | alter table benchmarksql.stock add constraint pk_stock 27 | primary key (s_w_id, s_i_id); 28 | 29 | alter table benchmarksql.item add constraint pk_item 30 | primary key (i_id); 31 | 32 | -------------------------------------------------------------------------------- /run/sqlIndexCreates: -------------------------------------------------------------------------------- 1 | 2 | alter table benchmarksql.warehouse add constraint pk_warehouse 3 | primary key (w_id); 4 | 5 | alter table benchmarksql.district add constraint pk_district 6 | primary key (d_w_id, d_id); 7 | 8 | alter table benchmarksql.customer add constraint pk_customer 9 | primary key (c_w_id, c_d_id, c_id); 10 | 11 | create index ndx_customer_name 12 | on benchmarksql.customer (c_w_id, c_d_id, c_last, c_first); 13 | 14 | alter table benchmarksql.oorder add constraint pk_oorder 15 | primary key (o_w_id, o_d_id, o_id); 16 | 17 | create unique index ndx_oorder_carrier 18 | on benchmarksql.oorder (o_w_id, o_d_id, o_carrier_id, o_id); 19 | 20 | alter table benchmarksql.new_order add constraint pk_new_order 21 | primary key (no_w_id, no_d_id, no_o_id); 22 | 23 | alter table benchmarksql.order_line add constraint pk_order_line 24 | primary key (ol_w_id, ol_d_id, ol_o_id, ol_number); 25 | 26 | alter table benchmarksql.stock add constraint pk_stock 27 | primary key (s_w_id, s_i_id); 28 | 29 | alter table benchmarksql.item add constraint pk_item 30 | primary key (i_id); 31 | 32 | vacuum analyze; 33 | -------------------------------------------------------------------------------- /src/client/jTPCCConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jTPCCConfig - Basic configuration parameters for jTPCC 3 | * 4 | * Copyright (C) 2003, Raul Barbosa 5 | * Copyright (C) 2004-2016, Denis Lussier 6 | * Copyright (C) 2016, Jan Wieck 7 | * 8 | */ 9 | 10 | import java.text.*; 11 | 12 | public interface jTPCCConfig 13 | { 14 | public final static String JTPCCVERSION = "4.1.1"; 15 | 16 | public final static int NEW_ORDER = 1, PAYMENT = 2, ORDER_STATUS = 3, DELIVERY = 4, STOCK_LEVEL = 5; 17 | 18 | public final static String[] nameTokens = {"BAR", "OUGHT", "ABLE", "PRI", "PRES", "ESE", "ANTI", "CALLY", "ATION", "EING"}; 19 | 20 | public final static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 21 | 22 | public final static int configCommitCount = 10000; // commit every n records in LoadData 23 | 24 | public final static int configWhseCount = 10; 25 | public final static int configItemCount = 100000; // tpc-c std = 100,000 26 | public final static int configDistPerWhse = 10; // tpc-c std = 10 27 | public final static int configCustPerDist = 3000; // tpc-c std = 3,000 28 | } 29 | -------------------------------------------------------------------------------- /src/pojo/District.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.Serializable; 3 | 4 | 5 | public class District implements Serializable { 6 | 7 | public int d_id; 8 | public int d_w_id; 9 | public int d_next_o_id; 10 | public float d_ytd; 11 | public float d_tax; 12 | public String d_name; 13 | public String d_street_1; 14 | public String d_street_2; 15 | public String d_city; 16 | public String d_state; 17 | public String d_zip; 18 | 19 | public String toString() 20 | { 21 | return ( 22 | "\n***************** District ********************" + 23 | "\n* d_id = " + d_id + 24 | "\n* d_w_id = " + d_w_id + 25 | "\n* d_ytd = " + d_ytd + 26 | "\n* d_tax = " + d_tax + 27 | "\n* d_next_o_id = " + d_next_o_id + 28 | "\n* d_name = " + d_name + 29 | "\n* d_street_1 = " + d_street_1 + 30 | "\n* d_street_2 = " + d_street_2 + 31 | "\n* d_city = " + d_city + 32 | "\n* d_state = " + d_state + 33 | "\n* d_zip = " + d_zip + 34 | "\n**********************************************" 35 | ); 36 | } 37 | 38 | } // end District -------------------------------------------------------------------------------- /src/pojo/OrderLine.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.Serializable; 3 | 4 | 5 | public class OrderLine implements Serializable { 6 | 7 | public int ol_w_id; 8 | public int ol_d_id; 9 | public int ol_o_id; 10 | public int ol_number; 11 | public int ol_i_id; 12 | public int ol_supply_w_id; 13 | public int ol_quantity; 14 | public long ol_delivery_d; 15 | public float ol_amount; 16 | public String ol_dist_info; 17 | 18 | public String toString() 19 | { 20 | return ( 21 | "\n***************** OrderLine ********************" + 22 | "\n* ol_w_id = " + ol_w_id + 23 | "\n* ol_d_id = " + ol_d_id + 24 | "\n* ol_o_id = " + ol_o_id + 25 | "\n* ol_number = " + ol_number + 26 | "\n* ol_i_id = " + ol_i_id + 27 | "\n* ol_delivery_d = " + ol_delivery_d + 28 | "\n* ol_amount = " + ol_amount + 29 | "\n* ol_supply_w_id = " + ol_supply_w_id + 30 | "\n* ol_quantity = " + ol_quantity + 31 | "\n* ol_dist_info = " + ol_dist_info + 32 | "\n**********************************************" 33 | ); 34 | } 35 | 36 | } // end OrderLine -------------------------------------------------------------------------------- /run/sqlExtraCreates.ora: -------------------------------------------------------------------------------- 1 | -- ---- 2 | -- Extra Schema objects/definitions for Oracle 3 | -- ---- 4 | 5 | -- ---- 6 | -- history.hist_id 7 | -- 8 | -- This is an extra column not present in the TPC-C 9 | -- specs. It is useful for replication systems like 10 | -- Bucardo and Slony-I, which like to have a primary 11 | -- key on a table. It is an auto-increment or serial 12 | -- column type. The definition below is compatible 13 | -- with Oracle 11g, using the sequence in a trigger. 14 | -- ---- 15 | -- Adjust the sequence above the current max(hist_id) 16 | alter sequence benchmarksql.hist_id_seq increment by 30000; 17 | declare 18 | n integer\; 19 | i integer\; 20 | dummy integer\; 21 | begin 22 | select max(hist_id) into n from benchmarksql.history\; 23 | i := 0\; 24 | while i <= n loop 25 | select benchmarksql.hist_id_seq.nextval into dummy from dual\; 26 | i := i + 30000\; 27 | end loop\; 28 | end\; 29 | ; 30 | alter sequence benchmarksql.hist_id_seq increment by 1; 31 | 32 | -- Create a trigger that forces hist_id to be hist_id_seq.nextval 33 | create trigger benchmarksql.history_before_insert 34 | before insert on benchmarksql.history 35 | for each row 36 | begin 37 | select benchmarksql.hist_id_seq.nextval into :new.hist_id from dual\; 38 | end\; 39 | ; 40 | 41 | -- Add a primary key history(hist_id) 42 | alter table benchmarksql.history add primary key (hist_id); 43 | -------------------------------------------------------------------------------- /src/pojo/Stock.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.Serializable; 3 | 4 | 5 | public class Stock implements Serializable { 6 | 7 | public int s_i_id; //PRIMARY KEY 2 8 | public int s_w_id; //PRIMARY KEY 1 9 | public int s_order_cnt; 10 | public int s_remote_cnt; 11 | public int s_quantity; 12 | public float s_ytd; 13 | public String s_data; 14 | public String s_dist_01; 15 | public String s_dist_02; 16 | public String s_dist_03; 17 | public String s_dist_04; 18 | public String s_dist_05; 19 | public String s_dist_06; 20 | public String s_dist_07; 21 | public String s_dist_08; 22 | public String s_dist_09; 23 | public String s_dist_10; 24 | 25 | public String toString() 26 | { 27 | return ( 28 | 29 | "\n***************** Stock ********************" + 30 | "\n* s_i_id = " + s_i_id + 31 | "\n* s_w_id = " + s_w_id + 32 | "\n* s_quantity = " + s_quantity + 33 | "\n* s_ytd = " + s_ytd + 34 | "\n* s_order_cnt = " + s_order_cnt + 35 | "\n* s_remote_cnt = " + s_remote_cnt + 36 | "\n* s_data = " + s_data + 37 | "\n* s_dist_01 = " + s_dist_01 + 38 | "\n* s_dist_02 = " + s_dist_02 + 39 | "\n* s_dist_03 = " + s_dist_03 + 40 | "\n* s_dist_04 = " + s_dist_04 + 41 | "\n* s_dist_05 = " + s_dist_05 + 42 | "\n* s_dist_06 = " + s_dist_06 + 43 | "\n* s_dist_07 = " + s_dist_07 + 44 | "\n* s_dist_08 = " + s_dist_08 + 45 | "\n* s_dist_09 = " + s_dist_09 + 46 | "\n* s_dist_10 = " + s_dist_10 + 47 | "\n**********************************************" 48 | ); 49 | } 50 | 51 | } // end Stock -------------------------------------------------------------------------------- /run/sqlTableCopies: -------------------------------------------------------------------------------- 1 | 2 | copy benchmarksql.warehouse 3 | (w_id, w_ytd, w_tax, w_name, w_street_1, w_street_2, w_city, w_state, w_zip) 4 | from '/tmp/csv/warehouse.csv' WITH CSV; 5 | 6 | copy benchmarksql.item 7 | (i_id, i_name, i_price, i_data, i_im_id) 8 | from '/tmp/csv/item.csv' WITH CSV; 9 | 10 | copy benchmarksql.stock 11 | (s_i_id, s_w_id, s_quantity, s_ytd, s_order_cnt, s_remote_cnt, s_data, 12 | s_dist_01, s_dist_02, s_dist_03, s_dist_04, s_dist_05, 13 | s_dist_06, s_dist_07, s_dist_08, s_dist_09, s_dist_10) 14 | from '/tmp/csv/stock.csv' WITH CSV; 15 | 16 | copy benchmarksql.district 17 | (d_id, d_w_id, d_ytd, d_tax, d_next_o_id, d_name, d_street_1, 18 | d_street_2, d_city, d_state, d_zip) 19 | from '/tmp/csv/district.csv' WITH CSV; 20 | 21 | copy benchmarksql.customer 22 | (c_id, c_d_id, c_w_id, c_discount, c_credit, c_last, c_first, c_credit_lim, 23 | c_balance, c_ytd_payment, c_payment_cnt, c_delivery_cnt, c_street_1, 24 | c_street_2, c_city, c_state, c_zip, c_phone, c_since, c_middle, c_data) 25 | from '/tmp/csv/customer.csv' WITH CSV; 26 | 27 | copy benchmarksql.history 28 | (hist_id, h_c_id, h_c_d_id, h_c_w_id, h_d_id, h_w_id, h_date, h_amount, h_data) 29 | from '/tmp/csv/cust-hist.csv' WITH CSV; 30 | 31 | copy benchmarksql.oorder 32 | (o_id, o_w_id, o_d_id, o_c_id, o_carrier_id, o_ol_cnt, o_all_local, o_entry_d) 33 | from '/tmp/csv/order.csv' WITH CSV; 34 | 35 | copy benchmarksql.order_line 36 | (ol_w_id, ol_d_id, ol_o_id, ol_number, ol_i_id, ol_delivery_d, 37 | ol_amount, ol_supply_w_id, ol_quantity, ol_dist_info) 38 | from '/tmp/csv/order-line.csv' WITH CSV; 39 | 40 | copy benchmarksql.new_order 41 | (no_w_id, no_d_id, no_o_id) 42 | from '/tmp/csv/new-order.csv' WITH CSV; 43 | -------------------------------------------------------------------------------- /src/pojo/Customer.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.Serializable; 3 | 4 | 5 | public class Customer implements Serializable { 6 | 7 | public int c_id; 8 | public int c_d_id; 9 | public int c_w_id; 10 | public int c_payment_cnt; 11 | public int c_delivery_cnt; 12 | public long c_since; 13 | public float c_discount; 14 | public float c_credit_lim; 15 | public float c_balance; 16 | public float c_ytd_payment; 17 | public String c_credit; 18 | public String c_last; 19 | public String c_first; 20 | public String c_street_1; 21 | public String c_street_2; 22 | public String c_city; 23 | public String c_state; 24 | public String c_zip; 25 | public String c_phone; 26 | public String c_middle; 27 | public String c_data; 28 | 29 | public String toString() 30 | { 31 | java.sql.Timestamp since = new java.sql.Timestamp(c_since); 32 | 33 | return ( 34 | "\n***************** Customer ********************" + 35 | "\n* c_id = " + c_id + 36 | "\n* c_d_id = " + c_d_id + 37 | "\n* c_w_id = " + c_w_id + 38 | "\n* c_discount = " + c_discount + 39 | "\n* c_credit = " + c_credit + 40 | "\n* c_last = " + c_last + 41 | "\n* c_first = " + c_first + 42 | "\n* c_credit_lim = " + c_credit_lim + 43 | "\n* c_balance = " + c_balance + 44 | "\n* c_ytd_payment = " + c_ytd_payment + 45 | "\n* c_payment_cnt = " + c_payment_cnt + 46 | "\n* c_delivery_cnt = " + c_delivery_cnt + 47 | "\n* c_street_1 = " + c_street_1 + 48 | "\n* c_street_2 = " + c_street_2 + 49 | "\n* c_city = " + c_city + 50 | "\n* c_state = " + c_state + 51 | "\n* c_zip = " + c_zip + 52 | "\n* c_phone = " + c_phone + 53 | "\n* c_since = " + since + 54 | "\n* c_middle = " + c_middle + 55 | "\n* c_data = " + c_data + 56 | "\n**********************************************" 57 | ); 58 | } 59 | 60 | } // end Customer -------------------------------------------------------------------------------- /run/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/client/jTPCCUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jTPCCUtil - utility functions for the Open Source Java implementation of 3 | * the TPC-C benchmark 4 | * 5 | * Copyright (C) 2003, Raul Barbosa 6 | * Copyright (C) 2004-2016, Denis Lussier 7 | * 8 | */ 9 | 10 | 11 | import java.io.*; 12 | import java.sql.*; 13 | import java.util.*; 14 | import java.text.*; 15 | 16 | public class jTPCCUtil implements jTPCCConfig 17 | { 18 | 19 | public static String getSysProp(String inSysProperty, String defaultValue) { 20 | 21 | String outPropertyValue = null; 22 | 23 | try { 24 | outPropertyValue = System.getProperty(inSysProperty, defaultValue); 25 | } catch (Exception e) { 26 | System.err.println("Error Reading Required System Property '" + inSysProperty + "'"); 27 | } 28 | 29 | return(outPropertyValue); 30 | 31 | } // end getSysProp 32 | 33 | 34 | public static String randomStr(long strLen){ 35 | 36 | char freshChar; 37 | String freshString; 38 | freshString=""; 39 | 40 | while(freshString.length() < (strLen - 1)){ 41 | 42 | freshChar= (char)(Math.random()*128); 43 | if(Character.isLetter(freshChar)){ 44 | freshString += freshChar; 45 | } 46 | } 47 | 48 | return (freshString); 49 | 50 | } // end randomStr 51 | 52 | 53 | public static String getCurrentTime() 54 | { 55 | return dateFormat.format(new java.util.Date()); 56 | } 57 | 58 | public static String formattedDouble(double d) 59 | { 60 | String dS = ""+d; 61 | return dS.length() > 6 ? dS.substring(0, 6) : dS; 62 | } 63 | 64 | public static int getItemID(Random r) 65 | { 66 | return nonUniformRandom(8191, 1, 100000, r); 67 | } 68 | 69 | public static int getCustomerID(Random r) 70 | { 71 | return nonUniformRandom(1023, 1, 3000, r); 72 | } 73 | 74 | public static String getLastName(Random r) 75 | { 76 | int num = (int)nonUniformRandom(255, 0, 999, r); 77 | return nameTokens[num/100] + nameTokens[(num/10)%10] + nameTokens[num%10]; 78 | } 79 | 80 | public static int randomNumber(int min, int max, Random r) 81 | { 82 | return (int)(r.nextDouble() * (max-min+1) + min); 83 | } 84 | 85 | 86 | public static int nonUniformRandom(int x, int min, int max, Random r) 87 | { 88 | return (((randomNumber(0, x, r) | randomNumber(min, max, r)) + randomNumber(0, x, r)) % (max-min+1)) + min; 89 | } 90 | 91 | } // end jTPCCUtil 92 | -------------------------------------------------------------------------------- /HOW-TO-RUN.txt: -------------------------------------------------------------------------------- 1 | 2 | Instructions for running 3 | ------------------------ 4 | Use of JDK7 is required. Sample JDBC Connection Property files are provided as follows: 5 | props.pg : for PostgreSQL/EnterpriseDB 6 | props.ora : for Oracle 7 | 8 | 0. As the user postgres, create the benchmarksql user with correct permissions. 9 | postgres=# CREATE USER benchmarksql WITH SUPERUSER PASSWORD 'password'; 10 | postgres=# GRANT ALL PRIVILEGES ON DATABASE postgres TO benchmarksql; 11 | 12 | 1. Go to the 'run' directory, edit the appropriate "props.???" 13 | file to point to the database instance you'd like to test. 14 | 15 | 2. Run the "sqlTableCreates" to create the base tables. 16 | 17 | $ ./runSQL.sh props.pg sqlTableCreates 18 | 19 | 20 | 3. Run the Loader command file to load all of the default data 21 | for a benchmark: 22 | 23 | 24 | A.) Approximately half a million rows (per Warehouse) will be loaded 25 | across 9 tables. 26 | 27 | $ ./runLoader.sh props.pg numWarehouses 1 28 | 29 | NOTE: You should run the sqlTableTruncates scripts if your tables 30 | are not already empty. 31 | 32 | B.) Alternatively, for PostgreSQL you may choose to generate the 33 | load data out to CSV files where it can be efficiently 34 | bulk loaded into the database as many times as required by your 35 | testing. 36 | 37 | $ ./runLoader.sh props.pg numWarehouses 1 fileLocation /tmp/csv/ 38 | 39 | These CSV files can be bulk loaded as follows: 40 | $ ./runSQL.sh props.pg sqlTableCopies 41 | 42 | You may truncate the data via: 43 | 44 | $ ./runSQL.sh props.pg sqlTableTruncates 45 | 46 | 4. Run the "runSQL" command file to execute the SQL script 47 | "sqlIndexCreates" to create the primary keys & other indexes 48 | on the tables. 49 | 50 | $ ./runSQL.sh props.pg sqlIndexCreates 51 | 52 | 53 | 5. Optionally run the "runSQL" command file to execute the SQL script 54 | "sqlExtraCreates." to make history.hist_id an auto-increment 55 | primary key. This column does not exist in the TPC-C standard and is 56 | provided for convenience of users of replication systems such as 57 | Bucardo or Slony-I. The benchmark itself will work with or without 58 | it being an actual auto-incrementing primary key. 59 | 60 | $ ./runSQL.sh props.pg sqlIndexCreates.pg 61 | 62 | 63 | 6. Run the "runBenchmark" command file to test the database. This command 64 | will create terminals and automatically start the transaction based on 65 | the parameters set in "props". 66 | 67 | $ ./runBenchmark.sh props.pg 68 | 69 | -------------------------------------------------------------------------------- /src/jdbc/jdbcIO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jdbcIO - execute JDBC statements 3 | * 4 | * Copyright (C) 2004-2016, Denis Lussier 5 | * 6 | */ 7 | 8 | 9 | import java.sql.*; 10 | import java.util.*; 11 | 12 | public class jdbcIO { 13 | 14 | public void insertOrder(PreparedStatement ordrPrepStmt, Oorder oorder) { 15 | 16 | try { 17 | 18 | ordrPrepStmt.setInt(1, oorder.o_id); 19 | ordrPrepStmt.setInt(2, oorder.o_w_id); 20 | ordrPrepStmt.setInt(3, oorder.o_d_id); 21 | ordrPrepStmt.setInt(4, oorder.o_c_id); 22 | ordrPrepStmt.setInt(5, oorder.o_carrier_id); 23 | ordrPrepStmt.setInt(6, oorder.o_ol_cnt); 24 | ordrPrepStmt.setInt(7, oorder.o_all_local); 25 | Timestamp entry_d = new java.sql.Timestamp(oorder.o_entry_d); 26 | ordrPrepStmt.setTimestamp(8, entry_d); 27 | 28 | ordrPrepStmt.addBatch(); 29 | 30 | } catch(SQLException se) { 31 | System.out.println(se.getMessage()); 32 | } catch (Exception e) { 33 | e.printStackTrace(); 34 | } 35 | 36 | } // end insertOrder() 37 | 38 | public void insertNewOrder(PreparedStatement nworPrepStmt, NewOrder new_order) { 39 | 40 | try { 41 | nworPrepStmt.setInt(1, new_order.no_w_id); 42 | nworPrepStmt.setInt(2, new_order.no_d_id); 43 | nworPrepStmt.setInt(3, new_order.no_o_id); 44 | 45 | nworPrepStmt.addBatch(); 46 | 47 | } catch(SQLException se) { 48 | System.out.println(se.getMessage()); 49 | } catch (Exception e) { 50 | e.printStackTrace(); 51 | } 52 | 53 | } // end insertNewOrder() 54 | 55 | public void insertOrderLine(PreparedStatement orlnPrepStmt, OrderLine order_line) { 56 | 57 | try { 58 | orlnPrepStmt.setInt(1, order_line.ol_w_id); 59 | orlnPrepStmt.setInt(2, order_line.ol_d_id); 60 | orlnPrepStmt.setInt(3, order_line.ol_o_id); 61 | orlnPrepStmt.setInt(4, order_line.ol_number); 62 | orlnPrepStmt.setLong(5, order_line.ol_i_id); 63 | 64 | Timestamp delivery_d = new Timestamp(order_line.ol_delivery_d); 65 | orlnPrepStmt.setTimestamp(6, delivery_d); 66 | 67 | orlnPrepStmt.setDouble(7, order_line.ol_amount); 68 | orlnPrepStmt.setLong(8, order_line.ol_supply_w_id); 69 | orlnPrepStmt.setDouble(9, order_line.ol_quantity); 70 | orlnPrepStmt.setString(10, order_line.ol_dist_info); 71 | 72 | orlnPrepStmt.addBatch(); 73 | 74 | } catch(SQLException se) { 75 | System.out.println(se.getMessage()); 76 | } catch (Exception e) { 77 | e.printStackTrace(); 78 | } 79 | 80 | } // end insertOrderLine() 81 | 82 | } // end class jdbcIO() 83 | -------------------------------------------------------------------------------- /run/sqlTableCopies.mysql: -------------------------------------------------------------------------------- 1 | LOAD DATA LOCAL INFILE '/tmp/csv/warehouse.csv' 2 | INTO TABLE `benchmarksql`.`warehouse` 3 | FIELDS ESCAPED BY '\\' 4 | TERMINATED BY ',' 5 | LINES TERMINATED BY '\n' 6 | (`w_id`, `w_ytd`, `w_tax`, `w_name`, `w_street_1`, `w_street_2`, `w_city`, `w_state`, `w_zip`); 7 | 8 | 9 | LOAD DATA LOCAL INFILE '/tmp/csv/item.csv' 10 | INTO TABLE `benchmarksql`.`item` 11 | FIELDS ESCAPED BY '\\' 12 | TERMINATED BY ',' 13 | LINES TERMINATED BY '\n' 14 | (`i_id`, `i_name`, `i_price`, `i_data`, `i_im_id`); 15 | 16 | 17 | LOAD DATA LOCAL INFILE '/tmp/csv/stock.csv' 18 | INTO TABLE `benchmarksql`.`stock` 19 | FIELDS ESCAPED BY '\\' 20 | TERMINATED BY ',' 21 | LINES TERMINATED BY '\n' 22 | (`s_i_id`, `s_w_id`, `s_quantity`, `s_ytd`, `s_order_cnt`, `s_remote_cnt`, `s_data`, 23 | `s_dist_01`, `s_dist_02`, `s_dist_03`, `s_dist_04`, `s_dist_05`, 24 | `s_dist_06`, `s_dist_07`, `s_dist_08`, `s_dist_09`, `s_dist_10`); 25 | 26 | LOAD DATA LOCAL INFILE '/tmp/csv/district.csv' 27 | INTO TABLE `benchmarksql`.`district` 28 | FIELDS ESCAPED BY '\\' 29 | TERMINATED BY ',' 30 | LINES TERMINATED BY '\n' 31 | (d_id, d_w_id, d_ytd, d_tax, d_next_o_id, d_name, d_street_1, 32 | d_street_2, d_city, d_state, d_zip); 33 | 34 | LOAD DATA LOCAL INFILE '/tmp/csv/customer.csv' 35 | INTO TABLE `benchmarksql`.`customer` 36 | FIELDS ESCAPED BY '\\' 37 | TERMINATED BY ',' 38 | LINES TERMINATED BY '\n' 39 | (c_id, c_d_id, c_w_id, c_discount, c_credit, c_last, c_first, c_credit_lim, 40 | c_balance, c_ytd_payment, c_payment_cnt, c_delivery_cnt, c_street_1, 41 | c_street_2, c_city, c_state, c_zip, c_phone, c_since, c_middle, c_data); 42 | 43 | LOAD DATA LOCAL INFILE '/tmp/csv/cust-hist.csv' 44 | INTO TABLE `benchmarksql`.`history` 45 | FIELDS ESCAPED BY '\\' 46 | TERMINATED BY ',' 47 | LINES TERMINATED BY '\n' 48 | (hist_id, h_c_id, h_c_d_id, h_c_w_id, h_d_id, h_w_id, h_date, h_amount, h_data); 49 | 50 | LOAD DATA LOCAL INFILE '/tmp/csv/order.csv' 51 | INTO TABLE `benchmarksql`.`oorder` 52 | FIELDS ESCAPED BY '\\' 53 | TERMINATED BY ',' 54 | LINES TERMINATED BY '\n' 55 | (o_id, o_w_id, o_d_id, o_c_id, o_carrier_id, o_ol_cnt, o_all_local, o_entry_d); 56 | 57 | LOAD DATA LOCAL INFILE '/tmp/csv/order-line.csv' 58 | INTO TABLE `benchmarksql`.`order_line` 59 | FIELDS ESCAPED BY '\\' 60 | TERMINATED BY ',' 61 | LINES TERMINATED BY '\n' 62 | (ol_w_id, ol_d_id, ol_o_id, ol_number, ol_i_id, ol_delivery_d, 63 | ol_amount, ol_supply_w_id, ol_quantity, ol_dist_info); 64 | 65 | LOAD DATA LOCAL INFILE '/tmp/csv/new-order.csv' 66 | INTO TABLE `benchmarksql`.`new_order` 67 | FIELDS ESCAPED BY '\\' 68 | TERMINATED BY ',' 69 | LINES TERMINATED BY '\n' 70 | (no_w_id, no_d_id, no_o_id); 71 | 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # benchmarksql 2 | 3 | This is a fork of BenchmarkSQL with additionl scripts and libaraies so that it can run on PostgreSQL, MySQL and Oracle. 4 | 5 | Currently the lastest version is 4.1.1 6 | 7 | There is also a fork of 3.0.9 with MySQL support in the history 8 | 9 | # how to run 10 | 11 | prepare for running 12 | ------------------------ 13 | 0. install ant 14 | 1. use ant compile 15 | ``` 16 | $ ant 17 | ``` 18 | Instructions for running 19 | ------------------------ 20 | Use of JDK7 is required. Sample JDBC Connection Property files are provided as follows: 21 | props.pg : for PostgreSQL/EnterpriseDB 22 | props.ora : for Oracle 23 | 24 | 0. As the user postgres, create the benchmarksql user with correct permissions. 25 | postgres=# CREATE USER benchmarksql WITH SUPERUSER PASSWORD 'password'; 26 | postgres=# GRANT ALL PRIVILEGES ON DATABASE postgres TO benchmarksql; 27 | 28 | 1. Go to the 'run' directory, edit the appropriate "props.???" 29 | file to point to the database instance you'd like to test. 30 | 31 | 2. Run the "sqlTableCreates" to create the base tables. 32 | 33 | $ ./runSQL.sh props.pg sqlTableCreates 34 | 35 | 36 | 3. Run the Loader command file to load all of the default data 37 | for a benchmark: 38 | 39 | 40 | A.) Approximately half a million rows (per Warehouse) will be loaded 41 | across 9 tables. 42 | 43 | $ ./runLoader.sh props.pg numWarehouses 1 44 | 45 | NOTE: You should run the sqlTableTruncates scripts if your tables 46 | are not already empty. 47 | 48 | B.) Alternatively, for PostgreSQL you may choose to generate the 49 | load data out to CSV files where it can be efficiently 50 | bulk loaded into the database as many times as required by your 51 | testing. 52 | 53 | $ ./runLoader.sh props.pg numWarehouses 1 fileLocation /tmp/csv/ 54 | 55 | These CSV files can be bulk loaded as follows: 56 | $ ./runSQL.sh props.pg sqlTableCopies 57 | 58 | You may truncate the data via: 59 | 60 | $ ./runSQL.sh props.pg sqlTableTruncates 61 | 62 | 4. Run the "runSQL" command file to execute the SQL script 63 | "sqlIndexCreates" to create the primary keys & other indexes 64 | on the tables. 65 | 66 | $ ./runSQL.sh props.pg sqlIndexCreates 67 | 68 | 69 | 5. Optionally run the "runSQL" command file to execute the SQL script 70 | "sqlExtraCreates." to make history.hist_id an auto-increment 71 | primary key. This column does not exist in the TPC-C standard and is 72 | provided for convenience of users of replication systems such as 73 | Bucardo or Slony-I. The benchmark itself will work with or without 74 | it being an actual auto-incrementing primary key. 75 | 76 | $ ./runSQL.sh props.pg sqlIndexCreates.pg 77 | 78 | 79 | 6. Run the "runBenchmark" command file to test the database. This command 80 | will create terminals and automatically start the transaction based on 81 | the parameters set in "props". 82 | 83 | $ ./runBenchmark.sh props.pg 84 | 85 | -------------------------------------------------------------------------------- /src/jdbc/ExecJDBC.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ExecJDBC - Command line program to process SQL DDL statements, from 3 | * a text input file, to any JDBC Data Source 4 | * 5 | * Copyright (C) 2004-2016, Denis Lussier 6 | * Copyright (C) 2016, Jan Wieck 7 | * 8 | */ 9 | 10 | import java.io.*; 11 | import java.sql.*; 12 | import java.util.*; 13 | 14 | 15 | public class ExecJDBC { 16 | 17 | 18 | public static void main(String[] args) { 19 | 20 | Connection conn = null; 21 | Statement stmt = null; 22 | String rLine = null; 23 | StringBuffer sql = new StringBuffer(); 24 | 25 | try { 26 | 27 | Properties ini = new Properties(); 28 | ini.load( new FileInputStream(System.getProperty("prop"))); 29 | 30 | // Register jdbcDriver 31 | Class.forName(ini.getProperty( "driver" )); 32 | 33 | // make connection 34 | conn = DriverManager.getConnection(ini.getProperty("conn"), 35 | ini.getProperty("user"),ini.getProperty("password")); 36 | conn.setAutoCommit(true); 37 | 38 | // Create Statement 39 | stmt = conn.createStatement(); 40 | 41 | // Open inputFile 42 | BufferedReader in = new BufferedReader 43 | (new FileReader(jTPCCUtil.getSysProp("commandFile",null))); 44 | 45 | // loop thru input file and concatenate SQL statement fragments 46 | while((rLine = in.readLine()) != null) { 47 | 48 | String line = rLine.trim(); 49 | 50 | if (line.length() != 0) { 51 | if (line.startsWith("--")) { 52 | System.out.println(line); // print comment line 53 | } else { 54 | if (line.endsWith("\\;")) 55 | { 56 | sql.append(line.replaceAll("\\\\;", ";")); 57 | sql.append("\n"); 58 | } 59 | else 60 | { 61 | sql.append(line.replaceAll("\\\\;", ";")); 62 | if (line.endsWith(";")) { 63 | String query = sql.toString(); 64 | 65 | execJDBC(stmt, query.substring(0, query.length() - 1)); 66 | sql = new StringBuffer(); 67 | } else { 68 | sql.append("\n"); 69 | } 70 | } 71 | } 72 | 73 | } //end if 74 | 75 | } //end while 76 | 77 | in.close(); 78 | 79 | } catch(IOException ie) { 80 | System.out.println(ie.getMessage()); 81 | 82 | } catch(SQLException se) { 83 | System.out.println(se.getMessage()); 84 | 85 | } catch(Exception e) { 86 | e.printStackTrace(); 87 | 88 | //exit Cleanly 89 | } finally { 90 | try { 91 | if (conn !=null) 92 | conn.close(); 93 | } catch(SQLException se) { 94 | se.printStackTrace(); 95 | } // end finally 96 | 97 | } // end try 98 | 99 | } // end main 100 | 101 | 102 | static void execJDBC(Statement stmt, String query) { 103 | 104 | System.out.println(query + ";"); 105 | 106 | try { 107 | 108 | stmt.execute(query); 109 | 110 | }catch(SQLException se) { 111 | System.out.println(se.getMessage()); 112 | } // end try 113 | 114 | } // end execJDBCCommand 115 | 116 | } // end ExecJDBC Class 117 | -------------------------------------------------------------------------------- /run/sqlTableCreates.oracle: -------------------------------------------------------------------------------- 1 | create table benchmarksql.warehouse ( 2 | w_id integer not null, 3 | w_ytd decimal(12,2), 4 | w_tax decimal(4,4), 5 | w_name varchar(10), 6 | w_street_1 varchar(20), 7 | w_street_2 varchar(20), 8 | w_city varchar(20), 9 | w_state char(2), 10 | w_zip char(9) 11 | ); 12 | 13 | create table benchmarksql.district ( 14 | d_w_id integer not null, 15 | d_id integer not null, 16 | d_ytd decimal(12,2), 17 | d_tax decimal(4,4), 18 | d_next_o_id integer, 19 | d_name varchar(10), 20 | d_street_1 varchar(20), 21 | d_street_2 varchar(20), 22 | d_city varchar(20), 23 | d_state char(2), 24 | d_zip char(9) 25 | ); 26 | 27 | create table benchmarksql.customer ( 28 | c_w_id integer not null, 29 | c_d_id integer not null, 30 | c_id integer not null, 31 | c_discount decimal(4,4), 32 | c_credit char(2), 33 | c_last varchar(16), 34 | c_first varchar(16), 35 | c_credit_lim decimal(12,2), 36 | c_balance decimal(12,2), 37 | c_ytd_payment float, 38 | c_payment_cnt integer, 39 | c_delivery_cnt integer, 40 | c_street_1 varchar(20), 41 | c_street_2 varchar(20), 42 | c_city varchar(20), 43 | c_state char(2), 44 | c_zip char(9), 45 | c_phone char(16), 46 | c_since timestamp, 47 | c_middle char(2), 48 | c_data varchar(500) 49 | ); 50 | 51 | create sequence benchmarksql.hist_id_seq; 52 | 53 | create table benchmarksql.history ( 54 | hist_id integer, 55 | h_c_id integer, 56 | h_c_d_id integer, 57 | h_c_w_id integer, 58 | h_d_id integer, 59 | h_w_id integer, 60 | h_date timestamp, 61 | h_amount decimal(6,2), 62 | h_data varchar(24) 63 | ); 64 | 65 | 66 | create table benchmarksql.oorder ( 67 | o_w_id integer not null, 68 | o_d_id integer not null, 69 | o_id integer not null, 70 | o_c_id integer, 71 | o_carrier_id integer, 72 | o_ol_cnt decimal(2,0), 73 | o_all_local decimal(1,0), 74 | o_entry_d timestamp 75 | ); 76 | 77 | 78 | create table benchmarksql.new_order ( 79 | no_w_id integer not null, 80 | no_d_id integer not null, 81 | no_o_id integer not null 82 | ); 83 | 84 | 85 | create table benchmarksql.order_line ( 86 | ol_w_id integer not null, 87 | ol_d_id integer not null, 88 | ol_o_id integer not null, 89 | ol_number integer not null, 90 | ol_i_id integer not null, 91 | ol_delivery_d timestamp, 92 | ol_amount decimal(6,2), 93 | ol_supply_w_id integer, 94 | ol_quantity decimal(2,0), 95 | ol_dist_info char(24) 96 | ); 97 | 98 | 99 | create table benchmarksql.stock ( 100 | s_w_id integer not null, 101 | s_i_id integer not null, 102 | s_quantity decimal(4,0), 103 | s_ytd decimal(8,2), 104 | s_order_cnt integer, 105 | s_remote_cnt integer, 106 | s_data varchar(50), 107 | s_dist_01 char(24), 108 | s_dist_02 char(24), 109 | s_dist_03 char(24), 110 | s_dist_04 char(24), 111 | s_dist_05 char(24), 112 | s_dist_06 char(24), 113 | s_dist_07 char(24), 114 | s_dist_08 char(24), 115 | s_dist_09 char(24), 116 | s_dist_10 char(24) 117 | ); 118 | 119 | 120 | create table benchmarksql.item ( 121 | i_id integer not null, 122 | i_name varchar(24), 123 | i_price decimal(5,2), 124 | i_data varchar(50), 125 | i_im_id integer 126 | ); 127 | 128 | -------------------------------------------------------------------------------- /run/sqlTableCreates: -------------------------------------------------------------------------------- 1 | DROP SCHEMA IF EXISTS benchmarksql CASCADE; 2 | 3 | CREATE SCHEMA benchmarksql; 4 | 5 | create table benchmarksql.warehouse ( 6 | w_id integer not null, 7 | w_ytd decimal(12,2), 8 | w_tax decimal(4,4), 9 | w_name varchar(10), 10 | w_street_1 varchar(20), 11 | w_street_2 varchar(20), 12 | w_city varchar(20), 13 | w_state char(2), 14 | w_zip char(9) 15 | ); 16 | 17 | create table benchmarksql.district ( 18 | d_w_id integer not null, 19 | d_id integer not null, 20 | d_ytd decimal(12,2), 21 | d_tax decimal(4,4), 22 | d_next_o_id integer, 23 | d_name varchar(10), 24 | d_street_1 varchar(20), 25 | d_street_2 varchar(20), 26 | d_city varchar(20), 27 | d_state char(2), 28 | d_zip char(9) 29 | ); 30 | 31 | create table benchmarksql.customer ( 32 | c_w_id integer not null, 33 | c_d_id integer not null, 34 | c_id integer not null, 35 | c_discount decimal(4,4), 36 | c_credit char(2), 37 | c_last varchar(16), 38 | c_first varchar(16), 39 | c_credit_lim decimal(12,2), 40 | c_balance decimal(12,2), 41 | c_ytd_payment float, 42 | c_payment_cnt integer, 43 | c_delivery_cnt integer, 44 | c_street_1 varchar(20), 45 | c_street_2 varchar(20), 46 | c_city varchar(20), 47 | c_state char(2), 48 | c_zip char(9), 49 | c_phone char(16), 50 | c_since timestamp, 51 | c_middle char(2), 52 | c_data varchar(500) 53 | ); 54 | 55 | create sequence benchmarksql.hist_id_seq; 56 | 57 | create table benchmarksql.history ( 58 | hist_id integer, 59 | h_c_id integer, 60 | h_c_d_id integer, 61 | h_c_w_id integer, 62 | h_d_id integer, 63 | h_w_id integer, 64 | h_date timestamp, 65 | h_amount decimal(6,2), 66 | h_data varchar(24) 67 | ); 68 | 69 | 70 | create table benchmarksql.oorder ( 71 | o_w_id integer not null, 72 | o_d_id integer not null, 73 | o_id integer not null, 74 | o_c_id integer, 75 | o_carrier_id integer, 76 | o_ol_cnt decimal(2,0), 77 | o_all_local decimal(1,0), 78 | o_entry_d timestamp 79 | ); 80 | 81 | 82 | create table benchmarksql.new_order ( 83 | no_w_id integer not null, 84 | no_d_id integer not null, 85 | no_o_id integer not null 86 | ); 87 | 88 | 89 | create table benchmarksql.order_line ( 90 | ol_w_id integer not null, 91 | ol_d_id integer not null, 92 | ol_o_id integer not null, 93 | ol_number integer not null, 94 | ol_i_id integer not null, 95 | ol_delivery_d timestamp, 96 | ol_amount decimal(6,2), 97 | ol_supply_w_id integer, 98 | ol_quantity decimal(2,0), 99 | ol_dist_info char(24) 100 | ); 101 | 102 | 103 | create table benchmarksql.stock ( 104 | s_w_id integer not null, 105 | s_i_id integer not null, 106 | s_quantity decimal(4,0), 107 | s_ytd decimal(8,2), 108 | s_order_cnt integer, 109 | s_remote_cnt integer, 110 | s_data varchar(50), 111 | s_dist_01 char(24), 112 | s_dist_02 char(24), 113 | s_dist_03 char(24), 114 | s_dist_04 char(24), 115 | s_dist_05 char(24), 116 | s_dist_06 char(24), 117 | s_dist_07 char(24), 118 | s_dist_08 char(24), 119 | s_dist_09 char(24), 120 | s_dist_10 char(24) 121 | ); 122 | 123 | 124 | create table benchmarksql.item ( 125 | i_id integer not null, 126 | i_name varchar(24), 127 | i_price decimal(5,2), 128 | i_data varchar(50), 129 | i_im_id integer 130 | ); 131 | 132 | -------------------------------------------------------------------------------- /run/sqlTableCreates.mysql: -------------------------------------------------------------------------------- 1 | DROP DATABASE IF EXISTS benchmarksql CASCADE; 2 | 3 | CREATE DATABASE benchmarksql; 4 | 5 | create table benchmarksql.warehouse ( 6 | w_id integer not null, 7 | w_ytd decimal(12,2), 8 | w_tax decimal(4,4), 9 | w_name varchar(10), 10 | w_street_1 varchar(20), 11 | w_street_2 varchar(20), 12 | w_city varchar(20), 13 | w_state char(2), 14 | w_zip char(9) 15 | ) engine=innodb; 16 | 17 | create table benchmarksql.district ( 18 | d_w_id integer not null, 19 | d_id integer not null, 20 | d_ytd decimal(12,2), 21 | d_tax decimal(4,4), 22 | d_next_o_id integer, 23 | d_name varchar(10), 24 | d_street_1 varchar(20), 25 | d_street_2 varchar(20), 26 | d_city varchar(20), 27 | d_state char(2), 28 | d_zip char(9) 29 | ) engine=innodb; 30 | 31 | create table benchmarksql.customer ( 32 | c_w_id integer not null, 33 | c_d_id integer not null, 34 | c_id integer not null, 35 | c_discount decimal(4,4), 36 | c_credit char(2), 37 | c_last varchar(16), 38 | c_first varchar(16), 39 | c_credit_lim decimal(12,2), 40 | c_balance decimal(12,2), 41 | c_ytd_payment float, 42 | c_payment_cnt integer, 43 | c_delivery_cnt integer, 44 | c_street_1 varchar(20), 45 | c_street_2 varchar(20), 46 | c_city varchar(20), 47 | c_state char(2), 48 | c_zip char(9), 49 | c_phone char(16), 50 | c_since timestamp, 51 | c_middle char(2), 52 | c_data varchar(500) 53 | ) engine=innodb; 54 | 55 | create table benchmarksql.history ( 56 | hist_id integer, 57 | h_c_id integer, 58 | h_c_d_id integer, 59 | h_c_w_id integer, 60 | h_d_id integer, 61 | h_w_id integer, 62 | h_date timestamp, 63 | h_amount decimal(6,2), 64 | h_data varchar(24) 65 | ) engine=innodb; 66 | 67 | 68 | create table benchmarksql.oorder ( 69 | o_w_id integer not null, 70 | o_d_id integer not null, 71 | o_id integer not null, 72 | o_c_id integer, 73 | o_carrier_id integer, 74 | o_ol_cnt decimal(2,0), 75 | o_all_local decimal(1,0), 76 | o_entry_d timestamp 77 | ) engine=innodb; 78 | 79 | 80 | create table benchmarksql.new_order ( 81 | no_w_id integer not null, 82 | no_d_id integer not null, 83 | no_o_id integer not null 84 | ) engine=innodb; 85 | 86 | 87 | create table benchmarksql.order_line ( 88 | ol_w_id integer not null, 89 | ol_d_id integer not null, 90 | ol_o_id integer not null, 91 | ol_number integer not null, 92 | ol_i_id integer not null, 93 | ol_delivery_d timestamp, 94 | ol_amount decimal(6,2), 95 | ol_supply_w_id integer, 96 | ol_quantity decimal(2,0), 97 | ol_dist_info char(24) 98 | ) engine=innodb; 99 | 100 | 101 | create table benchmarksql.stock ( 102 | s_w_id integer not null, 103 | s_i_id integer not null, 104 | s_quantity decimal(4,0), 105 | s_ytd decimal(8,2), 106 | s_order_cnt integer, 107 | s_remote_cnt integer, 108 | s_data varchar(50), 109 | s_dist_01 char(24), 110 | s_dist_02 char(24), 111 | s_dist_03 char(24), 112 | s_dist_04 char(24), 113 | s_dist_05 char(24), 114 | s_dist_06 char(24), 115 | s_dist_07 char(24), 116 | s_dist_08 char(24), 117 | s_dist_09 char(24), 118 | s_dist_10 char(24) 119 | ) engine=innodb; 120 | 121 | 122 | create table benchmarksql.item ( 123 | i_id integer not null, 124 | i_name varchar(24), 125 | i_price decimal(5,2), 126 | i_data varchar(50), 127 | i_im_id integer 128 | ) engine=innodb; 129 | 130 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | ********************************************************************* 2 | Change Log: 3 | 4 | Version 4.1.1a 2018-04-26 xgu0 5 | - Changes to make it work with MySQL such as libraries config files etc. 6 | 7 | Version 4.1.1 2016-01-31 jannicash 8 | - Changed the status line to update only once per second. The previous 9 | implementation was getting rather noisy at high throughput. 10 | - Fixed two preparedStatement() leaks that could cause ORA-01000 errors 11 | on longer runs with high throughput. 12 | - Fixed a problem in the calculation of sleep time between 13 | transactions when using limitTxnsPerMin that could cause the test 14 | to hang at the end. 15 | - Added support for escaping ; as \; in SQL files to be able to load 16 | functions and execute anonymous PL blocks (needed for next item). 17 | - Changed the definition of history.hist_id into a plain integer with 18 | no special functionality. Two new database vendor specific SQL 19 | scripts allow to enable the column after data load as an auto 20 | incrementing primary key. See HOW-TO-RUN.txt for details. 21 | 22 | Version 4.1.0 2014-03-13 lussman 23 | - Upgrade to using JDK 7 24 | - Upgrade to PostgreSQL JDBC 4.1 version 1101 driver 25 | - Stop claiming to support DB2 (only Postgres & Oracle are well tested) 26 | 27 | Version 4.0.9 2013-11-04 cadym 28 | - Incorporate new PostgreSQL JDBC 4 version 1100 driver 29 | - Changed default user from postgres to benchmarksql 30 | - Added id column as primary key to history table 31 | - Renamed schema to benchmarksql 32 | - Changed log4j format to be more readable 33 | - Created the "benchmark" schema to contain all tables 34 | - Incorporate new PostgreSQL JDBC4 version 1003 driver 35 | - Transaction rate pacing mechanism 36 | - Correct error with loading customer table from csv file 37 | - Status line report dynamically shown on terminal 38 | - Fix lookup by name in PaymentStatus and Delivery Transactions 39 | (in order to be more compatible with the TPC-C spec) 40 | - Rationalized the variable naming in the input parameter files 41 | (now that the GUI is gone, variable names still make sense) 42 | - Default log4j settings only writes to file (not terminal) 43 | 44 | Version 4.0.2 2013-06-06 lussman & cadym 45 | - Removed Swing & AWT GUI so that this program is runnable from 46 | the command line 47 | - Remove log4j usage from runSQL & runLoader (only used now for 48 | the actual running of the Benchmark) 49 | - Fix truncation problem with customer.csv file 50 | - Comment out "BadCredit" business logic that was not working 51 | and throwing stack traces 52 | - Fix log4j messages to always show the terminal name 53 | - Remove bogus log4j messages 54 | 55 | Version 3.0.9 2013-03-21 lussman 56 | - Config log4j for rotating log files once per minute 57 | - Default flat file location to '/tmp/csv/' in 58 | table copies script 59 | - Drop incomplete & untested Windoze '.bat' scripts 60 | - Standardize logging with log4j 61 | - Improve Logging with meaningful DEBUG and INFO levels 62 | - Simplify "build.xml" to eliminate nbproject dependency 63 | - Defaults read in from propeerties 64 | - Groudwork laid to eliminate the GUI 65 | - Default GUI console to PostgreSQL and 10 Warehouses 66 | 67 | Version 2.3.5 2013-01-29 lussman 68 | - Default build is now with JDK 1.6 and JDBC 4 Postgres 9.2 driver 69 | - Remove outdated JDBC 3 drivers (for JDK 1.5). You can run as 70 | before by a JDBC4 driver from any supported vendor. 71 | - Remove ExecJDBC warning about trying to rollback when in 72 | autocommit mode 73 | - Remove the extraneous COMMIT statements from the DDL scripts 74 | since ExecJDBC runs in autocommit mode 75 | - Fix the version number displayed in the console 76 | 77 | Version 2.3.3 2010-11-19 sjm 78 | - Added DB2 LUW V9.7 support, and supercedes patch 2983892 79 | - No other changes from 2.3.2 80 | 81 | ********************************************************************* 82 | -------------------------------------------------------------------------------- /src/client/jTPCC.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jTPCC - Open Source Java implementation of a TPC-C like benchmark 3 | * 4 | * Copyright (C) 2003, Raul Barbosa 5 | * Copyright (C) 2004-2016, Denis Lussier 6 | * Copyright (C) 2016, Jan Wieck 7 | * 8 | */ 9 | 10 | import org.apache.log4j.*; 11 | 12 | import java.io.*; 13 | import java.sql.*; 14 | import java.util.*; 15 | import java.text.*; 16 | 17 | 18 | public class jTPCC implements jTPCCConfig 19 | { 20 | private static org.apache.log4j.Logger log = Logger.getLogger(jTPCC.class); 21 | 22 | private int currentlyDisplayedTerminal; 23 | 24 | private jTPCCTerminal[] terminals; 25 | private String[] terminalNames; 26 | private boolean terminalsBlockingExit = false; 27 | private Random random; 28 | private long terminalsStarted = 0, sessionCount = 0, transactionCount; 29 | 30 | private long newOrderCounter, sessionStartTimestamp, sessionEndTimestamp, sessionNextTimestamp=0, sessionNextKounter=0; 31 | private long sessionEndTargetTime = -1, fastNewOrderCounter, recentTpmC=0, recentTpmTotal=0; 32 | private boolean signalTerminalsRequestEndSent = false, databaseDriverLoaded = false; 33 | 34 | private FileOutputStream fileOutputStream; 35 | private PrintStream printStreamReport; 36 | private String sessionStart, sessionEnd; 37 | private int limPerMin_Terminal; 38 | 39 | private double tpmC; 40 | 41 | public static void main(String args[]) 42 | { 43 | PropertyConfigurator.configure("log4j.xml"); 44 | new jTPCC(); 45 | } 46 | 47 | private String getProp (Properties p, String pName) 48 | { 49 | String prop = p.getProperty(pName); 50 | log.info("Term-00, " + pName + "=" + prop); 51 | return(prop); 52 | } 53 | 54 | public jTPCC() 55 | { 56 | 57 | // load the ini file 58 | Properties ini = new Properties(); 59 | try { 60 | ini.load( new FileInputStream(System.getProperty("prop"))); 61 | } catch (IOException e) { 62 | errorMessage("Term-00, could not load properties file"); 63 | } 64 | 65 | 66 | log.info("Term-00, "); 67 | log.info("Term-00, +-------------------------------------------------------------+"); 68 | log.info("Term-00, BenchmarkSQL v" + JTPCCVERSION); 69 | log.info("Term-00, +-------------------------------------------------------------+"); 70 | log.info("Term-00, (c) 2003, Raul Barbosa"); 71 | log.info("Term-00, (c) 2004-2016, Denis Lussier"); 72 | log.info("Term-00, (c) 2016, Jan Wieck"); 73 | log.info("Term-00, +-------------------------------------------------------------+"); 74 | log.info("Term-00, "); 75 | String iDriver = getProp(ini,"driver"); 76 | String iConn = getProp(ini,"conn"); 77 | String iUser = getProp(ini,"user"); 78 | String iPassword = ini.getProperty("password"); 79 | 80 | 81 | log.info("Term-00, "); 82 | String iWarehouses = getProp(ini,"warehouses"); 83 | String iTerminals = getProp(ini,"terminals"); 84 | 85 | String iRunTxnsPerTerminal = ini.getProperty("runTxnsPerTerminal"); 86 | String iRunMins = ini.getProperty("runMins"); 87 | if (Integer.parseInt(iRunTxnsPerTerminal) ==0 && Integer.parseInt(iRunMins)!=0){ 88 | log.info("Term-00, runMins" + "=" + iRunMins); 89 | }else if(Integer.parseInt(iRunTxnsPerTerminal) !=0 && Integer.parseInt(iRunMins)==0){ 90 | log.info("Term-00, runTxnsPerTerminal" + "=" + iRunTxnsPerTerminal); 91 | }else{ 92 | errorMessage("Term-00, Must indicate either transactions per terminal or number of run minutes!"); 93 | }; 94 | String limPerMin = getProp(ini,"limitTxnsPerMin"); 95 | log.info("Term-00, "); 96 | String iNewOrderWeight = getProp(ini,"newOrderWeight"); 97 | String iPaymentWeight = getProp(ini,"paymentWeight"); 98 | String iOrderStatusWeight = getProp(ini,"orderStatusWeight"); 99 | String iDeliveryWeight = getProp(ini,"deliveryWeight"); 100 | String iStockLevelWeight = getProp(ini,"stockLevelWeight"); 101 | 102 | log.info("Term-00, "); 103 | 104 | if(Integer.parseInt(limPerMin) !=0){ 105 | limPerMin_Terminal = Integer.parseInt(limPerMin)/Integer.parseInt(iTerminals); 106 | } 107 | else{ 108 | limPerMin_Terminal = -1; 109 | } 110 | 111 | 112 | boolean iRunMinsBool=false; 113 | 114 | 115 | this.random = new Random(System.currentTimeMillis()); 116 | 117 | fastNewOrderCounter = 0; 118 | updateStatusLine(); 119 | 120 | try 121 | { 122 | String driver = iDriver; 123 | printMessage("Loading database driver: \'" + driver + "\'..."); 124 | Class.forName(iDriver); 125 | databaseDriverLoaded = true; 126 | } 127 | catch(Exception ex) 128 | { 129 | errorMessage("Unable to load the database driver!"); 130 | databaseDriverLoaded = false; 131 | } 132 | 133 | 134 | if(databaseDriverLoaded) 135 | { 136 | try 137 | { 138 | boolean limitIsTime = iRunMinsBool; 139 | int numTerminals = -1, transactionsPerTerminal = -1, numWarehouses = -1; 140 | int newOrderWeightValue = -1, paymentWeightValue = -1, orderStatusWeightValue = -1, deliveryWeightValue = -1, stockLevelWeightValue = -1; 141 | long executionTimeMillis = -1; 142 | 143 | try 144 | { 145 | if (Integer.parseInt(iRunMins) != 0 && Integer.parseInt(iRunTxnsPerTerminal) ==0) 146 | { 147 | iRunMinsBool = true; 148 | } 149 | else if (Integer.parseInt(iRunMins) == 0 && Integer.parseInt(iRunTxnsPerTerminal) !=0) 150 | { 151 | iRunMinsBool = false; 152 | } 153 | else 154 | { 155 | throw new NumberFormatException(); 156 | } 157 | } 158 | catch(NumberFormatException e1) 159 | { 160 | errorMessage("Must indicate either transactions per terminal or number of run minutes!"); 161 | throw new Exception(); 162 | } 163 | 164 | try 165 | { 166 | numWarehouses = Integer.parseInt(iWarehouses); 167 | if(numWarehouses <= 0) 168 | throw new NumberFormatException(); 169 | } 170 | catch(NumberFormatException e1) 171 | { 172 | errorMessage("Invalid number of warehouses!"); 173 | throw new Exception(); 174 | } 175 | 176 | try 177 | { 178 | numTerminals = Integer.parseInt(iTerminals); 179 | if(numTerminals <= 0 || numTerminals > 10*numWarehouses) 180 | throw new NumberFormatException(); 181 | } 182 | catch(NumberFormatException e1) 183 | { 184 | errorMessage("Invalid number of terminals!"); 185 | throw new Exception(); 186 | } 187 | 188 | 189 | 190 | if(Long.parseLong(iRunMins) != 0 && Integer.parseInt(iRunTxnsPerTerminal) == 0) 191 | { 192 | try 193 | { 194 | executionTimeMillis = Long.parseLong(iRunMins) * 60000; 195 | if(executionTimeMillis <= 0) 196 | throw new NumberFormatException(); 197 | } 198 | catch(NumberFormatException e1) 199 | { 200 | errorMessage("Invalid number of minutes!"); 201 | throw new Exception(); 202 | } 203 | } 204 | else 205 | { 206 | try 207 | { 208 | transactionsPerTerminal = Integer.parseInt(iRunTxnsPerTerminal); 209 | if(transactionsPerTerminal <= 0) 210 | throw new NumberFormatException(); 211 | } 212 | catch(NumberFormatException e1) 213 | { 214 | errorMessage("Invalid number of transactions per terminal!"); 215 | throw new Exception(); 216 | } 217 | } 218 | 219 | try 220 | { 221 | newOrderWeightValue = Integer.parseInt(iNewOrderWeight); 222 | paymentWeightValue = Integer.parseInt(iPaymentWeight); 223 | orderStatusWeightValue = Integer.parseInt(iOrderStatusWeight); 224 | deliveryWeightValue = Integer.parseInt(iDeliveryWeight); 225 | stockLevelWeightValue = Integer.parseInt(iStockLevelWeight); 226 | 227 | if(newOrderWeightValue < 0 ||paymentWeightValue < 0 || orderStatusWeightValue < 0 || deliveryWeightValue < 0 || stockLevelWeightValue < 0) 228 | throw new NumberFormatException(); 229 | else if(newOrderWeightValue == 0 && paymentWeightValue == 0 && orderStatusWeightValue == 0 && deliveryWeightValue == 0 && stockLevelWeightValue == 0) 230 | throw new NumberFormatException(); 231 | } 232 | catch(NumberFormatException e1) 233 | { 234 | errorMessage("Invalid number in mix percentage!"); 235 | throw new Exception(); 236 | } 237 | 238 | if(newOrderWeightValue + paymentWeightValue + orderStatusWeightValue + deliveryWeightValue + stockLevelWeightValue > 100) 239 | { 240 | errorMessage("Sum of mix percentage parameters exceeds 100%!"); 241 | throw new Exception(); 242 | } 243 | 244 | newOrderCounter = 0; 245 | printMessage("Session started!"); 246 | if(!limitIsTime) 247 | printMessage("Creating " + numTerminals + " terminal(s) with " + transactionsPerTerminal + " transaction(s) per terminal..."); 248 | else 249 | printMessage("Creating " + numTerminals + " terminal(s) with " + (executionTimeMillis/60000) + " minute(s) of execution..."); 250 | printMessage("Transaction Weights: " + newOrderWeightValue + "% New-Order, " + paymentWeightValue + "% Payment, " + orderStatusWeightValue + "% Order-Status, " + deliveryWeightValue + "% Delivery, " + stockLevelWeightValue + "% Stock-Level"); 251 | 252 | printMessage("Number of Terminals\t" + numTerminals); 253 | 254 | terminals = new jTPCCTerminal[numTerminals]; 255 | terminalNames = new String[numTerminals]; 256 | terminalsStarted = numTerminals; 257 | try 258 | { 259 | String database = iConn; 260 | String username = iUser; 261 | String password = iPassword; 262 | 263 | int[][] usedTerminals = new int[numWarehouses][10]; 264 | for(int i = 0; i < numWarehouses; i++) 265 | for(int j = 0; j < 10; j++) 266 | usedTerminals[i][j] = 0; 267 | 268 | for(int i = 0; i < numTerminals; i++) 269 | { 270 | int terminalWarehouseID; 271 | int terminalDistrictID; 272 | do 273 | { 274 | terminalWarehouseID = (int)randomNumber(1, numWarehouses); 275 | terminalDistrictID = (int)randomNumber(1, 10); 276 | } 277 | while(usedTerminals[terminalWarehouseID-1][terminalDistrictID-1] == 1); 278 | usedTerminals[terminalWarehouseID-1][terminalDistrictID-1] = 1; 279 | 280 | String terminalName = "Term-" + (i>=9 ? ""+(i+1) : "0"+(i+1)); 281 | Connection conn = null; 282 | printMessage("Creating database connection for " + terminalName + "..."); 283 | conn = DriverManager.getConnection(database, username, password); 284 | conn.setAutoCommit(false); 285 | 286 | jTPCCTerminal terminal = new jTPCCTerminal 287 | (terminalName, terminalWarehouseID, terminalDistrictID, conn, 288 | transactionsPerTerminal, paymentWeightValue, orderStatusWeightValue, 289 | deliveryWeightValue, stockLevelWeightValue, numWarehouses, limPerMin_Terminal, this); 290 | 291 | terminals[i] = terminal; 292 | terminalNames[i] = terminalName; 293 | printMessage(terminalName + "\t" + terminalWarehouseID); 294 | } 295 | 296 | sessionEndTargetTime = executionTimeMillis; 297 | signalTerminalsRequestEndSent = false; 298 | 299 | 300 | printMessage("Transaction\tWeight"); 301 | printMessage("% New-Order\t" + newOrderWeightValue); 302 | printMessage("% Payment\t" + paymentWeightValue); 303 | printMessage("% Order-Status\t" + orderStatusWeightValue); 304 | printMessage("% Delivery\t" + deliveryWeightValue); 305 | printMessage("% Stock-Level\t" + stockLevelWeightValue); 306 | 307 | printMessage("Transaction Number\tTerminal\tType\tExecution Time (ms)\t\tComment"); 308 | 309 | printMessage("Created " + numTerminals + " terminal(s) successfully!"); 310 | boolean dummvar = true; 311 | 312 | 313 | 314 | //^Create Terminals, Start Transactions v // 315 | 316 | if(dummvar==true){ 317 | sessionStart = getCurrentTime(); 318 | sessionStartTimestamp = System.currentTimeMillis(); 319 | sessionNextTimestamp = sessionStartTimestamp; 320 | if(sessionEndTargetTime != -1) 321 | sessionEndTargetTime += sessionStartTimestamp; 322 | 323 | synchronized(terminals) 324 | { 325 | printMessage("Starting all terminals..."); 326 | transactionCount = 1; 327 | for(int i = 0; i < terminals.length; i++) 328 | (new Thread(terminals[i])).start(); 329 | 330 | } 331 | 332 | printMessage("All terminals started executing " + sessionStart); 333 | } 334 | } 335 | 336 | catch(Exception e1) 337 | { 338 | errorMessage("This session ended with errors!"); 339 | printStreamReport.close(); 340 | fileOutputStream.close(); 341 | 342 | throw new Exception(); 343 | } 344 | 345 | } 346 | catch(Exception ex) 347 | { 348 | } 349 | } 350 | updateStatusLine(); 351 | } 352 | 353 | private void signalTerminalsRequestEnd(boolean timeTriggered) 354 | { 355 | synchronized(terminals) 356 | { 357 | if(!signalTerminalsRequestEndSent) 358 | { 359 | if(timeTriggered) 360 | printMessage("The time limit has been reached."); 361 | printMessage("Signalling all terminals to stop..."); 362 | signalTerminalsRequestEndSent = true; 363 | 364 | for(int i = 0; i < terminals.length; i++) 365 | if(terminals[i] != null) 366 | terminals[i].stopRunningWhenPossible(); 367 | 368 | printMessage("Waiting for all active transactions to end..."); 369 | } 370 | } 371 | } 372 | 373 | public void signalTerminalEnded(jTPCCTerminal terminal, long countNewOrdersExecuted) 374 | { 375 | synchronized(terminals) 376 | { 377 | boolean found = false; 378 | terminalsStarted--; 379 | for(int i = 0; i < terminals.length && !found; i++) 380 | { 381 | if(terminals[i] == terminal) 382 | { 383 | terminals[i] = null; 384 | terminalNames[i] = "(" + terminalNames[i] + ")"; 385 | newOrderCounter += countNewOrdersExecuted; 386 | found = true; 387 | } 388 | } 389 | } 390 | 391 | if(terminalsStarted == 0) 392 | { 393 | sessionEnd = getCurrentTime(); 394 | sessionEndTimestamp = System.currentTimeMillis(); 395 | sessionEndTargetTime = -1; 396 | printMessage("All terminals finished executing " + sessionEnd); 397 | endReport(); 398 | terminalsBlockingExit = false; 399 | printMessage("Session finished!"); 400 | } 401 | } 402 | 403 | public void signalTerminalEndedTransaction(String terminalName, String transactionType, long executionTime, String comment, int newOrder) 404 | { 405 | transactionCount++; 406 | fastNewOrderCounter += newOrder; 407 | 408 | if(sessionEndTargetTime != -1 && System.currentTimeMillis() > sessionEndTargetTime) 409 | { 410 | signalTerminalsRequestEnd(true); 411 | } 412 | 413 | updateStatusLine(); 414 | 415 | } 416 | 417 | private void endReport() 418 | { 419 | long currTimeMillis = System.currentTimeMillis(); 420 | long freeMem = Runtime.getRuntime().freeMemory() / (1024*1024); 421 | long totalMem = Runtime.getRuntime().totalMemory() / (1024*1024); 422 | double tpmC = (6000000*fastNewOrderCounter/(currTimeMillis - sessionStartTimestamp))/100.0; 423 | double tpmTotal = (6000000*transactionCount/(currTimeMillis - sessionStartTimestamp))/100.0; 424 | 425 | 426 | System.out.println(""); 427 | log.info("Term-00, "); 428 | log.info("Term-00, "); 429 | log.info("Term-00, Measured tpmC (NewOrders) = " + tpmC); 430 | log.info("Term-00, Measured tpmTOTAL = " + tpmTotal); 431 | log.info("Term-00, Session Start = " + sessionStart ); 432 | log.info("Term-00, Session End = " + sessionEnd); 433 | log.info("Term-00, Transaction Count = " + (transactionCount-1)); 434 | 435 | } 436 | 437 | private void printMessage(String message) 438 | { 439 | log.trace("Term-00, " + message); 440 | } 441 | 442 | private void errorMessage(String message) 443 | { 444 | log.error("Term-00, "+ message); 445 | } 446 | 447 | private void exit() 448 | { 449 | System.exit(0); 450 | } 451 | 452 | private long randomNumber(long min, long max) 453 | { 454 | return (long)(random.nextDouble() * (max-min+1) + min); 455 | } 456 | 457 | private String getCurrentTime() 458 | { 459 | return dateFormat.format(new java.util.Date()); 460 | } 461 | 462 | private String getFileNameSuffix() 463 | { 464 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); 465 | return dateFormat.format(new java.util.Date()); 466 | } 467 | 468 | synchronized private void updateStatusLine() 469 | { 470 | long currTimeMillis = System.currentTimeMillis(); 471 | 472 | if(currTimeMillis > sessionNextTimestamp) 473 | { 474 | StringBuilder informativeText = new StringBuilder(""); 475 | Formatter fmt = new Formatter(informativeText); 476 | double tpmC = (6000000*fastNewOrderCounter/(currTimeMillis - sessionStartTimestamp))/100.0; 477 | double tpmTotal = (6000000*transactionCount/(currTimeMillis - sessionStartTimestamp))/100.0; 478 | 479 | sessionNextTimestamp += 1000; /* update this every seconds */ 480 | 481 | fmt.format("Term-00, Running Average tpmTOTAL: %.2f", tpmTotal); 482 | 483 | /* XXX What is the meaning of these numbers? */ 484 | recentTpmC = (fastNewOrderCounter - sessionNextKounter) * 12; 485 | recentTpmTotal= (transactionCount-sessionNextKounter)*12; 486 | sessionNextKounter = fastNewOrderCounter; 487 | fmt.format(" Current tpmTOTAL: %d", recentTpmTotal); 488 | 489 | long freeMem = Runtime.getRuntime().freeMemory() / (1024*1024); 490 | long totalMem = Runtime.getRuntime().totalMemory() / (1024*1024); 491 | fmt.format(" Memory Usage: %dMB / %dMB ", (totalMem - freeMem), totalMem); 492 | 493 | System.out.print(informativeText); 494 | for (int count = 0; count < 1+informativeText.length(); count++) 495 | System.out.print("\b"); 496 | } 497 | } 498 | } 499 | -------------------------------------------------------------------------------- /src/LoadData/LoadData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2004-2016, Denis Lussier 3 | * 4 | * LoadData - Load Sample Data directly into database tables or create CSV files for 5 | * each table that can then be bulk loaded (again & again & again ...) :-) 6 | * 7 | * Two optional parameter sets for the command line: 8 | * 9 | * numWarehouses=9999 10 | * 11 | * fileLocation=/temp/csv/ 12 | * 13 | * "numWarehouses" defaults to "1" and when "fileLocation" is omitted the generated 14 | * data is loaded into the database tables directly. 15 | *************************************************************************************** 16 | */ 17 | 18 | import java.sql.*; 19 | import java.util.*; 20 | import java.io.*; 21 | import java.lang.Integer; 22 | 23 | public class LoadData implements jTPCCConfig { 24 | 25 | 26 | // *********** JDBC specific variables *********************** 27 | private static Connection conn = null; 28 | private static Statement stmt = null; 29 | private static java.sql.Timestamp sysdate = null; 30 | private static PreparedStatement custPrepStmt; 31 | private static PreparedStatement distPrepStmt; 32 | private static PreparedStatement histPrepStmt; 33 | private static PreparedStatement itemPrepStmt; 34 | private static PreparedStatement nworPrepStmt; 35 | private static PreparedStatement ordrPrepStmt; 36 | private static PreparedStatement orlnPrepStmt; 37 | private static PreparedStatement stckPrepStmt; 38 | private static PreparedStatement whsePrepStmt; 39 | 40 | // ********** general vars ********************************** 41 | private static java.util.Date now = null; 42 | private static java.util.Date startDate = null; 43 | private static java.util.Date endDate = null; 44 | 45 | private static Random gen; 46 | private static String dbType; 47 | private static int numWarehouses = 0; 48 | private static String fileLocation = ""; 49 | private static boolean outputFiles = false; 50 | private static PrintWriter out = null; 51 | private static long lastTimeMS = 0; 52 | 53 | 54 | public static void main(String[] args) { 55 | 56 | System.out.println("Starting BenchmarkSQL LoadData"); 57 | 58 | System.out.println("----------------- Initialization -------------------"); 59 | 60 | numWarehouses = configWhseCount; 61 | for (int i = 0; i < args.length; i++) 62 | { 63 | System.out.println(args[i]); 64 | String str = args[i]; 65 | if (str.toLowerCase().startsWith("numwarehouses")) 66 | { 67 | String val = args[i + 1]; 68 | numWarehouses = Integer.parseInt(val); 69 | } 70 | 71 | if (str.toLowerCase().startsWith("filelocation")) 72 | { 73 | fileLocation = args[i + 1]; 74 | outputFiles = true; 75 | } 76 | } 77 | 78 | 79 | if (outputFiles == false) { 80 | initJDBC(); 81 | } 82 | 83 | // seed the random number generator 84 | gen = new Random(System.currentTimeMillis()); 85 | 86 | 87 | //######################### MAINLINE ###################################### 88 | startDate = new java.util.Date(); 89 | System.out.println(""); 90 | System.out.println("------------- LoadData StartTime = " + startDate + 91 | "-------------"); 92 | 93 | long startTimeMS = new java.util.Date().getTime(); 94 | lastTimeMS = startTimeMS; 95 | 96 | System.out.println(""); 97 | long totalRows = loadWhse(numWarehouses); 98 | System.out.println(""); 99 | totalRows += loadItem(configItemCount); 100 | System.out.println(""); 101 | totalRows += loadStock(numWarehouses, configItemCount); 102 | System.out.println(""); 103 | totalRows += loadDist(numWarehouses, configDistPerWhse); 104 | System.out.println(""); 105 | totalRows += loadCust(numWarehouses, configDistPerWhse, configCustPerDist); 106 | System.out.println(""); 107 | totalRows += loadOrder(numWarehouses, configDistPerWhse, configCustPerDist); 108 | 109 | long runTimeMS = (new java.util.Date().getTime()) + 1 - startTimeMS; 110 | endDate = new java.util.Date(); 111 | System.out.println(""); 112 | System.out.println("------------- LoadJDBC Statistics --------------------"); 113 | System.out.println(" Start Time = " + startDate); 114 | System.out.println(" End Time = " + endDate); 115 | System.out.println(" Run Time = " + (int)runTimeMS/1000 + " Seconds"); 116 | System.out.println(" Rows Loaded = " + totalRows + " Rows"); 117 | System.out.println("Rows Per Second = " + (totalRows/(runTimeMS/1000)) + " Rows/Sec"); 118 | System.out.println("------------------------------------------------------"); 119 | 120 | //exit Cleanly 121 | try { 122 | if (outputFiles == false) 123 | { 124 | if (conn !=null) 125 | conn.close(); 126 | } 127 | } catch(SQLException se) { 128 | se.printStackTrace(); 129 | } // end try 130 | 131 | } // end main 132 | 133 | 134 | static void transRollback () { 135 | if (outputFiles == false) 136 | { 137 | try { 138 | conn.rollback(); 139 | } catch(SQLException se) { 140 | System.out.println(se.getMessage()); 141 | } 142 | } else { 143 | out.close(); 144 | } 145 | } 146 | 147 | 148 | static void transCommit() { 149 | if (outputFiles == false) 150 | { 151 | try { 152 | conn.commit(); 153 | } catch(SQLException se) { 154 | System.out.println(se.getMessage()); 155 | transRollback(); 156 | } 157 | } else { 158 | out.close(); 159 | } 160 | } 161 | 162 | 163 | static void initJDBC() { 164 | 165 | try { 166 | 167 | // load the ini file 168 | Properties ini = new Properties(); 169 | ini.load( new FileInputStream(System.getProperty("prop"))); 170 | 171 | // display the values we need 172 | System.out.println("driver=" + ini.getProperty("driver")); 173 | System.out.println("conn=" + ini.getProperty("conn")); 174 | System.out.println("user=" + ini.getProperty("user")); 175 | System.out.println("password=******"); 176 | 177 | // Register jdbcDriver 178 | Class.forName(ini.getProperty( "driver" )); 179 | 180 | // make connection 181 | conn = DriverManager.getConnection(ini.getProperty("conn"), 182 | ini.getProperty("user"),ini.getProperty("password")); 183 | conn.setAutoCommit(false); 184 | 185 | // Create Statement 186 | stmt = conn.createStatement(); 187 | 188 | distPrepStmt = conn.prepareStatement 189 | ("INSERT INTO benchmarksql.district " + 190 | " (d_id, d_w_id, d_ytd, d_tax, d_next_o_id, d_name, d_street_1, d_street_2, d_city, d_state, d_zip) " + 191 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); 192 | 193 | itemPrepStmt = conn.prepareStatement 194 | ("INSERT INTO benchmarksql.item " + 195 | " (i_id, i_name, i_price, i_data, i_im_id) " + 196 | "VALUES (?, ?, ?, ?, ?)"); 197 | 198 | custPrepStmt = conn.prepareStatement 199 | ("INSERT INTO benchmarksql.customer " + 200 | " (c_id, c_d_id, c_w_id, " + 201 | "c_discount, c_credit, c_last, c_first, c_credit_lim, " + 202 | "c_balance, c_ytd_payment, c_payment_cnt, c_delivery_cnt, " + 203 | "c_street_1, c_street_2, c_city, c_state, c_zip, " + 204 | "c_phone, c_since, c_middle, c_data) " + 205 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); 206 | 207 | histPrepStmt = conn.prepareStatement 208 | ("INSERT INTO benchmarksql.history " + 209 | " (hist_id, h_c_id, h_c_d_id, h_c_w_id, " + 210 | "h_d_id, h_w_id, " + 211 | "h_date, h_amount, h_data) " + 212 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); 213 | 214 | ordrPrepStmt = conn.prepareStatement 215 | ("INSERT INTO benchmarksql.oorder " + 216 | " (o_id, o_w_id, o_d_id, o_c_id, " + 217 | "o_carrier_id, o_ol_cnt, o_all_local, o_entry_d) " + 218 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); 219 | 220 | orlnPrepStmt = conn.prepareStatement 221 | ("INSERT INTO benchmarksql.order_line " + 222 | " (ol_w_id, ol_d_id, ol_o_id, " + 223 | "ol_number, ol_i_id, ol_delivery_d, " + 224 | "ol_amount, ol_supply_w_id, ol_quantity, ol_dist_info) " + 225 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); 226 | 227 | nworPrepStmt = conn.prepareStatement 228 | ("INSERT INTO benchmarksql.new_order " + 229 | " (no_w_id, no_d_id, no_o_id) " + 230 | "VALUES (?, ?, ?)"); 231 | 232 | stckPrepStmt = conn.prepareStatement 233 | ("INSERT INTO benchmarksql.stock " + 234 | " (s_i_id, s_w_id, s_quantity, s_ytd, s_order_cnt, s_remote_cnt, s_data, " + 235 | "s_dist_01, s_dist_02, s_dist_03, s_dist_04, s_dist_05, " + 236 | "s_dist_06, s_dist_07, s_dist_08, s_dist_09, s_dist_10) " + 237 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); 238 | 239 | whsePrepStmt = conn.prepareStatement 240 | ("INSERT INTO benchmarksql.warehouse " + 241 | " (w_id, w_ytd, w_tax, w_name, w_street_1, w_street_2, w_city, w_state, w_zip) " + 242 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); 243 | 244 | } catch(SQLException se) { 245 | System.out.println(se.getMessage()); 246 | transRollback(); 247 | 248 | } catch(Exception e) { 249 | e.printStackTrace(); 250 | transRollback(); 251 | 252 | } // end try 253 | 254 | } // end initJDBC() 255 | 256 | 257 | static int loadItem(int itemKount) { 258 | 259 | int k = 0; 260 | int t = 0; 261 | int randPct = 0; 262 | int len = 0; 263 | int startORIGINAL = 0; 264 | 265 | try { 266 | 267 | now = new java.util.Date(); 268 | t = itemKount; 269 | System.out.println("Start Item Load for " + t + " Items @ " + now + " ..."); 270 | 271 | if (outputFiles == true) 272 | { 273 | out = new PrintWriter(new FileOutputStream(fileLocation + "item.csv")); 274 | System.out.println("Writing Item file to: " + fileLocation + "item.csv"); 275 | } 276 | 277 | Item item = new Item(); 278 | 279 | for (int i=1; i <= itemKount; i++) { 280 | 281 | item.i_id = i; 282 | item.i_name = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(14,24,gen)); 283 | item.i_price = (float)(jTPCCUtil.randomNumber(100,10000,gen)/100.0); 284 | 285 | // i_data 286 | randPct = jTPCCUtil.randomNumber(1, 100, gen); 287 | len = jTPCCUtil.randomNumber(26, 50, gen); 288 | if ( randPct > 10 ) { 289 | // 90% of time i_data isa random string of length [26 .. 50] 290 | item.i_data = jTPCCUtil.randomStr(len); 291 | } else { 292 | // 10% of time i_data has "ORIGINAL" crammed somewhere in middle 293 | startORIGINAL = jTPCCUtil.randomNumber(2, (len - 8), gen); 294 | item.i_data = 295 | jTPCCUtil.randomStr(startORIGINAL - 1) + 296 | "ORIGINAL" + 297 | jTPCCUtil.randomStr(len - startORIGINAL - 9); 298 | } 299 | 300 | item.i_im_id = jTPCCUtil.randomNumber(1, 10000, gen); 301 | 302 | k++; 303 | 304 | if (outputFiles == false) 305 | { 306 | itemPrepStmt.setLong(1, item.i_id); 307 | itemPrepStmt.setString(2, item.i_name); 308 | itemPrepStmt.setDouble(3, item.i_price); 309 | itemPrepStmt.setString(4, item.i_data); 310 | itemPrepStmt.setLong(5, item.i_im_id); 311 | itemPrepStmt.addBatch(); 312 | 313 | if (( k % configCommitCount) == 0) { 314 | long tmpTime = new java.util.Date().getTime(); 315 | String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000) + " "; 316 | System.out.println(etStr.substring(0, 30) + " Writing record " + k + " of " + t); 317 | lastTimeMS = tmpTime; 318 | itemPrepStmt.executeBatch(); 319 | itemPrepStmt.clearBatch(); 320 | transCommit(); 321 | } 322 | } else { 323 | String str = ""; 324 | str = str + item.i_id + ","; 325 | str = str + item.i_name + ","; 326 | str = str + item.i_price + ","; 327 | str = str + item.i_data + ","; 328 | str = str + item.i_im_id; 329 | out.println(str); 330 | 331 | if (( k % configCommitCount) == 0) { 332 | long tmpTime = new java.util.Date().getTime(); 333 | String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000) + " "; 334 | System.out.println(etStr.substring(0, 30) + " Writing record " + k + " of " + t); 335 | lastTimeMS = tmpTime; 336 | } 337 | } 338 | 339 | } // end for 340 | 341 | long tmpTime = new java.util.Date().getTime(); 342 | String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000) + " "; 343 | System.out.println(etStr.substring(0, 30) + " Writing final records " + k + " of " + t); 344 | lastTimeMS = tmpTime; 345 | 346 | if (outputFiles == false) 347 | { 348 | itemPrepStmt.executeBatch(); 349 | } 350 | transCommit(); 351 | now = new java.util.Date(); 352 | System.out.println("End Item Load @ " + now); 353 | 354 | } catch(SQLException se) { 355 | System.out.println(se.getMessage()); 356 | transRollback(); 357 | } catch(Exception e) { 358 | e.printStackTrace(); 359 | transRollback(); 360 | } 361 | 362 | return(k); 363 | 364 | } // end loadItem() 365 | 366 | 367 | 368 | static int loadWhse(int whseKount) { 369 | 370 | try { 371 | 372 | now = new java.util.Date(); 373 | System.out.println("Start Whse Load for " + whseKount + " Whses @ " + now + " ..."); 374 | 375 | if (outputFiles == true) 376 | { 377 | out = new PrintWriter(new FileOutputStream(fileLocation + "warehouse.csv")); 378 | System.out.println("Writing Warehouse file to: " + fileLocation + "warehouse.csv"); 379 | } 380 | 381 | Warehouse warehouse = new Warehouse(); 382 | for (int i=1; i <= whseKount; i++) { 383 | 384 | warehouse.w_id = i; 385 | warehouse.w_ytd = 300000; 386 | 387 | // random within [0.0000 .. 0.2000] 388 | warehouse.w_tax = (float)((jTPCCUtil.randomNumber(0,2000,gen))/10000.0); 389 | 390 | warehouse.w_name = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(6,10,gen)); 391 | warehouse.w_street_1 = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10,20,gen)); 392 | warehouse.w_street_2 = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10,20,gen)); 393 | warehouse.w_city = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10,20,gen)); 394 | warehouse.w_state = jTPCCUtil.randomStr(3).toUpperCase(); 395 | warehouse.w_zip = "123456789"; 396 | 397 | if (outputFiles == false) 398 | { 399 | whsePrepStmt.setLong(1, warehouse.w_id); 400 | whsePrepStmt.setDouble(2, warehouse.w_ytd); 401 | whsePrepStmt.setDouble(3, warehouse.w_tax); 402 | whsePrepStmt.setString(4, warehouse.w_name); 403 | whsePrepStmt.setString(5, warehouse.w_street_1); 404 | whsePrepStmt.setString(6, warehouse.w_street_2); 405 | whsePrepStmt.setString(7, warehouse.w_city); 406 | whsePrepStmt.setString(8, warehouse.w_state); 407 | whsePrepStmt.setString(9, warehouse.w_zip); 408 | whsePrepStmt.executeUpdate(); 409 | } else { 410 | String str = ""; 411 | str = str + warehouse.w_id + ","; 412 | str = str + warehouse.w_ytd + ","; 413 | str = str + warehouse.w_tax + ","; 414 | str = str + warehouse.w_name + ","; 415 | str = str + warehouse.w_street_1 + ","; 416 | str = str + warehouse.w_street_2 + ","; 417 | str = str + warehouse.w_city + ","; 418 | str = str + warehouse.w_state + ","; 419 | str = str + warehouse.w_zip; 420 | out.println(str); 421 | } 422 | 423 | } // end for 424 | 425 | transCommit(); 426 | now = new java.util.Date(); 427 | 428 | long tmpTime = new java.util.Date().getTime(); 429 | System.out.println("Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000)); 430 | lastTimeMS = tmpTime; 431 | System.out.println("End Whse Load @ " + now); 432 | 433 | } catch(SQLException se) { 434 | System.out.println(se.getMessage()); 435 | transRollback(); 436 | } catch(Exception e) { 437 | e.printStackTrace(); 438 | transRollback(); 439 | } 440 | 441 | return (whseKount); 442 | 443 | } // end loadWhse() 444 | 445 | 446 | 447 | static int loadStock(int whseKount, int itemKount) { 448 | 449 | int k = 0; 450 | int t = 0; 451 | int randPct = 0; 452 | int len = 0; 453 | int startORIGINAL = 0; 454 | 455 | try { 456 | 457 | now = new java.util.Date(); 458 | t = (whseKount * itemKount); 459 | System.out.println("Start Stock Load for " + t + " units @ " + now + " ..."); 460 | 461 | if (outputFiles == true) 462 | { 463 | out = new PrintWriter(new FileOutputStream(fileLocation + "stock.csv")); 464 | System.out.println("Writing Stock file to: " + fileLocation + "stock.csv"); 465 | } 466 | 467 | Stock stock = new Stock(); 468 | 469 | for (int i=1; i <= itemKount; i++) { 470 | 471 | for (int w=1; w <= whseKount; w++) { 472 | 473 | stock.s_i_id = i; 474 | stock.s_w_id = w; 475 | stock.s_quantity = jTPCCUtil.randomNumber(10, 100, gen); 476 | stock.s_ytd = 0; 477 | stock.s_order_cnt = 0; 478 | stock.s_remote_cnt = 0; 479 | 480 | // s_data 481 | randPct = jTPCCUtil.randomNumber(1, 100, gen); 482 | len = jTPCCUtil.randomNumber(26, 50, gen); 483 | if ( randPct > 10 ) { 484 | // 90% of time i_data isa random string of length [26 .. 50] 485 | stock.s_data = jTPCCUtil.randomStr(len); 486 | } else { 487 | // 10% of time i_data has "ORIGINAL" crammed somewhere in middle 488 | startORIGINAL = jTPCCUtil.randomNumber(2, (len - 8), gen); 489 | stock.s_data = 490 | jTPCCUtil.randomStr(startORIGINAL - 1) + 491 | "ORIGINAL" + 492 | jTPCCUtil.randomStr(len - startORIGINAL - 9); 493 | } 494 | 495 | stock.s_dist_01 = jTPCCUtil.randomStr(24); 496 | stock.s_dist_02 = jTPCCUtil.randomStr(24); 497 | stock.s_dist_03 = jTPCCUtil.randomStr(24); 498 | stock.s_dist_04 = jTPCCUtil.randomStr(24); 499 | stock.s_dist_05 = jTPCCUtil.randomStr(24); 500 | stock.s_dist_06 = jTPCCUtil.randomStr(24); 501 | stock.s_dist_07 = jTPCCUtil.randomStr(24); 502 | stock.s_dist_08 = jTPCCUtil.randomStr(24); 503 | stock.s_dist_09 = jTPCCUtil.randomStr(24); 504 | stock.s_dist_10 = jTPCCUtil.randomStr(24); 505 | 506 | k++; 507 | if (outputFiles == false) 508 | { 509 | stckPrepStmt.setLong(1, stock.s_i_id); 510 | stckPrepStmt.setLong(2, stock.s_w_id); 511 | stckPrepStmt.setDouble(3, stock.s_quantity); 512 | stckPrepStmt.setDouble(4, stock.s_ytd); 513 | stckPrepStmt.setLong(5, stock.s_order_cnt); 514 | stckPrepStmt.setLong(6, stock.s_remote_cnt); 515 | stckPrepStmt.setString(7, stock.s_data); 516 | stckPrepStmt.setString(8, stock.s_dist_01); 517 | stckPrepStmt.setString(9, stock.s_dist_02); 518 | stckPrepStmt.setString(10, stock.s_dist_03); 519 | stckPrepStmt.setString(11, stock.s_dist_04); 520 | stckPrepStmt.setString(12, stock.s_dist_05); 521 | stckPrepStmt.setString(13, stock.s_dist_06); 522 | stckPrepStmt.setString(14, stock.s_dist_07); 523 | stckPrepStmt.setString(15, stock.s_dist_08); 524 | stckPrepStmt.setString(16, stock.s_dist_09); 525 | stckPrepStmt.setString(17, stock.s_dist_10); 526 | stckPrepStmt.addBatch(); 527 | if (( k % configCommitCount) == 0) { 528 | long tmpTime = new java.util.Date().getTime(); 529 | String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000) + " "; 530 | System.out.println(etStr.substring(0, 30) + " Writing record " + k + " of " + t); 531 | lastTimeMS = tmpTime; 532 | stckPrepStmt.executeBatch(); 533 | stckPrepStmt.clearBatch(); 534 | transCommit(); 535 | } 536 | } else { 537 | String str = ""; 538 | str = str + stock.s_i_id + ","; 539 | str = str + stock.s_w_id + ","; 540 | str = str + stock.s_quantity + ","; 541 | str = str + stock.s_ytd + ","; 542 | str = str + stock.s_order_cnt + ","; 543 | str = str + stock.s_remote_cnt + ","; 544 | str = str + stock.s_data + ","; 545 | str = str + stock.s_dist_01 + ","; 546 | str = str + stock.s_dist_02 + ","; 547 | str = str + stock.s_dist_03 + ","; 548 | str = str + stock.s_dist_04 + ","; 549 | str = str + stock.s_dist_05 + ","; 550 | str = str + stock.s_dist_06 + ","; 551 | str = str + stock.s_dist_07 + ","; 552 | str = str + stock.s_dist_08 + ","; 553 | str = str + stock.s_dist_09 + ","; 554 | str = str + stock.s_dist_10; 555 | out.println(str); 556 | 557 | if (( k % configCommitCount) == 0) { 558 | long tmpTime = new java.util.Date().getTime(); 559 | String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000) + " "; 560 | System.out.println(etStr.substring(0, 30) + " Writing record " + k + " of " + t); 561 | lastTimeMS = tmpTime; 562 | } 563 | } 564 | 565 | } // end for [w] 566 | 567 | } // end for [i] 568 | 569 | 570 | long tmpTime = new java.util.Date().getTime(); 571 | String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000) + " "; 572 | System.out.println(etStr.substring(0, 30) + " Writing final records " + k + " of " + t); 573 | lastTimeMS = tmpTime; 574 | if (outputFiles == false) 575 | { 576 | stckPrepStmt.executeBatch(); 577 | } 578 | transCommit(); 579 | 580 | now = new java.util.Date(); 581 | System.out.println("End Stock Load @ " + now); 582 | 583 | } catch(SQLException se) { 584 | System.out.println(se.getMessage()); 585 | transRollback(); 586 | 587 | } catch(Exception e) { 588 | e.printStackTrace(); 589 | transRollback(); 590 | } 591 | 592 | return (k); 593 | 594 | } // end loadStock() 595 | 596 | 597 | 598 | static int loadDist(int whseKount, int distWhseKount) { 599 | 600 | int k = 0; 601 | int t = 0; 602 | 603 | try { 604 | 605 | now = new java.util.Date(); 606 | 607 | if (outputFiles == true) 608 | { 609 | out = new PrintWriter(new FileOutputStream(fileLocation + "district.csv")); 610 | System.out.println("Writing District file to: " + fileLocation + "district.csv"); 611 | } 612 | 613 | District district = new District(); 614 | 615 | t = (whseKount * distWhseKount); 616 | System.out.println("Start District Data for " + t + " Dists @ " + now + " ..."); 617 | 618 | for (int w=1; w <= whseKount; w++) { 619 | 620 | for (int d=1; d <= distWhseKount; d++) { 621 | 622 | district.d_id = d; 623 | district.d_w_id = w; 624 | district.d_ytd = 30000; 625 | 626 | // random within [0.0000 .. 0.2000] 627 | district.d_tax = (float)((jTPCCUtil.randomNumber(0,2000,gen))/10000.0); 628 | 629 | district.d_next_o_id = 3001; 630 | district.d_name = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(6,10,gen)); 631 | district.d_street_1 = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10,20,gen)); 632 | district.d_street_2 = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10,20,gen)); 633 | district.d_city = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10,20,gen)); 634 | district.d_state = jTPCCUtil.randomStr(3).toUpperCase(); 635 | district.d_zip = "123456789"; 636 | 637 | k++; 638 | if (outputFiles == false) 639 | { 640 | distPrepStmt.setLong(1, district.d_id); 641 | distPrepStmt.setLong(2, district.d_w_id); 642 | distPrepStmt.setDouble(3, district.d_ytd); 643 | distPrepStmt.setDouble(4, district.d_tax); 644 | distPrepStmt.setLong(5, district.d_next_o_id); 645 | distPrepStmt.setString(6, district.d_name); 646 | distPrepStmt.setString(7, district.d_street_1); 647 | distPrepStmt.setString(8, district.d_street_2); 648 | distPrepStmt.setString(9, district.d_city); 649 | distPrepStmt.setString(10, district.d_state); 650 | distPrepStmt.setString(11, district.d_zip); 651 | distPrepStmt.executeUpdate(); 652 | } else { 653 | String str = ""; 654 | str = str + district.d_id + ","; 655 | str = str + district.d_w_id + ","; 656 | str = str + district.d_ytd + ","; 657 | str = str + district.d_tax + ","; 658 | str = str + district.d_next_o_id + ","; 659 | str = str + district.d_name + ","; 660 | str = str + district.d_street_1 + ","; 661 | str = str + district.d_street_2 + ","; 662 | str = str + district.d_city + ","; 663 | str = str + district.d_state + ","; 664 | str = str + district.d_zip; 665 | out.println(str); 666 | } 667 | 668 | } // end for [d] 669 | 670 | } // end for [w] 671 | 672 | long tmpTime = new java.util.Date().getTime(); 673 | String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000) + " "; 674 | System.out.println(etStr.substring(0, 30) + " Writing record " + k + " of " + t); 675 | lastTimeMS = tmpTime; 676 | transCommit(); 677 | now = new java.util.Date(); 678 | System.out.println("End District Load @ " + now); 679 | 680 | } 681 | catch(SQLException se) { 682 | System.out.println(se.getMessage()); 683 | transRollback(); 684 | } 685 | catch(Exception e) { 686 | e.printStackTrace(); 687 | transRollback(); 688 | } 689 | 690 | return (k); 691 | 692 | } // end loadDist() 693 | 694 | 695 | 696 | static int loadCust(int whseKount, int distWhseKount, int custDistKount) { 697 | 698 | int k = 0; 699 | int t = 0; 700 | int i = 1; 701 | double cCreditLim = 0; 702 | Customer customer = new Customer(); 703 | History history = new History(); 704 | PrintWriter outHist = null; 705 | 706 | try { 707 | 708 | now = new java.util.Date(); 709 | 710 | if (outputFiles == true) 711 | { 712 | out = new PrintWriter(new FileOutputStream(fileLocation + "customer.csv")); 713 | System.out.println("Writing Customer file to: " + fileLocation + "customer.csv"); 714 | outHist = new PrintWriter(new FileOutputStream(fileLocation + "cust-hist.csv")); 715 | System.out.println("Writing Customer History file to: " + fileLocation + "cust-hist.csv"); 716 | } 717 | 718 | t = (whseKount * distWhseKount * custDistKount * 2); 719 | System.out.println("Start Cust-Hist Load for " + t + " Cust-Hists @ " + now + " ..."); 720 | 721 | for (int w=1; w <= whseKount; w++) { 722 | 723 | for (int d=1; d <= distWhseKount; d++) { 724 | 725 | for (int c=1; c <= custDistKount; c++) { 726 | 727 | sysdate = new java.sql.Timestamp(System.currentTimeMillis()); 728 | 729 | customer.c_id = c; 730 | customer.c_d_id = d; 731 | customer.c_w_id = w; 732 | 733 | // discount is random between [0.0000 ... 0.5000] 734 | customer.c_discount = 735 | (float)(jTPCCUtil.randomNumber(1,5000,gen) / 10000.0); 736 | 737 | if (jTPCCUtil.randomNumber(1,100,gen) <= 90) { 738 | customer.c_credit = "BC"; // 10% Bad Credit 739 | } else { 740 | customer.c_credit = "GC"; // 90% Good Credit 741 | } 742 | //customer.c_credit = "GC"; 743 | 744 | customer.c_last = jTPCCUtil.getLastName(gen); 745 | customer.c_first = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(8,16,gen)); 746 | customer.c_credit_lim = 50000; 747 | 748 | customer.c_balance = -10; 749 | customer.c_ytd_payment = 10; 750 | customer.c_payment_cnt = 1; 751 | customer.c_delivery_cnt = 0; 752 | 753 | customer.c_street_1 = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10,20,gen)); 754 | customer.c_street_2 = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10,20,gen)); 755 | customer.c_city = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10,20,gen)); 756 | customer.c_state = jTPCCUtil.randomStr(3).toUpperCase(); 757 | customer.c_zip = "123456789"; 758 | 759 | customer.c_phone = "(732)744-1700"; 760 | 761 | customer.c_since = sysdate.getTime(); 762 | customer.c_middle = "OE"; 763 | customer.c_data = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(300,500,gen)); 764 | 765 | history.hist_id = i; 766 | i++; 767 | history.h_c_id = c; 768 | history.h_c_d_id = d; 769 | history.h_c_w_id = w; 770 | history.h_d_id = d; 771 | history.h_w_id = w; 772 | history.h_date = sysdate.getTime(); 773 | history.h_amount = 10; 774 | history.h_data = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10,24,gen)); 775 | 776 | k = k + 2; 777 | if (outputFiles == false) 778 | { 779 | custPrepStmt.setLong(1, customer.c_id); 780 | custPrepStmt.setLong(2, customer.c_d_id); 781 | custPrepStmt.setLong(3, customer.c_w_id); 782 | custPrepStmt.setDouble(4, customer.c_discount); 783 | custPrepStmt.setString(5, customer.c_credit); 784 | custPrepStmt.setString(6, customer.c_last); 785 | custPrepStmt.setString(7, customer.c_first); 786 | custPrepStmt.setDouble(8, customer.c_credit_lim); 787 | custPrepStmt.setDouble(9, customer.c_balance); 788 | custPrepStmt.setDouble(10, customer.c_ytd_payment); 789 | custPrepStmt.setDouble(11, customer.c_payment_cnt); 790 | custPrepStmt.setDouble(12, customer.c_delivery_cnt); 791 | custPrepStmt.setString(13, customer.c_street_1); 792 | custPrepStmt.setString(14, customer.c_street_2); 793 | custPrepStmt.setString(15, customer.c_city); 794 | custPrepStmt.setString(16, customer.c_state); 795 | custPrepStmt.setString(17, customer.c_zip); 796 | custPrepStmt.setString(18, customer.c_phone); 797 | 798 | Timestamp since = new Timestamp(customer.c_since); 799 | custPrepStmt.setTimestamp(19, since); 800 | custPrepStmt.setString(20, customer.c_middle); 801 | custPrepStmt.setString(21, customer.c_data); 802 | 803 | custPrepStmt.addBatch(); 804 | 805 | histPrepStmt.setInt(1, history.hist_id); 806 | histPrepStmt.setInt(2, history.h_c_id); 807 | histPrepStmt.setInt(3, history.h_c_d_id); 808 | histPrepStmt.setInt(4, history.h_c_w_id); 809 | 810 | histPrepStmt.setInt(5, history.h_d_id); 811 | histPrepStmt.setInt(6, history.h_w_id); 812 | Timestamp hdate = new Timestamp(history.h_date); 813 | histPrepStmt.setTimestamp(7, hdate); 814 | histPrepStmt.setDouble(8, history.h_amount); 815 | histPrepStmt.setString(9, history.h_data); 816 | 817 | histPrepStmt.addBatch(); 818 | 819 | 820 | if (( k % configCommitCount) == 0) { 821 | long tmpTime = new java.util.Date().getTime(); 822 | String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000) + " "; 823 | System.out.println(etStr.substring(0, 30) + " Writing record " + k + " of " + t); 824 | lastTimeMS = tmpTime; 825 | 826 | custPrepStmt.executeBatch(); 827 | histPrepStmt.executeBatch(); 828 | custPrepStmt.clearBatch(); 829 | custPrepStmt.clearBatch(); 830 | transCommit(); 831 | } 832 | } else { 833 | String str = ""; 834 | str = str + customer.c_id + ","; 835 | str = str + customer.c_d_id + ","; 836 | str = str + customer.c_w_id + ","; 837 | str = str + customer.c_discount + ","; 838 | str = str + customer.c_credit + ","; 839 | str = str + customer.c_last + ","; 840 | str = str + customer.c_first + ","; 841 | str = str + customer.c_credit_lim + ","; 842 | str = str + customer.c_balance + ","; 843 | str = str + customer.c_ytd_payment + ","; 844 | str = str + customer.c_payment_cnt + ","; 845 | str = str + customer.c_delivery_cnt + ","; 846 | str = str + customer.c_street_1 + ","; 847 | str = str + customer.c_street_2 + ","; 848 | str = str + customer.c_city + ","; 849 | str = str + customer.c_state + ","; 850 | str = str + customer.c_zip + ","; 851 | str = str + customer.c_phone +","; 852 | Timestamp since = new Timestamp(customer.c_since); 853 | str = str + since + ","; 854 | str = str + customer.c_middle + ","; 855 | str = str + customer.c_data; 856 | out.println(str); 857 | 858 | str = ""; 859 | str = str + history.hist_id + ","; 860 | str = str + history.h_c_id + ","; 861 | str = str + history.h_c_d_id + ","; 862 | str = str + history.h_c_w_id + ","; 863 | str = str + history.h_d_id + ","; 864 | str = str + history.h_w_id + ","; 865 | Timestamp hdate = new Timestamp(history.h_date); 866 | str = str + hdate + ","; 867 | str = str + history.h_amount + ","; 868 | str = str + history.h_data; 869 | outHist.println(str); 870 | 871 | if (( k % configCommitCount) == 0) { 872 | long tmpTime = new java.util.Date().getTime(); 873 | String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000) + " "; 874 | System.out.println(etStr.substring(0, 30) + " Writing record " + k + " of " + t); 875 | lastTimeMS = tmpTime; 876 | 877 | } 878 | } 879 | 880 | } // end for [c] 881 | 882 | } // end for [d] 883 | 884 | } // end for [w] 885 | 886 | 887 | 888 | long tmpTime = new java.util.Date().getTime(); 889 | String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000) + " "; 890 | System.out.println(etStr.substring(0, 30) + " Writing record " + k + " of " + t); 891 | lastTimeMS = tmpTime; 892 | if (outputFiles == true) { 893 | out.close(); 894 | outHist.close(); 895 | } else { 896 | custPrepStmt.executeBatch(); 897 | histPrepStmt.executeBatch(); 898 | transCommit(); 899 | } 900 | 901 | now = new java.util.Date(); 902 | System.out.println("End Cust-Hist Data Load @ " + now); 903 | 904 | } catch(SQLException se) { 905 | System.out.println(se.getMessage()); 906 | transRollback(); 907 | if (outputFiles == true) { 908 | out.close(); 909 | outHist.close(); 910 | } 911 | } catch(Exception e) { 912 | e.printStackTrace(); 913 | transRollback(); 914 | if (outputFiles == true) { 915 | out.close(); 916 | outHist.close(); 917 | } 918 | } 919 | 920 | return(k); 921 | 922 | } // end loadCust() 923 | 924 | 925 | 926 | static int loadOrder(int whseKount, int distWhseKount, int custDistKount) { 927 | 928 | int k = 0; 929 | int t = 0; 930 | PrintWriter outO = null; 931 | PrintWriter outLine = null; 932 | PrintWriter outNewOrder = null; 933 | 934 | try { 935 | 936 | if (outputFiles == true) 937 | { 938 | outO = new PrintWriter(new FileOutputStream(fileLocation + "order.csv")); 939 | System.out.println("Writing Order file to: " + fileLocation + "order.csv"); 940 | outLine = new PrintWriter(new FileOutputStream(fileLocation + "order-line.csv")); 941 | System.out.println("Writing OrderLine file to: " + fileLocation + "order-line.csv"); 942 | outNewOrder = new PrintWriter(new FileOutputStream(fileLocation + "new-order.csv")); 943 | System.out.println("Writing NewOrder file to: " + fileLocation + "new-order.csv"); 944 | } 945 | 946 | now = new java.util.Date(); 947 | Oorder oorder = new Oorder(); 948 | NewOrder new_order = new NewOrder(); 949 | OrderLine order_line = new OrderLine(); 950 | jdbcIO myJdbcIO = new jdbcIO(); 951 | 952 | t = (whseKount * distWhseKount * custDistKount); 953 | t = (t * 11) + (t / 3); 954 | System.out.println("whse=" + whseKount +", dist=" + distWhseKount + 955 | ", cust=" + custDistKount); 956 | System.out.println("Start Order-Line-New Load for approx " + 957 | t + " rows @ " + now + " ..."); 958 | 959 | for (int w=1; w <= whseKount; w++) { 960 | 961 | for (int d=1; d <= distWhseKount; d++) { 962 | 963 | for (int c=1; c <= custDistKount; c++) { 964 | 965 | oorder.o_id = c; 966 | oorder.o_w_id = w; 967 | oorder.o_d_id = d; 968 | oorder.o_c_id = jTPCCUtil.randomNumber(1, custDistKount, gen); 969 | oorder.o_carrier_id = jTPCCUtil.randomNumber(1, 10, gen); 970 | oorder.o_ol_cnt = jTPCCUtil.randomNumber(5, 15, gen); 971 | oorder.o_all_local = 1; 972 | oorder.o_entry_d = System.currentTimeMillis(); 973 | 974 | k++; 975 | if (outputFiles == false) 976 | { 977 | myJdbcIO.insertOrder(ordrPrepStmt, oorder); 978 | } else { 979 | String str = ""; 980 | str = str + oorder.o_id + ","; 981 | str = str + oorder.o_w_id + ","; 982 | str = str + oorder.o_d_id + ","; 983 | str = str + oorder.o_c_id + ","; 984 | str = str + oorder.o_carrier_id + ","; 985 | str = str + oorder.o_ol_cnt + ","; 986 | str = str + oorder.o_all_local + ","; 987 | Timestamp entry_d = new java.sql.Timestamp(oorder.o_entry_d); 988 | str = str + entry_d; 989 | outO.println(str); 990 | } 991 | 992 | // 900 rows in the NEW-ORDER table corresponding to the last 993 | // 900 rows in the ORDER table for that district (i.e., with 994 | // NO_O_ID between 2,101 and 3,000) 995 | 996 | if (c > 2100 ) { 997 | 998 | new_order.no_w_id = w; 999 | new_order.no_d_id = d; 1000 | new_order.no_o_id = c; 1001 | 1002 | k++; 1003 | if (outputFiles == false) 1004 | { 1005 | myJdbcIO.insertNewOrder(nworPrepStmt, new_order); 1006 | } else { 1007 | String str = ""; 1008 | str = str + new_order.no_w_id+ ","; 1009 | str = str + new_order.no_d_id+ ","; 1010 | str = str + new_order.no_o_id; 1011 | outNewOrder.println(str); 1012 | } 1013 | 1014 | 1015 | } // end new order 1016 | 1017 | for (int l=1; l <= oorder.o_ol_cnt; l++) { 1018 | 1019 | order_line.ol_w_id = w; 1020 | order_line.ol_d_id = d; 1021 | order_line.ol_o_id = c; 1022 | order_line.ol_number = l; // ol_number 1023 | order_line.ol_i_id = jTPCCUtil.randomNumber(1, 100000, gen); 1024 | order_line.ol_delivery_d = oorder.o_entry_d; 1025 | 1026 | if (order_line.ol_o_id < 2101) { 1027 | order_line.ol_amount = 0; 1028 | } else { 1029 | // random within [0.01 .. 9,999.99] 1030 | order_line.ol_amount = 1031 | (float)(jTPCCUtil.randomNumber(1, 999999, gen) / 100.0); 1032 | } 1033 | 1034 | order_line.ol_supply_w_id = jTPCCUtil.randomNumber(1, numWarehouses, gen); 1035 | order_line.ol_quantity = 5; 1036 | order_line.ol_dist_info = jTPCCUtil.randomStr(24); 1037 | 1038 | k++; 1039 | if (outputFiles == false) 1040 | { 1041 | myJdbcIO.insertOrderLine(orlnPrepStmt, order_line); 1042 | } else { 1043 | String str = ""; 1044 | str = str + order_line.ol_w_id + ","; 1045 | str = str + order_line.ol_d_id + ","; 1046 | str = str + order_line.ol_o_id + ","; 1047 | str = str + order_line.ol_number + ","; 1048 | str = str + order_line.ol_i_id + ","; 1049 | Timestamp delivery_d = new Timestamp(order_line.ol_delivery_d); 1050 | str = str + delivery_d + ","; 1051 | str = str + order_line.ol_amount + ","; 1052 | str = str + order_line.ol_supply_w_id + ","; 1053 | str = str + order_line.ol_quantity + ","; 1054 | str = str + order_line.ol_dist_info; 1055 | outLine.println(str); 1056 | } 1057 | 1058 | if (( k % configCommitCount) == 0) { 1059 | long tmpTime = new java.util.Date().getTime(); 1060 | String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000) + " "; 1061 | System.out.println(etStr.substring(0, 30) + " Writing record " + k + " of " + t); 1062 | lastTimeMS = tmpTime; 1063 | if (outputFiles == false) 1064 | { 1065 | ordrPrepStmt.executeBatch(); 1066 | nworPrepStmt.executeBatch(); 1067 | orlnPrepStmt.executeBatch(); 1068 | ordrPrepStmt.clearBatch(); 1069 | nworPrepStmt.clearBatch(); 1070 | orlnPrepStmt.clearBatch(); 1071 | transCommit(); 1072 | } 1073 | } 1074 | 1075 | } // end for [l] 1076 | 1077 | } // end for [c] 1078 | 1079 | } // end for [d] 1080 | 1081 | } // end for [w] 1082 | 1083 | 1084 | System.out.println(" Writing final records " + k + " of " + t); 1085 | 1086 | if (outputFiles == true) 1087 | { 1088 | outO.close(); 1089 | outLine.close(); 1090 | outNewOrder.close(); 1091 | } else { 1092 | ordrPrepStmt.executeBatch(); 1093 | nworPrepStmt.executeBatch(); 1094 | orlnPrepStmt.executeBatch(); 1095 | transCommit(); 1096 | } 1097 | now = new java.util.Date(); 1098 | System.out.println("End Orders Load @ " + now); 1099 | 1100 | } 1101 | catch(SQLException se) { 1102 | System.out.println(se.getMessage()); 1103 | transRollback(); 1104 | if (outputFiles == true) { 1105 | outO.close(); 1106 | outLine.close(); 1107 | outNewOrder.close(); 1108 | } 1109 | } 1110 | catch(Exception e) { 1111 | e.printStackTrace(); 1112 | transRollback(); 1113 | if (outputFiles == true) 1114 | { 1115 | outO.close(); 1116 | outLine.close(); 1117 | outNewOrder.close(); 1118 | } 1119 | } 1120 | 1121 | return(k); 1122 | 1123 | } // end loadOrder() 1124 | 1125 | } // end LoadData Class 1126 | -------------------------------------------------------------------------------- /src/client/jTPCCTerminal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * jTPCCTerminal - Terminal emulator code for jTPCC (transactions) 3 | * 4 | * Copyright (C) 2003, Raul Barbosa 5 | * Copyright (C) 2004-2016, Denis Lussier 6 | * Copyright (C) 2016, Jan Wieck 7 | * 8 | */ 9 | import org.apache.log4j.*; 10 | 11 | import java.io.*; 12 | import java.sql.*; 13 | import java.sql.Date; 14 | import java.util.*; 15 | import javax.swing.*; 16 | 17 | 18 | public class jTPCCTerminal implements jTPCCConfig, Runnable 19 | { 20 | private static org.apache.log4j.Logger log = Logger.getLogger(jTPCCTerminal.class); 21 | 22 | private String terminalName; 23 | private Connection conn = null; 24 | private Statement stmt = null; 25 | private Statement stmt1 = null; 26 | private ResultSet rs = null; 27 | private int terminalWarehouseID, terminalDistrictID; 28 | private int paymentWeight, orderStatusWeight, deliveryWeight, stockLevelWeight, limPerMin_Terminal; 29 | private jTPCC parent; 30 | private Random gen; 31 | 32 | private int transactionCount = 1, numTransactions, numWarehouses, newOrderCounter; 33 | private long totalTnxs = 1; 34 | private StringBuffer query = null; 35 | private int result = 0; 36 | private boolean stopRunningSignal = false; 37 | 38 | private PreparedStatement getNewName = null; 39 | //NewOrder Txn 40 | private PreparedStatement stmtGetCustWhse = null; 41 | private PreparedStatement stmtGetDist = null; 42 | private PreparedStatement stmtInsertNewOrder = null; 43 | private PreparedStatement stmtUpdateDist = null; 44 | private PreparedStatement stmtInsertOOrder = null; 45 | private PreparedStatement stmtGetItem = null; 46 | private PreparedStatement stmtGetStock = null; 47 | private PreparedStatement stmtUpdateStock = null; 48 | private PreparedStatement stmtInsertOrderLine = null; 49 | 50 | //Payment Txn 51 | private PreparedStatement payUpdateWhse = null; 52 | private PreparedStatement payGetWhse = null; 53 | private PreparedStatement payUpdateDist = null; 54 | private PreparedStatement payGetDist = null; 55 | private PreparedStatement payCountCust = null; 56 | private PreparedStatement payCursorCustByName = null; 57 | private PreparedStatement payGetCust = null; 58 | private PreparedStatement payGetCustCdata = null; 59 | private PreparedStatement payUpdateCustBalCdata = null; 60 | private PreparedStatement payUpdateCustBal = null; 61 | private PreparedStatement payInsertHist = null; 62 | 63 | //Order Status Txn 64 | private PreparedStatement ordStatCountCust = null; 65 | private PreparedStatement ordStatGetCust = null; 66 | private PreparedStatement ordStatGetNewestOrd = null; 67 | private PreparedStatement ordStatGetCustBal = null; 68 | private PreparedStatement ordStatGetOrder = null; 69 | private PreparedStatement ordStatGetOrderLines = null; 70 | 71 | //Delivery Txn 72 | private PreparedStatement delivGetOrderId = null; 73 | private PreparedStatement delivDeleteNewOrder = null; 74 | private PreparedStatement delivGetCustId = null; 75 | private PreparedStatement delivUpdateCarrierId = null; 76 | private PreparedStatement delivUpdateDeliveryDate = null; 77 | private PreparedStatement delivSumOrderAmount = null; 78 | private PreparedStatement delivUpdateCustBalDelivCnt = null; 79 | 80 | //Stock Level Txn 81 | private PreparedStatement stockGetDistOrderId = null; 82 | private PreparedStatement stockGetCountStock = null; 83 | 84 | long terminalStartTime = 0; 85 | long transactionEnd = 0; 86 | 87 | public jTPCCTerminal 88 | (String terminalName, int terminalWarehouseID, int terminalDistrictID, Connection conn, 89 | int numTransactions, int paymentWeight, int orderStatusWeight, 90 | int deliveryWeight, int stockLevelWeight, int numWarehouses, int limPerMin_Terminal, jTPCC parent) throws SQLException 91 | { 92 | this.terminalName = terminalName; 93 | this.conn = conn; 94 | this.stmt = conn.createStatement(); 95 | this.stmt.setMaxRows(200); 96 | this.stmt.setFetchSize(100); 97 | 98 | this.stmt1 = conn.createStatement(); 99 | this.stmt1.setMaxRows(1); 100 | 101 | this.terminalWarehouseID = terminalWarehouseID; 102 | this.terminalDistrictID = terminalDistrictID; 103 | this.parent = parent; 104 | this.numTransactions = numTransactions; 105 | this.paymentWeight = paymentWeight; 106 | this.orderStatusWeight = orderStatusWeight; 107 | this.deliveryWeight = deliveryWeight; 108 | this.stockLevelWeight = stockLevelWeight; 109 | this.numWarehouses = numWarehouses; 110 | this.newOrderCounter = 0; 111 | this.limPerMin_Terminal = limPerMin_Terminal; 112 | 113 | terminalMessage(""); 114 | terminalMessage("Terminal \'" + terminalName + "\' has WarehouseID=" + terminalWarehouseID + " and DistrictID=" + terminalDistrictID + "."); 115 | terminalStartTime = System.currentTimeMillis(); 116 | } 117 | 118 | public void run() 119 | { 120 | gen = new Random(System.currentTimeMillis() * conn.hashCode()); 121 | 122 | executeTransactions(numTransactions); 123 | try 124 | { 125 | printMessage(""); 126 | printMessage("Closing statement and connection..."); 127 | 128 | stmt.close(); 129 | conn.close(); 130 | } 131 | catch(Exception e) 132 | { 133 | printMessage(""); 134 | printMessage("An error occurred!"); 135 | logException(e); 136 | } 137 | 138 | printMessage(""); 139 | printMessage("Terminal \'" + terminalName + "\' finished after " + (transactionCount-1) + " transaction(s)."); 140 | 141 | parent.signalTerminalEnded(this, newOrderCounter); 142 | } 143 | 144 | public void stopRunningWhenPossible() 145 | { 146 | stopRunningSignal = true; 147 | printMessage(""); 148 | printMessage("Terminal received stop signal!"); 149 | printMessage("Finishing current transaction before exit..."); 150 | } 151 | 152 | private void executeTransactions(int numTransactions) 153 | { 154 | boolean stopRunning = false; 155 | 156 | if(numTransactions != -1) 157 | printMessage("Executing " + numTransactions + " transactions..."); 158 | else 159 | printMessage("Executing for a limited time..."); 160 | 161 | for(int i = 0; (i < numTransactions || numTransactions == -1) && !stopRunning; i++) 162 | { 163 | 164 | long transactionType = jTPCCUtil.randomNumber(1, 100, gen); 165 | int skippedDeliveries = 0, newOrder = 0; 166 | String transactionTypeName; 167 | 168 | long transactionStart = System.currentTimeMillis(); 169 | 170 | if(transactionType <= paymentWeight) 171 | { 172 | executeTransaction(PAYMENT); 173 | transactionTypeName = "Payment"; 174 | } 175 | else if(transactionType <= paymentWeight + stockLevelWeight) 176 | { 177 | executeTransaction(STOCK_LEVEL); 178 | transactionTypeName = "Stock-Level"; 179 | } 180 | else if(transactionType <= paymentWeight + stockLevelWeight + orderStatusWeight) 181 | { 182 | executeTransaction(ORDER_STATUS); 183 | transactionTypeName = "Order-Status"; 184 | } 185 | else if(transactionType <= paymentWeight + stockLevelWeight + orderStatusWeight + deliveryWeight) 186 | { 187 | skippedDeliveries = executeTransaction(DELIVERY); 188 | transactionTypeName = "Delivery"; 189 | } 190 | else 191 | { 192 | executeTransaction(NEW_ORDER); 193 | transactionTypeName = "New-Order"; 194 | newOrderCounter++; 195 | newOrder = 1; 196 | } 197 | 198 | long transactionEnd = System.currentTimeMillis(); 199 | 200 | if(!transactionTypeName.equals("Delivery")) 201 | { 202 | parent.signalTerminalEndedTransaction(this.terminalName, transactionTypeName, transactionEnd - transactionStart, null, newOrder); 203 | } 204 | else 205 | { 206 | parent.signalTerminalEndedTransaction(this.terminalName, transactionTypeName, transactionEnd - transactionStart, (skippedDeliveries == 0 ? "None" : "" + skippedDeliveries + " delivery(ies) skipped."), newOrder); 207 | } 208 | 209 | if(limPerMin_Terminal>0){ 210 | long elapse = transactionEnd-transactionStart; 211 | long timePerTx = 60000/limPerMin_Terminal; 212 | 213 | if(elapse 1) 247 | { 248 | supplierWarehouseIDs[i] = terminalWarehouseID; 249 | } 250 | else 251 | { 252 | do 253 | { 254 | supplierWarehouseIDs[i] = jTPCCUtil.randomNumber(1, numWarehouses, gen); 255 | } 256 | while(supplierWarehouseIDs[i] == terminalWarehouseID && numWarehouses > 1); 257 | allLocal = 0; 258 | } 259 | orderQuantities[i] = jTPCCUtil.randomNumber(1, 10, gen); 260 | } 261 | 262 | // we need to cause 1% of the new orders to be rolled back. 263 | if(jTPCCUtil.randomNumber(1, 100, gen) == 1) 264 | itemIDs[numItems-1] = -12345; 265 | 266 | terminalMessage(""); 267 | terminalMessage("Starting txn:" + terminalName + ":" + 268 | transactionCount + " (New-Order)"); 269 | newOrderTransaction(terminalWarehouseID, districtID, customerID, numItems, allLocal, itemIDs, supplierWarehouseIDs, orderQuantities); 270 | break; 271 | 272 | 273 | case PAYMENT: 274 | districtID = jTPCCUtil.randomNumber(1, 10, gen); 275 | 276 | int x = jTPCCUtil.randomNumber(1, 100, gen); 277 | int customerDistrictID; 278 | int customerWarehouseID; 279 | if(x <= 85) 280 | { 281 | customerDistrictID = districtID; 282 | customerWarehouseID = terminalWarehouseID; 283 | } 284 | else 285 | { 286 | customerDistrictID = jTPCCUtil.randomNumber(1, 10, gen); 287 | do 288 | { 289 | customerWarehouseID = jTPCCUtil.randomNumber(1, numWarehouses, gen); 290 | } 291 | while(customerWarehouseID == terminalWarehouseID && numWarehouses > 1); 292 | } 293 | 294 | int y = jTPCCUtil.randomNumber(1, 100, gen); 295 | boolean customerByName=false; 296 | String customerLastName = null; 297 | customerID = -1; 298 | if(y <= 60) 299 | { 300 | // 60% lookups by last name 301 | customerByName = true; 302 | customerLastName = jTPCCUtil.getLastName(gen); 303 | printMessage("Last name lookup = " + customerLastName); 304 | } 305 | else 306 | { 307 | // 40% lookups by customer ID 308 | customerByName = false; 309 | customerID = jTPCCUtil.getCustomerID(gen); 310 | } 311 | 312 | customerByName = false; 313 | customerID = jTPCCUtil.getCustomerID(gen); 314 | 315 | 316 | 317 | float paymentAmount = (float)(jTPCCUtil.randomNumber(100, 500000, gen)/100.0); 318 | 319 | terminalMessage(""); 320 | terminalMessage("Starting transaction #" + transactionCount + " (Payment)..."); 321 | paymentTransaction(terminalWarehouseID, customerWarehouseID, paymentAmount, districtID, customerDistrictID, customerID, customerLastName, customerByName); 322 | break; 323 | 324 | 325 | case STOCK_LEVEL: 326 | int threshold = jTPCCUtil.randomNumber(10, 20, gen); 327 | 328 | terminalMessage(""); 329 | terminalMessage("Starting transaction #" + transactionCount + " (Stock-Level)..."); 330 | stockLevelTransaction(terminalWarehouseID, terminalDistrictID, threshold); 331 | break; 332 | 333 | 334 | case ORDER_STATUS: 335 | districtID = jTPCCUtil.randomNumber(1, 10, gen); 336 | 337 | y = jTPCCUtil.randomNumber(1, 100, gen); 338 | customerByName=false; 339 | customerLastName = null; 340 | customerID = -1; 341 | 342 | 343 | customerID = jTPCCUtil.getCustomerID(gen); 344 | customerByName = false; 345 | 346 | 347 | 348 | terminalMessage(""); 349 | terminalMessage("Starting transaction #" + transactionCount + " (Order-Status)..."); 350 | orderStatusTransaction(terminalWarehouseID, districtID, customerID, customerLastName, customerByName); 351 | break; 352 | 353 | 354 | case DELIVERY: 355 | int orderCarrierID = jTPCCUtil.randomNumber(1, 10, gen); 356 | 357 | terminalMessage(""); 358 | terminalMessage("Starting transaction #" + transactionCount + " (Delivery)..."); 359 | result = deliveryTransaction(terminalWarehouseID, orderCarrierID); 360 | break; 361 | 362 | 363 | default: 364 | error("EMPTY-TYPE"); 365 | break; 366 | } 367 | transactionCount++; 368 | 369 | return result; 370 | } 371 | 372 | 373 | private int deliveryTransaction(int w_id, int o_carrier_id) 374 | { 375 | int d_id, no_o_id, c_id; 376 | float ol_total; 377 | int[] orderIDs; 378 | int skippedDeliveries = 0; 379 | boolean newOrderRemoved; 380 | 381 | Oorder oorder = new Oorder(); 382 | OrderLine order_line = new OrderLine(); 383 | NewOrder new_order = new NewOrder(); 384 | new_order.no_w_id = w_id; 385 | 386 | try 387 | { 388 | orderIDs = new int[10]; 389 | for(d_id = 1; d_id <= 10; d_id++) 390 | { 391 | new_order.no_d_id = d_id; 392 | 393 | do 394 | { 395 | no_o_id = -1; 396 | 397 | if (delivGetOrderId == null) { 398 | delivGetOrderId = conn.prepareStatement( 399 | "SELECT no_o_id FROM benchmarksql.new_order WHERE no_d_id = ?" + 400 | " AND no_w_id = ?" + 401 | " ORDER BY no_o_id ASC"); 402 | } 403 | 404 | delivGetOrderId.setInt(1, d_id); 405 | delivGetOrderId.setInt(2, w_id); 406 | 407 | rs = delivGetOrderId.executeQuery(); 408 | if (rs.next()) { 409 | no_o_id = rs.getInt("no_o_id"); 410 | } 411 | 412 | orderIDs[(int)d_id-1] = no_o_id; 413 | rs.close(); 414 | rs = null; 415 | 416 | newOrderRemoved = false; 417 | if(no_o_id != -1) 418 | { 419 | new_order.no_o_id = no_o_id; 420 | 421 | if (delivDeleteNewOrder == null) { 422 | delivDeleteNewOrder = conn.prepareStatement( 423 | "DELETE FROM benchmarksql.new_order" + 424 | " WHERE no_d_id = ?" + 425 | " AND no_w_id = ?" + 426 | " AND no_o_id = ?"); 427 | } 428 | 429 | delivDeleteNewOrder.setInt(1, d_id); 430 | delivDeleteNewOrder.setInt(2, w_id); 431 | delivDeleteNewOrder.setInt(3, no_o_id); 432 | 433 | result = delivDeleteNewOrder.executeUpdate(); 434 | if (result > 0) { 435 | newOrderRemoved = true; 436 | } 437 | 438 | } 439 | } 440 | while(no_o_id != -1 && !newOrderRemoved); 441 | 442 | 443 | if(no_o_id != -1) 444 | { 445 | if (delivGetCustId == null) { 446 | delivGetCustId = conn.prepareStatement( 447 | "SELECT o_c_id" + 448 | " FROM benchmarksql.oorder" + 449 | " WHERE o_id = ?" + 450 | " AND o_d_id = ?" + 451 | " AND o_w_id = ?"); 452 | } 453 | 454 | delivGetCustId.setInt(1, no_o_id); 455 | delivGetCustId.setInt(2, d_id); 456 | delivGetCustId.setInt(3, w_id); 457 | 458 | rs = delivGetCustId.executeQuery(); 459 | if (!rs.next()) { 460 | log.error("delivGetCustId() not found! " + 461 | "O_ID=" + no_o_id + " O_D_ID=" + d_id + " O_W_ID=" + w_id); 462 | } 463 | 464 | c_id = rs.getInt("o_c_id"); 465 | rs.close(); 466 | rs = null; 467 | 468 | if (delivUpdateCarrierId == null) { 469 | delivUpdateCarrierId = conn.prepareStatement( 470 | "UPDATE benchmarksql.oorder SET o_carrier_id = ?" + 471 | " WHERE o_id = ?" + 472 | " AND o_d_id = ?" + 473 | " AND o_w_id = ?"); 474 | } 475 | 476 | delivUpdateCarrierId.setInt(1, o_carrier_id); 477 | delivUpdateCarrierId.setInt(2, no_o_id); 478 | delivUpdateCarrierId.setInt(3, d_id); 479 | delivUpdateCarrierId.setInt(4, w_id); 480 | 481 | result = delivUpdateCarrierId.executeUpdate(); 482 | if (result != 1) { 483 | log.error("delivUpdateCarrierId() not found! " + 484 | "O_ID=" + no_o_id + " O_D_ID=" + d_id + " O_W_ID=" + w_id); 485 | } 486 | 487 | if (delivUpdateDeliveryDate == null) { 488 | delivUpdateDeliveryDate = conn.prepareStatement( 489 | "UPDATE benchmarksql.order_line SET ol_delivery_d = ?" + 490 | " WHERE ol_o_id = ?" + 491 | " AND ol_d_id = ?" + 492 | " AND ol_w_id = ?"); 493 | } 494 | 495 | delivUpdateDeliveryDate.setTimestamp(1, new Timestamp(System.currentTimeMillis())); 496 | delivUpdateDeliveryDate.setInt(2,no_o_id); 497 | delivUpdateDeliveryDate.setInt(3,d_id); 498 | delivUpdateDeliveryDate.setInt(4,w_id); 499 | 500 | result = delivUpdateDeliveryDate.executeUpdate(); 501 | if (result == 0) { 502 | log.error("delivUpdateDeliveryDate() not found! " + 503 | "OL_O_ID=" + no_o_id + " OL_D_ID=" + d_id + " OL_W_ID=" + w_id); 504 | } 505 | 506 | if (delivSumOrderAmount == null) { 507 | delivSumOrderAmount = conn.prepareStatement( 508 | "SELECT SUM(ol_amount) AS ol_total" + 509 | " FROM benchmarksql.order_line" + 510 | " WHERE ol_o_id = ?" + 511 | " AND ol_d_id = ?" + 512 | " AND ol_w_id = ?"); 513 | } 514 | 515 | delivSumOrderAmount.setInt(1, no_o_id); 516 | delivSumOrderAmount.setInt(2, d_id); 517 | delivSumOrderAmount.setInt(3, w_id); 518 | 519 | rs = delivSumOrderAmount.executeQuery(); 520 | if (!rs.next()) { 521 | log.error("delivSumOrderAmount() not found! " + 522 | "OL_O_ID=" + no_o_id + " OL_D_ID=" + d_id + " OL_W_ID=" + w_id); 523 | } 524 | 525 | ol_total = rs.getFloat("ol_total"); 526 | rs.close(); 527 | rs = null; 528 | 529 | if (delivUpdateCustBalDelivCnt == null) { 530 | delivUpdateCustBalDelivCnt = conn.prepareStatement( 531 | "UPDATE benchmarksql.customer SET c_balance = c_balance + ?" + 532 | ", c_delivery_cnt = c_delivery_cnt + 1" + 533 | " WHERE c_id = ?" + 534 | " AND c_d_id = ?" + 535 | " AND c_w_id = ?"); 536 | } 537 | 538 | delivUpdateCustBalDelivCnt.setFloat(1, ol_total); 539 | delivUpdateCustBalDelivCnt.setInt(2, c_id); 540 | delivUpdateCustBalDelivCnt.setInt(3, d_id); 541 | delivUpdateCustBalDelivCnt.setInt(4, w_id); 542 | 543 | result = delivUpdateCustBalDelivCnt.executeUpdate(); 544 | if (result == 0) { 545 | log.error("delivUpdateCustBalDelivCnt() not found! " + 546 | "C_ID=" + c_id + " C_W_ID=" + w_id + " C_D_ID=" + d_id); 547 | } 548 | } 549 | } 550 | 551 | conn.commit(); 552 | 553 | StringBuffer terminalMessage = new StringBuffer(); 554 | terminalMessage("+---------------------------- DELIVERY ---------------------------+"); 555 | terminalMessage(" Date: " + jTPCCUtil.getCurrentTime()); 556 | terminalMessage(" "); 557 | terminalMessage(" Warehouse: " + w_id); 558 | terminalMessage(" Carrier: " + o_carrier_id); 559 | terminalMessage(" "); 560 | terminalMessage(" Delivered Orders"); 561 | terminalMessage(" "); 562 | for(int i = 1; i <= 10; i++) 563 | { 564 | if(orderIDs[i-1] >= 0) 565 | { 566 | terminalMessage(" District " + (i < 10 ? " " : "") + i + ": Order number " + orderIDs[i-1] + " was delivered."); 567 | } 568 | else 569 | { 570 | terminalMessage(" District " + (i < 10 ? " " : "") + i + ": No orders to be delivered."); 571 | 572 | skippedDeliveries++; 573 | } 574 | } 575 | terminalMessage("+-----------------------------------------------------------------+"); 576 | } 577 | catch(Exception e) 578 | { 579 | error("DELIVERY"); 580 | logException(e); 581 | try 582 | { 583 | terminalMessage("Performing ROLLBACK..."); 584 | conn.rollback(); 585 | } 586 | catch(Exception e1) 587 | { 588 | error("DELIVERY-ROLLBACK"); 589 | logException(e1); 590 | } 591 | } 592 | 593 | return skippedDeliveries; 594 | } 595 | 596 | 597 | private void orderStatusTransaction(int w_id, int d_id, int c_id, String c_last, boolean c_by_name) 598 | { 599 | int namecnt, o_id = -1, o_carrier_id = -1; 600 | float c_balance; 601 | String c_first, c_middle; 602 | java.sql.Date entdate = null; 603 | Vector orderLines = new Vector (); 604 | 605 | 606 | try 607 | { 608 | if(c_by_name) 609 | { 610 | if (ordStatCountCust == null) { 611 | ordStatCountCust = conn.prepareStatement( 612 | "SELECT count(*) AS namecnt FROM benchmarksql.customer" + 613 | " WHERE c_last = ? AND c_d_id = ? AND c_w_id = ?"); 614 | } 615 | 616 | ordStatCountCust.setString(1, c_last); 617 | ordStatCountCust.setInt(2, d_id); 618 | ordStatCountCust.setInt(3, w_id); 619 | 620 | rs = ordStatCountCust.executeQuery(); 621 | if (!rs.next()) { 622 | log.error("ordStatCountCust() C_LAST=" + c_last + " C_D_ID=" + d_id + " C_W_ID=" + w_id); 623 | } 624 | 625 | namecnt = rs.getInt("namecnt"); 626 | rs.close(); 627 | rs = null; 628 | 629 | // pick the middle customer from the list of customers 630 | 631 | if (ordStatGetCust == null) { 632 | ordStatGetCust = conn.prepareStatement( 633 | "SELECT c_balance, c_first, c_middle, c_id FROM benchmarksql.customer" + 634 | " WHERE c_last = ?" + 635 | " AND c_d_id = ?" + 636 | " AND c_w_id = ?" + 637 | " ORDER BY c_w_id, c_d_id, c_last, c_first"); 638 | } 639 | 640 | ordStatGetCust.setString(1, c_last); 641 | ordStatGetCust.setInt(2, d_id); 642 | ordStatGetCust.setInt(3, w_id); 643 | String customerLastName; 644 | 645 | rs = ordStatGetCust.executeQuery(); 646 | if (!rs.next()) { 647 | error("Customer with these conditions does not exist"); 648 | customerLastName = jTPCCUtil.getLastName(gen); 649 | printMessage("New last name lookup = " + customerLastName); 650 | orderStatusTransaction(w_id, d_id, c_id, c_last, c_by_name); 651 | } 652 | 653 | if(namecnt%2 == 1) namecnt++; 654 | for(int i = 1; i < namecnt / 2; i++) rs.next(); 655 | c_id = rs.getInt("c_id"); 656 | c_first = rs.getString("c_first"); 657 | c_middle = rs.getString("c_middle"); 658 | c_balance = rs.getFloat("c_balance"); 659 | ordStatCountCust = null;////// 660 | rs.close(); 661 | rs = null; 662 | } else { 663 | 664 | if (ordStatGetCustBal == null) { 665 | ordStatGetCustBal = conn.prepareStatement( 666 | "SELECT c_balance, c_first, c_middle, c_last" + 667 | " FROM benchmarksql.customer" + 668 | " WHERE c_id = ?" + 669 | " AND c_d_id = ?" + 670 | " AND c_w_id = ?"); 671 | } 672 | 673 | ordStatGetCustBal.setInt(1, c_id); 674 | ordStatGetCustBal.setInt(2, d_id); 675 | ordStatGetCustBal.setInt(3, w_id); 676 | 677 | rs = ordStatGetCustBal.executeQuery(); 678 | if (!rs.next()) { 679 | log.error("ordStatGetCustBal() not found! C_ID=" + c_id + " C_D_ID=" + d_id + " C_W_ID=" + w_id); 680 | } 681 | 682 | c_last = rs.getString("c_last"); 683 | c_first = rs.getString("c_first"); 684 | c_middle = rs.getString("c_middle"); 685 | c_balance = rs.getFloat("c_balance"); 686 | rs.close(); 687 | rs = null; 688 | } 689 | 690 | // find the newest order for the customer 691 | 692 | if (ordStatGetNewestOrd == null) { 693 | ordStatGetNewestOrd = conn.prepareStatement( 694 | "SELECT MAX(o_id) AS maxorderid FROM benchmarksql.oorder" + 695 | " WHERE o_w_id = ?" + 696 | " AND o_d_id = ?" + 697 | " AND o_c_id = ?"); 698 | } 699 | ordStatGetNewestOrd.setInt(1, w_id); 700 | ordStatGetNewestOrd.setInt(2, d_id); 701 | ordStatGetNewestOrd.setInt(3, c_id); 702 | rs = ordStatGetNewestOrd.executeQuery(); 703 | 704 | if(rs.next()) 705 | { 706 | o_id = rs.getInt("maxorderid"); 707 | rs.close(); 708 | rs = null; 709 | 710 | // retrieve the carrier & order date for the most recent order. 711 | 712 | if (ordStatGetOrder == null) { 713 | ordStatGetOrder = conn.prepareStatement( 714 | "SELECT o_carrier_id, o_entry_d" + 715 | " FROM benchmarksql.oorder" + 716 | " WHERE o_w_id = ?" + 717 | " AND o_d_id = ?" + 718 | " AND o_c_id = ?" + 719 | " AND o_id = ?"); 720 | } 721 | ordStatGetOrder.setInt(1, w_id); 722 | ordStatGetOrder.setInt(2, d_id); 723 | ordStatGetOrder.setInt(3, c_id); 724 | ordStatGetOrder.setInt(4, o_id); 725 | rs = ordStatGetOrder.executeQuery(); 726 | 727 | if(rs.next()) 728 | { 729 | o_carrier_id = rs.getInt("o_carrier_id"); 730 | entdate = rs.getDate("o_entry_d"); 731 | } 732 | } 733 | rs.close(); 734 | rs = null; 735 | 736 | // retrieve the order lines for the most recent order 737 | 738 | if (ordStatGetOrderLines == null) { 739 | ordStatGetOrderLines = conn.prepareStatement( 740 | "SELECT ol_i_id, ol_supply_w_id, ol_quantity," + 741 | " ol_amount, ol_delivery_d" + 742 | " FROM benchmarksql.order_line" + 743 | " WHERE ol_o_id = ?" + 744 | " AND ol_d_id =?" + 745 | " AND ol_w_id = ?"); 746 | } 747 | ordStatGetOrderLines.setInt(1, o_id); 748 | ordStatGetOrderLines.setInt(2, d_id); 749 | ordStatGetOrderLines.setInt(3, w_id); 750 | rs = ordStatGetOrderLines.executeQuery(); 751 | 752 | while(rs.next()) 753 | { 754 | StringBuffer orderLine = new StringBuffer(); 755 | orderLine.append("["); 756 | orderLine.append(rs.getLong("ol_supply_w_id")); 757 | orderLine.append(" - "); 758 | orderLine.append(rs.getLong("ol_i_id")); 759 | orderLine.append(" - "); 760 | orderLine.append(rs.getLong("ol_quantity")); 761 | orderLine.append(" - "); 762 | orderLine.append(jTPCCUtil.formattedDouble(rs.getDouble("ol_amount"))); 763 | orderLine.append(" - "); 764 | if(rs.getDate("ol_delivery_d") != null) 765 | orderLine.append(rs.getDate("ol_delivery_d")); 766 | else 767 | orderLine.append("99-99-9999"); 768 | orderLine.append("]"); 769 | orderLines.add(orderLine.toString()); 770 | } 771 | rs.close(); 772 | rs = null; 773 | 774 | 775 | StringBuffer terminalMessage = new StringBuffer(); 776 | terminalMessage(""); 777 | terminalMessage("+-------------------------- ORDER-STATUS -------------------------+"); 778 | terminalMessage(" Date: " + jTPCCUtil.getCurrentTime()); 779 | terminalMessage(" "); 780 | terminalMessage(" Warehouse: " + w_id); 781 | terminalMessage(" District: " + d_id); 782 | terminalMessage(" "); 783 | terminalMessage(" Customer: " + c_id); 784 | terminalMessage(" Name: " + c_first + " " + c_middle + " " + c_last); 785 | terminalMessage(" Balance: " + c_balance); 786 | terminalMessage(""); 787 | if(o_id == -1) 788 | { 789 | terminalMessage(" Customer has no orders placed."); 790 | } 791 | else 792 | { 793 | terminalMessage(" Order-Number: " + o_id); 794 | terminalMessage(" Entry-Date: " + entdate); 795 | terminalMessage(" Carrier-Number: " + o_carrier_id); 796 | terminalMessage(""); 797 | if(orderLines.size() != 0) 798 | { 799 | terminalMessage(" [Supply_W - Item_ID - Qty - Amount - Delivery-Date]"); 800 | Enumeration orderLinesEnum = orderLines.elements(); 801 | while(orderLinesEnum.hasMoreElements()) 802 | { 803 | terminalMessage((String)orderLinesEnum.nextElement()); 804 | } 805 | } 806 | else 807 | { 808 | terminalMessage(" This Order has no Order-Lines."); 809 | } 810 | } 811 | terminalMessage("+-----------------------------------------------------------------+"); 812 | } 813 | catch(Exception e) 814 | { 815 | error("ORDER-STATUS"); 816 | logException(e); 817 | } 818 | } 819 | 820 | 821 | private void newOrderTransaction 822 | (int w_id, int d_id, int c_id, int o_ol_cnt, int o_all_local, int[] itemIDs, int[] supplierWarehouseIDs, int[] orderQuantities) 823 | { 824 | float c_discount, w_tax, d_tax = 0, i_price; 825 | int d_next_o_id, o_id = -1, s_quantity; 826 | String c_last = null, c_credit = null, i_name, i_data, s_data; 827 | String s_dist_01, s_dist_02, s_dist_03, s_dist_04, s_dist_05; 828 | String s_dist_06, s_dist_07, s_dist_08, s_dist_09, s_dist_10, ol_dist_info = null; 829 | float[] itemPrices = new float[o_ol_cnt]; 830 | float[] orderLineAmounts = new float[o_ol_cnt]; 831 | String[] itemNames = new String[o_ol_cnt]; 832 | int[] stockQuantities = new int[o_ol_cnt]; 833 | char[] brandGeneric = new char[o_ol_cnt]; 834 | int ol_supply_w_id, ol_i_id, ol_quantity; 835 | int s_remote_cnt_increment; 836 | float ol_amount, total_amount = 0; 837 | boolean newOrderRowInserted; 838 | 839 | Warehouse whse = new Warehouse(); 840 | Customer cust = new Customer(); 841 | District dist = new District(); 842 | NewOrder nwor = new NewOrder(); 843 | Oorder ordr = new Oorder(); 844 | OrderLine orln = new OrderLine(); 845 | Stock stck = new Stock(); 846 | Item item = new Item(); 847 | 848 | try { 849 | 850 | if (stmtGetCustWhse == null) { 851 | stmtGetCustWhse = conn.prepareStatement( 852 | "SELECT c_discount, c_last, c_credit, w_tax" + 853 | " FROM benchmarksql.customer, benchmarksql.warehouse" + 854 | " WHERE w_id = ? AND w_id = c_w_id" + 855 | " AND c_d_id = ? AND c_id = ?"); 856 | } 857 | 858 | stmtGetCustWhse.setInt(1, w_id); 859 | stmtGetCustWhse.setInt(2, d_id); 860 | stmtGetCustWhse.setInt(3, c_id); 861 | 862 | rs = stmtGetCustWhse.executeQuery(); 863 | if (!rs.next()) { 864 | log.error("stmtGetCustWhse() not found! " + "W_ID=" + w_id + " C_D_ID=" + d_id + " C_ID=" + c_id); 865 | } 866 | 867 | c_discount = rs.getFloat("c_discount"); 868 | c_last = rs.getString("c_last"); 869 | c_credit = rs.getString("c_credit"); 870 | w_tax = rs.getFloat("w_tax"); 871 | rs.close(); 872 | rs = null; 873 | 874 | newOrderRowInserted = false; 875 | while(!newOrderRowInserted) 876 | { 877 | 878 | if (stmtGetDist == null) { 879 | stmtGetDist = conn.prepareStatement( 880 | "SELECT d_next_o_id, d_tax FROM benchmarksql.district" + 881 | " WHERE d_id = ? AND d_w_id = ? FOR UPDATE"); 882 | } 883 | 884 | stmtGetDist.setInt(1, d_id); 885 | stmtGetDist.setInt(2, w_id); 886 | 887 | rs = stmtGetDist.executeQuery(); 888 | if (!rs.next()) { 889 | log.error("stmtGetDist() not found! " + "D_ID=" + d_id + " D_W_ID=" + w_id); 890 | } 891 | 892 | d_next_o_id = rs.getInt("d_next_o_id"); 893 | d_tax = rs.getFloat("d_tax"); 894 | rs.close(); 895 | rs = null; 896 | o_id = d_next_o_id; 897 | 898 | try 899 | { 900 | if (stmtInsertNewOrder == null) { 901 | stmtInsertNewOrder = conn.prepareStatement( 902 | "INSERT INTO benchmarksql.NEW_ORDER (no_o_id, no_d_id, no_w_id) " + 903 | "VALUES ( ?, ?, ?)"); 904 | } 905 | 906 | stmtInsertNewOrder.setInt(1, o_id); 907 | stmtInsertNewOrder.setInt(2, d_id); 908 | stmtInsertNewOrder.setInt(3, w_id); 909 | stmtInsertNewOrder.executeUpdate(); 910 | newOrderRowInserted = true; 911 | } 912 | catch(SQLException e2) 913 | { 914 | printMessage("The row was already on table new_order. Restarting..."); 915 | } 916 | } 917 | 918 | 919 | if (stmtUpdateDist == null) { 920 | stmtUpdateDist = conn.prepareStatement( 921 | "UPDATE benchmarksql.district SET d_next_o_id = d_next_o_id + 1 " + 922 | " WHERE d_id = ? AND d_w_id = ?"); 923 | } 924 | 925 | stmtUpdateDist.setInt(1,d_id); 926 | stmtUpdateDist.setInt(2,w_id); 927 | 928 | result = stmtUpdateDist.executeUpdate(); 929 | if (result == 0) { 930 | log.error("stmtUpdateDist() Cannot update next_order_id on DISTRICT for D_ID=" + d_id + " D_W_ID=" + w_id); 931 | } 932 | 933 | if (stmtInsertOOrder == null) { 934 | stmtInsertOOrder = conn.prepareStatement( 935 | "INSERT INTO benchmarksql.OORDER " + 936 | " (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_ol_cnt, o_all_local)" + 937 | " VALUES (?, ?, ?, ?, ?, ?, ?)"); 938 | } 939 | 940 | stmtInsertOOrder.setInt(1,o_id); 941 | stmtInsertOOrder.setInt(2,d_id); 942 | stmtInsertOOrder.setInt(3,w_id); 943 | stmtInsertOOrder.setInt(4,c_id); 944 | stmtInsertOOrder.setTimestamp(5, new Timestamp(System.currentTimeMillis())); 945 | stmtInsertOOrder.setInt(6,o_ol_cnt); 946 | stmtInsertOOrder.setInt(7,o_all_local); 947 | 948 | stmtInsertOOrder.executeUpdate(); 949 | 950 | for(int ol_number = 1; ol_number <= o_ol_cnt; ol_number++) { 951 | ol_supply_w_id = supplierWarehouseIDs[ol_number-1]; 952 | ol_i_id = itemIDs[ol_number-1]; 953 | ol_quantity = orderQuantities[ol_number-1]; 954 | 955 | if ( ol_i_id == -12345) { 956 | // an expected condition generated 1% of the time in the test data... 957 | // we throw an illegal access exception and the transaction gets rolled back later on 958 | throw new IllegalAccessException("Expected NEW-ORDER error condition excersing rollback functionality"); 959 | } 960 | 961 | if (stmtGetItem == null) { 962 | stmtGetItem = conn.prepareStatement( 963 | "SELECT i_price, i_name , i_data FROM benchmarksql.item WHERE i_id = ?"); 964 | } 965 | stmtGetItem.setInt(1, ol_i_id); 966 | 967 | rs = stmtGetItem.executeQuery(); 968 | if (!rs.next()) { 969 | log.error("stmtGetItem() not found! " + "I_ID=" + ol_i_id); 970 | } 971 | 972 | i_price = rs.getFloat("i_price"); 973 | i_name = rs.getString("i_name"); 974 | i_data = rs.getString("i_data"); 975 | rs.close(); 976 | rs = null; 977 | 978 | itemPrices[ol_number-1] = i_price; 979 | itemNames[ol_number-1] = i_name; 980 | 981 | if (stmtGetStock == null) { 982 | stmtGetStock = conn.prepareStatement( 983 | "SELECT s_quantity, s_data, s_dist_01, s_dist_02, s_dist_03, s_dist_04, s_dist_05, " + 984 | " s_dist_06, s_dist_07, s_dist_08, s_dist_09, s_dist_10" + 985 | " FROM benchmarksql.stock WHERE s_i_id = ? AND s_w_id = ? FOR UPDATE"); 986 | } 987 | 988 | stmtGetStock.setInt(1, ol_i_id); 989 | stmtGetStock.setInt(2, ol_supply_w_id); 990 | 991 | rs = stmtGetStock.executeQuery(); 992 | if (!rs.next()) { 993 | log.error("stmtGetStock() not found! " + "I_ID=" + ol_i_id + " W_ID=" + ol_supply_w_id); 994 | } 995 | 996 | s_quantity = rs.getInt("s_quantity"); 997 | s_data = rs.getString("s_data"); 998 | s_dist_01 = rs.getString("s_dist_01"); 999 | s_dist_02 = rs.getString("s_dist_02"); 1000 | s_dist_03 = rs.getString("s_dist_03"); 1001 | s_dist_04 = rs.getString("s_dist_04"); 1002 | s_dist_05 = rs.getString("s_dist_05"); 1003 | s_dist_06 = rs.getString("s_dist_06"); 1004 | s_dist_07 = rs.getString("s_dist_07"); 1005 | s_dist_08 = rs.getString("s_dist_08"); 1006 | s_dist_09 = rs.getString("s_dist_09"); 1007 | s_dist_10 = rs.getString("s_dist_10"); 1008 | rs.close(); 1009 | rs = null; 1010 | 1011 | stockQuantities[ol_number-1] = s_quantity; 1012 | 1013 | if(s_quantity - ol_quantity >= 10) { 1014 | s_quantity -= ol_quantity; 1015 | } else { 1016 | s_quantity += -ol_quantity + 91; 1017 | } 1018 | 1019 | if(ol_supply_w_id == w_id) { 1020 | s_remote_cnt_increment = 0; 1021 | } else { 1022 | s_remote_cnt_increment = 1; 1023 | } 1024 | 1025 | 1026 | if (stmtUpdateStock == null) { 1027 | stmtUpdateStock = conn.prepareStatement( 1028 | "UPDATE benchmarksql.stock SET s_quantity = ? , s_ytd = s_ytd + ?, s_remote_cnt = s_remote_cnt + ? " + 1029 | " WHERE s_i_id = ? AND s_w_id = ?"); 1030 | } 1031 | stmtUpdateStock.setInt(1,s_quantity); 1032 | stmtUpdateStock.setInt(2, ol_quantity); 1033 | stmtUpdateStock.setInt(3,s_remote_cnt_increment); 1034 | stmtUpdateStock.setInt(4,ol_i_id); 1035 | stmtUpdateStock.setInt(5,ol_supply_w_id); 1036 | stmtUpdateStock.addBatch(); 1037 | 1038 | ol_amount = ol_quantity * i_price; 1039 | orderLineAmounts[ol_number-1] = ol_amount; 1040 | total_amount += ol_amount; 1041 | 1042 | if(i_data.indexOf("GENERIC") != -1 && s_data.indexOf("GENERIC") != -1) { 1043 | brandGeneric[ol_number-1] = 'B'; 1044 | } else { 1045 | brandGeneric[ol_number-1] = 'G'; 1046 | } 1047 | 1048 | switch((int)d_id) { 1049 | case 1: ol_dist_info = s_dist_01; break; 1050 | case 2: ol_dist_info = s_dist_02; break; 1051 | case 3: ol_dist_info = s_dist_03; break; 1052 | case 4: ol_dist_info = s_dist_04; break; 1053 | case 5: ol_dist_info = s_dist_05; break; 1054 | case 6: ol_dist_info = s_dist_06; break; 1055 | case 7: ol_dist_info = s_dist_07; break; 1056 | case 8: ol_dist_info = s_dist_08; break; 1057 | case 9: ol_dist_info = s_dist_09; break; 1058 | case 10: ol_dist_info = s_dist_10; break; 1059 | } 1060 | 1061 | if (stmtInsertOrderLine == null) { 1062 | stmtInsertOrderLine = conn.prepareStatement( 1063 | "INSERT INTO benchmarksql.order_line (ol_o_id, ol_d_id, ol_w_id, ol_number, ol_i_id, ol_supply_w_id," + 1064 | " ol_quantity, ol_amount, ol_dist_info) VALUES (?,?,?,?,?,?,?,?,?)"); 1065 | } 1066 | stmtInsertOrderLine.setInt(1, o_id); 1067 | stmtInsertOrderLine.setInt(2, d_id); 1068 | stmtInsertOrderLine.setInt(3, w_id); 1069 | stmtInsertOrderLine.setInt(4, ol_number); 1070 | stmtInsertOrderLine.setInt(5, ol_i_id); 1071 | stmtInsertOrderLine.setInt(6, ol_supply_w_id); 1072 | stmtInsertOrderLine.setInt(7, ol_quantity); 1073 | stmtInsertOrderLine.setFloat(8, ol_amount); 1074 | stmtInsertOrderLine.setString(9, ol_dist_info); 1075 | stmtInsertOrderLine.addBatch(); 1076 | 1077 | } // end-for 1078 | 1079 | stmtInsertOrderLine.executeBatch(); 1080 | stmtUpdateStock.executeBatch(); 1081 | transCommit(); 1082 | stmtInsertOrderLine.clearBatch(); 1083 | stmtUpdateStock.clearBatch(); 1084 | 1085 | total_amount *= (1+w_tax+d_tax)*(1-c_discount); 1086 | 1087 | StringBuffer terminalMessage = new StringBuffer(); 1088 | terminalMessage("+--------------------------- NEW-ORDER ---------------------------+"); 1089 | terminalMessage(" Date: "+ jTPCCUtil.getCurrentTime()); 1090 | terminalMessage(" "); 1091 | terminalMessage(" Warehouse: " + w_id); 1092 | terminalMessage(" Tax: " + w_tax); 1093 | terminalMessage(" District: " + d_id); 1094 | terminalMessage(" Tax: " + d_tax); 1095 | terminalMessage(" Order: " + o_id); 1096 | terminalMessage(" Lines: " + o_ol_cnt); 1097 | terminalMessage(" "); 1098 | terminalMessage(" Customer: " + c_id); 1099 | terminalMessage(" Name: " + c_last); 1100 | terminalMessage(" Credit: " + c_credit); 1101 | terminalMessage(" %Disc: " + c_discount); 1102 | terminalMessage(" "); 1103 | terminalMessage(" Order-Line List [Supp_W - Item_ID - Item Name - Qty - Stock - B/G - Price - Amount]"); 1104 | for(int i = 0; i < o_ol_cnt; i++) 1105 | { 1106 | terminalMessage(" [" + supplierWarehouseIDs[i] + " - " + itemIDs[i] + " - " + itemNames[i] + " - " + orderQuantities[i] + " - " + stockQuantities[i] + " - " + brandGeneric[i] + " - " + jTPCCUtil.formattedDouble(itemPrices[i]) + " - " + jTPCCUtil.formattedDouble(orderLineAmounts[i]) + "]"); 1107 | } 1108 | terminalMessage(" Total Amount: " + total_amount); 1109 | terminalMessage(" "); 1110 | terminalMessage(" Execution Status: New order placed!"); 1111 | terminalMessage("+-----------------------------------------------------------------+"); 1112 | 1113 | } //// ugh :-), this is the end of the try block at the begining of this method ///////// 1114 | 1115 | catch (SQLException ex) { 1116 | log.error("--- Unexpected SQLException caught in NEW-ORDER Txn ---"); 1117 | while (ex != null) { 1118 | log.error(ex.getMessage()); 1119 | ex = ex.getNextException(); 1120 | } 1121 | 1122 | } catch (Exception e) { 1123 | if (e instanceof IllegalAccessException) { 1124 | StringBuffer terminalMessage = new StringBuffer(); 1125 | terminalMessage("+---- NEW-ORDER Rollback Txn expected to happen for 1% of Txn's -----+"); 1126 | terminalMessage(" Warehouse: " + w_id); 1127 | terminalMessage(" District: " + d_id); 1128 | terminalMessage(" Order: " + o_id); 1129 | terminalMessage(" Customer: " + c_id); 1130 | terminalMessage(" Name: " + c_last); 1131 | terminalMessage(" Credit: " + c_credit); 1132 | terminalMessage(" Execution Status: Item number is not valid!"); 1133 | terminalMessage("+-----------------------------------------------------------------+"); 1134 | 1135 | 1136 | try { 1137 | terminalMessage("Performing ROLLBACK in NEW-ORDER Txn..."); 1138 | transRollback(); 1139 | stmtInsertOrderLine.clearBatch(); 1140 | stmtUpdateStock.clearBatch(); 1141 | } catch(Exception e1){ 1142 | error("NEW-ORDER-ROLLBACK"); 1143 | logException(e1); 1144 | } 1145 | } 1146 | } 1147 | } 1148 | 1149 | 1150 | private void stockLevelTransaction(int w_id, int d_id, int threshold) 1151 | { 1152 | int o_id = 0; 1153 | int i_id = 0; 1154 | int stock_count = 0; 1155 | 1156 | District dist = new District(); 1157 | OrderLine orln = new OrderLine(); 1158 | Stock stck = new Stock(); 1159 | 1160 | printMessage("Stock Level Txn for W_ID=" + w_id + ", D_ID=" + d_id + ", threshold=" + threshold); 1161 | 1162 | try 1163 | { 1164 | if (stockGetDistOrderId == null) { 1165 | stockGetDistOrderId = conn.prepareStatement( 1166 | "SELECT d_next_o_id" + 1167 | " FROM benchmarksql.district" + 1168 | " WHERE d_w_id = ?" + 1169 | " AND d_id = ?"); 1170 | } 1171 | 1172 | stockGetDistOrderId.setInt(1, w_id); 1173 | stockGetDistOrderId.setInt(2, d_id); 1174 | 1175 | rs = stockGetDistOrderId.executeQuery(); 1176 | if (!rs.next()) { 1177 | log.error("stockGetDistOrderId() not found! D_W_ID=" + w_id + " D_ID=" + d_id); 1178 | } 1179 | 1180 | o_id = rs.getInt("d_next_o_id"); 1181 | rs.close(); 1182 | rs = null; 1183 | 1184 | printMessage("Next Order ID for District = " + o_id); 1185 | 1186 | if (stockGetCountStock == null) { 1187 | stockGetCountStock = conn.prepareStatement( 1188 | "SELECT COUNT(DISTINCT (s_i_id)) AS stock_count" + 1189 | " FROM benchmarksql.order_line, benchmarksql.stock" + 1190 | " WHERE ol_w_id = ?" + 1191 | " AND ol_d_id = ?" + 1192 | " AND ol_o_id < ?" + 1193 | " AND ol_o_id >= ? - 20" + 1194 | " AND s_w_id = ?" + 1195 | " AND s_i_id = ol_i_id" + 1196 | " AND s_quantity < ?"); 1197 | } 1198 | 1199 | stockGetCountStock.setInt(1, w_id); 1200 | stockGetCountStock.setInt(2, d_id); 1201 | stockGetCountStock.setInt(3, o_id); 1202 | stockGetCountStock.setInt(4, o_id); 1203 | stockGetCountStock.setInt(5, w_id); 1204 | stockGetCountStock.setInt(6, threshold); 1205 | 1206 | rs = stockGetCountStock.executeQuery(); 1207 | if (!rs.next()) { 1208 | log.error("stockGetCountStock() not found! W_ID=" + w_id + " D_ID=" + d_id + " O_ID=" + o_id); 1209 | } 1210 | 1211 | stock_count = rs.getInt("stock_count"); 1212 | rs.close(); 1213 | rs = null; 1214 | 1215 | StringBuffer terminalMessage = new StringBuffer(); 1216 | terminalMessage("+-------------------------- STOCK-LEVEL --------------------------+"); 1217 | terminalMessage(" Warehouse: " + w_id); 1218 | terminalMessage(" District: " + d_id); 1219 | terminalMessage(" "); 1220 | terminalMessage(" Stock Level Threshold: " + threshold); 1221 | terminalMessage(" Low Stock Count: " + stock_count); 1222 | terminalMessage("+-----------------------------------------------------------------+"); 1223 | } 1224 | catch(Exception e) 1225 | { 1226 | error("STOCK-LEVEL"); 1227 | logException(e); 1228 | } 1229 | } 1230 | 1231 | 1232 | private void paymentTransaction(int w_id, int c_w_id, float h_amount, int d_id, int c_d_id, int c_id, String c_last, boolean c_by_name) 1233 | { 1234 | String w_street_1, w_street_2, w_city, w_state, w_zip, w_name; 1235 | String d_street_1, d_street_2, d_city, d_state, d_zip, d_name; 1236 | int namecnt; 1237 | String c_first, c_middle, c_street_1, c_street_2, c_city, c_state, c_zip; 1238 | String c_phone, c_credit = null, c_data = null, c_new_data, h_data; 1239 | float c_credit_lim, c_discount, c_balance = 0; 1240 | java.sql.Date c_since; 1241 | 1242 | Warehouse whse = new Warehouse(); 1243 | Customer cust = new Customer(); 1244 | District dist = new District(); 1245 | History hist = new History(); 1246 | 1247 | try 1248 | { 1249 | 1250 | if (payUpdateWhse == null) { 1251 | payUpdateWhse = conn.prepareStatement( 1252 | "UPDATE benchmarksql.warehouse SET w_ytd = w_ytd + ? WHERE w_id = ? "); 1253 | } 1254 | 1255 | payUpdateWhse.setFloat(1,h_amount); 1256 | payUpdateWhse.setInt(2,w_id); 1257 | 1258 | result = payUpdateWhse.executeUpdate(); 1259 | if (result == 0) { 1260 | log.error("payUpdateWhse() not found! W_ID=" + w_id); 1261 | } 1262 | 1263 | if (payGetWhse == null) { 1264 | payGetWhse = conn.prepareStatement( 1265 | "SELECT w_street_1, w_street_2, w_city, w_state, w_zip, w_name" + 1266 | " FROM benchmarksql.warehouse WHERE w_id = ?"); 1267 | } 1268 | 1269 | payGetWhse.setInt(1, w_id); 1270 | 1271 | rs = payGetWhse.executeQuery(); 1272 | if (!rs.next()) { 1273 | log.error("payGetWhse() not found! W_ID=" + w_id); 1274 | } 1275 | 1276 | w_street_1 = rs.getString("w_street_1"); 1277 | w_street_2 = rs.getString("w_street_2"); 1278 | w_city = rs.getString("w_city"); 1279 | w_state = rs.getString("w_state"); 1280 | w_zip = rs.getString("w_zip"); 1281 | w_name = rs.getString("w_name"); 1282 | rs.close(); 1283 | rs = null; 1284 | 1285 | if (payUpdateDist == null) { 1286 | payUpdateDist = conn.prepareStatement( 1287 | "UPDATE benchmarksql.district SET d_ytd = d_ytd + ? WHERE d_w_id = ? AND d_id = ?"); 1288 | } 1289 | payUpdateDist.setFloat(1, h_amount); 1290 | payUpdateDist.setInt(2, w_id); 1291 | payUpdateDist.setInt(3, d_id); 1292 | result = payUpdateDist.executeUpdate(); 1293 | if (result == 0) { 1294 | log.error("payUpdateDist() not found! D_ID=" + d_id + " D_W_ID=" + w_id); 1295 | } 1296 | 1297 | if (payGetDist == null) { 1298 | payGetDist = conn.prepareStatement( 1299 | "SELECT d_street_1, d_street_2, d_city, d_state, d_zip, d_name" + 1300 | " FROM benchmarksql.district WHERE d_w_id = ? AND d_id = ?"); 1301 | } 1302 | 1303 | payGetDist.setInt(1, w_id); 1304 | payGetDist.setInt(2, d_id); 1305 | 1306 | rs = payGetDist.executeQuery(); 1307 | if (!rs.next()) { 1308 | log.error("payGetDist() not found! D_ID=" + d_id + " D_W_ID=" + w_id); 1309 | } 1310 | 1311 | d_street_1 = rs.getString("d_street_1"); 1312 | d_street_2 = rs.getString("d_street_2"); 1313 | d_city = rs.getString("d_city"); 1314 | d_state = rs.getString("d_state"); 1315 | d_zip = rs.getString("d_zip"); 1316 | d_name = rs.getString("d_name"); 1317 | rs.close(); 1318 | rs = null; 1319 | 1320 | if(c_by_name) { 1321 | // payment is by customer name 1322 | if (payCountCust == null) { 1323 | //"SELECT count(c_id)) AS namecnt FROM customer " + 1324 | payCountCust = conn.prepareStatement( 1325 | "SELECT count(*) AS namecnt FROM benchmarksql.customer " + 1326 | " WHERE c_last = ? AND c_d_id = ? AND c_w_id = ?"); 1327 | } 1328 | 1329 | payCountCust.setString(1, c_last); 1330 | payCountCust.setInt(2, c_d_id); 1331 | payCountCust.setInt(3, c_w_id); 1332 | 1333 | rs = payCountCust.executeQuery(); 1334 | if (!rs.next()) { 1335 | error("Customer with these conditions does not exist"); 1336 | String customernewLastName = jTPCCUtil.getLastName(gen); 1337 | printMessage("New last name lookup = " + customernewLastName); 1338 | paymentTransaction(w_id, c_w_id, h_amount, d_id, c_d_id, c_id, customernewLastName, c_by_name); 1339 | } 1340 | 1341 | namecnt = rs.getInt("namecnt"); 1342 | rs.close(); 1343 | rs = null; 1344 | 1345 | if (payCursorCustByName == null) { 1346 | payCursorCustByName = conn.prepareStatement( 1347 | "SELECT c_first, c_middle, c_id, c_street_1, c_street_2, c_city, c_state, c_zip," + 1348 | " c_phone, c_credit, c_credit_lim, c_discount, c_balance, c_since " + 1349 | " FROM benchmarksql.customer WHERE c_w_id = ? AND c_d_id = ? AND c_last = ? " + 1350 | "ORDER BY c_w_id, c_d_id, c_last, c_first "); 1351 | } 1352 | 1353 | payCursorCustByName.setInt(1, c_w_id); 1354 | payCursorCustByName.setInt(2, c_d_id); 1355 | payCursorCustByName.setString(3, c_last); 1356 | 1357 | rs = payCursorCustByName.executeQuery(); 1358 | if (!rs.next()) { 1359 | log.error("payCursorCustByName() not found! C_LAST=" + c_last + " C_D_ID=" + c_d_id + " C_W_ID=" + c_w_id); 1360 | } 1361 | 1362 | if(namecnt%2 == 1) namecnt++; 1363 | for(int i = 1; i < namecnt / 2; i++) rs.next(); 1364 | c_id = rs.getInt("c_id"); 1365 | c_first = rs.getString("c_first"); 1366 | c_middle = rs.getString("c_middle"); 1367 | c_street_1 = rs.getString("c_street_1"); 1368 | c_street_2 = rs.getString("c_street_2"); 1369 | c_city = rs.getString("c_city"); 1370 | c_state = rs.getString("c_state"); 1371 | c_zip = rs.getString("c_zip"); 1372 | c_phone = rs.getString("c_phone"); 1373 | c_credit = rs.getString("c_credit"); 1374 | c_credit_lim = rs.getFloat("c_credit_lim"); 1375 | c_discount = rs.getFloat("c_discount"); 1376 | c_balance = rs.getFloat("c_balance"); 1377 | c_since = rs.getDate("c_since"); 1378 | rs.close(); 1379 | rs = null; 1380 | } else { 1381 | // payment is by customer ID 1382 | if (payGetCust == null) { 1383 | payGetCust = conn.prepareStatement( 1384 | "SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip," + 1385 | " c_phone, c_credit, c_credit_lim, c_discount, c_balance, c_since " + 1386 | " FROM benchmarksql.customer WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?"); 1387 | } 1388 | 1389 | payGetCust.setInt(1, c_w_id); 1390 | payGetCust.setInt(2, c_d_id); 1391 | payGetCust.setInt(3, c_id); 1392 | 1393 | rs = payGetCust.executeQuery(); 1394 | if (!rs.next()) { 1395 | log.error("payGetCust() not found! C_ID=" + c_id + " C_D_ID=" + c_d_id + " C_W_ID=" + c_w_id); 1396 | } 1397 | 1398 | c_last = rs.getString("c_last"); 1399 | c_first = rs.getString("c_first"); 1400 | c_middle = rs.getString("c_middle"); 1401 | c_street_1 = rs.getString("c_street_1"); 1402 | c_street_2 = rs.getString("c_street_2"); 1403 | c_city = rs.getString("c_city"); 1404 | c_state = rs.getString("c_state"); 1405 | c_zip = rs.getString("c_zip"); 1406 | c_phone = rs.getString("c_phone"); 1407 | c_credit = rs.getString("c_credit"); 1408 | c_credit_lim = rs.getFloat("c_credit_lim"); 1409 | c_discount = rs.getFloat("c_discount"); 1410 | c_balance = rs.getFloat("c_balance"); 1411 | c_since = rs.getDate("c_since"); 1412 | rs.close(); 1413 | rs = null; 1414 | } 1415 | 1416 | 1417 | c_balance += h_amount; 1418 | 1419 | if(c_credit.equals("BC")) { // bad credit 1420 | 1421 | if (payGetCustCdata == null) { 1422 | payGetCustCdata = conn.prepareStatement( 1423 | "SELECT c_data FROM benchmarksql.customer WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?"); 1424 | } 1425 | 1426 | payGetCustCdata.setInt(1, c_w_id); 1427 | payGetCustCdata.setInt(2, c_d_id); 1428 | payGetCustCdata.setInt(3, c_id); 1429 | 1430 | rs = payGetCustCdata.executeQuery(); 1431 | if (!rs.next()) { 1432 | log.error("payGetCustCdata() not found! C_ID=" + c_id + " C_W_ID=" + c_w_id + " C_D_ID=" + c_d_id); 1433 | } 1434 | 1435 | c_data = rs.getString("c_data"); 1436 | rs.close(); 1437 | rs = null; 1438 | 1439 | c_new_data = c_id + " " + c_d_id + " " + c_w_id + " " + d_id + " " + w_id + " " + h_amount + " |"; 1440 | if(c_data.length() > c_new_data.length()) { 1441 | c_new_data += c_data.substring(0, c_data.length()-c_new_data.length()); 1442 | } else { 1443 | c_new_data += c_data; 1444 | } 1445 | if(c_new_data.length() > 500) c_new_data = c_new_data.substring(0, 500); 1446 | 1447 | if (payUpdateCustBalCdata == null) { 1448 | payUpdateCustBalCdata = conn.prepareStatement( 1449 | "UPDATE benchmarksql.customer SET c_balance = ?, c_data = ? " + 1450 | " WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?"); 1451 | } 1452 | payUpdateCustBalCdata.setFloat(1, c_balance); 1453 | payUpdateCustBalCdata.setString(2, c_new_data); 1454 | payUpdateCustBalCdata.setInt(3, c_w_id); 1455 | payUpdateCustBalCdata.setInt(4, c_d_id); 1456 | payUpdateCustBalCdata.setInt(5, c_id); 1457 | 1458 | result = payUpdateCustBalCdata.executeUpdate(); 1459 | if (result == 0) { 1460 | log.error("payUpdateCustBalCdata() Error in PYMNT Txn updating Customer!" + 1461 | " C_ID=" + c_id + " C_W_ID=" + c_w_id + " C_D_ID=" + c_d_id); 1462 | } 1463 | 1464 | } else { // GoodCredit 1465 | 1466 | 1467 | if (payUpdateCustBal == null) { 1468 | payUpdateCustBal = conn.prepareStatement( 1469 | "UPDATE benchmarksql.customer SET c_balance = ? WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?"); 1470 | } 1471 | 1472 | payUpdateCustBal.setFloat(1, c_balance); 1473 | payUpdateCustBal.setInt(2, c_w_id); 1474 | payUpdateCustBal.setInt(3, c_d_id); 1475 | payUpdateCustBal.setInt(4, c_id); 1476 | 1477 | result = payUpdateCustBal.executeUpdate(); 1478 | if (result == 0) { 1479 | log.error("payUpdateCustBal() not found! C_ID=" + c_id + " C_W_ID=" + c_w_id + " C_D_ID=" + c_d_id); 1480 | } 1481 | 1482 | } 1483 | 1484 | 1485 | if(w_name.length() > 10) w_name = w_name.substring(0, 10); 1486 | if(d_name.length() > 10) d_name = d_name.substring(0, 10); 1487 | h_data = w_name + " " + d_name; 1488 | 1489 | 1490 | if (payInsertHist == null) { 1491 | payInsertHist = conn.prepareStatement( 1492 | "INSERT INTO benchmarksql.history (h_c_d_id, h_c_w_id, h_c_id, h_d_id, h_w_id, h_date, h_amount, h_data) " + 1493 | " VALUES (?,?,?,?,?,?,?,?)"); 1494 | } 1495 | payInsertHist.setInt(1, c_d_id); 1496 | payInsertHist.setInt(2, c_w_id); 1497 | payInsertHist.setInt(3, c_id); 1498 | payInsertHist.setInt(4, d_id); 1499 | payInsertHist.setInt(5, w_id); 1500 | payInsertHist.setTimestamp(6, new Timestamp(System.currentTimeMillis())); 1501 | payInsertHist.setFloat(7, h_amount); 1502 | payInsertHist.setString(8, h_data); 1503 | payInsertHist.executeUpdate(); 1504 | 1505 | transCommit(); 1506 | printMessage("Succesful INSERT into history table"); 1507 | 1508 | StringBuffer terminalMessage = new StringBuffer(); 1509 | terminalMessage("+---------------------------- PAYMENT ----------------------------+"); 1510 | terminalMessage(" Date: " + jTPCCUtil.getCurrentTime()); 1511 | terminalMessage(" "); 1512 | terminalMessage(" Warehouse: " + w_id); 1513 | terminalMessage(" Street: " + w_street_1); 1514 | terminalMessage(" Street: " + w_street_2); 1515 | terminalMessage(" City: " + w_city + " State: " + w_state + " Zip: " + w_zip); 1516 | terminalMessage(" "); 1517 | terminalMessage(" District: " + d_id); 1518 | terminalMessage(" Street: " + d_street_1); 1519 | terminalMessage(" Street: " + d_street_2); 1520 | terminalMessage(" City: " + d_city + " State: " + d_state + " Zip: " + d_zip); 1521 | terminalMessage(" "); 1522 | terminalMessage(" Customer: " + c_id); 1523 | terminalMessage(" Name: " + c_first + " " + c_middle + " " + c_last); 1524 | terminalMessage(" Street: " + c_street_1); 1525 | terminalMessage(" Street: " + c_street_2); 1526 | terminalMessage(" City: " + c_city + " State: " + c_state + " Zip: " + c_zip); 1527 | 1528 | terminalMessage(""); 1529 | if (c_since != null) 1530 | { 1531 | terminalMessage(" Since: " + c_since); 1532 | } else { 1533 | terminalMessage(" Since: "); 1534 | } 1535 | terminalMessage(" Credit: " + c_credit); 1536 | terminalMessage(" %Disc: " + c_discount); 1537 | terminalMessage(" Phone: " + c_phone); 1538 | terminalMessage(" "); 1539 | terminalMessage(" Amount Paid: " + h_amount); 1540 | terminalMessage(" Credit Limit: " + c_credit_lim); 1541 | terminalMessage(" New Cust-Balance: " + c_balance); 1542 | 1543 | if(c_credit.equals("BC")) 1544 | { 1545 | if(c_data.length() > 50) 1546 | { 1547 | terminalMessage.append(" Cust-Data: " + c_data.substring(0, 50)); 1548 | int data_chunks = c_data.length() > 200 ? 4 : c_data.length()/50; 1549 | for(int n = 1; n < data_chunks; n++) 1550 | terminalMessage.append(" " + c_data.substring(n*50, (n+1)*50)); 1551 | terminalMessage(terminalMessage.toString()); 1552 | } 1553 | else 1554 | { 1555 | terminalMessage(" Cust-Data: " + c_data); 1556 | } 1557 | } 1558 | 1559 | terminalMessage("+-----------------------------------------------------------------+"); 1560 | 1561 | } 1562 | catch(Exception e) 1563 | { 1564 | error("PAYMENT"); 1565 | logException(e); 1566 | try 1567 | { 1568 | terminalMessage("Performing ROLLBACK..."); 1569 | transRollback(); 1570 | } 1571 | catch(Exception e1) 1572 | { 1573 | error("PAYMENT-ROLLBACK"); 1574 | logException(e1); 1575 | } 1576 | } 1577 | } 1578 | 1579 | private void error(String type) { 1580 | log.error(terminalName + ", TERMINAL=" + terminalName + " TYPE=" + type + " COUNT=" + transactionCount); 1581 | System.out.println(terminalName + ", TERMINAL=" + terminalName + " TYPE=" + type + " COUNT=" + transactionCount); 1582 | } 1583 | 1584 | private void logException(Exception e) 1585 | { 1586 | StringWriter stringWriter = new StringWriter(); 1587 | PrintWriter printWriter = new PrintWriter(stringWriter); 1588 | e.printStackTrace(printWriter); 1589 | printWriter.close(); 1590 | log.error(stringWriter.toString()); 1591 | } 1592 | 1593 | private void terminalMessage(String message) { 1594 | log.trace(terminalName + ", " + message); 1595 | } 1596 | 1597 | private void printMessage(String message) { 1598 | log.trace(terminalName + ", " + message); 1599 | 1600 | } 1601 | 1602 | 1603 | void transRollback () { 1604 | try { 1605 | conn.rollback(); 1606 | } catch(SQLException se) { 1607 | log.error(se.getMessage()); 1608 | } 1609 | } 1610 | 1611 | 1612 | void transCommit() { 1613 | try { 1614 | conn.commit(); 1615 | } catch(SQLException se) { 1616 | log.error(se.getMessage()); 1617 | transRollback(); 1618 | } 1619 | 1620 | } // end transCommit() 1621 | 1622 | 1623 | 1624 | } 1625 | --------------------------------------------------------------------------------