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

public Class DeleteAllQuery

extends ModifyAllQuery
Class Inheritance
Imports
java.util.*, org.eclipse.persistence.exceptions.*, org.eclipse.persistence.expressions.*, org.eclipse.persistence.descriptors.DescriptorEvent, .DescriptorEventManager, .ClassDescriptor, org.eclipse.persistence.internal.sessions.AbstractRecord, .UnitOfWorkImpl, .AbstractSession

Purpose: Query used to delete a collection of objects. This is used by mappings to delete all of their target objects in a single database call. The SQL/SQLStatements must be provided.

DeleteAll can also be used with an Expression (or JPQL) to dynamically delete a set of objects from the database, and invalidate them in the cache.

Responsibilities:

Author
Yvon Lavoie
Since
TOPLink/Java 1.0

Field Summary

Modifier and TypeField and Description
protected boolean
isInMemoryOnly

Defines if objects should be remove from the persistence context only (no database).

protected List<Object>
objects

List containing objects to be deleted, these should be removed from the identity map after deletion.

Inherited from org.eclipse.persistence.queries.ModifyAllQuery:
defaultBuilderINVALIDATE_CACHEisPreparedUsingTempStorageNO_CACHEreferenceClassreferenceClassNameresult

Constructor Summary

AccessConstructor and Description
public
DeleteAllQuery()

PUBLIC:

public
DeleteAllQuery(Class<?> referenceClass)

PUBLIC: Create a new delete all query for the class specified.

public
DeleteAllQuery(Class<?> referenceClass, Expression selectionCriteria)

PUBLIC: Create a new delete all query for the class and the selection criteria specified.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

Integer the number of objects (rows) deleted.
executeDatabaseQuery
()

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

INTERNAL: Perform the work to delete a collection of objects.
public void
executeDeleteAll(AbstractSession session, AbstractRecord translationRow, Vector<E> objects)

INTERNAL: Delete all queries are executed specially to avoid cloning and ensure preparing.

public Object
executeInUnitOfWork(UnitOfWorkImpl
- the session in which the receiver will be executed.
unitOfWork
,
AbstractRecord
- the arguments
translationRow
)

Overrides org.eclipse.persistence.queries.ModifyAllQuery.executeInUnitOfWork.

INTERNAL: This method has to be broken.
protected QueryRedirector
getDefaultRedirector()

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

INTERNAL: Returns the specific default redirector for this query type.
public List<Object>
getObjects()

PUBLIC: Return the objects that are to be deleted

public boolean
isDeleteAllQuery()

Overrides org.eclipse.persistence.queries.DatabaseQuery.isDeleteAllQuery.

PUBLIC: Return if this is a delete all query.
public boolean
isInMemoryOnly()

INTERNAL: Return if objects should be remove from the persistence context only (no database).

protected void
prepare()

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

INTERNAL: Prepare the receiver for execution in a session.
public void
setIsInMemoryOnly(boolean isInMemoryOnly)

INTERNAL: Set if objects should be remove from the persistence context only (no database).

public void
setObjects(List<Object> objectCollection)

PUBLIC (REQUIRED): Set the objects to be deleted.

Inherited from org.eclipse.persistence.queries.ModifyAllQuery:
clonedQueryExecutionCompletegetCacheUsagegetExpressionBuildergetReferenceClassgetReferenceClassNameinitializeDefaultBuilderinitializeQuerySpecificDefaultBuilderinvalidateCacheisModifyAllQueryisPreparedUsingTempStoragemergeChangesIntoSharedCachesetCacheUsagesetExpressionBuildersetIsPreparedUsingTempStoragesetReferenceClasssetReferenceClassNamesetShouldDeferExecutionInUOWshouldDeferExecutionInUOWshouldInvalidateCache

Field Detail

isInMemoryOnlyback to summary
protected boolean isInMemoryOnly

Defines if objects should be remove from the persistence context only (no database). This is used if delete was already cascaded by the database.

objectsback to summary
protected List<Object> objects

