public TPCCNewOrderStoredProcedure(string sessionId, NewOrderInParameters inParams) { this.pid = int.Parse(sessionId); this.sessionId = sessionId; this.input = inParams; this.currentState = NewOrderState.ToStart; this.errMsg = ""; }
public Order(int itemNumber, int quantityRequested) { _newOrderState = new NewOrderState(this); _openOrderState = new OpenOrderState(this); _closedOrderState = new ClosedOrderState(this); _state = _newOrderState; _itemNumber = itemNumber; _quantityRequested = quantityRequested; _newQuantityRequested = quantityRequested; }
public override void Start() { // init this.output = new TPCCWorkloadOutput(); output.txFinalStatus = TxFinalStatus.UNKNOWN; this.olCount = this.input.OL_I_IDs.Length; this.items = new ItemPayload[olCount]; this.totalFee = 0.0; this.itemsData = new Tuple <string, int, char, double, double> [olCount]; this.i = 0; // the first step this.currentState = NewOrderState.ReadItems; ReadItem(); }
public override void InsertCallBack(string tableId, object recordKey, object payload) { switch (this.currentState) { case NewOrderState.InsertO: this.currentState = NewOrderState.UpdateD; this.dpl.D_NEXT_O_ID = this.D_NEXT_O_ID + 1; this.AddReq(this.dpkStr, JsonConvert.SerializeObject(this.dpl), OperationType.Update); break; case NewOrderState.InsertNO: this.i = 0; this.currentState = NewOrderState.InsertOLsReadS; ReadStock(); break; case NewOrderState.InsertOLsInsertOL: // add to output var brand = (items[i].I_DATA.Contains("ORIGINAL") && spl.S_DATA.Contains("ORIGINAL")) ? 'B' : 'G'; itemsData[i] = new Tuple <string, int, char, double, double>(items[i].I_NAME, spl.S_QUANTITY, brand, items[i].I_PRICE, input.OL_QUANTITYs[i] * items[i].I_PRICE); this.i += 1; if (this.i < this.olCount) { this.currentState = NewOrderState.InsertOLsReadS; ReadStock(); } else { this.buildOutput(); this.Close("normal close"); } break; default: this.Close("exception insert"); break; } this.StoreCurrentState(); }
public override void UpdateCallBack(string tableId, object recordKey, object newPayload) { switch (this.currentState) { case NewOrderState.UpdateD: this.currentState = NewOrderState.ReadInitNO; NewOrderPkey nopk = new NewOrderPkey { NO_O_ID = D_NEXT_O_ID, NO_D_ID = input.D_ID, NO_W_ID = input.W_ID }; this.nopkStr = nopk.ToString(); this.AddReq(this.nopkStr, null, OperationType.InitiRead); break; case NewOrderState.InsertOLsUpdateS: this.currentState = NewOrderState.InsertOLsReadInitOL; OrderLinePkey olpk = new OrderLinePkey { OL_O_ID = D_NEXT_O_ID, OL_D_ID = input.D_ID, OL_W_ID = input.W_ID, OL_NUMBER = (uint)i + 1 }; this.olpkStr = olpk.ToString(); this.AddReq(this.olpkStr, null, OperationType.InitiRead); break; default: this.Close("exception update"); break; } this.StoreCurrentState(); }
public override void ReadCallback(string tableId, object recordKey, object payload) { switch (this.currentState) { case NewOrderState.ReadItems: if (payload == null) { this.Close("read item failed"); break; } items[i++] = JsonConvert.DeserializeObject <ItemPayload>(payload as string); if (this.i < this.olCount) { ReadItem(); } else { this.currentState = NewOrderState.ReadW; WarehousePkey wpk = new WarehousePkey { W_ID = input.W_ID }; this.AddReq(wpk.ToString()); } break; case NewOrderState.ReadW: if (payload == null) { this.Close("read W fail"); break; } WarehousePayload wpl = JsonConvert.DeserializeObject <WarehousePayload>(payload as string); this.W_TAX = wpl.W_TAX; this.currentState = NewOrderState.ReadD; DistrictPkey dpk = new DistrictPkey { D_ID = input.D_ID, D_W_ID = input.W_ID }; this.dpkStr = dpk.ToString(); this.AddReq(this.dpkStr); break; case NewOrderState.ReadD: if (payload == null) { this.Close("read D fail"); break; } this.dpl = JsonConvert.DeserializeObject <DistrictPayload>(payload as string); this.D_NEXT_O_ID = dpl.D_NEXT_O_ID; this.currentState = NewOrderState.ReadC; CustomerPkey cpk = new CustomerPkey { C_ID = input.C_ID, C_D_ID = input.D_ID, C_W_ID = input.W_ID }; this.AddReq(cpk.ToString()); break; case NewOrderState.ReadC: if (payload == null) { this.Close("read C fail"); break; } this.cpl = JsonConvert.DeserializeObject <CustomerPayload>(payload as string); this.C_DISCOUNT = cpl.C_DISCOUNT; // this.currentState = NewOrderState.ReadInitO; OrderPkey opk = new OrderPkey { O_ID = D_NEXT_O_ID, O_D_ID = input.D_ID, O_W_ID = input.W_ID }; this.opkStr = opk.ToString(); this.AddReq(this.opkStr, null, OperationType.InitiRead); break; case NewOrderState.ReadInitO: if (payload != null) { this.Close("read init O fail"); break; } this.currentState = NewOrderState.InsertO; // all local or not bool allLocal = true; for (i = 0; i < this.olCount; i++) { allLocal = allLocal & input.OL_I_IDs[i] == input.W_ID; } OrderPayload opl = new OrderPayload { O_C_ID = input.C_ID, O_ENTRY_D = input.O_ENTRY_D, O_CARRIER_ID = Constants.NullCarrierID, O_OL_CNT = (uint)input.OL_I_IDs.Length, O_ALL_LOCAL = Convert.ToUInt32(allLocal) }; AddReq(this.opkStr, JsonConvert.SerializeObject(opl), OperationType.Insert); break; case NewOrderState.ReadInitNO: if (payload != null) { this.Close("read init NO fail"); break; } this.currentState = NewOrderState.InsertNO; this.AddReq(this.nopkStr, Constants.PlaceHolders, OperationType.Insert); break; case NewOrderState.InsertOLsReadS: if (payload == null) { this.Close("insert OL read S fail"); break; } this.currentState = NewOrderState.InsertOLsUpdateS; this.spl = JsonConvert.DeserializeObject <StockPayload>(payload as string); uint OL_QUANTITY = input.OL_QUANTITYs[i]; this.spl.S_YTD += OL_QUANTITY; if (spl.S_QUANTITY >= OL_QUANTITY + 10) { spl.S_QUANTITY -= (int)OL_QUANTITY; } else { spl.S_QUANTITY += 91 - (int)OL_QUANTITY; } spl.S_ORDER_CNT += 1; if (input.OL_SUPPLY_W_IDs[i] != input.W_ID) { spl.S_REMOTE_CNT += 1; } this.AddReq(this.spkStr, JsonConvert.SerializeObject(spl), OperationType.Update); break; case NewOrderState.InsertOLsReadInitOL: if (payload != null) { this.Close("insert OL read init OL fail"); break; } this.currentState = NewOrderState.InsertOLsInsertOL; double OL_AMOUNT = input.OL_QUANTITYs[i] * items[i].I_PRICE; this.totalFee += OL_AMOUNT; OrderLinePayload olpl = new OrderLinePayload { OL_I_ID = input.OL_I_IDs[i], OL_SUPPLY_W_ID = input.OL_SUPPLY_W_IDs[i], OL_DELIVERY_D = null, OL_QUANTITY = input.OL_QUANTITYs[i], OL_AMOUNT = OL_AMOUNT, OL_DIST_INFO = spl.S_DIST_01 // TODO, assign to S_DIST_XX, where XX equals to D_ID }; this.AddReq(this.olpkStr, JsonConvert.SerializeObject(olpl), OperationType.Insert); break; default: this.Close("exception read"); break; } this.StoreCurrentState(); }