Skip to content

feat: Add setForUpdate support to Query class#626

Open
EdwinBetanc0urt wants to merge 1 commit into
solop-develop:developfrom
EdwinBetanc0urt:feature/query-for-update-clause
Open

feat: Add setForUpdate support to Query class#626
EdwinBetanc0urt wants to merge 1 commit into
solop-develop:developfrom
EdwinBetanc0urt:feature/query-for-update-clause

Conversation

@EdwinBetanc0urt

Copy link
Copy Markdown
Member

Summary

  • Port the setForUpdate(boolean) method from iDempiere so Query can emit a row-level FOR UPDATE lock, matching upstream behavior.

Changes

  • base/src/main/java/org/compiere/model/Query.java
    • Add forUpdate field (default false).
    • Add fluent setForUpdate(boolean) setter.
    • In buildSQL(), append FOR UPDATE after the access filter; add the OF <table> qualifier on PostgreSQL.

Notes

  • Backported from iDempiere org.compiere.model.Query (commit bf1e799).
  • The clause applies to every buildSQL path (list/first/scroll/iterate); do not combine setForUpdate(true) with aggregate/count on the same Query.
  • Locking only takes effect inside an active transaction (non-null trxName).

Test plan

  • new Query(ctx, table, where, trxName).setForUpdate(true).first() yields ... FOR UPDATE OF <table> on PostgreSQL and locks the row until commit/rollback.
  • ./gradlew build green.

## Summary
- Port the `setForUpdate(boolean)` method from iDempiere so `Query` can emit a
  row-level `FOR UPDATE` lock, matching upstream behavior.

## Changes
- `base/src/main/java/org/compiere/model/Query.java`
  - Add `forUpdate` field (default `false`).
  - Add fluent `setForUpdate(boolean)` setter.
  - In `buildSQL()`, append `FOR UPDATE` after the access filter; add the
    `OF <table>` qualifier on PostgreSQL.

## Notes
- Backported from iDempiere `org.compiere.model.Query` (commit bf1e799).
- The clause applies to every `buildSQL` path (list/first/scroll/iterate);
  do not combine `setForUpdate(true)` with aggregate/count on the same Query.
- Locking only takes effect inside an active transaction (non-null trxName).

## Test plan
- [ ] `new Query(ctx, table, where, trxName).setForUpdate(true).first()` yields
      `... FOR UPDATE OF <table>` on PostgreSQL and locks the row until commit/rollback.
- [ ] `./gradlew build` green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant