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

public abstract Class DatabaseQueryMechanism

extends Object
implements Cloneable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Cloneable
Known Direct Subclasses
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism
Imports
java.io.Serializable, java.sql.ResultSet, .SQLException, java.util.Collection, .Iterator, .List, .Vector, org.eclipse.persistence.descriptors.ClassDescriptor, .DescriptorEvent, .DescriptorEventManager, .DescriptorQueryManager, .VersionLockingPolicy, org.eclipse.persistence.exceptions.DatabaseException, .OptimisticLockException, .QueryException, org.eclipse.persistence.expressions.Expression, org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor, .DatabaseCall, .DatasourceCall, org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy, org.eclipse.persistence.internal.helper.DatabaseField, org.eclipse.persistence.internal.sessions.AbstractRecord, .AbstractSession, .CommitManager, .ObjectChangeSet, .RepeatableWriteUnitOfWork, .UnitOfWorkChangeSet, .UnitOfWorkImpl, org.eclipse.persistence.mappings.DatabaseMapping.WriteType, org.eclipse.persistence.queries.DatabaseQuery, .DoesExistQuery, .ModifyQuery, .ObjectBuildingQuery, .ReadObjectQuery, .WriteObjectQuery, org.eclipse.persistence.sessions.DatabaseRecord, org.eclipse.persistence.tools.profiler.QueryMonitor

Purpose: Abstract class for all database query mechanism objects. DatabaseQueryMechanism is actually a helper class and currently is required for all types of queries. Most of the work performed by the query framework is performed in the query mechanism. The query mechanism contains the internal knowledge necessary to perform the specific database operation.

Responsibilities: Provide a common protocol for query mechanism objects. Provides all of the database specific work for the assigned query.

Author
Yvon Lavoie
Since
TOPLink/Java 1.0

Field Summary

Modifier and TypeField and Description
protected DatabaseQuery
query

The database query that uses this mechanism.

Constructor Summary

AccessConstructor and Description
protected
DatabaseQueryMechanism()

Initialize the state of the query.

protected
DatabaseQueryMechanism(DatabaseQuery
- owner of mechanism
query
)

Initialize the state of the query

Method Summary

Modifier and TypeMethod and Description
protected void
addWriteLockFieldForInsert()

Add the initial write lock value to the row for insert.

public void
buildSelectionCriteria(AbstractSession session)

Internal: In the case of EJBQL, an expression needs to be generated.

public Object
checkCacheForObject(AbstractRecord translationRow, AbstractSession session)

Perform a cache lookup for the query.

public Object
clone()

Overrides java.lang.Object.clone.

Clone the mechanism
public DatabaseQueryMechanism
clone(DatabaseQuery queryClone)

Clone the mechanism for the specified query clone.

public abstract DatabaseCall
cursorSelectAllRows()

Read all rows from the database using a cursored stream.

public abstract Integer
public abstract Integer

Returns:

the row count.
deleteObject
()

Delete an object This should be overridden by subclasses.

public abstract Object

Returns:

true if the first result is a result set and false if it is an update count or there are no results other than through INOUT and OUT parameterts, if any.
execute
()

Execute a execute SQL call.

public void
executeDeferredCall(DatasourceCall call)

Execute the call that was deferred to the commit manager.

public abstract Object

Returns:

the row count.
executeNoSelect
()

Execute a non selecting SQL call This should be overridden by subclasses.

public abstract Vector<E>
executeSelect()

Execute a select SQL call and return the rows.

public Object
executeWrite()

Check whether the object already exists on the database; then perform an insert or update, as appropriate.

public Object
executeWriteWithChangeSet()

Check whether the object already exists on the cadatabase; then perform an insert or update, as appropriate.

public abstract DatabaseCall
generateKeysExecuteNoSelect()

Execute a non selecting SQL call, that returns the generated keys This should be overridden by subclasses.

protected ClassDescriptor
getDescriptor()

Convenience method

protected AbstractSession
getExecutionSession()

Convenience method

public AbstractRecord
getModifyRow()

Convenience method

