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:
- java.io.Serializable, java.lang.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");
- See Also:
- Serialized Form
- Author:
- Guy Pelletier
Fields inherited from class org.eclipse.persistence.queries.DatabaseQuery |
accessors, allowNativeSQLQuery, argumentFields, arguments, argumentTypeNames, argumentTypes, argumentValues, BATCH_FETCH_PROPERTY, CascadeAggregateDelete, CascadeAllParts, CascadeByMapping, CascadeDependentParts, cascadePolicy, CascadePrivateParts, descriptor, doNotRedirect, executionSession, flushOnExecute, hintString, isCustomQueryUsed, isExecutionClone, isNativeConnectionRequired, isPrepared, isUserDefined, isUserDefinedSQLCall, monitorName, name, NoCascading, nullableArguments, parameterDelimiter, partitioningPolicy, properties, queryMechanism, queryTimeout, redirector, session, sessionName, shouldBindAllParameters, shouldCacheStatement, shouldCloneCall, shouldMaintainCache, shouldPrepare, shouldRetrieveBypassCache, shouldStoreBypassCache, shouldUseWrapperPolicy, shouldValidateUpdateCallCacheUse, sourceMapping, translationRow |
Constructor Summary |
UpdateAllQuery()
PUBLIC:
Constructs a default update all query. |
UpdateAllQuery(java.lang.Class referenceClass)
PUBLIC:
Constructs an update all query for the Class type specified. |
UpdateAllQuery(java.lang.Class referenceClass,
Expression selectionCriteria)
PUBLIC:
Constructs an update all query for the specified Class type and selection criteria. |
UpdateAllQuery(java.lang.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,
java.lang.Object value)
PUBLIC:
Adds the update (SET) clause to the query. |
void |
addUpdate(java.lang.String attributeName,
Expression value)
PUBLIC:
Adds the update (SET) clause to the query. |
void |
addUpdate(java.lang.String attributeName,
java.lang.Object value)
PUBLIC:
Adds the update (SET) clause to the query. |
protected void |
addUpdateInternal(java.lang.Object fieldObject,
java.lang.Object valueObject)
INTERNAL: |
java.lang.Object |
executeDatabaseQuery()
INTERNAL:
Issue the SQL to the database and then merge into the cache. |
protected QueryRedirector |
getDefaultRedirector()
INTERNAL:
Returns the specific default redirector for this query type. |
java.util.HashMap |
getUpdateClauses()
INTERNAL:
Return the updates stored for an update all query |
protected void |
initializeQuerySpecificDefaultBuilder()
INTERNAL:
Initialize the expression builder which should be used for this query. |
boolean |
isUpdateAllQuery()
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, isModifyQuery, isPreparedUsingTempStorage, mergeChangesIntoSharedCache, setCacheUsage, setExpressionBuilder, setIsPreparedUsingTempStorage, setReferenceClass, setReferenceClassName, setShouldDeferExecutionInUOW, shouldDeferExecutionInUOW, shouldInvalidateCache |
Methods inherited from class org.eclipse.persistence.queries.DatabaseQuery |
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, getArguments, getArgumentTypeNames, getArgumentTypes, getArgumentValues, getBatchObjects, getCall, getCascadePolicy, getDatasourceCall, getDatasourceCalls, getDescriptor, getDomainClassNounName, getDoNotRedirect, getEJBQLString, getExecutionSession, getFlushOnExecute, getHintString, getJPQLString, getMonitorName, getName, getNullableArguments, getParameterDelimiter, getParameterDelimiterChar, getPartitioningPolicy, getProperties, getProperty, getQueryMechanism, getQueryNounName, getQueryTimeout, 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, isModifyAllQuery, isNativeConnectionRequired, isObjectBuildingQuery, isObjectLevelModifyQuery, isObjectLevelReadQuery, isPrepared, isReadAllQuery, isReadObjectQuery, isReadQuery, isReportQuery, isSQLCallQuery, isUpdateObjectQuery, isUserDefined, isUserDefinedSQLCall, isValueReadQuery, isWriteObjectQuery, maintainCache, prepareCall, prepareCustomQuery, prepareForExecution, prepareForRemoteExecution, prepareFromQuery, 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, setRedirector, setSelectionCriteria, setSession, setSessionName, setShouldBindAllParameters, setShouldBindAllParameters, setShouldCacheStatement, setShouldMaintainCache, setShouldPrepare, setShouldRetrieveBypassCache, setShouldStoreBypassCache, setShouldUseWrapperPolicy, setShouldValidateUpdateCallCacheUse, setSourceMapping, setSQLStatement, setSQLString, setTranslationRow, shouldAllowNativeSQLQuery, shouldBindAllParameters, shouldCacheStatement, shouldCascadeAllParts, shouldCascadeByMapping, shouldCascadeOnlyDependentParts, shouldCascadeParts, shouldCascadePrivateParts, shouldCloneCall, shouldIgnoreBindAllParameters, shouldIgnoreCacheStatement, shouldMaintainCache, shouldPrepare, shouldPrepare, shouldRetrieveBypassCache, shouldStoreBypassCache, shouldUseWrapperPolicy, shouldValidateUpdateCallCacheUse, storeBypassCache, toString |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
m_updateClauses
protected java.util.HashMap m_updateClauses
UpdateAllQuery
public UpdateAllQuery()
- PUBLIC:
Constructs a default update all query.
UpdateAllQuery
public UpdateAllQuery(java.lang.Class referenceClass)
- PUBLIC:
Constructs an update all query for the Class type specified.
- Parameters:
referenceClass
- Class
UpdateAllQuery
public UpdateAllQuery(java.lang.Class referenceClass,
Expression selectionCriteria)
- PUBLIC:
Constructs an update all query for the specified Class type and selection criteria.
- Parameters:
referenceClass
- Class type to be consideredselectionCriteria
- Expression
UpdateAllQuery
public UpdateAllQuery(java.lang.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 consideredbuilder
- ExpressionBuilder
addUpdate
public void addUpdate(Expression field,
java.lang.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' clausevalue
- Object, the new value
addUpdate
public void addUpdate(java.lang.String attributeName,
java.lang.Object value)
- 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 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 fieldvalue
- Expression, representation of a database query 'where' clause that describes the new value
addUpdate
public void addUpdate(java.lang.String attributeName,
Expression value)
- 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
protected void addUpdateInternal(java.lang.Object fieldObject,
java.lang.Object valueObject)
- INTERNAL:
executeDatabaseQuery
public java.lang.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 java.util.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