Class UpdateUtil
entityUtil instead unless a developer
has explicitly told you to use this.
A bulk statement bypasses the entity lifecycle completely: no lifecycle scripts run, no calculated fields recompute, no revision history is written and no audit events fire for the affected rows. The rows change and nothing else in the application learns that they did, so the damage from a wrong statement is silent and can be wide.
It also binds the configuration to the entity model: the statement names entities and fields directly, so a later data-model change breaks a script that nothing in the build can see.
entityUtil.updateEntity(...) and entityUtil.deleteEntity(...) are the right
tools for changing data from a script, and they are the right tools nearly every time. Reach for
this only when someone has decided a set-based statement is genuinely required - a one-off data
repair, or a volume that entity-at-a-time work cannot carry - and has said so.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectLast resort: runs a bulk update or delete, bypassing the entity lifecycle; preferentityUtil.updateEntity(...).static ObjectupdateParam(String queryStr, Map<String, Object> params) Last resort: runs a parameterised bulk update or delete, bypassing the entity lifecycle; preferentityUtil.updateEntity(...).
-
Constructor Details
-
UpdateUtil
public UpdateUtil(com.ssgllc.fish.service.GenericQueryService genericQueryService)
-
-
Method Details
-
update
Last resort: runs a bulk update or delete, bypassing the entity lifecycle; preferentityUtil.updateEntity(...). Inline any values, or preferupdateParam(String, Map)so they are bound rather than concatenated.
Prefer
entityUtil.updateEntity(...) or entityUtil.deleteEntity(...). A bulk statement fires no lifecycle scripts, recomputes no calculated fields and writes no revision history. Use this only when a developer has said a set-based statement is required.- Parameters:
queryStr- the JPQL update or delete statement- Returns:
- the number of rows affected
- Throws:
Exception- if the statement is invalid or the update fails
Groovy example:
// mutates rows: this is a bulk statement, not a query
return updateUtil.update("update Role r set r.description = 'unset' where r.description is null")
Returns:
the number of rows updated
-
updateParam
Last resort: runs a parameterised bulk update or delete, bypassing the entity lifecycle; preferentityUtil.updateEntity(...). Prefer this overupdate(String)whenever a value comes from data - binding keeps the value out of the statement text.
Prefer
entityUtil.updateEntity(...) or entityUtil.deleteEntity(...). A bulk statement fires no lifecycle scripts, recomputes no calculated fields and writes no revision history. Use this only when a developer has said a set-based statement is required.- Parameters:
queryStr- the JPQL statement, using:nameplaceholdersparams- placeholder names to values- Returns:
- the number of rows affected
- Throws:
Exception- if the statement is invalid, a placeholder is unbound, or the update fails
Groovy example:
def params = ['statusId': bpmUtil.getConceptIdFromCode('OrderStatus', 'CLOSED')]
return updateUtil.updateParam("update Order o set o.statusId = :statusId where o.closedDate is not null", params)
Returns:
the number of orders closed
-