List containing objects to be deleted, these should be removed from the identity map after deletion.

Constructor Detail

DeleteAllQueryback to summary
public DeleteAllQuery()

PUBLIC:

DeleteAllQueryback to summary
public DeleteAllQuery(Class<?> referenceClass)

PUBLIC: Create a new delete all query for the class specified.

DeleteAllQueryback to summary
public DeleteAllQuery(Class<?> referenceClass, Expression selectionCriteria)

PUBLIC: Create a new delete all query for the class and the selection criteria specified.

Method Detail

executeDatabaseQueryback to summary
public Object executeDatabaseQuery() throws DatabaseException

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

INTERNAL: Perform the work to delete a collection of objects. This skips the optimistic lock check and should not called for objects using locking.

Returns:Object

Integer the number of objects (rows) deleted.

Annotations
@Override
Exceptions
DatabaseException:
- an error has occurred on the database.
executeDeleteAllback to summary
public void executeDeleteAll(AbstractSession session, AbstractRecord translationRow, Vector<E> objects) throws DatabaseException

INTERNAL: Delete all queries are executed specially to avoid cloning and ensure preparing.

executeInUnitOfWorkback to summary
public Object executeInUnitOfWork(UnitOfWorkImpl unitOfWork, AbstractRecord translationRow) throws DatabaseException

Overrides org.eclipse.persistence.queries.ModifyAllQuery.executeInUnitOfWork.

INTERNAL: This method has to be broken. If commit manager is not active either an exception should be thrown (ObjectLevelModify case), or a transaction should be started early and execute on parent if remote (dataModify case). A modify query is NEVER executed on the parent, unless remote session.

Parameters
unitOfWork:UnitOfWorkImpl

Doc from org.eclipse.persistence.queries.ModifyAllQuery.executeInUnitOfWork.

- the session in which the receiver will be executed.

translationRow:AbstractRecord

Doc from org.eclipse.persistence.queries.ModifyAllQuery.executeInUnitOfWork.

- the arguments

Returns:Object

Doc from org.eclipse.persistence.queries.ModifyAllQuery.executeInUnitOfWork.

An object, the result of executing the query.

Annotations
@Override
Exceptions
DatabaseException:

Doc from org.eclipse.persistence.queries.ModifyAllQuery.executeInUnitOfWork.

- 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
getObjectsback to summary
public List<Object> getObjects()

PUBLIC: Return the objects that are to be deleted

isDeleteAllQueryback to summary
public boolean isDeleteAllQuery()

Overrides org.eclipse.persistence.queries.DatabaseQuery.isDeleteAllQuery.

PUBLIC: Return if this is a delete all query.

Annotations
@Override
isInMemoryOnlyback to summary
public boolean isInMemoryOnly()

INTERNAL: Return if objects should be remove from the persistence context only (no database). This is used if delete was already cascaded by the database.

prepareback to summary
protected void prepare() throws QueryException

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

INTERNAL: Prepare the receiver for execution in a session.

Annotations
@Override
setIsInMemoryOnlyback to summary
public void setIsInMemoryOnly(boolean isInMemoryOnly)

INTERNAL: Set if objects should be remove from the persistence context only (no database). This is used if delete was already cascaded by the database.

setObjectsback to summary
public void setObjects(List<Object> objectCollection)

PUBLIC (REQUIRED): Set the objects to be deleted. Also REQUIRED is a selection criteria or SQL string that performs the deletion of the objects. This does not generate the SQL call from the deleted objects.

List objects used as an indicator of one of two possible ways the query may behave:

objects != null - the "old" functionality used by OneToMany mapping objects deleted from the cache, either selection expression or custom sql should be provided for deletion from db;

objects == null - the "new" functionality (on par with UpdateAllQuery) the cache is either left alone or in-memory query finds the cached objects to be deleted, and these objects are invalidated in cache.

Note that empty objects is still objects != case. Signal that no cache altering is required. Used by AggregationCollectionMapping and OneToManyMapping in case they use indirection and the ValueHolder has not been instantiated.