public DatabaseQuery
getQuery()

Return the query that uses the mechanism.

protected ReadObjectQuery
getReadObjectQuery()

Convenience method

public Expression
getSelectionCriteria()

Return the selection criteria for the mechanism.

protected AbstractSession
getSession()

Convenience method

protected AbstractRecord
getTranslationRow()

Convenience method

protected WriteObjectQuery
getWriteObjectQuery()

Convenience method

public abstract void
insertObject()

Insert an object.

public void
insertObject(boolean reprepare)

Insert an object and provide the opportunity to reprepare prior to the insert.

public void
insertObjectForWrite()

Insert an object in the database.

public boolean
isCallQueryMechanism()

Return true if this is a call query mechanism

public boolean
isExpressionQueryMechanism()

Return true if this is an expression query mechanism

public boolean
isJPQLCallQueryMechanism()

Delete a collection of objects This should be overridden by subclasses.

public boolean
isQueryByExampleMechanism()

Return true if this is a query by example mechanism

public boolean
isStatementQueryMechanism()

Return true if this is a statement query mechanism

protected void
performUserDefinedInsert()

Insert the object using the user defined query.

protected void
performUserDefinedUpdate()

Update the object using the user defined query.

protected void
performUserDefinedWrite(WriteObjectQuery userDefinedWriteQuery)

Write the object using the specified user-defined query.

public void
prepare()

This is different from 'prepareForExecution()' in that this is called on the original query, and the other is called on the clone of the query.

public abstract void
prepareCursorSelectAllRows()

Pre-pare for a cursored execute.

public abstract void
prepareDeleteAll()

Prepare for a delete all.

public abstract void
prepareDeleteObject()

Prepare for a delete.

public abstract void
prepareDoesExist(DatabaseField field)

Pre-pare for a select execute.

public abstract void
prepareExecute()

Prepare for a raw execute call.

public abstract void
prepareExecuteNoSelect()

Prepare for a raw (non-object), non-selecting call.

public abstract void
prepareExecuteSelect()

Prepare for a raw (non-object) select call.

public abstract void
prepareInsertObject()

Prepare for an insert.

public abstract void
prepareReportQuerySelectAllRows()

Pre-pare for a select execute.

public abstract void
prepareReportQuerySubSelect()

Pre-pare a report query for a sub-select.

public abstract void
prepareSelectAllRows()

Prepare for a select returning (possibly) multiple rows.

public abstract void
prepareSelectOneRow()

Prepare for a select returning a single row.

public abstract void
prepareUpdateAll()

Prepare for an update all.

public abstract void
prepareUpdateObject()

Prepare for an update.

protected void
registerObjectInIdentityMap(Object object, ClassDescriptor descriptor, AbstractSession session)

Store the query object in the identity map.

public abstract Vector<E>
selectAllReportQueryRows()

INTERNAL: Read all rows from the database.

public abstract Vector<E>
selectAllRows()

Read and return rows from the database.

public abstract AbstractRecord
selectOneRow()

Read and return a row from the database.

public abstract AbstractRecord
selectRowForDoesExist(DatabaseField field)

Read and return a row from the database for an existence check.

public void
setQuery(DatabaseQuery query)

Set the query that uses this mechanism.

protected void
shallowInsertObjectForWrite(Object object, WriteObjectQuery writeQuery, CommitManager commitManager)

Shallow insert the specified object, if necessary.

public void
unprepare()

Unprepare the call if required.

public abstract Integer
updateAll()

Issue update SQL statement

protected void
updateForeignKeyFieldAfterInsert()

Update the foreign key fields when resolving a bi-directonal reference in a UOW.

protected abstract void
updateForeignKeyFieldAfterInsert(WriteObjectQuery writeQuery)

Update the foreign key fields when resolving a bi-directonal reference in a UOW.

public void
updateForeignKeyFieldBeforeDelete()

Update the foreign key fields to null when resolving a deletion cycle.

public abstract Integer
updateObject()

Update an object.

protected void
updateObjectAndRowWithReturnRow(Collection<E> returnFields, boolean isFirstCallForInsert)

protected void
updateObjectAndRowWithSequenceNumber()

Update the object's primary key by fetching a new sequence number from the accessor.

protected void
updateObjectAndRowWithSequenceNumber(DatabaseCall call)

Update the object's primary key by getting the generated keys from the call If there are no generated keys or the value is NULL, then default back to the updateObjectAndRowWithSequenceNumber()

public void
updateObjectForWrite()

Update the object.

public void
Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

queryback to summary
protected DatabaseQuery query

The database query that uses this mechanism.

Constructor Detail

DatabaseQueryMechanismback to summary
protected DatabaseQueryMechanism()

Initialize the state of the query.

DatabaseQueryMechanismback to summary
protected DatabaseQueryMechanism(DatabaseQuery query)

Initialize the state of the query

Parameters
query:DatabaseQuery

- owner of mechanism

Method Detail

addWriteLockFieldForInsertback to summary
protected void addWriteLockFieldForInsert()

Add the initial write lock value to the row for insert.

buildSelectionCriteriaback to summary
public void buildSelectionCriteria(AbstractSession session)

Internal: In the case of EJBQL, an expression needs to be generated. Build the required expression.

checkCacheForObjectback to summary
public Object checkCacheForObject(AbstractRecord translationRow, AbstractSession session)

Perform a cache lookup for the query. If the translation row contains all the parameters (which are part of the primary key) from the prepared call, then a cache check will be performed. If the object is found in the cache, return it; otherwise return null.

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Clone the mechanism

Returns:Object

Doc from java.lang.Object.clone.

a clone of this instance.

Annotations
@Override
cloneback to summary
public DatabaseQueryMechanism clone(DatabaseQuery queryClone)

Clone the mechanism for the specified query clone.

cursorSelectAllRowsback to summary
public abstract DatabaseCall cursorSelectAllRows() throws DatabaseException

Read all rows from the database using a cursored stream.

Exceptions
DatabaseException:
- an error has occurred on the database
deleteAllback to summary
public abstract Integer deleteAll() throws DatabaseException
deleteObjectback to summary
public abstract Integer deleteObject() throws DatabaseException

Delete an object This should be overridden by subclasses.

Returns:Integer

the row count.

executeback to summary
public abstract Object execute() throws DatabaseException

Execute a execute SQL call. This should be overridden by subclasses.

Returns:Object

true if the first result is a result set and false if it is an update count or there are no results other than through INOUT and OUT parameterts, if any.

executeDeferredCallback to summary
public void executeDeferredCall(DatasourceCall call)

Execute the call that was deferred to the commit manager. This is used to allow multiple table batching and deadlock avoidance.

executeNoSelectback to summary
public abstract Object executeNoSelect() throws DatabaseException

Execute a non selecting SQL call This should be overridden by subclasses.

Returns:Object

the row count.

executeSelectback to summary
public abstract Vector<E> executeSelect() throws DatabaseException

Execute a select SQL call and return the rows. This should be overriden by subclasses.

executeWriteback to summary
public Object executeWrite() throws DatabaseException, OptimisticLockException

Check whether the object already exists on the database; then perform an insert or update, as appropriate. This write is used for non-unit of work (old-commit) operations. Return the object being written.

executeWriteWithChangeSetback to summary
public Object executeWriteWithChangeSet() throws DatabaseException, OptimisticLockException

Check whether the object already exists on the cadatabase; then perform an insert or update, as appropriate. This method was moved here, from WriteObjectQuery.execute(), so we can hide the source. Return the object being written.

generateKeysExecuteNoSelectback to summary
public abstract DatabaseCall generateKeysExecuteNoSelect() throws DatabaseException

Execute a non selecting SQL call, that returns the generated keys This should be overridden by subclasses.

getDescriptorback to summary
protected ClassDescriptor getDescriptor()

Convenience method

getExecutionSessionback to summary
protected AbstractSession getExecutionSession()

Convenience method

getModifyRowback to summary
public AbstractRecord getModifyRow()

Convenience method

