Top Description Fields Constructors Methods
org.eclipse.persistence.queries

public Class DoesExistQuery

extends DatabaseQuery
Class Inheritance
Imports
org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.exceptions.*, org.eclipse.persistence.internal.helper.*, org.eclipse.persistence.internal.identitymaps.CacheKey, org.eclipse.persistence.internal.sessions.AbstractRecord, .UnitOfWorkImpl, .AbstractSession

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.

Author
Yvon Lavoie
Since
TOPLink/Java 1.0

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public boolean
checkCacheFirst

Flag to determine if the cache should be check first in addition to another option.

public static final int
protected boolean
checkDatabaseIfInvalid

Flag to determine cache invalidation policy support.

protected int
existencePolicy

Flag to determine existence check policy.

protected Object
protected Object
primaryKey

Query that is performing the does exist check.

Inherited from org.eclipse.persistence.queries.DatabaseQuery:
accessorsallowNativeSQLQueryargumentFieldsargumentParameterTypesargumentsargumentTypeNamesargumentTypesargumentValuesBATCH_FETCH_PROPERTYCascadeAggregateDeleteCascadeAllPartsCascadeByMappingCascadeDependentPartscascadePolicyCascadePrivatePartsdescriptordescriptorsdoNotRedirectexecutionSessionflushOnExecutehintStringisCustomQueryUsedisExecutionCloneisNativeConnectionRequiredisPreparedisUserDefinedisUserDefinedSQLCallmonitorNamenameNoCascadingnullableArgumentsparameterDelimiterpartitioningPolicypropertiesqueryMechanismqueryTimeoutqueryTimeoutUnitredirectorsessionsessionNameshouldBindAllParametersshouldCacheStatementshouldCloneCallshouldMaintainCacheshouldPrepareshouldRetrieveBypassCacheshouldReturnGeneratedKeysshouldStoreBypassCacheshouldUseWrapperPolicyshouldValidateUpdateCallCacheUsesourceMappingtranslationRow

Constructor Summary

AccessConstructor and Description
public
DoesExistQuery()

PUBLIC: Initialize the state of the query .

public
DoesExistQuery(Object object)

PUBLIC: Create a query to check if the object exists.

public
DoesExistQuery(Call call)

PUBLIC: Create a query to check if the object exists.

Method Summary

Modifier and TypeMethod and Description
public void
assumeExistenceForDoesExist()

PUBLIC: Assume that if the objects primary key does not include null then it must exist.

public void
assumeNonExistenceForDoesExist()

PUBLIC: Assume that the object does not exist.

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.

public void
checkDatabaseForDoesExist()

PUBLIC: Perform does exist check on the database through selecting the primary key.

public void
checkDescriptor(Object object, AbstractSession session)

INTERNAL: Ensure that the descriptor has been set.

public Object
checkEarlyReturn(Object object, Object primaryKey, AbstractSession session, AbstractRecord translationRow)

INTERNAL: Check if existence can be determined without going to the database.

public Object
checkEarlyReturn(AbstractSession session, AbstractRecord translationRow)

Overrides org.eclipse.persistence.queries.DatabaseQuery.checkEarlyReturn.

INTERNAL: Check if existence can be determined without going to the database.
public Object
executeDatabaseQuery()

Implements abstract org.eclipse.persistence.queries.DatabaseQuery.executeDatabaseQuery.

INTERNAL: Return if the object exists on the database.
public boolean
getCheckCacheFirst()

INTERNAL:

public boolean
protected DatabaseField
getDoesExistField()

INTERNAL: Return the write lock field or the first primary key field if not using locking.

public int
getExistencePolicy()

INTERNAL: Return the existence policy for this existence Query

public Object
getObject()

PUBLIC: Return the object.

public Object
getPrimaryKey()

INTERNAL: Return the primaryKey.

public Class<?>
getReferenceClass()

Overrides org.eclipse.persistence.queries.DatabaseQuery.getReferenceClass.

Return the domain class associated with this query.
public String
getReferenceClassName()

Overrides org.eclipse.persistence.queries.DatabaseQuery.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.
protected void
prepare()

Overrides org.eclipse.persistence.queries.DatabaseQuery.prepare.

INTERNAL: Prepare the receiver for execution in a session.
public void
prepareForExecution()

Overrides org.eclipse.persistence.queries.DatabaseQuery.prepareForExecution.

INTERNAL: Prepare the receiver for execution in a session.
public void
setCheckCacheFirst(boolean checkCacheFirst)

INTERNAL: Sets checkCacheFirst flag.

public void
setCheckDatabaseIfInvalid(boolean checkCacheFirst)

INTERNAL: Sets checkDatabaseIfInvalid flag.

public void
setExistencePolicy(int existencePolicy)

INTERNAL: Set if the existence policy, this must be set to one of the constants.

public void
setObject(Object object)

PUBLIC: Set the object.

public void
setPrimaryKey(Object primaryKey)

INTERNAL: Set the primaryKey.

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

public boolean
shouldAssumeNonExistenceForDoesExist()

PUBLIC: Returns true if the does exist check should assume non existence.

public boolean
shouldCheckCacheForDoesExist()

PUBLIC: Returns true if the does exist check should be based only on a cache check.

public boolean
shouldCheckDatabaseForDoesExist()

PUBLIC: Returns true if the does exist check should query the database.

Inherited from org.eclipse.persistence.queries.DatabaseQuery:
addArgumentaddArgumentaddArgumentaddArgumentaddArgumentaddArgumentaddArgumentByTypeNameaddArgumentValueaddArgumentValuesaddCalladdStatementbindAllParametersbuildArgumentFieldsbuildSelectionCriteriacacheStatementcascadeAllPartscascadeByMappingcascadeOnlyDependentPartscascadePrivatePartscheckDescriptorcheckForCustomQuerycheckPreparecheckPreparecloneclonedQueryExecutionCompleteconvertClassNamesToClassescopyFromQuerydontBindAllParametersdontCacheStatementdontCascadePartsdontMaintainCacheexecuteexecuteInUnitOfWorkextractRemoteResultgetAccessorgetAccessorsgetArgumentParameterTypesgetArgumentsgetArgumentTypeNamesgetArgumentTypesgetArgumentValuesgetBatchObjectsgetCallgetCascadePolicygetDatasourceCallgetDatasourceCallsgetDefaultRedirectorgetDescriptorgetDescriptorsgetDomainClassNounNamegetDoNotRedirectgetEJBQLStringgetExecutionSessiongetFlushOnExecutegetHintStringgetJPQLStringgetMonitorNamegetNamegetNullableArgumentsgetParameterDelimitergetParameterDelimiterChargetPartitioningPolicygetPropertiesgetPropertygetQueryMechanismgetQueryNounNamegetQueryTimeoutgetQueryTimeoutUnitgetRedirectorgetRedirectorForQuerygetSelectionCriteriagetSensorNamegetSessiongetSessionNamegetShouldBindAllParametersgetSourceMappinggetSQLStatementgetSQLStringgetSQLStringsgetTranslatedSQLStringgetTranslatedSQLStringsgetTranslationRowhasAccessorhasArgumentshasNullableArgumentshasPropertieshasQueryMechanismhasSessionNameignoreBindAllParametersignoreCacheStatementisCallQueryisCascadeOfAggregateDeleteisCustomQueryUsedisCustomSelectionQueryisDataModifyQueryisDataReadQueryisDefaultPropertiesQueryisDeleteAllQueryisDeleteObjectQueryisDirectReadQueryisExecutionCloneisExpressionQueryisInsertObjectQueryisJPQLCallQueryisModifyAllQueryisModifyQueryisNativeConnectionRequiredisObjectBuildingQueryisObjectLevelModifyQueryisObjectLevelReadQueryisPreparedisReadAllQueryisReadObjectQueryisReadQueryisReportQueryisResultSetMappingQueryisSQLCallQueryisUpdateAllQueryisUpdateObjectQueryisUserDefinedisUserDefinedSQLCallisValueReadQueryisWriteObjectQuerymaintainCacheprepareCallprepareCustomQueryprepareForRemoteExecutionprepareFromQueryprepareInternalredirectQueryremoteExecuteremoteExecuteremovePropertyreplaceValueHoldersInresetMonitorNameretrieveBypassCacherowFromArgumentssetAccessorsetAccessorssetAllowNativeSQLQuerysetArgumentssetArgumentTypeNamessetArgumentTypessetArgumentValuessetBatchObjectssetCallsetCascadePolicysetDatasourceCallsetDescriptorsetDoNotRedirectsetEJBQLStringsetExecutionSessionsetFlushOnExecutesetHintStringsetIsCustomQueryUsedsetIsExecutionClonesetIsNativeConnectionRequiredsetIsPreparedsetIsUserDefinedsetIsUserDefinedSQLCallsetJPQLStringsetNamesetNullableArgumentssetParameterDelimitersetPartitioningPolicysetPropertiessetPropertysetQueryMechanismsetQueryTimeoutsetQueryTimeoutUnitsetRedirectorsetSelectionCriteriasetSessionsetSessionNamesetShouldBindAllParameterssetShouldBindAllParameterssetShouldCacheStatementsetShouldMaintainCachesetShouldPreparesetShouldRetrieveBypassCachesetShouldReturnGeneratedKeyssetShouldStoreBypassCachesetShouldUseWrapperPolicysetShouldValidateUpdateCallCacheUsesetSourceMappingsetSQLStatementsetSQLStringsetTranslationRowshouldAllowNativeSQLQueryshouldBindAllParametersshouldCacheStatementshouldCascadeAllPartsshouldCascadeByMappingshouldCascadeOnlyDependentPartsshouldCascadePartsshouldCascadePrivatePartsshouldCloneCallshouldIgnoreBindAllParametersshouldIgnoreCacheStatementshouldMaintainCacheshouldPrepareshouldPrepareshouldRetrieveBypassCacheshouldReturnGeneratedKeysshouldStoreBypassCacheshouldUseWrapperPolicyshouldValidateUpdateCallCacheUsestoreBypassCachetoString

