You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将Procedure的“Execute in new LUW”属性从False改True有何差异?求示例

GeneXus Procedure「Execute in new LUW」属性修改差异及示例

核心差异(False vs True)

LUW(逻辑工作单元)对应数据库事务,决定操作的原子性范围:

  • 设为False(默认):

    • Procedure继承调用方的事务上下文,和调用方共享同一个LUW。
    • 所有数据库操作和调用方的操作绑定,要么一起提交,要么一起回滚。
    • 只要Procedure执行出错,整个调用链的事务都会回滚。
  • 改为True:

    • Procedure启动独立的新LUW,和调用方事务完全隔离。
    • 内部数据库操作在独立事务中执行,完成后自动提交(手动回滚除外),不影响调用方事务。
    • 即使Procedure执行失败,仅回滚自身操作,调用方已执行的事务不受影响。

使用示例

场景1:默认False(共享事务)

现有两个Procedure:Proc_UpdateUser(更新用户邮箱)、Proc_LogOperation(记录操作日志),均设为False。

调用代码:

Event 'UpdateUserEmail'
    &UserId = 123
    &NewEmail = 'user@newdomain.com'
    Call Proc_UpdateUser(&UserId, &NewEmail)
    Call Proc_LogOperation(&UserId, 'Email updated')
    Commit // 同时提交两个Procedure的操作
EndEvent

如果Proc_LogOperation插入日志失败,Proc_UpdateUser的邮箱更新也会被回滚——因为两者在同一个LUW里。

场景2:设为True(独立事务)

将Proc_LogOperation的「Execute in new LUW」改为True。

调用代码:

Event 'UpdateUserEmail'
    &UserId = 123
    &NewEmail = 'user@newdomain.com'
    Call Proc_UpdateUser(&UserId, &NewEmail)
    Call Proc_LogOperation(&UserId, 'Email updated') // 独立事务,执行后自动提交
    Commit // 仅提交Proc_UpdateUser的操作
EndEvent

此时若Proc_LogOperation执行失败,只会回滚日志插入,Proc_UpdateUser的邮箱更新依然生效——两者事务完全隔离。

属性设置界面截图

GeneXus Procedure的Execute in new LUW属性设置界面

内容的提问来源于stack exchange,提问作者dragonquila

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 22:18:09