Class DoesExistQuery

java.lang.Object
org.eclipse.persistence.queries.DatabaseQuery
org.eclipse.persistence.queries.DoesExistQuery
All Implemented Interfaces:
Serializable, 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.

Since:
TOPLink/Java 1.0
See Also:
  • Field Details

    • AssumeNonExistence

      public static final int AssumeNonExistence
      See Also:
    • AssumeExistence

      public static final int AssumeExistence
      See Also:
    • CheckCache

      public static final int CheckCache
      See Also:
    • CheckDatabase

      public static final int CheckDatabase
      See Also:
    • primaryKey

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

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

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

    • 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 Object checkEarlyReturn(Object object, Object primaryKey, AbstractSession session, 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 Object checkEarlyReturn(AbstractSession session, 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 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 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 Object getObject()
      PUBLIC: Return the object.
    • getPrimaryKey

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

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

      public 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
    • prepare

      protected void prepare() throws QueryException
      INTERNAL: Prepare the receiver for execution in a session.
      Overrides:
      prepare in class DatabaseQuery
      Throws:
      QueryException
    • checkDescriptor

      public void checkDescriptor(Object object, AbstractSession session) throws QueryException
      INTERNAL: Ensure that the descriptor has been set.
      Throws:
      QueryException
    • prepareForExecution

      public void prepareForExecution() throws QueryException
      INTERNAL: Prepare the receiver for execution in a session.
      Overrides:
      prepareForExecution in class DatabaseQuery
      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(Object object)
      PUBLIC: Set the object.
    • setPrimaryKey

      public void setPrimaryKey(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
    • 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
    • getCheckDatabaseIfInvalid

      public boolean getCheckDatabaseIfInvalid()
      INTERNAL: