📄 loaddata.java
字号:
for (int w=1; w <= whseKount; w++) {
for (int d=1; d <= distWhseKount; d++) {
for (int c=1; c <= custDistKount; c++) {
sysdate = new java.sql.Timestamp(System.currentTimeMillis());
customer.c_id = c;
customer.c_d_id = d;
customer.c_w_id = w;
// discount is random between [0.0000 ... 0.5000]
customer.c_discount =
(float)(jTPCCUtil.randomNumber(1,5000,gen) / 10000.0);
if (jTPCCUtil.randomNumber(1,100,gen) <= 10) {
customer.c_credit = "BC"; // 10% Bad Credit
} else {
customer.c_credit = "GC"; // 90% Good Credit
}
customer.c_last = jTPCCUtil.getLastName(gen);
customer.c_first = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(8,16,gen));
customer.c_credit_lim = 50000;
customer.c_balance = -10;
customer.c_ytd_payment = 10;
customer.c_payment_cnt = 1;
customer.c_delivery_cnt = 0;
customer.c_street_1 = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10,20,gen));
customer.c_street_2 = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10,20,gen));
customer.c_city = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10,20,gen));
customer.c_state = jTPCCUtil.randomStr(3).toUpperCase();
customer.c_zip = "123456789";
customer.c_phone = "(732)744-1700";
customer.c_since = sysdate.getTime();
customer.c_middle = "OE";
customer.c_data = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(300,500,gen));
history.h_c_id = c;
history.h_c_d_id = d;
history.h_c_w_id = w;
history.h_d_id = d;
history.h_w_id = w;
history.h_date = sysdate.getTime();
history.h_amount = 10;
history.h_data = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10,24,gen));
k = k + 2;
if (outputFiles == false)
{
custPrepStmt.setLong(1, customer.c_id);
custPrepStmt.setLong(2, customer.c_d_id);
custPrepStmt.setLong(3, customer.c_w_id);
custPrepStmt.setDouble(4, customer.c_discount);
custPrepStmt.setString(5, customer.c_credit);
custPrepStmt.setString(6, customer.c_last);
custPrepStmt.setString(7, customer.c_first);
custPrepStmt.setDouble(8, customer.c_credit_lim);
custPrepStmt.setDouble(9, customer.c_balance);
custPrepStmt.setDouble(10, customer.c_ytd_payment);
custPrepStmt.setDouble(11, customer.c_payment_cnt);
custPrepStmt.setDouble(12, customer.c_delivery_cnt);
custPrepStmt.setString(13, customer.c_street_1);
custPrepStmt.setString(14, customer.c_street_2);
custPrepStmt.setString(15, customer.c_city);
custPrepStmt.setString(16, customer.c_state);
custPrepStmt.setString(17, customer.c_zip);
custPrepStmt.setString(18, customer.c_phone);
Timestamp since = new Timestamp(customer.c_since);
custPrepStmt.setTimestamp(19, since);
custPrepStmt.setString(20, customer.c_middle);
custPrepStmt.setString(21, customer.c_data);
custPrepStmt.addBatch();
histPrepStmt.setInt(1, history.h_c_id);
histPrepStmt.setInt(2, history.h_c_d_id);
histPrepStmt.setInt(3, history.h_c_w_id);
histPrepStmt.setInt(4, history.h_d_id);
histPrepStmt.setInt(5, history.h_w_id);
Timestamp hdate = new Timestamp(history.h_date);
histPrepStmt.setTimestamp(6, hdate);
histPrepStmt.setDouble(7, history.h_amount);
histPrepStmt.setString(8, history.h_data);
histPrepStmt.addBatch();
if (( k % configCommitCount) == 0) {
long tmpTime = new java.util.Date().getTime();
String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000) + " ";
System.out.println(etStr.substring(0, 30) + " Writing record " + k + " of " + t);
lastTimeMS = tmpTime;
custPrepStmt.executeBatch();
histPrepStmt.executeBatch();
custPrepStmt.clearBatch();
custPrepStmt.clearBatch();
transCommit();
}
} else {
String str = "";
str = str + customer.c_id + ",";
str = str + customer.c_d_id + ",";
str = str + customer.c_w_id + ",";
str = str + customer.c_discount + ",";
str = str + customer.c_credit + ",";
str = str + customer.c_last + ",";
str = str + customer.c_first + ",";
str = str + customer.c_credit_lim + ",";
str = str + customer.c_balance + ",";
str = str + customer.c_ytd_payment + ",";
str = str + customer.c_payment_cnt + ",";
str = str + customer.c_delivery_cnt + ",";
str = str + customer.c_street_1 + ",";
str = str + customer.c_street_2 + ",";
str = str + customer.c_city + ",";
str = str + customer.c_state + ",";
str = str + customer.c_zip + ",";
str = str + customer.c_phone;
out.println(str);
str = "";
str = str + history.h_c_id + ",";
str = str + history.h_c_d_id + ",";
str = str + history.h_c_w_id + ",";
str = str + history.h_d_id + ",";
str = str + history.h_w_id + ",";
Timestamp hdate = new Timestamp(history.h_date);
str = str + hdate + ",";
str = str + history.h_amount + ",";
str = str + history.h_data;
outHist.println(str);
if (( k % configCommitCount) == 0) {
long tmpTime = new java.util.Date().getTime();
String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000) + " ";
System.out.println(etStr.substring(0, 30) + " Writing record " + k + " of " + t);
lastTimeMS = tmpTime;
}
}
} // end for [c]
} // end for [d]
} // end for [w]
long tmpTime = new java.util.Date().getTime();
String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000) + " ";
System.out.println(etStr.substring(0, 30) + " Writing record " + k + " of " + t);
lastTimeMS = tmpTime;
custPrepStmt.executeBatch();
histPrepStmt.executeBatch();
transCommit();
now = new java.util.Date();
if (outputFiles == true)
{
outHist.close();
}
System.out.println("End Cust-Hist Data Load @ " + now);
} catch(SQLException se) {
System.out.println(se.getMessage());
transRollback();
if (outputFiles == true)
{
outHist.close();
}
} catch(Exception e) {
e.printStackTrace();
transRollback();
if (outputFiles == true)
{
outHist.close();
}
}
return(k);
} // end loadCust()
static int loadOrder(int whseKount, int distWhseKount, int custDistKount) {
int k = 0;
int t = 0;
PrintWriter outLine = null;
PrintWriter outNewOrder = null;
try {
if (outputFiles == true)
{
out = new PrintWriter(new FileOutputStream(fileLocation + "order.csv"));
System.out.println("\nWriting Order file to: " + fileLocation + "order.csv");
outLine = new PrintWriter(new FileOutputStream(fileLocation + "order-line.csv"));
System.out.println("\nWriting Order Line file to: " + fileLocation + "order-line.csv");
outNewOrder = new PrintWriter(new FileOutputStream(fileLocation + "new-order.csv"));
System.out.println("\nWriting New Order file to: " + fileLocation + "new-order.csv");
}
now = new java.util.Date();
Oorder oorder = new Oorder();
NewOrder new_order = new NewOrder();
OrderLine order_line = new OrderLine();
jdbcIO myJdbcIO = new jdbcIO();
t = (whseKount * distWhseKount * custDistKount);
t = (t * 11) + (t / 3);
System.out.println("whse=" + whseKount +", dist=" + distWhseKount +
", cust=" + custDistKount);
System.out.println("\nStart Order-Line-New Load for approx " +
t + " rows @ " + now + " ...");
for (int w=1; w <= whseKount; w++) {
for (int d=1; d <= distWhseKount; d++) {
for (int c=1; c <= custDistKount; c++) {
oorder.o_id = c;
oorder.o_w_id = w;
oorder.o_d_id = d;
oorder.o_c_id = jTPCCUtil.randomNumber(1, custDistKount, gen);
oorder.o_carrier_id = jTPCCUtil.randomNumber(1, 10, gen);
oorder.o_ol_cnt = jTPCCUtil.randomNumber(5, 15, gen);
oorder.o_all_local = 1;
oorder.o_entry_d = System.currentTimeMillis();
k++;
if (outputFiles == false)
{
myJdbcIO.insertOrder(ordrPrepStmt, oorder);
} else {
String str = "";
str = str + oorder.o_id + ",";
str = str + oorder.o_w_id + ",";
str = str + oorder.o_d_id + ",";
str = str + oorder.o_c_id + ",";
str = str + oorder.o_carrier_id + ",";
str = str + oorder.o_ol_cnt + ",";
str = str + oorder.o_all_local + ",";
Timestamp entry_d = new java.sql.Timestamp(oorder.o_entry_d);
str = str + entry_d;
out.println(str);
}
// 900 rows in the NEW-ORDER table corresponding to the last
// 900 rows in the ORDER table for that district (i.e., with
// NO_O_ID between 2,101 and 3,000)
if (c > 2100 ) {
new_order.no_w_id = w;
new_order.no_d_id = d;
new_order.no_o_id = c;
k++;
if (outputFiles == false)
{
myJdbcIO.insertNewOrder(nworPrepStmt, new_order);
} else {
String str = "";
str = str + new_order.no_w_id+ ",";
str = str + new_order.no_d_id+ ",";
str = str + new_order.no_o_id;
outNewOrder.println(str);
}
} // end new order
for (int l=1; l <= oorder.o_ol_cnt; l++) {
order_line.ol_w_id = w;
order_line.ol_d_id = d;
order_line.ol_o_id = c;
order_line.ol_number = l; // ol_number
order_line.ol_i_id = jTPCCUtil.randomNumber(1, 100000, gen);
order_line.ol_delivery_d = oorder.o_entry_d;
if (order_line.ol_o_id < 2101) {
order_line.ol_amount = 0;
} else {
// random within [0.01 .. 9,999.99]
order_line.ol_amount =
(float)(jTPCCUtil.randomNumber(1, 999999, gen) / 100.0);
}
order_line.ol_supply_w_id = jTPCCUtil.randomNumber(1, numWarehouses, gen);
order_line.ol_quantity = 5;
order_line.ol_dist_info = jTPCCUtil.randomStr(24);
k++;
if (outputFiles == false)
{
myJdbcIO.insertOrderLine(orlnPrepStmt, order_line);
} else {
String str = "";
str = str + order_line.ol_w_id + ",";
str = str + order_line.ol_d_id + ",";
str = str + order_line.ol_o_id + ",";
str = str + order_line.ol_number + ",";
str = str + order_line.ol_i_id + ",";
Timestamp delivery_d = new Timestamp(order_line.ol_delivery_d);
str = str + delivery_d + ",";
str = str + order_line.ol_amount + ",";
str = str + order_line.ol_supply_w_id + ",";
str = str + order_line.ol_quantity + ",";
str = str + order_line.ol_dist_info;
outLine.println(str);
}
if (( k % configCommitCount) == 0) {
long tmpTime = new java.util.Date().getTime();
String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS)/1000.000) + " ";
System.out.println(etStr.substring(0, 30) + " Writing record " + k + " of " + t);
lastTimeMS = tmpTime;
if (outputFiles == false)
{
ordrPrepStmt.executeBatch();
nworPrepStmt.executeBatch();
orlnPrepStmt.executeBatch();
ordrPrepStmt.clearBatch();
nworPrepStmt.clearBatch();
orlnPrepStmt.clearBatch();
transCommit();
}
}
} // end for [l]
} // end for [c]
} // end for [d]
} // end for [w]
System.out.println(" Writing final records " + k + " of " + t);
if (outputFiles == false)
{
ordrPrepStmt.executeBatch();
nworPrepStmt.executeBatch();
orlnPrepStmt.executeBatch();
} else {
outLine.close();
outNewOrder.close();
}
transCommit();
now = new java.util.Date();
System.out.println("End Orders Load @ " + now);
} catch(Exception e) {
e.printStackTrace();
transRollback();
if (outputFiles == true)
{
outLine.close();
outNewOrder.close();
}
}
return(k);
} // end loadOrder()
} // end LoadData Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -