Module org.eclipse.persistence.core
Class DatabaseQueryMechanism
- java.lang.Object
-
- org.eclipse.persistence.internal.queries.DatabaseQueryMechanism
-
- All Implemented Interfaces:
Serializable,Cloneable
- Direct Known Subclasses:
DatasourceCallQueryMechanism
public abstract class DatabaseQueryMechanism extends Object implements Cloneable, Serializable
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.
- Since:
- TOPLink/Java 1.0
- Author:
- Yvon Lavoie
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected DatabaseQueryqueryThe database query that uses this mechanism.
-
Constructor Summary
Constructors Modifier Constructor Description protectedDatabaseQueryMechanism()Initialize the state of the query.protectedDatabaseQueryMechanism(DatabaseQuery query)Initialize the state of the query
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddWriteLockFieldForInsert()Add the initial write lock value to the row for insert.voidbuildSelectionCriteria(AbstractSession session)Internal: In the case of EJBQL, an expression needs to be generated.ObjectcheckCacheForObject(AbstractRecord translationRow, AbstractSession session)Perform a cache lookup for the query.Objectclone()Clone the mechanismDatabaseQueryMechanismclone(DatabaseQuery queryClone)Clone the mechanism for the specified query clone.abstract DatabaseCallcursorSelectAllRows()Read all rows from the database using a cursored stream.abstract IntegerdeleteAll()abstract IntegerdeleteObject()Delete an object This should be overridden by subclasses.abstract Objectexecute()Execute a execute SQL call.voidexecuteDeferredCall(DatasourceCall call)Execute the call that was deferred to the commit manager.abstract ObjectexecuteNoSelect()Execute a non selecting SQL call This should be overridden by subclasses.abstract VectorexecuteSelect()Execute a select SQL call and return the rows.ObjectexecuteWrite()Check whether the object already exists on the database; then perform an insert or update, as appropriate.ObjectexecuteWriteWithChangeSet()Check whether the object already exists on the cadatabase; then perform an insert or update, as appropriate.abstract DatabaseCallgenerateKeysExecuteNoSelect()Execute a non selecting SQL call, that returns the generated keys This should be overridden by subclasses.protected ClassDescriptorgetDescriptor()Convenience methodprotected AbstractSessiongetExecutionSession()Convenience methodAbstractRecordgetModifyRow()Convenience methodDatabaseQuerygetQuery()Return the query that uses the mechanism.protected ReadObjectQuerygetReadObjectQuery()Convenience methodExpressiongetSelectionCriteria()Return the selection criteria for the mechanism.protected AbstractSessiongetSession()Convenience methodprotected AbstractRecordgetTranslationRow()Convenience methodprotected WriteObjectQuerygetWriteObjectQuery()Convenience methodabstract voidinsertObject()Insert an object.voidinsertObject(boolean reprepare)Insert an object and provide the opportunity to reprepare prior to the insert.voidinsertObjectForWrite()Insert an object in the database.booleanisCallQueryMechanism()Return true if this is a call query mechanismbooleanisExpressionQueryMechanism()Return true if this is an expression query mechanismbooleanisJPQLCallQueryMechanism()Delete a collection of objects This should be overridden by subclasses.booleanisQueryByExampleMechanism()Return true if this is a query by example mechanismbooleanisStatementQueryMechanism()Return true if this is a statement query mechanismprotected voidperformUserDefinedInsert()Insert the object using the user defined query.protected voidperformUserDefinedUpdate()Update the object using the user defined query.protected voidperformUserDefinedWrite(WriteObjectQuery userDefinedWriteQuery)Write the object using the specified user-defined query.voidprepare()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.abstract voidprepareCursorSelectAllRows()Pre-pare for a cursored execute.abstract voidprepareDeleteAll()Prepare for a delete all.abstract voidprepareDeleteObject()Prepare for a delete.abstract voidprepareDoesExist(DatabaseField field)Pre-pare for a select execute.abstract voidprepareExecute()Prepare for a raw execute call.abstract voidprepareExecuteNoSelect()Prepare for a raw (non-object), non-selecting call.abstract voidprepareExecuteSelect()Prepare for a raw (non-object) select call.abstract voidprepareInsertObject()Prepare for an insert.abstract voidprepareReportQuerySelectAllRows()Pre-pare for a select execute.abstract voidprepareReportQuerySubSelect()Pre-pare a report query for a sub-select.abstract voidprepareSelectAllRows()Prepare for a select returning (possibly) multiple rows.abstract voidprepareSelectOneRow()Prepare for a select returning a single row.abstract voidprepareUpdateAll()Prepare for an update all.abstract voidprepareUpdateObject()Prepare for an update.protected voidregisterObjectInIdentityMap(Object object, ClassDescriptor descriptor, AbstractSession session)Store the query object in the identity map.abstract VectorselectAllReportQueryRows()INTERNAL: Read all rows from the database.abstract VectorselectAllRows()Read and return rows from the database.abstract AbstractRecordselectOneRow()Read and return a row from the database.abstract AbstractRecordselectRowForDoesExist(DatabaseField field)Read and return a row from the database for an existence check.voidsetQuery(DatabaseQuery query)Set the query that uses this mechanism.protected voidshallowInsertObjectForWrite(Object object, WriteObjectQuery writeQuery, CommitManager commitManager)Shallow insert the specified object, if necessary.voidunprepare()Unprepare the call if required.abstract IntegerupdateAll()Issue update SQL statementprotected voidupdateForeignKeyFieldAfterInsert()Update the foreign key fields when resolving a bi-directonal reference in a UOW.protected abstract voidupdateForeignKeyFieldAfterInsert(WriteObjectQuery writeQuery)Update the foreign key fields when resolving a bi-directonal reference in a UOW.voidupdateForeignKeyFieldBeforeDelete()Update the foreign key fields to null when resolving a deletion cycle.abstract IntegerupdateObject()Update an object.protected voidupdateObjectAndRowWithReturnRow(Collection returnFields, boolean isFirstCallForInsert)protected voidupdateObjectAndRowWithSequenceNumber()Update the object's primary key by fetching a new sequence number from the accessor.protected voidupdateObjectAndRowWithSequenceNumber(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 theupdateObjectAndRowWithSequenceNumber()voidupdateObjectForWrite()Update the object.voidupdateObjectForWriteWithChangeSet()Update the object.
-
-
-
Field Detail
-
query
protected DatabaseQuery query
The database query that uses this mechanism.
-
-
Constructor Detail
-
DatabaseQueryMechanism
protected DatabaseQueryMechanism()
Initialize the state of the query.
-
DatabaseQueryMechanism
protected DatabaseQueryMechanism(DatabaseQuery query)
Initialize the state of the query- Parameters:
query- - owner of mechanism
-
-
Method Detail
-
addWriteLockFieldForInsert
protected void addWriteLockFieldForInsert()
Add the initial write lock value to the row for insert.
-
buildSelectionCriteria
public void buildSelectionCriteria(AbstractSession session)
Internal: In the case of EJBQL, an expression needs to be generated. Build the required expression.
-
checkCacheForObject
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.
-
clone
public DatabaseQueryMechanism clone(DatabaseQuery queryClone)
Clone the mechanism for the specified query clone.
-
cursorSelectAllRows
public abstract DatabaseCall cursorSelectAllRows() throws DatabaseException
Read all rows from the database using a cursored stream.- Throws:
DatabaseException- - an error has occurred on the database
-
isJPQLCallQueryMechanism
public boolean isJPQLCallQueryMechanism()
Delete a collection of objects This should be overridden by subclasses.- Throws:
DatabaseException- - an error has occurred on the database
-
deleteAll
public abstract Integer deleteAll() throws DatabaseException
- Throws:
DatabaseException
-
deleteObject
public abstract Integer deleteObject() throws DatabaseException
Delete an object This should be overridden by subclasses.- Returns:
- the row count.
- Throws:
DatabaseException
-
execute
public abstract Object execute() throws DatabaseException
Execute a execute SQL call. This should be overridden by subclasses.- 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.
- Throws:
DatabaseException
-
executeNoSelect
public abstract Object executeNoSelect() throws DatabaseException
Execute a non selecting SQL call This should be overridden by subclasses.- Returns:
- the row count.
- Throws:
DatabaseException
-
generateKeysExecuteNoSelect
public abstract DatabaseCall generateKeysExecuteNoSelect() throws DatabaseException
Execute a non selecting SQL call, that returns the generated keys This should be overridden by subclasses.- Throws:
DatabaseException
-
executeSelect
public abstract Vector executeSelect() throws DatabaseException
Execute a select SQL call and return the rows. This should be overriden by subclasses.- Throws:
DatabaseException
-
executeWrite
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.
-
executeDeferredCall
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.
-
executeWriteWithChangeSet
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.
-
getDescriptor
protected ClassDescriptor getDescriptor()
Convenience method
-
getModifyRow
public AbstractRecord getModifyRow()
Convenience method
-
getQuery
public DatabaseQuery getQuery()
Return the query that uses the mechanism.
-
getReadObjectQuery
protected ReadObjectQuery getReadObjectQuery()
Convenience method
-
getSelectionCriteria
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.
-
getSession
protected AbstractSession getSession()
Convenience method
-
getExecutionSession
protected AbstractSession getExecutionSession()
Convenience method
-
getTranslationRow
protected AbstractRecord getTranslationRow()
Convenience method
-
getWriteObjectQuery
protected WriteObjectQuery getWriteObjectQuery()
Convenience method
-
insertObject
public abstract void insertObject() throws DatabaseExceptionInsert an object.- Throws:
DatabaseException
-
insertObject
public void insertObject(boolean reprepare)
Insert an object and provide the opportunity to reprepare prior to the insert. This will be overridden CR#3237
-
insertObjectForWrite
public void insertObjectForWrite()
Insert an object in the database. This is used for both uow and non-uow (old-commit and change-set) operations.
-
isCallQueryMechanism
public boolean isCallQueryMechanism()
Return true if this is a call query mechanism
-
isExpressionQueryMechanism
public boolean isExpressionQueryMechanism()
Return true if this is an expression query mechanism
-
isQueryByExampleMechanism
public boolean isQueryByExampleMechanism()
Return true if this is a query by example mechanism
-
isStatementQueryMechanism
public boolean isStatementQueryMechanism()
Return true if this is a statement query mechanism
-
performUserDefinedInsert
protected void performUserDefinedInsert()
Insert the object using the user defined query. This ensures that the query is cloned and prepared correctly.
-
performUserDefinedUpdate
protected void performUserDefinedUpdate()
Update the object using the user defined query. This ensures that the query is cloned and prepared correctly.
-
performUserDefinedWrite
protected void performUserDefinedWrite(WriteObjectQuery userDefinedWriteQuery)
Write the object using the specified user-defined query. This ensures that the query is cloned and prepared correctly.
-
prepare
public void prepare() throws QueryExceptionThis 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.- Throws:
QueryException
-
prepareCursorSelectAllRows
public abstract void prepareCursorSelectAllRows() throws QueryExceptionPre-pare for a cursored execute. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareDeleteAll
public abstract void prepareDeleteAll() throws QueryExceptionPrepare for a delete all. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareDeleteObject
public abstract void prepareDeleteObject() throws QueryExceptionPrepare for a delete. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareDoesExist
public abstract void prepareDoesExist(DatabaseField field) throws QueryException
Pre-pare for a select execute. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareExecuteNoSelect
public abstract void prepareExecuteNoSelect() throws QueryExceptionPrepare for a raw (non-object), non-selecting call. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareExecute
public abstract void prepareExecute() throws QueryExceptionPrepare for a raw execute call. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareExecuteSelect
public abstract void prepareExecuteSelect() throws QueryExceptionPrepare for a raw (non-object) select call. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareInsertObject
public abstract void prepareInsertObject() throws QueryExceptionPrepare for an insert. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareReportQuerySelectAllRows
public abstract void prepareReportQuerySelectAllRows() throws QueryExceptionPre-pare for a select execute. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareReportQuerySubSelect
public abstract void prepareReportQuerySubSelect() throws QueryExceptionPre-pare a report query for a sub-select.- Throws:
QueryException
-
prepareSelectAllRows
public abstract void prepareSelectAllRows() throws QueryExceptionPrepare for a select returning (possibly) multiple rows. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareSelectOneRow
public abstract void prepareSelectOneRow() throws QueryExceptionPrepare for a select returning a single row. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareUpdateObject
public abstract void prepareUpdateObject() throws QueryExceptionPrepare for an update. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareUpdateAll
public abstract void prepareUpdateAll() throws QueryExceptionPrepare for an update all. This is sent to the original query before cloning.- Throws:
QueryException
-
registerObjectInIdentityMap
protected void registerObjectInIdentityMap(Object object, ClassDescriptor descriptor, AbstractSession session)
Store the query object in the identity map.
-
selectAllReportQueryRows
public abstract Vector selectAllReportQueryRows() throws DatabaseException
INTERNAL: Read all rows from the database.- Throws:
DatabaseException
-
selectAllRows
public abstract Vector selectAllRows() throws DatabaseException
Read and return rows from the database.- Throws:
DatabaseException
-
selectOneRow
public abstract AbstractRecord selectOneRow() throws DatabaseException
Read and return a row from the database.- Throws:
DatabaseException
-
selectRowForDoesExist
public abstract AbstractRecord selectRowForDoesExist(DatabaseField field) throws DatabaseException
Read and return a row from the database for an existence check.- Throws:
DatabaseException
-
setQuery
public void setQuery(DatabaseQuery query)
Set the query that uses this mechanism.
-
shallowInsertObjectForWrite
protected void shallowInsertObjectForWrite(Object object, WriteObjectQuery writeQuery, CommitManager commitManager) throws DatabaseException, OptimisticLockException
Shallow insert the specified object, if necessary.
-
updateForeignKeyFieldAfterInsert
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.
-
updateAll
public abstract Integer updateAll() throws DatabaseException
Issue update SQL statement- Throws:
DatabaseException
-
updateObject
public abstract Integer updateObject() throws DatabaseException
Update an object. Return the row count.- Throws:
DatabaseException
-
updateForeignKeyFieldAfterInsert
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.
-
updateForeignKeyFieldBeforeDelete
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.
-
updateObjectAndRowWithReturnRow
protected void updateObjectAndRowWithReturnRow(Collection returnFields, boolean isFirstCallForInsert)
-
updateObjectAndRowWithSequenceNumber
protected void updateObjectAndRowWithSequenceNumber() throws DatabaseExceptionUpdate the object's primary key by fetching a new sequence number from the accessor.- Throws:
DatabaseException
-
updateObjectAndRowWithSequenceNumber
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 theupdateObjectAndRowWithSequenceNumber()- Throws:
DatabaseException
-
updateObjectForWrite
public void updateObjectForWrite()
Update the object. This is only used for non-unit-of-work updates.
-
updateObjectForWriteWithChangeSet
public void updateObjectForWriteWithChangeSet()
Update the object. This is used by the unit-of-work update.
-
unprepare
public void unprepare()
Unprepare the call if required.
-
-