Class UpdateAllQuery

All Implemented Interfaces:
Serializable, Cloneable

public class UpdateAllQuery extends ModifyAllQuery
PUBLIC: A Query Class used to perform a bulk update using TopLink's expression framework. This class is provided to help optimize performance. It can be used in place of reading in all the objects to be changed and issuing single updates per instance. With this approach a single SQL UPDATE statement can be issued and then, based on the Expression provided, any objects in the cache that are effected by the update can be invalidated.

Notes:

  • By default, if a UOW is being used, this query will be deferred until the UOW commits.
  • UpdateAllQuery does not support foreign key updates unless the relationship is 1-1 (without back pointers.)

Example of Usage: Adding an area code.
UpdateAllQuery updateQuery = new UpdateAllQuery(Employee.class);
updateQuery.setSelectionCriteria(eb.get("areaCode").isNull());
updateQuery.addUpdate(eb.get("areaCode"), "613");

Since:
March 1, 2004
See Also:
  • Field Details

    • m_updateClauses

      protected HashMap m_updateClauses
  • Constructor Details

    • UpdateAllQuery

      public UpdateAllQuery()
      PUBLIC: Constructs a default update all query.
    • UpdateAllQuery

      public UpdateAllQuery(Class<?> referenceClass)
      PUBLIC: Constructs an update all query for the Class type specified.
      Parameters:
      referenceClass - Class
    • UpdateAllQuery

      public UpdateAllQuery(Class<?> referenceClass, Expression selectionCriteria)
      PUBLIC: Constructs an update all query for the specified Class type and selection criteria.
      Parameters:
      referenceClass - Class type to be considered
      selectionCriteria - Expression
    • UpdateAllQuery

      public UpdateAllQuery(Class<?> referenceClass, ExpressionBuilder expressionBuilder)
      PUBLIC: Constructs an update all query for the Class type specified and the given ExpressionBuilder. This sets the default builder which is used for all associated expressions in the query.
      Parameters:
      referenceClass - Class type to be considered
      expressionBuilder - ExpressionBuilder
  • Method Details

    • addUpdate

      public void addUpdate(Expression field, Object value)
      PUBLIC: Adds the update (SET) clause to the query. Uses default ExpressionBuilder.
      Parameters:
      field - Expression Object level representation of a database query 'where' clause
      value - Object, the new value
    • addUpdate

      public void addUpdate(String attributeName, Object value)
      PUBLIC: Adds the update (SET) clause to the query. Uses default ExpressionBuilder.
      Parameters:
      attributeName - String, the name of the attribute
      value - Object, the new value
    • addUpdate

      public void addUpdate(Expression field, Expression value)
      PUBLIC: Adds the update (SET) clause to the query. This method ensures that the builder has the session and reference class set for both given Expressions. Uses default ExpressionBuilder.
      Parameters:
      field - Expression, representation of a database query 'where' clause that describes the field
      value - Expression, representation of a database query 'where' clause that describes the new value
    • addUpdate

      public void addUpdate(String attributeName, Expression value)
      PUBLIC: Adds the update (SET) clause to the query. Uses default ExpressionBuilder.
      Parameters:
      attributeName - String, the name of the attribute
      value - Expression, the new value
    • addUpdateInternal

      protected void addUpdateInternal(Object fieldObject, Object valueObject)
      INTERNAL:
    • executeDatabaseQuery

      public Object executeDatabaseQuery() throws DatabaseException
      INTERNAL: Issue the SQL to the database and then merge into the cache. If we are within a UoW, the merge to the cache must not be done until the UoW merges into the parent. The UoW will trigger the merge to occur at the correct time and will ensure the cache setting is set to none at that time.
      Specified by:
      executeDatabaseQuery in class DatabaseQuery
      Returns:
      - the result of executing the query.
      Throws:
      DatabaseException - - an error has occurred on the database.
    • getDefaultRedirector

      protected QueryRedirector getDefaultRedirector()
      INTERNAL: Returns the specific default redirector for this query type. There are numerous default query redirectors. See ClassDescriptor for their types.
      Overrides:
      getDefaultRedirector in class DatabaseQuery
    • getUpdateClauses

      public HashMap getUpdateClauses()
      INTERNAL: Return the updates stored for an update all query
    • isUpdateAllQuery

      public boolean isUpdateAllQuery()
      INTERNAL: Return true if this is an update all query.
      Overrides:
      isUpdateAllQuery in class DatabaseQuery
    • prepare

      protected void prepare() throws QueryException
      INTERNAL:
      Overrides:
      prepare in class DatabaseQuery
      Throws:
      QueryException
    • initializeQuerySpecificDefaultBuilder

      protected void initializeQuerySpecificDefaultBuilder()
      INTERNAL: Initialize the expression builder which should be used for this query. If there is a where clause, use its expression builder. If after this method defaultBuilder is still null, then initializeDefaultBuilder method will generate and cache it.
      Overrides:
      initializeQuerySpecificDefaultBuilder in class ModifyAllQuery