getQueryback to summary
public DatabaseQuery getQuery()

Return the query that uses the mechanism.

getReadObjectQueryback to summary
protected ReadObjectQuery getReadObjectQuery()

Convenience method

getSelectionCriteriaback to summary
public Expression getSelectionCriteria()

Return the selection criteria for the mechanism. By default this is null. This method exists because both statement and expression mechanisms use an expression and some code in the mappings depends on returning this.

getSessionback to summary
protected AbstractSession getSession()

Convenience method

getTranslationRowback to summary
protected AbstractRecord getTranslationRow()

Convenience method

getWriteObjectQueryback to summary
protected WriteObjectQuery getWriteObjectQuery()

Convenience method

insertObjectback to summary
public abstract void insertObject() throws DatabaseException

Insert an object.

insertObjectback to summary
public void insertObject(boolean reprepare)

Insert an object and provide the opportunity to reprepare prior to the insert. This will be overridden CR#3237

insertObjectForWriteback to summary
public void insertObjectForWrite()

Insert an object in the database. This is used for both uow and non-uow (old-commit and change-set) operations.

isCallQueryMechanismback to summary
public boolean isCallQueryMechanism()

Return true if this is a call query mechanism

isExpressionQueryMechanismback to summary
public boolean isExpressionQueryMechanism()

Return true if this is an expression query mechanism

isJPQLCallQueryMechanismback to summary
public boolean isJPQLCallQueryMechanism()

Delete a collection of objects This should be overridden by subclasses.

Exceptions
DatabaseException:
- an error has occurred on the database
isQueryByExampleMechanismback to summary
public boolean isQueryByExampleMechanism()

Return true if this is a query by example mechanism

isStatementQueryMechanismback to summary
public boolean isStatementQueryMechanism()

Return true if this is a statement query mechanism

performUserDefinedInsertback to summary
protected void performUserDefinedInsert()

Insert the object using the user defined query. This ensures that the query is cloned and prepared correctly.

performUserDefinedUpdateback to summary
protected void performUserDefinedUpdate()

Update the object using the user defined query. This ensures that the query is cloned and prepared correctly.

performUserDefinedWriteback to summary
protected void performUserDefinedWrite(WriteObjectQuery userDefinedWriteQuery)

Write the object using the specified user-defined query. This ensures that the query is cloned and prepared correctly.

prepareback to summary
public void prepare() throws QueryException

This is different from 'prepareForExecution()' in that this is called on the original query, and the other is called on the clone of the query. This query is copied for concurrency so this prepare can only setup things that will apply to any future execution of this query.

prepareCursorSelectAllRowsback to summary
public abstract void prepareCursorSelectAllRows() throws QueryException

Pre-pare for a cursored execute. This is sent to the original query before cloning.

prepareDeleteAllback to summary
public abstract void prepareDeleteAll() throws QueryException

Prepare for a delete all. This is sent to the original query before cloning.

prepareDeleteObjectback to summary
public abstract void prepareDeleteObject() throws QueryException

Prepare for a delete. This is sent to the original query before cloning.

prepareDoesExistback to summary
public abstract void prepareDoesExist(DatabaseField field) throws QueryException

Pre-pare for a select execute. This is sent to the original query before cloning.

prepareExecuteback to summary
public abstract void prepareExecute() throws QueryException

Prepare for a raw execute call. This is sent to the original query before cloning.

prepareExecuteNoSelectback to summary
public abstract void prepareExecuteNoSelect() throws QueryException

Prepare for a raw (non-object), non-selecting call. This is sent to the original query before cloning.

prepareExecuteSelectback to summary
public abstract void prepareExecuteSelect() throws QueryException

Prepare for a raw (non-object) select call. This is sent to the original query before cloning.

prepareInsertObjectback to summary
public abstract void prepareInsertObject() throws QueryException

Prepare for an insert. This is sent to the original query before cloning.

prepareReportQuerySelectAllRowsback to summary
public abstract void prepareReportQuerySelectAllRows() throws QueryException

Pre-pare for a select execute. This is sent to the original query before cloning.

