Class DatabaseQueryMechanism

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable
    Direct Known Subclasses:
    DatasourceCallQueryMechanism

    public abstract class DatabaseQueryMechanism
    extends java.lang.Object
    implements java.lang.Cloneable, java.io.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 Detail

      • query

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

      • DatabaseQueryMechanism

        public DatabaseQueryMechanism()
        Initialize the state of the query.
      • DatabaseQueryMechanism

        public 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 java.lang.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 java.lang.Object clone()
        Clone the mechanism
        Overrides:
        clone in class java.lang.Object
      • isJPQLCallQueryMechanism

        public boolean isJPQLCallQueryMechanism()
        Delete a collection of objects This should be overridden by subclasses.
        Throws:
        DatabaseException - - an error has occurred on the database
      • deleteObject

        public abstract java.lang.Integer deleteObject()
                                                throws DatabaseException
        Delete an object This should be overridden by subclasses.
        Returns:
        the row count.
        Throws:
        DatabaseException
      • execute

        public abstract java.lang.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 java.lang.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 java.util.Vector executeSelect()
                                                throws DatabaseException
        Execute a select SQL call and return the rows. This should be overriden by subclasses.
        Throws:
        DatabaseException
      • 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 java.lang.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.
      • getExecutionSession

        protected AbstractSession getExecutionSession()
        Convenience method
      • getTranslationRow

        protected AbstractRecord getTranslationRow()
        Convenience method
      • getWriteObjectQuery

        protected WriteObjectQuery getWriteObjectQuery()
        Convenience method
      • 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​(java.lang.Object object,
                                                   ClassDescriptor descriptor,
                                                   AbstractSession session)
        Store the query object in the identity map.
      • selectAllReportQueryRows

        public abstract java.util.Vector selectAllReportQueryRows()
                                                           throws DatabaseException
        INTERNAL: Read all rows from the database.
        Throws:
        DatabaseException
      • setQuery

        public void setQuery​(DatabaseQuery query)
        Set the query that uses this mechanism.
      • 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.
      • 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​(java.util.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
      • 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.