Top Description Fields Constructors Methods
org.eclipse.persistence.queries

public Class UpdateAllQuery

extends ModifyAllQuery
Class Inheritance
Imports
java.util.*, org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.exceptions.*, org.eclipse.persistence.expressions.*

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
Since
March 1, 2004

Field Summary

Modifier and TypeField and Description
protected HashMap<K, V>
Inherited from org.eclipse.persistence.queries.ModifyAllQuery:
defaultBuilderINVALIDATE_CACHEisPreparedUsingTempStorageNO_CACHEreferenceClassreferenceClassNameresult

Constructor Summary

AccessConstructor and Description
public
UpdateAllQuery()

PUBLIC: Constructs a default update all query.

public
UpdateAllQuery(Class<?>
Class
referenceClass
)

PUBLIC: Constructs an update all query for the Class type specified.

public
UpdateAllQuery(Class<?>
Class type to be considered
referenceClass
,
Expression
Expression
selectionCriteria
)

PUBLIC: Constructs an update all query for the specified Class type and selection criteria.

public
UpdateAllQuery(Class<?>
Class type to be considered
referenceClass
,
ExpressionBuilder
ExpressionBuilder
expressionBuilder
)

PUBLIC: Constructs an update all query for the Class type specified and the given ExpressionBuilder.

Method Summary

Modifier and TypeMethod and Description
public void
addUpdate(Expression
Expression Object level representation of a database query 'where' clause
field
,
Object
Object, the new value
value
)

PUBLIC: Adds the update (SET) clause to the query.

public void
addUpdate(String
String, the name of the attribute
attributeName
,
Object
Object, the new value
value
)

PUBLIC: Adds the update (SET) clause to the query.

public void
addUpdate(Expression
Expression, representation of a database query 'where' clause that describes the field
field
,
Expression
Expression, representation of a database query 'where' clause that describes the new value
value
)

PUBLIC: Adds the update (SET) clause to the query.

public void
addUpdate(String
String, the name of the attribute
attributeName
,
Expression
Expression, the new value
value
)

PUBLIC: Adds the update (SET) clause to the query.

protected void
addUpdateInternal(Object fieldObject, Object valueObject)

INTERNAL:

public Object
executeDatabaseQuery()

Implements abstract org.eclipse.persistence.queries.DatabaseQuery.executeDatabaseQuery.

INTERNAL: Issue the SQL to the database and then merge into the cache.
protected QueryRedirector
getDefaultRedirector()

Overrides org.eclipse.persistence.queries.DatabaseQuery.getDefaultRedirector.

INTERNAL: Returns the specific default redirector for this query type.
public HashMap<K, V>
getUpdateClauses()

INTERNAL: Return the updates stored for an update all query

protected void
initializeQuerySpecificDefaultBuilder()

Overrides org.eclipse.persistence.queries.ModifyAllQuery.initializeQuerySpecificDefaultBuilder.

INTERNAL: Initialize the expression builder which should be used for this query.
public boolean
isUpdateAllQuery()

Overrides org.eclipse.persistence.queries.DatabaseQuery.isUpdateAllQuery.

INTERNAL: Return true if this is an update all query.
protected void
Inherited from org.eclipse.persistence.queries.ModifyAllQuery:
clonedQueryExecutionCompleteexecuteInUnitOfWorkgetCacheUsagegetExpressionBuildergetReferenceClassgetReferenceClassNameinitializeDefaultBuilderinvalidateCacheisModifyAllQueryisPreparedUsingTempStoragemergeChangesIntoSharedCachesetCacheUsagesetExpressionBuildersetIsPreparedUsingTempStoragesetReferenceClasssetReferenceClassNamesetShouldDeferExecutionInUOWshouldDeferExecutionInUOWshouldInvalidateCache

Field Detail

m_updateClausesback to summary
protected HashMap<K, V> m_updateClauses

Constructor Detail

UpdateAllQueryback to summary
public UpdateAllQuery()

PUBLIC: Constructs a default update all query.

UpdateAllQueryback to summary
public UpdateAllQuery(Class<?> referenceClass)

PUBLIC: Constructs an update all query for the Class type specified.

Parameters
referenceClass:Class<?>

Class

UpdateAllQueryback to summary
public UpdateAllQuery(Class<?> referenceClass, Expression selectionCriteria)

PUBLIC: Constructs an update all query for the specified Class type and selection criteria.

Parameters
referenceClass:Class<?>

Class type to be considered

selectionCriteria:Expression

Expression

UpdateAllQueryback to summary
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<?>

Class type to be considered

expressionBuilder:ExpressionBuilder

ExpressionBuilder

Method Detail

addUpdateback to summary
public void addUpdate(Expression field, Object value)

PUBLIC: Adds the update (SET) clause to the query. Uses default ExpressionBuilder.

Parameters
field:Expression

Expression Object level representation of a database query 'where' clause

value:Object

Object, the new value

addUpdateback to summary
public void addUpdate(String attributeName, Object value)

PUBLIC: Adds the update (SET) clause to the query. Uses default ExpressionBuilder.

Parameters
attributeName:String

String, the name of the attribute

value:Object

Object, the new value

addUpdateback to summary
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

Expression, representation of a database query 'where' clause that describes the field

value:Expression

Expression, representation of a database query 'where' clause that describes the new value

addUpdateback to summary
public void addUpdate(String attributeName, Expression value)

PUBLIC: Adds the update (SET) clause to the query. Uses default ExpressionBuilder.

Parameters
attributeName:String

String, the name of the attribute

value:Expression

Expression, the new value

addUpdateInternalback to summary
protected void addUpdateInternal(Object fieldObject, Object valueObject)

INTERNAL:

executeDatabaseQueryback to summary
public Object executeDatabaseQuery() throws DatabaseException

Implements abstract org.eclipse.persistence.queries.DatabaseQuery.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.

Returns:Object

Doc from org.eclipse.persistence.queries.DatabaseQuery.executeDatabaseQuery.

- the result of executing the query.

Annotations
@Override
Exceptions
DatabaseException:

Doc from org.eclipse.persistence.queries.DatabaseQuery.executeDatabaseQuery.

- an error has occurred on the database.

getDefaultRedirectorback to summary
protected QueryRedirector getDefaultRedirector()

Overrides org.eclipse.persistence.queries.DatabaseQuery.getDefaultRedirector.

INTERNAL: Returns the specific default redirector for this query type. There are numerous default query redirectors. See ClassDescriptor for their types.

Annotations
@Override
getUpdateClausesback to summary
public HashMap<K, V> getUpdateClauses()

INTERNAL: Return the updates stored for an update all query

initializeQuerySpecificDefaultBuilderback to summary
protected void initializeQuerySpecificDefaultBuilder()

Overrides org.eclipse.persistence.queries.ModifyAllQuery.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.

Annotations
@Override
isUpdateAllQueryback to summary
public boolean isUpdateAllQuery()

Overrides org.eclipse.persistence.queries.DatabaseQuery.isUpdateAllQuery.

INTERNAL: Return true if this is an update all query.

Annotations
@Override
prepareback to summary
protected void prepare() throws QueryException

Overrides org.eclipse.persistence.queries.DatabaseQuery.prepare.

INTERNAL:

Annotations
@Override