Package org.eclipse.persistence.queries
Class UpdateAllQuery
java.lang.Object
org.eclipse.persistence.queries.DatabaseQuery
org.eclipse.persistence.queries.ModifyQuery
org.eclipse.persistence.queries.ModifyAllQuery
org.eclipse.persistence.queries.UpdateAllQuery
- All Implemented Interfaces:
Serializable
,Cloneable
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");
- See Also:
- Author:
- Guy Pelletier
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.persistence.queries.DatabaseQuery
DatabaseQuery.ParameterType
-
Field Summary
Fields inherited from class org.eclipse.persistence.queries.ModifyAllQuery
defaultBuilder, INVALIDATE_CACHE, isPreparedUsingTempStorage, NO_CACHE, referenceClass, referenceClassName, result
Fields inherited from class org.eclipse.persistence.queries.ModifyQuery
forceBatchStatementExecution, isBatchExecutionSupported, modifyRow
Fields inherited from class org.eclipse.persistence.queries.DatabaseQuery
accessors, allowNativeSQLQuery, argumentFields, argumentParameterTypes, arguments, argumentTypeNames, argumentTypes, argumentValues, BATCH_FETCH_PROPERTY, CascadeAggregateDelete, CascadeAllParts, CascadeByMapping, CascadeDependentParts, cascadePolicy, CascadePrivateParts, descriptor, descriptors, doNotRedirect, executionSession, flushOnExecute, hintString, isCustomQueryUsed, isExecutionClone, isNativeConnectionRequired, isPrepared, isUserDefined, isUserDefinedSQLCall, monitorName, name, NoCascading, nullableArguments, parameterDelimiter, partitioningPolicy, properties, queryMechanism, queryTimeout, queryTimeoutUnit, redirector, session, sessionName, shouldBindAllParameters, shouldCacheStatement, shouldCloneCall, shouldMaintainCache, shouldPrepare, shouldRetrieveBypassCache, shouldReturnGeneratedKeys, shouldStoreBypassCache, shouldUseWrapperPolicy, shouldValidateUpdateCallCacheUse, sourceMapping, translationRow
-
Constructor Summary
ConstructorDescriptionPUBLIC: 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
Modifier and TypeMethodDescriptionvoid
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
(Expression field, Object value) PUBLIC: Adds the update (SET) clause to the query.void
addUpdate
(Expression field, Expression value) PUBLIC: Adds the update (SET) clause to the query.protected void
addUpdateInternal
(Object fieldObject, Object valueObject) INTERNAL:INTERNAL: Issue the SQL to the database and then merge into the cache.protected QueryRedirector
INTERNAL: Returns the specific default redirector for this query type.INTERNAL: Return the updates stored for an update all queryprotected void
INTERNAL: Initialize the expression builder which should be used for this query.boolean
INTERNAL: Return true if this is an update all query.protected void
prepare()
INTERNAL:Methods inherited from class org.eclipse.persistence.queries.ModifyAllQuery
clonedQueryExecutionComplete, executeInUnitOfWork, getCacheUsage, getExpressionBuilder, getReferenceClass, getReferenceClassName, initializeDefaultBuilder, invalidateCache, isModifyAllQuery, isPreparedUsingTempStorage, mergeChangesIntoSharedCache, setCacheUsage, setExpressionBuilder, setIsPreparedUsingTempStorage, setReferenceClass, setReferenceClassName, setShouldDeferExecutionInUOW, shouldDeferExecutionInUOW, shouldInvalidateCache
Methods inherited from class org.eclipse.persistence.queries.ModifyQuery
forceBatchStatementExecution, getModifyRow, isBatchExecutionSupported, isModifyQuery, setForceBatchStatementExecution, setIsBatchExecutionSupported, setModifyRow
Methods inherited from class org.eclipse.persistence.queries.DatabaseQuery
addArgument, addArgument, addArgument, addArgument, addArgument, addArgument, addArgumentByTypeName, addArgumentValue, addArgumentValues, addCall, addStatement, bindAllParameters, buildArgumentFields, buildSelectionCriteria, cacheStatement, cascadeAllParts, cascadeByMapping, cascadeOnlyDependentParts, cascadePrivateParts, checkDescriptor, checkEarlyReturn, checkForCustomQuery, checkPrepare, checkPrepare, clone, convertClassNamesToClasses, copyFromQuery, dontBindAllParameters, dontCacheStatement, dontCascadeParts, dontMaintainCache, execute, extractRemoteResult, getAccessor, getAccessors, getArgumentParameterTypes, getArguments, getArgumentTypeNames, getArgumentTypes, getArgumentValues, getBatchObjects, getCall, getCascadePolicy, getDatasourceCall, getDatasourceCalls, getDescriptor, getDescriptors, getDomainClassNounName, getDoNotRedirect, getEJBQLString, getExecutionSession, getFlushOnExecute, getHintString, getJPQLString, getMonitorName, getName, getNullableArguments, getParameterDelimiter, getParameterDelimiterChar, getPartitioningPolicy, getProperties, getProperty, getQueryMechanism, getQueryNounName, getQueryTimeout, getQueryTimeoutUnit, getRedirector, getRedirectorForQuery, getSelectionCriteria, getSensorName, getSession, getSessionName, getShouldBindAllParameters, getSourceMapping, getSQLStatement, getSQLString, getSQLStrings, getTranslatedSQLString, getTranslatedSQLStrings, getTranslationRow, hasAccessor, hasArguments, hasNullableArguments, hasProperties, hasQueryMechanism, hasSessionName, ignoreBindAllParameters, ignoreCacheStatement, isCallQuery, isCascadeOfAggregateDelete, isCustomQueryUsed, isCustomSelectionQuery, isDataModifyQuery, isDataReadQuery, isDefaultPropertiesQuery, isDeleteAllQuery, isDeleteObjectQuery, isDirectReadQuery, isExecutionClone, isExpressionQuery, isInsertObjectQuery, isJPQLCallQuery, isNativeConnectionRequired, isObjectBuildingQuery, isObjectLevelModifyQuery, isObjectLevelReadQuery, isPrepared, isReadAllQuery, isReadObjectQuery, isReadQuery, isReportQuery, isResultSetMappingQuery, isSQLCallQuery, isUpdateObjectQuery, isUserDefined, isUserDefinedSQLCall, isValueReadQuery, isWriteObjectQuery, maintainCache, prepareCall, prepareCustomQuery, prepareForExecution, prepareForRemoteExecution, prepareFromQuery, prepareInternal, redirectQuery, remoteExecute, remoteExecute, removeProperty, replaceValueHoldersIn, resetMonitorName, retrieveBypassCache, rowFromArguments, setAccessor, setAccessors, setAllowNativeSQLQuery, setArguments, setArgumentTypeNames, setArgumentTypes, setArgumentValues, setBatchObjects, setCall, setCascadePolicy, setDatasourceCall, setDescriptor, setDoNotRedirect, setEJBQLString, setExecutionSession, setFlushOnExecute, setHintString, setIsCustomQueryUsed, setIsExecutionClone, setIsNativeConnectionRequired, setIsPrepared, setIsUserDefined, setIsUserDefinedSQLCall, setJPQLString, setName, setNullableArguments, setParameterDelimiter, setPartitioningPolicy, setProperties, setProperty, setQueryMechanism, setQueryTimeout, setQueryTimeoutUnit, setRedirector, setSelectionCriteria, setSession, setSessionName, setShouldBindAllParameters, setShouldBindAllParameters, setShouldCacheStatement, setShouldMaintainCache, setShouldPrepare, setShouldRetrieveBypassCache, setShouldReturnGeneratedKeys, setShouldStoreBypassCache, setShouldUseWrapperPolicy, setShouldValidateUpdateCallCacheUse, setSourceMapping, setSQLStatement, setSQLString, setTranslationRow, shouldAllowNativeSQLQuery, shouldBindAllParameters, shouldCacheStatement, shouldCascadeAllParts, shouldCascadeByMapping, shouldCascadeOnlyDependentParts, shouldCascadeParts, shouldCascadePrivateParts, shouldCloneCall, shouldIgnoreBindAllParameters, shouldIgnoreCacheStatement, shouldMaintainCache, shouldPrepare, shouldPrepare, shouldRetrieveBypassCache, shouldReturnGeneratedKeys, shouldStoreBypassCache, shouldUseWrapperPolicy, shouldValidateUpdateCallCacheUse, storeBypassCache, toString
-
Field Details
-
m_updateClauses
-
-
Constructor Details
-
UpdateAllQuery
public UpdateAllQuery()PUBLIC: Constructs a default update all query. -
UpdateAllQuery
PUBLIC: Constructs an update all query for the Class type specified.- Parameters:
referenceClass
- Class
-
UpdateAllQuery
PUBLIC: Constructs an update all query for the specified Class type and selection criteria.- Parameters:
referenceClass
- Class type to be consideredselectionCriteria
- Expression
-
UpdateAllQuery
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 consideredexpressionBuilder
- ExpressionBuilder
-
-
Method Details
-
addUpdate
PUBLIC: Adds the update (SET) clause to the query. Uses default ExpressionBuilder.- Parameters:
field
- Expression Object level representation of a database query 'where' clausevalue
- Object, the new value
-
addUpdate
PUBLIC: Adds the update (SET) clause to the query. Uses default ExpressionBuilder.- Parameters:
attributeName
- String, the name of the attributevalue
- Object, the new value
-
addUpdate
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 fieldvalue
- Expression, representation of a database query 'where' clause that describes the new value
-
addUpdate
PUBLIC: Adds the update (SET) clause to the query. Uses default ExpressionBuilder.- Parameters:
attributeName
- String, the name of the attributevalue
- Expression, the new value
-
addUpdateInternal
INTERNAL: -
executeDatabaseQuery
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 classDatabaseQuery
- Returns:
- - the result of executing the query.
- Throws:
DatabaseException
- - an error has occurred on the database.
-
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 classDatabaseQuery
-
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 classDatabaseQuery
-
prepare
INTERNAL:- Overrides:
prepare
in classDatabaseQuery
- 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 classModifyAllQuery
-