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
See Also:
  • Field Details

    • query

      protected DatabaseQuery query
      The database query that uses this mechanism.
  • Constructor Details

    • 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 Details

    • 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 Object clone()
      Clone the mechanism
      Overrides:
      clone in class Object
    • 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.
      Throws:
      DatabaseException
      OptimisticLockException
    • 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.
      Throws:
      DatabaseException
      OptimisticLockException
    • 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 DatabaseException
      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

      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 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.
      Throws:
      QueryException
    • prepareCursorSelectAllRows

      public abstract void prepareCursorSelectAllRows() throws QueryException
      Pre-pare for a cursored execute. This is sent to the original query before cloning.
      Throws:
      QueryException
    • prepareDeleteAll

      public abstract void prepareDeleteAll() throws QueryException
      Prepare for a delete all. This is sent to the original query before cloning.
      Throws:
      QueryException
    • prepareDeleteObject

      public abstract void prepareDeleteObject() throws QueryException
      Prepare 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 QueryException
      Prepare 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 QueryException
      Prepare for a raw execute call. This is sent to the original query before cloning.
      Throws:
      QueryException
    • prepareExecuteSelect

      public abstract void prepareExecuteSelect() throws QueryException
      Prepare for a raw (non-object) select call. This is sent to the original query before cloning.
      Throws:
      QueryException
    • prepareInsertObject

      public abstract void prepareInsertObject() throws QueryException
      Prepare for an insert. This is sent to the original query before cloning.
      Throws:
      QueryException
    • prepareReportQuerySelectAllRows

      public abstract void prepareReportQuerySelectAllRows() throws QueryException
      Pre-pare for a select execute. This is sent to the original query before cloning.
      Throws:
      QueryException
    • prepareReportQuerySubSelect

      public abstract void prepareReportQuerySubSelect() throws QueryException
      Pre-pare a report query for a sub-select.
      Throws:
      QueryException
    • prepareSelectAllRows

      public abstract void prepareSelectAllRows() throws QueryException
      Prepare for a select returning (possibly) multiple rows. This is sent to the original query before cloning.
      Throws:
      QueryException
    • prepareSelectOneRow

      public abstract void prepareSelectOneRow() throws QueryException
      Prepare for a select returning a single row. This is sent to the original query before cloning.
      Throws:
      QueryException
    • prepareUpdateObject

      public abstract void prepareUpdateObject() throws QueryException
      Prepare for an update. This is sent to the original query before cloning.
      Throws:
      QueryException
    • prepareUpdateAll

      public abstract void prepareUpdateAll() throws QueryException
      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

      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.
      Throws:
      DatabaseException
      OptimisticLockException
    • 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 DatabaseException
      Update 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 the updateObjectAndRowWithSequenceNumber()
      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.