如何为多个请求预先分配事务
我们可以为多个请求传播事务吗?例如在线购买。
用户选择行项目,
第 1 步:选择项目后,当他单击按钮时,应在仓库表中搜索项目是否有所需数量。搜索后,它将显示可用的项目表。
步骤2:用户点击处理,从仓库表中扣除可用物品并计算总数并显示订单表。
第 3 步:用户单击“结帐”按钮并输入信用卡详细信息,然后处理订单。
我希望所有这三个步骤应该在一个事务中执行。 Spring事务管理是否可行?
can we propagate transaction for multiple request. for example in online buying.
user select line items and
step 1: after selecting items when he clicks the button the items should be searched in a warehouse table for required quantity is available or not. after searching it will display table of items with availability.
step 2: user clinks process than the available items are deducted from warehouse table and calculates total and display the order table.
step 3: than user clicks check out button and enters the credit card details an the order is processed.
i want all these three steps should execute in one transaction. is it possible in spring transaction management.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
理论上这是可能的,但这是一个非常糟糕的主意。这是一个坏主意的原因是,例如,用户可能在完成事务之前去吃午饭,并且您将一直锁定数据库对象,在最坏的情况下,您的系统将无法运行。
In theory it is possible but would be very poor idea. The reason it's bad idea is that user may, for example, go for lunch before completing transaction and you will have database objects locked for all this time preventing , in the worst case scenario, your system from functioning.
是的,这实际上只是一个过程,分为三个步骤,但在用户提交购买之前,交易实际上不应开始。如果用户在中间中止该过程(例如,放弃非空购物车),则不应开始任何 DB 或 CC 事务。仅在进程最后执行 tx,并在此时一次性执行 DB 和 CC 处理。
Yes, this actually is only one process, spread across three steps, but the transaction should not actually begin until the user has commmitted the purchase. If the user aborts the process in the middle (e.g., abandons a non-empty shopping cart), no DB or CC transaction should have been begun. Execute the tx at the very end of the process only, and at that point do both DB and CC processing in one shot.