📄 jtpccterminal.java
字号:
ordStatGetCust.setInt(2, d_id);
ordStatGetCust.setInt(3, w_id);
rs = ordStatGetCust.executeQuery();
if(!rs.next()) throw new Exception("C_LAST=" + c_last + " C_D_ID=" + d_id + " C_W_ID=" + w_id + " not found!");
if(namecnt%2 == 1) namecnt++;
for(int i = 1; i < namecnt / 2; i++) rs.next();
c_id = rs.getInt("c_id");
c_first = rs.getString("c_first");
c_middle = rs.getString("c_middle");
c_balance = rs.getFloat("c_balance");
rs.close();
rs = null;
}
else
{
if (ordStatGetCustBal == null) {
ordStatGetCustBal = conn.prepareStatement(
"SELECT c_balance, c_first, c_middle, c_last" +
" FROM customer" +
" WHERE c_id = ?" +
" AND c_d_id = ?" +
" AND c_w_id = ?");
}
ordStatGetCustBal.setInt(1, c_id);
ordStatGetCustBal.setInt(2, d_id);
ordStatGetCustBal.setInt(3, w_id);
rs = ordStatGetCustBal.executeQuery();
if(!rs.next()) throw new Exception("C_ID=" + c_id + " C_D_ID=" + d_id + " C_W_ID=" + w_id + " not found!");
c_last = rs.getString("c_last");
c_first = rs.getString("c_first");
c_middle = rs.getString("c_middle");
c_balance = rs.getFloat("c_balance");
rs.close();
rs = null;
}
// find the newest order for the customer
if (ordStatGetNewestOrd == null) {
ordStatGetNewestOrd = conn.prepareStatement(
"SELECT MAX(o_id) AS maxorderid FROM oorder" +
" WHERE o_w_id = ?" +
" AND o_d_id = ?" +
" AND o_c_id = ?");
}
ordStatGetNewestOrd.setInt(1, w_id);
ordStatGetNewestOrd.setInt(2, d_id);
ordStatGetNewestOrd.setInt(3, c_id);
rs = ordStatGetNewestOrd.executeQuery();
if(rs.next())
{
o_id = rs.getInt("maxorderid");
rs.close();
rs = null;
// retrieve the carrier & order date for the most recent order.
if (ordStatGetOrder == null) {
ordStatGetOrder = conn.prepareStatement(
"SELECT o_carrier_id, o_entry_d" +
" FROM oorder" +
" WHERE o_w_id = ?" +
" AND o_d_id = ?" +
" AND o_c_id = ?" +
" AND o_id = ?");
}
ordStatGetOrder.setInt(1, w_id);
ordStatGetOrder.setInt(2, d_id);
ordStatGetOrder.setInt(3, c_id);
ordStatGetOrder.setInt(4, o_id);
rs = ordStatGetOrder.executeQuery();
if(rs.next())
{
o_carrier_id = rs.getInt("o_carrier_id");
entdate = rs.getDate("o_entry_d");
}
}
rs.close();
rs = null;
// retrieve the order lines for the most recent order
if (ordStatGetOrderLines == null) {
ordStatGetOrderLines = conn.prepareStatement(
"SELECT ol_i_id, ol_supply_w_id, ol_quantity," +
" ol_amount, ol_delivery_d" +
" FROM order_line" +
" WHERE ol_o_id = ?" +
" AND ol_d_id =?" +
" AND ol_w_id = ?");
}
ordStatGetOrderLines.setInt(1, o_id);
ordStatGetOrderLines.setInt(2, d_id);
ordStatGetOrderLines.setInt(3, w_id);
rs = ordStatGetOrderLines.executeQuery();
while(rs.next())
{
StringBuffer orderLine = new StringBuffer();
orderLine.append("[");
orderLine.append(rs.getLong("ol_supply_w_id"));
orderLine.append(" - ");
orderLine.append(rs.getLong("ol_i_id"));
orderLine.append(" - ");
orderLine.append(rs.getLong("ol_quantity"));
orderLine.append(" - ");
orderLine.append(jTPCCUtil.formattedDouble(rs.getDouble("ol_amount")));
orderLine.append(" - ");
if(rs.getDate("ol_delivery_d") != null)
orderLine.append(rs.getDate("ol_delivery_d"));
else
orderLine.append("99-99-9999");
orderLine.append("]");
orderLines.add(orderLine.toString());
}
rs.close();
rs = null;
StringBuffer terminalMessage = new StringBuffer();
terminalMessage.append("\n");
terminalMessage.append("+-------------------------- ORDER-STATUS -------------------------+\n");
terminalMessage.append(" Date: ");
terminalMessage.append(jTPCCUtil.getCurrentTime());
terminalMessage.append("\n\n Warehouse: ");
terminalMessage.append(w_id);
terminalMessage.append("\n District: ");
terminalMessage.append(d_id);
terminalMessage.append("\n\n Customer: ");
terminalMessage.append(c_id);
terminalMessage.append("\n Name: ");
terminalMessage.append(c_first);
terminalMessage.append(" ");
terminalMessage.append(c_middle);
terminalMessage.append(" ");
terminalMessage.append(c_last);
terminalMessage.append("\n Balance: ");
terminalMessage.append(c_balance);
terminalMessage.append("\n\n");
if(o_id == -1)
{
terminalMessage.append(" Customer has no orders placed.\n");
}
else
{
terminalMessage.append(" Order-Number: ");
terminalMessage.append(o_id);
terminalMessage.append("\n Entry-Date: ");
terminalMessage.append(entdate);
terminalMessage.append("\n Carrier-Number: ");
terminalMessage.append(o_carrier_id);
terminalMessage.append("\n\n");
if(orderLines.size() != 0)
{
terminalMessage.append(" [Supply_W - Item_ID - Qty - Amount - Delivery-Date]\n");
Enumeration orderLinesEnum = orderLines.elements();
while(orderLinesEnum.hasMoreElements())
{
terminalMessage.append(" ");
terminalMessage.append((String)orderLinesEnum.nextElement());
terminalMessage.append("\n");
}
}
else
{
terminalMessage(" This Order has no Order-Lines.\n");
}
}
terminalMessage.append("+-----------------------------------------------------------------+\n\n");
terminalMessage(terminalMessage.toString());
}
catch(Exception e)
{
error("ORDER-STATUS");
logException(e);
}
}
private void newOrderTransaction(int w_id, int d_id, int c_id, int o_ol_cnt, int o_all_local, int[] itemIDs, int[] supplierWarehouseIDs, int[] orderQuantities)
{
float c_discount, w_tax, d_tax = 0, i_price;
int d_next_o_id, o_id = -1, s_quantity;
String c_last = null, c_credit = null, i_name, i_data, s_data;
String s_dist_01, s_dist_02, s_dist_03, s_dist_04, s_dist_05;
String s_dist_06, s_dist_07, s_dist_08, s_dist_09, s_dist_10, ol_dist_info = null;
float[] itemPrices = new float[o_ol_cnt];
float[] orderLineAmounts = new float[o_ol_cnt];
String[] itemNames = new String[o_ol_cnt];
int[] stockQuantities = new int[o_ol_cnt];
char[] brandGeneric = new char[o_ol_cnt];
int ol_supply_w_id, ol_i_id, ol_quantity;
int s_remote_cnt_increment;
float ol_amount, total_amount = 0;
boolean newOrderRowInserted;
Warehouse whse = new Warehouse();
Customer cust = new Customer();
District dist = new District();
NewOrder nwor = new NewOrder();
Oorder ordr = new Oorder();
OrderLine orln = new OrderLine();
Stock stck = new Stock();
Item item = new Item();
try {
if (stmtGetCustWhse == null) {
stmtGetCustWhse = conn.prepareStatement(
"SELECT c_discount, c_last, c_credit, w_tax" +
" FROM customer, warehouse" +
" WHERE w_id = ? AND w_id = c_w_id" +
" AND c_d_id = ? AND c_id = ?");
}
stmtGetCustWhse.setInt(1, w_id);
stmtGetCustWhse.setInt(2, d_id);
stmtGetCustWhse.setInt(3, c_id);
rs = stmtGetCustWhse.executeQuery();
if(!rs.next()) throw new Exception("W_ID=" + w_id + " C_D_ID=" + d_id + " C_ID=" + c_id + " not found!");
c_discount = rs.getFloat("c_discount");
c_last = rs.getString("c_last");
c_credit = rs.getString("c_credit");
w_tax = rs.getFloat("w_tax");
rs.close();
rs = null;
newOrderRowInserted = false;
while(!newOrderRowInserted)
{
if (stmtGetDist == null) {
stmtGetDist = conn.prepareStatement(
"SELECT d_next_o_id, d_tax FROM district" +
" WHERE d_id = ? AND d_w_id = ? FOR UPDATE");
}
stmtGetDist.setInt(1, d_id);
stmtGetDist.setInt(2, w_id);
rs = stmtGetDist.executeQuery();
if(!rs.next()) throw new Exception("D_ID=" + d_id + " D_W_ID=" + w_id + " not found!");
d_next_o_id = rs.getInt("d_next_o_id");
d_tax = rs.getFloat("d_tax");
rs.close();
rs = null;
o_id = d_next_o_id;
try
{
if (stmtInsertNewOrder == null) {
stmtInsertNewOrder = conn.prepareStatement(
"INSERT INTO NEW_ORDER (no_o_id, no_d_id, no_w_id) " +
"VALUES ( ?, ?, ?)");
}
stmtInsertNewOrder.setInt(1, o_id);
stmtInsertNewOrder.setInt(2, d_id);
stmtInsertNewOrder.setInt(3, w_id);
stmtInsertNewOrder.executeUpdate();
newOrderRowInserted = true;
}
catch(SQLException e2)
{
printMessage("The row was already on table new_order. Restarting...");
}
}
if (stmtUpdateDist == null) {
stmtUpdateDist = conn.prepareStatement(
"UPDATE district SET d_next_o_id = d_next_o_id + 1 " +
" WHERE d_id = ? AND d_w_id = ?");
}
stmtUpdateDist.setInt(1,d_id);
stmtUpdateDist.setInt(2,w_id);
result = stmtUpdateDist.executeUpdate();
if(result == 0) throw new Exception("Error!! Cannot update next_order_id on DISTRICT for D_ID=" + d_id + " D_W_ID=" + w_id);
if (stmtInsertOOrder == null) {
stmtInsertOOrder = conn.prepareStatement(
"INSERT INTO OORDER " +
" (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_ol_cnt, o_all_local)" +
" VALUES (?, ?, ?, ?, ?, ?, ?)");
}
stmtInsertOOrder.setInt(1,o_id);
stmtInsertOOrder.setInt(2,d_id);
stmtInsertOOrder.setInt(3,w_id);
stmtInsertOOrder.setInt(4,c_id);
stmtInsertOOrder.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
stmtInsertOOrder.setInt(6,o_ol_cnt);
stmtInsertOOrder.setInt(7,o_all_local);
stmtInsertOOrder.executeUpdate();
for(int ol_number = 1; ol_number <= o_ol_cnt; ol_number++) {
ol_supply_w_id = supplierWarehouseIDs[ol_number-1];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -