Package org.eclipse.persistence.queries
Class DoesExistQuery
- java.lang.Object
-
- org.eclipse.persistence.queries.DatabaseQuery
-
- org.eclipse.persistence.queries.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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.persistence.queries.DatabaseQuery
DatabaseQuery.ParameterType
-
-
Field Summary
Fields Modifier and Type Field Description static int
AssumeExistence
static int
AssumeNonExistence
static int
CheckCache
boolean
checkCacheFirst
Flag to determine if the cache should be check first in addition to another option.static int
CheckDatabase
protected boolean
checkDatabaseIfInvalid
Flag to determine cache invalidation policy support.protected int
existencePolicy
Flag to determine existence check policy.protected java.lang.Object
object
protected java.lang.Object
primaryKey
Query that is performing the does exist check.-
Fields inherited from class org.eclipse.persistence.queries.DatabaseQuery
accessors, allowNativeSQLQuery, argumentFields, argumentParameterTypes, arguments, argumentTypeNames, argumentTypes, argumentValues, BATCH_FETCH_PROPERTY, CascadeAggregateDelete, CascadeAllParts, CascadeByMapping, CascadeDependentParts, cascadePolicy, CascadePrivateParts, descriptor, descriptors, doNotRedirect, executionSession, flushOnExecute, hintString, isCustomQueryUsed, isExecutionClone, isNativeConnectionRequired, isPrepared, isUserDefined, isUserDefinedSQLCall, monitorName, name, NoCascading, nullableArguments, parameterDelimiter, partitioningPolicy, properties, queryMechanism, queryTimeout, queryTimeoutUnit, redirector, session, sessionName, shouldBindAllParameters, shouldCacheStatement, shouldCloneCall, shouldMaintainCache, shouldPrepare, shouldRetrieveBypassCache, shouldReturnGeneratedKeys, shouldStoreBypassCache, shouldUseWrapperPolicy, shouldValidateUpdateCallCacheUse, sourceMapping, translationRow
-
-
Constructor Summary
Constructors Constructor Description DoesExistQuery()
PUBLIC: Initialize the state of the query .DoesExistQuery(java.lang.Object object)
PUBLIC: Create a query to check if the object exists.DoesExistQuery(Call call)
PUBLIC: Create a query to check if the object exists.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assumeExistenceForDoesExist()
PUBLIC: Assume that if the objects primary key does not include null then it must exist.void
assumeNonExistenceForDoesExist()
PUBLIC: Assume that the object does not exist.void
checkCacheForDoesExist()
PUBLIC: Assume that if the objects primary key does not include null and it is in the cache, then is must exist.void
checkDatabaseForDoesExist()
PUBLIC: Perform does exist check on the database through selecting the primary key.void
checkDescriptor(java.lang.Object object, org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: Ensure that the descriptor has been set.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.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.java.lang.Object
executeDatabaseQuery()
INTERNAL: Return if the object exists on the database.boolean
getCheckCacheFirst()
INTERNAL:boolean
getCheckDatabaseIfInvalid()
INTERNAL:protected org.eclipse.persistence.internal.helper.DatabaseField
getDoesExistField()
INTERNAL: Return the write lock field or the first primary key field if not using locking.int
getExistencePolicy()
INTERNAL: Return the existence policy for this existence Queryjava.lang.Object
getObject()
PUBLIC: Return the object.java.lang.Object
getPrimaryKey()
INTERNAL: Return the primaryKey.java.lang.Class
getReferenceClass()
Return the domain class associated with this query.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.protected void
prepare()
INTERNAL: Prepare the receiver for execution in a session.void
prepareForExecution()
INTERNAL: Prepare the receiver for execution in a session.void
setCheckCacheFirst(boolean checkCacheFirst)
INTERNAL: Sets checkCacheFirst flag.void
setCheckDatabaseIfInvalid(boolean checkCacheFirst)
INTERNAL: Sets checkDatabaseIfInvalid flag.void
setExistencePolicy(int existencePolicy)
INTERNAL: Set if the existence policy, this must be set to one of the constants.void
setObject(java.lang.Object object)
PUBLIC: Set the object.void
setPrimaryKey(java.lang.Object primaryKey)
INTERNAL: Set the primaryKey.boolean
shouldAssumeExistenceForDoesExist()
PUBLIC: Returns true if the does exist check should be based only on whether the primary key of the object is setboolean
shouldAssumeNonExistenceForDoesExist()
PUBLIC: Returns true if the does exist check should assume non existence.boolean
shouldCheckCacheForDoesExist()
PUBLIC: Returns true if the does exist check should be based only on a cache check.boolean
shouldCheckDatabaseForDoesExist()
PUBLIC: Returns true if the does exist check should query the database.-
Methods inherited from class org.eclipse.persistence.queries.DatabaseQuery
addArgument, addArgument, addArgument, addArgument, addArgument, addArgument, addArgumentByTypeName, addArgumentValue, addArgumentValues, addCall, addStatement, bindAllParameters, buildArgumentFields, buildSelectionCriteria, cacheStatement, cascadeAllParts, cascadeByMapping, cascadeOnlyDependentParts, cascadePrivateParts, checkDescriptor, checkForCustomQuery, checkPrepare, checkPrepare, clone, clonedQueryExecutionComplete, convertClassNamesToClasses, copyFromQuery, dontBindAllParameters, dontCacheStatement, dontCascadeParts, dontMaintainCache, execute, executeInUnitOfWork, extractRemoteResult, getAccessor, getAccessors, getArgumentParameterTypes, getArguments, getArgumentTypeNames, getArgumentTypes, getArgumentValues, getBatchObjects, getCall, getCascadePolicy, getDatasourceCall, getDatasourceCalls, getDefaultRedirector, getDescriptor, getDescriptors, getDomainClassNounName, getDoNotRedirect, getEJBQLString, getExecutionSession, getFlushOnExecute, getHintString, getJPQLString, getMonitorName, getName, getNullableArguments, getParameterDelimiter, getParameterDelimiterChar, getPartitioningPolicy, getProperties, getProperty, getQueryMechanism, getQueryNounName, getQueryTimeout, getQueryTimeoutUnit, getRedirector, getRedirectorForQuery, getSelectionCriteria, getSensorName, getSession, getSessionName, getShouldBindAllParameters, getSourceMapping, getSQLStatement, getSQLString, getSQLStrings, getTranslatedSQLString, getTranslatedSQLStrings, getTranslationRow, hasAccessor, hasArguments, hasNullableArguments, hasProperties, hasQueryMechanism, hasSessionName, ignoreBindAllParameters, ignoreCacheStatement, isCallQuery, isCascadeOfAggregateDelete, isCustomQueryUsed, isCustomSelectionQuery, isDataModifyQuery, isDataReadQuery, isDefaultPropertiesQuery, isDeleteAllQuery, isDeleteObjectQuery, isDirectReadQuery, isExecutionClone, isExpressionQuery, isInsertObjectQuery, isJPQLCallQuery, isModifyAllQuery, isModifyQuery, isNativeConnectionRequired, isObjectBuildingQuery, isObjectLevelModifyQuery, isObjectLevelReadQuery, isPrepared, isReadAllQuery, isReadObjectQuery, isReadQuery, isReportQuery, isResultSetMappingQuery, isSQLCallQuery, isUpdateAllQuery, isUpdateObjectQuery, isUserDefined, isUserDefinedSQLCall, isValueReadQuery, isWriteObjectQuery, maintainCache, prepareCall, prepareCustomQuery, prepareForRemoteExecution, prepareFromQuery, prepareInternal, redirectQuery, remoteExecute, remoteExecute, removeProperty, replaceValueHoldersIn, resetMonitorName, retrieveBypassCache, rowFromArguments, setAccessor, setAccessors, setAllowNativeSQLQuery, setArguments, setArgumentTypeNames, setArgumentTypes, setArgumentValues, setBatchObjects, setCall, setCascadePolicy, setDatasourceCall, setDescriptor, setDoNotRedirect, setEJBQLString, setExecutionSession, setFlushOnExecute, setHintString, setIsCustomQueryUsed, setIsExecutionClone, setIsNativeConnectionRequired, setIsPrepared, setIsUserDefined, setIsUserDefinedSQLCall, setJPQLString, setName, setNullableArguments, setParameterDelimiter, setPartitioningPolicy, setProperties, setProperty, setQueryMechanism, setQueryTimeout, setQueryTimeoutUnit, setRedirector, setSelectionCriteria, setSession, setSessionName, setShouldBindAllParameters, setShouldBindAllParameters, setShouldCacheStatement, setShouldMaintainCache, setShouldPrepare, setShouldRetrieveBypassCache, setShouldReturnGeneratedKeys, setShouldStoreBypassCache, setShouldUseWrapperPolicy, setShouldValidateUpdateCallCacheUse, setSourceMapping, setSQLStatement, setSQLString, setTranslationRow, shouldAllowNativeSQLQuery, shouldBindAllParameters, shouldCacheStatement, shouldCascadeAllParts, shouldCascadeByMapping, shouldCascadeOnlyDependentParts, shouldCascadeParts, shouldCascadePrivateParts, shouldCloneCall, shouldIgnoreBindAllParameters, shouldIgnoreCacheStatement, shouldMaintainCache, shouldPrepare, shouldPrepare, shouldRetrieveBypassCache, shouldReturnGeneratedKeys, shouldStoreBypassCache, shouldUseWrapperPolicy, shouldValidateUpdateCallCacheUse, storeBypassCache, toString
-
-
-
-
Field Detail
-
AssumeNonExistence
public static final int AssumeNonExistence
- See Also:
- Constant Field Values
-
AssumeExistence
public static final int AssumeExistence
- See Also:
- Constant Field Values
-
CheckCache
public static final int CheckCache
- See Also:
- Constant Field Values
-
CheckDatabase
public static final int CheckDatabase
- See Also:
- Constant Field Values
-
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 classDatabaseQuery
-
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 classDatabaseQuery
- 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 classDatabaseQuery
-
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 classDatabaseQuery
-
prepare
protected void prepare() throws QueryException
INTERNAL: Prepare the receiver for execution in a session.- Overrides:
prepare
in classDatabaseQuery
- Throws:
QueryException
-
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
-
prepareForExecution
public void prepareForExecution() throws QueryException
INTERNAL: Prepare the receiver for execution in a session.- Overrides:
prepareForExecution
in classDatabaseQuery
- 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:
-
-