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
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
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected DatabaseQuery
The database query that uses this mechanism. -
Constructor Summary
ModifierConstructorDescriptionprotected
Initialize the state of the query.protected
Initialize the state of the query -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Add the initial write lock value to the row for insert.void
buildSelectionCriteria
(AbstractSession session) Internal: In the case of EJBQL, an expression needs to be generated.checkCacheForObject
(AbstractRecord translationRow, AbstractSession session) Perform a cache lookup for the query.clone()
Clone the mechanismclone
(DatabaseQuery queryClone) Clone the mechanism for the specified query clone.abstract DatabaseCall
Read all rows from the database using a cursored stream.abstract Integer
abstract Integer
Delete an object This should be overridden by subclasses.abstract Object
execute()
Execute a execute SQL call.void
Execute the call that was deferred to the commit manager.abstract Object
Execute a non selecting SQL call This should be overridden by subclasses.abstract Vector
Execute a select SQL call and return the rows.Check whether the object already exists on the database; then perform an insert or update, as appropriate.Check whether the object already exists on the cadatabase; then perform an insert or update, as appropriate.abstract DatabaseCall
Execute a non selecting SQL call, that returns the generated keys This should be overridden by subclasses.protected ClassDescriptor
Convenience methodprotected AbstractSession
Convenience methodConvenience methodgetQuery()
Return the query that uses the mechanism.protected ReadObjectQuery
Convenience methodReturn the selection criteria for the mechanism.protected AbstractSession
Convenience methodprotected AbstractRecord
Convenience methodprotected WriteObjectQuery
Convenience methodabstract void
Insert an object.void
insertObject
(boolean reprepare) Insert an object and provide the opportunity to reprepare prior to the insert.void
Insert an object in the database.boolean
Return true if this is a call query mechanismboolean
Return true if this is an expression query mechanismboolean
Delete a collection of objects This should be overridden by subclasses.boolean
Return true if this is a query by example mechanismboolean
Return true if this is a statement query mechanismprotected void
Insert the object using the user defined query.protected void
Update the object using the user defined query.protected void
performUserDefinedWrite
(WriteObjectQuery userDefinedWriteQuery) Write the object using the specified user-defined query.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.abstract void
Pre-pare for a cursored execute.abstract void
Prepare for a delete all.abstract void
Prepare for a delete.abstract void
prepareDoesExist
(DatabaseField field) Pre-pare for a select execute.abstract void
Prepare for a raw execute call.abstract void
Prepare for a raw (non-object), non-selecting call.abstract void
Prepare for a raw (non-object) select call.abstract void
Prepare for an insert.abstract void
Pre-pare for a select execute.abstract void
Pre-pare a report query for a sub-select.abstract void
Prepare for a select returning (possibly) multiple rows.abstract void
Prepare for a select returning a single row.abstract void
Prepare for an update all.abstract void
Prepare for an update.protected void
registerObjectInIdentityMap
(Object object, ClassDescriptor descriptor, AbstractSession session) Store the query object in the identity map.abstract Vector
INTERNAL: Read all rows from the database.abstract Vector
Read and return rows from the database.abstract AbstractRecord
Read and return a row from the database.abstract AbstractRecord
Read and return a row from the database for an existence check.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.void
Unprepare the call if required.abstract Integer
Issue update SQL statementprotected void
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.void
Update the foreign key fields to null when resolving a deletion cycle.abstract Integer
Update an object.protected void
updateObjectAndRowWithReturnRow
(Collection returnFields, boolean isFirstCallForInsert) protected void
Update the object's primary key by fetching a new sequence number from the accessor.protected void
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()
void
Update the object.void
Update the object.
-
Field Details
-
query
The database query that uses this mechanism.
-
-
Constructor Details
-
DatabaseQueryMechanism
protected DatabaseQueryMechanism()Initialize the state of the query. -
DatabaseQueryMechanism
Initialize the state of the query- Parameters:
query
- - owner of mechanism
-
-
Method Details
-
addWriteLockFieldForInsert
protected void addWriteLockFieldForInsert()Add the initial write lock value to the row for insert. -
buildSelectionCriteria
Internal: In the case of EJBQL, an expression needs to be generated. Build the required expression. -
checkCacheForObject
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
Clone the mechanism -
clone
Clone the mechanism for the specified query clone. -
cursorSelectAllRows
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
- Throws:
DatabaseException
-
deleteObject
Delete an object This should be overridden by subclasses.- Returns:
- the row count.
- Throws:
DatabaseException
-
execute
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
Execute a non selecting SQL call This should be overridden by subclasses.- Returns:
- the row count.
- Throws:
DatabaseException
-
generateKeysExecuteNoSelect
Execute a non selecting SQL call, that returns the generated keys This should be overridden by subclasses.- Throws:
DatabaseException
-
executeSelect
Execute a select SQL call and return the rows. This should be overriden by subclasses.- Throws:
DatabaseException
-
executeWrite
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
Execute the call that was deferred to the commit manager. This is used to allow multiple table batching and deadlock avoidance. -
executeWriteWithChangeSet
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
Convenience method -
getModifyRow
Convenience method -
getQuery
Return the query that uses the mechanism. -
getReadObjectQuery
Convenience method -
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
Convenience method -
getExecutionSession
Convenience method -
getTranslationRow
Convenience method -
getWriteObjectQuery
Convenience method -
insertObject
Insert 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
Write the object using the specified user-defined query. This ensures that the query is cloned and prepared correctly. -
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. 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
Pre-pare for a cursored execute. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareDeleteAll
Prepare for a delete all. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareDeleteObject
Prepare for a delete. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareDoesExist
Pre-pare for a select execute. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareExecuteNoSelect
Prepare for a raw (non-object), non-selecting call. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareExecute
Prepare for a raw execute call. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareExecuteSelect
Prepare for a raw (non-object) select call. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareInsertObject
Prepare for an insert. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareReportQuerySelectAllRows
Pre-pare for a select execute. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareReportQuerySubSelect
Pre-pare a report query for a sub-select.- Throws:
QueryException
-
prepareSelectAllRows
Prepare for a select returning (possibly) multiple rows. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareSelectOneRow
Prepare for a select returning a single row. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareUpdateObject
Prepare for an update. This is sent to the original query before cloning.- Throws:
QueryException
-
prepareUpdateAll
Prepare 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
INTERNAL: Read all rows from the database.- Throws:
DatabaseException
-
selectAllRows
Read and return rows from the database.- Throws:
DatabaseException
-
selectOneRow
Read and return a row from the database.- Throws:
DatabaseException
-
selectRowForDoesExist
Read and return a row from the database for an existence check.- Throws:
DatabaseException
-
setQuery
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
Issue update SQL statement- Throws:
DatabaseException
-
updateObject
Update an object. Return the row count.- Throws:
DatabaseException
-
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. -
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
Update the object's primary key by fetching a new sequence number from the accessor.- Throws:
DatabaseException
-
updateObjectAndRowWithSequenceNumber
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.
-