prepareReportQuerySubSelectback to summary
public abstract void prepareReportQuerySubSelect() throws QueryException

Pre-pare a report query for a sub-select.

prepareSelectAllRowsback to summary
public abstract void prepareSelectAllRows() throws QueryException

Prepare for a select returning (possibly) multiple rows. This is sent to the original query before cloning.

prepareSelectOneRowback to summary
public abstract void prepareSelectOneRow() throws QueryException

Prepare for a select returning a single row. This is sent to the original query before cloning.

prepareUpdateAllback to summary
public abstract void prepareUpdateAll() throws QueryException

Prepare for an update all. This is sent to the original query before cloning.

prepareUpdateObjectback to summary
public abstract void prepareUpdateObject() throws QueryException

Prepare for an update. This is sent to the original query before cloning.

registerObjectInIdentityMapback to summary
protected void registerObjectInIdentityMap(Object object, ClassDescriptor descriptor, AbstractSession session)

Store the query object in the identity map.

selectAllReportQueryRowsback to summary
public abstract Vector<E> selectAllReportQueryRows() throws DatabaseException

INTERNAL: Read all rows from the database.

selectAllRowsback to summary
public abstract Vector<E> selectAllRows() throws DatabaseException

Read and return rows from the database.

selectOneRowback to summary
public abstract AbstractRecord selectOneRow() throws DatabaseException

Read and return a row from the database.

selectRowForDoesExistback to summary
public abstract AbstractRecord selectRowForDoesExist(DatabaseField field) throws DatabaseException

Read and return a row from the database for an existence check.

setQueryback to summary
public void setQuery(DatabaseQuery query)

Set the query that uses this mechanism.

shallowInsertObjectForWriteback to summary
protected void shallowInsertObjectForWrite(Object object, WriteObjectQuery writeQuery, CommitManager commitManager) throws DatabaseException, OptimisticLockException

Shallow insert the specified object, if necessary.

unprepareback to summary
public void unprepare()

Unprepare the call if required.

updateAllback to summary
public abstract Integer updateAll() throws DatabaseException

Issue update SQL statement

updateForeignKeyFieldAfterInsertback to summary
protected void updateForeignKeyFieldAfterInsert()

Update the foreign key fields when resolving a bi-directonal reference in a UOW. This must always be dynamic as it is called within an insert query and is really part of the insert and does not fire update events or worry about locking.

updateForeignKeyFieldAfterInsertback to summary
protected abstract void updateForeignKeyFieldAfterInsert(WriteObjectQuery writeQuery)

Update the foreign key fields when resolving a bi-directonal reference in a UOW. This must always be dynamic as it is called within an insert query and is really part of the insert and does not fire update events or worry about locking.

updateForeignKeyFieldBeforeDeleteback to summary
public void updateForeignKeyFieldBeforeDelete()

Update the foreign key fields to null when resolving a deletion cycle. This must always be dynamic as it is called within an delete query and is really part of the delete and does not fire update events or worry about locking.

updateObjectback to summary
public abstract Integer updateObject() throws DatabaseException

Update an object. Return the row count.

updateObjectAndRowWithReturnRowback to summary
protected void updateObjectAndRowWithReturnRow(Collection<E> returnFields, boolean isFirstCallForInsert)
updateObjectAndRowWithSequenceNumberback to summary
protected void updateObjectAndRowWithSequenceNumber() throws DatabaseException

Update the object's primary key by fetching a new sequence number from the accessor.

updateObjectAndRowWithSequenceNumberback to summary
protected void updateObjectAndRowWithSequenceNumber(DatabaseCall call) throws DatabaseException

Update the object's primary key by getting the generated keys from the call If there are no generated keys or the value is NULL, then default back to the updateObjectAndRowWithSequenceNumber()

updateObjectForWriteback to summary
public void updateObjectForWrite()

Update the object. This is only used for non-unit-of-work updates.

updateObjectForWriteWithChangeSetback to summary
public void updateObjectForWriteWithChangeSet()

Update the object. This is used by the unit-of-work update.