Class UpdateUtil

java.lang.Object
com.ssgllc.fish.service.util.published.UpdateUtil

@Component public class UpdateUtil extends Object
Last resort for bulk JPQL updates and deletes. Use 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
    Constructor
    Description
    UpdateUtil(com.ssgllc.fish.service.GenericQueryService genericQueryService)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Object
    update(String queryStr)
    Last resort: runs a bulk update or delete, bypassing the entity lifecycle; prefer entityUtil.updateEntity(...).
    static Object
    updateParam(String queryStr, Map<String,Object> params)
    Last resort: runs a parameterised bulk update or delete, bypassing the entity lifecycle; prefer entityUtil.updateEntity(...).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • UpdateUtil

      public UpdateUtil(com.ssgllc.fish.service.GenericQueryService genericQueryService)
  • Method Details

    • update

      public static Object update(String queryStr) throws Exception
      Last resort: runs a bulk update or delete, bypassing the entity lifecycle; prefer entityUtil.updateEntity(...). Inline any values, or prefer updateParam(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

      public static Object updateParam(String queryStr, Map<String,Object> params) throws Exception
      Last resort: runs a parameterised bulk update or delete, bypassing the entity lifecycle; prefer entityUtil.updateEntity(...). Prefer this over update(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 :name placeholders
      params - 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