Class DoesExistQuery

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class DoesExistQuery
    extends DatabaseQuery

    Purpose: This should only be used by the descriptor, this should not be executed directly. Used to determine if an object resides on the database. DoesExistQuery is normally used to determine whether to make an update or insert statement when writing an object.

    Responsibilities: Verify the existence of an object. Used only by a write object query.

    See Also:
    Serialized Form
    Author:
    Yvon Lavoie
    Since:
    TOPLink/Java 1.0
    • Field Detail

      • primaryKey

        protected java.lang.Object primaryKey
        Query that is performing the does exist check.
      • object

        protected java.lang.Object object
      • existencePolicy

        protected int existencePolicy
        Flag to determine existence check policy.
      • checkDatabaseIfInvalid

        protected boolean checkDatabaseIfInvalid
        Flag to determine cache invalidation policy support. This overrides the CheckCache existence setting if the object is invalid or if the cache cannot be trusted because a flush or DML has occurred. The default is true.
      • checkCacheFirst

        public boolean checkCacheFirst
        Flag to determine if the cache should be check first in addition to another option. The default is true;
    • Constructor Detail

      • DoesExistQuery

        public DoesExistQuery()
        PUBLIC: Initialize the state of the query . By default the cache is checked, if non cache is used the descriptor should throw a exception and validate.
      • DoesExistQuery

        public DoesExistQuery​(java.lang.Object object)
        PUBLIC: Create a query to check if the object exists.
      • DoesExistQuery

        public DoesExistQuery​(Call call)
        PUBLIC: Create a query to check if the object exists.
    • Method Detail

      • assumeExistenceForDoesExist

        public void assumeExistenceForDoesExist()
        PUBLIC: Assume that if the objects primary key does not include null then it must exist. This may be used if the user's system guarantees that an object with non-null key exists.
      • assumeNonExistenceForDoesExist

        public void assumeNonExistenceForDoesExist()
        PUBLIC: Assume that the object does not exist. This may be used if the user's system guarantees objects must always be inserted.
      • checkCacheForDoesExist

        public void checkCacheForDoesExist()
        PUBLIC: Assume that if the objects primary key does not include null and it is in the cache, then is must exist. This should only be used if a full identity map is being used, and a new object in the client cannot have been inserted by another client.
      • checkDatabaseForDoesExist

        public void checkDatabaseForDoesExist()
        PUBLIC: Perform does exist check on the database through selecting the primary key.
      • checkEarlyReturn

        public java.lang.Object checkEarlyReturn​(java.lang.Object object,
                                                 java.lang.Object primaryKey,
                                                 org.eclipse.persistence.internal.sessions.AbstractSession session,
                                                 org.eclipse.persistence.internal.sessions.AbstractRecord translationRow)
        INTERNAL: Check if existence can be determined without going to the database. Note that custom query check is not require for does exist as the custom is always used. Used by unit of work, and will return null if checkDatabaseIfInvalid is set and the cachekey is invalidated
      • checkEarlyReturn

        public java.lang.Object checkEarlyReturn​(org.eclipse.persistence.internal.sessions.AbstractSession session,
                                                 org.eclipse.persistence.internal.sessions.AbstractRecord translationRow)
        INTERNAL: Check if existence can be determined without going to the database. Note that custom query check is not require for does exist as the custom is always used.
        Overrides:
        checkEarlyReturn in class DatabaseQuery
      • executeDatabaseQuery

        public java.lang.Object executeDatabaseQuery()
                                              throws DatabaseException
        INTERNAL: Return if the object exists on the database. This must be a Boolean object to conform with returning an object. If using optimistic locking, check that the value matches.
        Specified by:
        executeDatabaseQuery in class DatabaseQuery
        Returns:
        - the result of executing the query.
        Throws:
        DatabaseException - - an error has occurred on the database.
      • getDoesExistField

        protected org.eclipse.persistence.internal.helper.DatabaseField getDoesExistField()
        INTERNAL: Return the write lock field or the first primary key field if not using locking.
      • getExistencePolicy

        public int getExistencePolicy()
        INTERNAL: Return the existence policy for this existence Query
      • getObject

        public java.lang.Object getObject()
        PUBLIC: Return the object.
      • getPrimaryKey

        public java.lang.Object getPrimaryKey()
        INTERNAL: Return the primaryKey.
      • getReferenceClass

        public java.lang.Class getReferenceClass()
        Return the domain class associated with this query.
        Overrides:
        getReferenceClass in class DatabaseQuery
      • getReferenceClassName

        public java.lang.String getReferenceClassName()
        INTERNAL: Return the name of the reference class for this query Note: Although the API is designed to avoid requirement of classes being on the classpath, this is not a user defined query type, so it is ok to access the class.
        Overrides:
        getReferenceClassName in class DatabaseQuery
      • checkDescriptor

        public void checkDescriptor​(java.lang.Object object,
                                    org.eclipse.persistence.internal.sessions.AbstractSession session)
                             throws QueryException
        INTERNAL: Ensure that the descriptor has been set.
        Throws:
        QueryException
      • setExistencePolicy

        public void setExistencePolicy​(int existencePolicy)
        INTERNAL: Set if the existence policy, this must be set to one of the constants.
      • setObject

        public void setObject​(java.lang.Object object)
        PUBLIC: Set the object.
      • setPrimaryKey

        public void setPrimaryKey​(java.lang.Object primaryKey)
        INTERNAL: Set the primaryKey.
      • shouldAssumeExistenceForDoesExist

        public boolean shouldAssumeExistenceForDoesExist()
        PUBLIC: Returns true if the does exist check should be based only on whether the primary key of the object is set
      • shouldAssumeNonExistenceForDoesExist

        public boolean shouldAssumeNonExistenceForDoesExist()
        PUBLIC: Returns true if the does exist check should assume non existence.
      • shouldCheckCacheForDoesExist

        public boolean shouldCheckCacheForDoesExist()
        PUBLIC: Returns true if the does exist check should be based only on a cache check. Default behavior.
      • shouldCheckDatabaseForDoesExist

        public boolean shouldCheckDatabaseForDoesExist()
        PUBLIC: Returns true if the does exist check should query the database.
      • setCheckCacheFirst

        public void setCheckCacheFirst​(boolean checkCacheFirst)
        INTERNAL: Sets checkCacheFirst flag. If true, existence check will first go to the cache. It will then check other options if it is not found in the cache
        Parameters:
        checkCacheFirst -
      • getCheckCacheFirst

        public boolean getCheckCacheFirst()
        INTERNAL:
      • setCheckDatabaseIfInvalid

        public void setCheckDatabaseIfInvalid​(boolean checkCacheFirst)
        INTERNAL: Sets checkDatabaseIfInvalid flag. If true, query will go to the database when it finds the object in the cache and it is invalid. This is only valid when it checks the cache, and is true by default
        Parameters:
        checkCacheFirst -
      • getCheckDatabaseIfInvalid

        public boolean getCheckDatabaseIfInvalid()
        INTERNAL: