org.eclipse.persistence.queries
Class UpdateAllQuery

java.lang.Object
  extended by org.eclipse.persistence.queries.DatabaseQuery
      extended by org.eclipse.persistence.queries.ModifyQuery
          extended by org.eclipse.persistence.queries.ModifyAllQuery
              extended by org.eclipse.persistence.queries.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:

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");

Author:
Guy Pelletier
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.eclipse.persistence.queries.ModifyAllQuery
INVALIDATE_CACHE, NO_CACHE
 
Fields inherited from class org.eclipse.persistence.queries.DatabaseQuery
BATCH_FETCH_PROPERTY, CascadeAggregateDelete, CascadeAllParts, CascadeByMapping, CascadeDependentParts, CascadePrivateParts, NoCascading
 
Constructor Summary
UpdateAllQuery()
          PUBLIC: Constructs a default update all query.
UpdateAllQuery(Class referenceClass)
          PUBLIC: Constructs an update all query for the Class type specified.
UpdateAllQuery(Class referenceClass, Expression selectionCriteria)
          PUBLIC: Constructs an update all query for the specified Class type and selection criteria.
UpdateAllQuery(Class referenceClass, ExpressionBuilder expressionBuilder)
          PUBLIC: Constructs an update all query for the Class type specified and the given ExpressionBuilder.
 
Method Summary
 void addUpdate(Expression field, Expression value)
          PUBLIC: Adds the update (SET) clause to the query.
 void addUpdate(Expression field, Object value)
          PUBLIC: Adds the update (SET) clause to the query.
 void addUpdate(String attributeName, Expression value)
          PUBLIC: Adds the update (SET) clause to the query.
 void addUpdate(String attributeName, Object value)
          PUBLIC: Adds the update (SET) clause to the query.
 Object executeDatabaseQuery()
          INTERNAL: Issue the SQL to the database and then merge into the cache.
 HashMap getUpdateClauses()
          INTERNAL: Return the updates stored for an update all query
 boolean isUpdateAllQuery()
          INTERNAL: Return true if this is an update all query.
 
Methods inherited from class org.eclipse.persistence.queries.ModifyAllQuery
executeInUnitOfWork, getCacheUsage, getExpressionBuilder, getReferenceClass, getReferenceClassName, isModifyQuery, isPreparedUsingTempStorage, mergeChangesIntoSharedCache, setCacheUsage, setExpressionBuilder, setIsPreparedUsingTempStorage, setReferenceClass, setReferenceClassName, setShouldDeferExecutionInUOW, shouldDeferExecutionInUOW
 
Methods inherited from class org.eclipse.persistence.queries.ModifyQuery
forceBatchStatementExecution, getModifyRow, setForceBatchStatementExecution, setModifyRow
 
Methods inherited from class org.eclipse.persistence.queries.DatabaseQuery
addArgument, addArgument, addArgument, addArgumentByTypeName, addArgumentValue, addArgumentValues, addCall, addStatement, bindAllParameters, buildArgumentFields, cacheStatement, cascadeAllParts, cascadeByMapping, cascadeOnlyDependentParts, cascadePrivateParts, checkDescriptor, checkEarlyReturn, checkPrepare, checkPrepare, clone, convertClassNamesToClasses, copyFromQuery, dontBindAllParameters, dontCacheStatement, dontCascadeParts, dontMaintainCache, execute, extractRemoteResult, getAccessor, getArguments, getArgumentTypeNames, getArgumentTypes, getArgumentValues, getBatchObjects, getCall, getCascadePolicy, getDatasourceCall, getDatasourceCalls, getDescriptor, getDomainClassNounName, getDoNotRedirect, getEJBQLString, getExecutionSession, getFlushOnExecute, getHintString, getJPQLString, getName, getProperties, getProperty, getQueryMechanism, getQueryNounName, getQueryTimeout, getRedirector, getSelectionCriteria, getSensorName, getSession, getSessionName, getShouldBindAllParameters, getSourceMapping, getSQLStatement, getSQLString, getSQLStrings, getTranslatedSQLString, getTranslatedSQLStrings, getTranslationRow, hasAccessor, hasArguments, hasProperties, hasQueryMechanism, hasSessionName, ignoreBindAllParameters, ignoreCacheStatement, isCallQuery, isCascadeOfAggregateDelete, isCustomQueryUsed, isDataModifyQuery, isDataReadQuery, isDefaultPropertiesQuery, isDeleteAllQuery, isDeleteObjectQuery, isDirectReadQuery, isExecutionClone, isExpressionQuery, isInsertObjectQuery, isJPQLCallQuery, isModifyAllQuery, isNativeConnectionRequired, isObjectBuildingQuery, isObjectLevelModifyQuery, isObjectLevelReadQuery, isPrepared, isReadAllQuery, isReadObjectQuery, isReadQuery, isReportQuery, isSQLCallQuery, isUpdateObjectQuery, isUserDefined, isValueReadQuery, isWriteObjectQuery, maintainCache, prepareCall, prepareForExecution, prepareFromQuery, redirectQuery, remoteExecute, removeProperty, replaceValueHoldersIn, retrieveBypassCache, rowFromArguments, setAccessor, setArguments, setArgumentTypeNames, setArgumentTypes, setArgumentValues, setBatchObjects, setCall, setCascadePolicy, setDatasourceCall, setDescriptor, setDoNotRedirect, setEJBQLString, setFlushOnExecute, setHintString, setIsExecutionClone, setIsNativeConnectionRequired, setIsPrepared, setIsUserDefined, setJPQLString, setName, setProperties, setProperty, setQueryTimeout, setRedirector, setSelectionCriteria, setSession, setSessionName, setShouldBindAllParameters, setShouldBindAllParameters, setShouldCacheStatement, setShouldMaintainCache, setShouldPrepare, setShouldRetrieveBypassCache, setShouldStoreBypassCache, setShouldUseWrapperPolicy, setSourceMapping, setSQLStatement, setSQLString, setTranslationRow, shouldBindAllParameters, shouldCacheStatement, shouldCascadeAllParts, shouldCascadeByMapping, shouldCascadeOnlyDependentParts, shouldCascadeParts, shouldCascadePrivateParts, shouldCloneCall, shouldIgnoreBindAllParameters, shouldIgnoreCacheStatement, shouldMaintainCache, shouldPrepare, shouldRetrieveBypassCache, shouldStoreBypassCache, shouldUseWrapperPolicy, storeBypassCache, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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
builder - ExpressionBuilder
Method Detail

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

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.

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