feat: Add setForUpdate support to Query class#626
Open
EdwinBetanc0urt wants to merge 1 commit into
Open
Conversation
## 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
setForUpdate(boolean)method from iDempiere soQuerycan emit a row-levelFOR UPDATElock, matching upstream behavior.Changes
base/src/main/java/org/compiere/model/Query.javaforUpdatefield (defaultfalse).setForUpdate(boolean)setter.buildSQL(), appendFOR UPDATEafter the access filter; add theOF <table>qualifier on PostgreSQL.Notes
org.compiere.model.Query(commit bf1e799).buildSQLpath (list/first/scroll/iterate); do not combinesetForUpdate(true)with aggregate/count on the same Query.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 buildgreen.