Field Detail

AssumeExistenceback to summary
public static final int AssumeExistence
AssumeNonExistenceback to summary
public static final int AssumeNonExistence
CheckCacheback to summary
public static final int CheckCache
checkCacheFirstback to summary
public boolean checkCacheFirst

Flag to determine if the cache should be check first in addition to another option. The default is true;

CheckDatabaseback to summary
public static final int CheckDatabase
checkDatabaseIfInvalidback to summary
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.

existencePolicyback to summary
protected int existencePolicy

Flag to determine existence check policy.

objectback to summary
protected Object object
primaryKeyback to summary
protected Object primaryKey

Query that is performing the does exist check.

Constructor Detail

DoesExistQueryback to summary
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.

DoesExistQueryback to summary
public DoesExistQuery(Object object)

PUBLIC: Create a query to check if the object exists.

DoesExistQueryback to summary
public DoesExistQuery(Call call)

PUBLIC: Create a query to check if the object exists.

Method Detail

assumeExistenceForDoesExistback to summary
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.

assumeNonExistenceForDoesExistback to summary
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.

checkCacheForDoesExistback to summary
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.

checkDatabaseForDoesExistback to summary
public void checkDatabaseForDoesExist()

PUBLIC: Perform does exist check on the database through selecting the primary key.

checkDescriptorback to summary
public void checkDescriptor(Object object, AbstractSession session) throws QueryException

INTERNAL: Ensure that the descriptor has been set.

checkEarlyReturnback to summary
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

checkEarlyReturnback to summary
public Object checkEarlyReturn(AbstractSession session, AbstractRecord translationRow)

Overrides org.eclipse.persistence.queries.DatabaseQuery.checkEarlyReturn.

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.

Annotations
@Override
executeDatabaseQueryback to summary
public Object executeDatabaseQuery() throws DatabaseException

Implements abstract org.eclipse.persistence.queries.DatabaseQuery.executeDatabaseQuery.

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.

Returns:Object

Doc from org.eclipse.persistence.queries.DatabaseQuery.executeDatabaseQuery.

- the result of executing the query.

Annotations
@Override
Exceptions
DatabaseException:
- an error has occurred on the database.
getCheckCacheFirstback to summary
public boolean getCheckCacheFirst()

INTERNAL:

getCheckDatabaseIfInvalidback to summary
public boolean getCheckDatabaseIfInvalid()

INTERNAL:

getDoesExistFieldback to summary
protected DatabaseField getDoesExistField()

INTERNAL: Return the write lock field or the first primary key field if not using locking.

getExistencePolicyback to summary
public int getExistencePolicy()

INTERNAL: Return the existence policy for this existence Query

getObjectback to summary
public Object getObject()

PUBLIC: Return the object.

getPrimaryKeyback to summary
public Object getPrimaryKey()

INTERNAL: Return the primaryKey.

getReferenceClassback to summary
public Class<?> getReferenceClass()

Overrides org.eclipse.persistence.queries.DatabaseQuery.getReferenceClass.

Return the domain class associated with this query.

Annotations
@Override
getReferenceClassNameback to summary
public String getReferenceClassName()

Overrides org.eclipse.persistence.queries.DatabaseQuery.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.

Annotations
@Override
prepareback to summary
protected void prepare() throws QueryException

Overrides org.eclipse.persistence.queries.DatabaseQuery.prepare.

INTERNAL: Prepare the receiver for execution in a session.

Annotations
@Override
prepareForExecutionback to summary
public void prepareForExecution() throws QueryException

Overrides org.eclipse.persistence.queries.DatabaseQuery.prepareForExecution.

INTERNAL: Prepare the receiver for execution in a session.

Annotations
@Override
setCheckCacheFirstback to summary
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

setCheckDatabaseIfInvalidback to summary
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

setExistencePolicyback to summary
public void setExistencePolicy(int existencePolicy)

INTERNAL: Set if the existence policy, this must be set to one of the constants.

setObjectback to summary
public void setObject(Object object)

PUBLIC: Set the object.

setPrimaryKeyback to summary
public void setPrimaryKey(Object primaryKey)

INTERNAL: Set the primaryKey.

shouldAssumeExistenceForDoesExistback to summary
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

shouldAssumeNonExistenceForDoesExistback to summary
public boolean shouldAssumeNonExistenceForDoesExist()

PUBLIC: Returns true if the does exist check should assume non existence.

shouldCheckCacheForDoesExistback to summary
public boolean shouldCheckCacheForDoesExist()

PUBLIC: Returns true if the does exist check should be based only on a cache check. Default behavior.

shouldCheckDatabaseForDoesExistback to summary
public boolean shouldCheckDatabaseForDoesExist()

PUBLIC: Returns true if the does exist check should query the database.