public abstract class ObjectLevelReadQuery extends ObjectBuildingQuery
Purpose: Abstract class for all read queries using objects.
Description: Contains common behavior for all read queries using objects.
Modifier and Type | Field and Description |
---|---|
protected Vector |
additionalFields
Allow for additional fields to be selected, used for m-m batch reading.
|
protected int |
cacheUsage
Allow for the cache usage to be specified to enable in-memory querying.
|
static int |
CheckCacheByExactPrimaryKey |
static int |
CheckCacheByPrimaryKey |
static int |
CheckCacheOnly |
static int |
CheckCacheThenDatabase |
static int |
ConformResultsInUnitOfWork |
protected ExpressionBuilder |
defaultBuilder
Provide a default builder so that it's easier to be consistent
|
protected short |
distinctState
Indicates if distinct should be used or not.
|
static int |
DoNotCheckCache |
static short |
DONT_USE_DISTINCT |
protected long |
executionTime
Used to set the read time on objects that use this query.
|
protected FetchGroup |
fetchGroup
Allow for a query level fetch group to be set.
|
protected String |
fetchGroupName
The pre-defined fetch group name.
|
protected InMemoryQueryIndirectionPolicy |
inMemoryQueryIndirectionPolicy
CR 3677
Used to determine behaviour of indirection in InMemoryQuerying
This should have been just a constant similar to distinct locking, etc.
|
protected JoinedAttributeManager |
joinedAttributeManager
Stores the helper object for dealing with joined attributes
|
static String |
LOCK_RESULT_PROPERTY
INTERNAL: This is the key for accessing unregistered and locked result in the query's properties.
|
protected Vector |
nonFetchJoinAttributeExpressions
Stores the non fetchjoin attributes, these are joins that will be
represented in the where clause but not in the select
|
protected boolean |
shouldIncludeData
Allow for a complex result to be return including the rows and objects, used for m-m batch reading.
|
protected boolean |
shouldProcessResultsInUnitOfWork
CMP only.
|
protected boolean |
shouldRefreshIdentityMapResult
Allows for the resulting objects to be refresh with the data from the database.
|
protected boolean |
shouldRegisterResultsInUnitOfWork
INTERNAL: for bug 2612601 allow ability not to register results in UOW.
|
protected boolean |
shouldUseDefaultFetchGroup
Flag to turn on/off the use of the default fetch group.
|
static short |
UNCOMPUTED_DISTINCT |
static short |
USE_DISTINCT |
static int |
UseDescriptorSetting |
protected boolean |
wasDefaultLockMode
PERF: Store if the query originally used the default lock mode.
|
DEFAULT_LOCK_MODE, isPrePrepared, LOCK, LOCK_NOWAIT, lockingClause, NO_LOCK, referenceClass, referenceClassName, shouldRefreshRemoteIdentityMapResult, shouldUseExclusiveConnection
firstResult, maxRows, queryId
accessor, arguments, argumentTypeNames, argumentTypes, argumentValues, CascadeAggregateDelete, CascadeAllParts, CascadeByMapping, CascadeDependentParts, cascadePolicy, CascadePrivateParts, descriptor, flushOnExecute, isPrepared, isUserDefined, name, NoCascading, properties, queryMechanism, session, sessionName, shouldBindAllParameters, shouldCacheStatement, shouldCloneCall, shouldMaintainCache, shouldPrepare, shouldUseWrapperPolicy, translationRow
False, True, Undefined
Constructor and Description |
---|
ObjectLevelReadQuery()
INTERNAL:
Initialize the state of the query
|
Modifier and Type | Method and Description |
---|---|
void |
acquireLocks()
PUBLIC:
Set the query to lock, this will also turn refreshCache on.
|
void |
acquireLocksWithoutWaiting()
PUBLIC:
Set the query to lock without waiting (blocking), this will also turn refreshCache on.
|
void |
addAdditionalField(DatabaseField field)
INTERNAL:
Additional fields can be added to a query.
|
void |
addAdditionalField(Expression fieldExpression)
INTERNAL:
Additional fields can be added to a query.
|
void |
addJoinedAttribute(Expression attributeExpression)
PUBLIC:
Specify the to-one or to-many mapped attribute to be optimized in this query.
|
void |
addJoinedAttribute(String attributeName)
PUBLIC:
Specify the one-to-one mapped attribute to be optimized in this query.
|
void |
addNonFetchJoinedAttribute(Expression attributeExpression)
PUBLIC:
Specify the one-to-one mapped attribute to be optimized in this query.
|
void |
addNonFetchJoinedAttribute(String attributeName)
PUBLIC:
Specify the one-to-one mapped attribute to be optimized in this query.
|
protected void |
addSelectionFieldsForJoinedExpressions(List fields,
List joinedExpressions)
INTERNAL:
Iterate through a list of joined expressions and add the fields they represent to a list
of fields.
|
Object |
buildObject(AbstractRecord row)
INTERNAL:
Called by CursoredStream to construct objects from rows.
|
void |
changeDescriptor(AbstractSession theSession)
INTERNAL:
The reference class has been changed, need to reset the
descriptor.
|
void |
checkCacheOnly()
PUBLIC:
The cache will checked completely, if the object is not found null will be returned or an error if the query is too complex.
|
void |
checkDescriptor(AbstractSession session)
INTERNAL:
Ensure that the descriptor has been set.
|
Object |
checkEarlyReturn(AbstractSession session,
AbstractRecord translationRow)
INTERNAL:
Check to see if this query already knows the return vale without preforming any further work.
|
protected abstract Object |
checkEarlyReturnImpl(AbstractSession session,
AbstractRecord translationRow)
INTERNAL:
Contains the body of the check early return call, implemented by subclasses.
|
void |
checkPrepare(AbstractSession session,
AbstractRecord translationRow)
INTERNAL:
Check to see if this query needs to be prepare and prepare it.
|
protected void |
checkPrePrepare(AbstractSession session)
INTERNAL:
ObjectLevelReadQueries now have an explicit pre-prepare stage, which
is for checking for pessimistic locking, and computing any joined
attributes declared on the descriptor.
|
Object |
clone()
INTERNAL:
Clone the query
|
protected Object |
conformIndividualResult(Object result,
UnitOfWorkImpl unitOfWork,
AbstractRecord arguments,
Expression selectionCriteriaClone,
IdentityHashtable alreadyReturned,
boolean buildDirectlyFromRows)
INTERNAL:
Conforms and registers an individual result.
|
void |
conformResultsInUnitOfWork()
PUBLIC:
The cache will checked completely, if the object is not found the database will be queried,
and the database result will be verified with what is in the cache and/or unit of work including new objects.
|
Object |
deepClone()
INTERNAL:
Clone the query, including its selection criteria.
|
void |
dontAcquireLocks()
PUBLIC:
Set the query not to lock.
|
void |
dontCheckCache()
PUBLIC:
This can be used to explicitly disable the cache hit.
|
void |
dontRefreshIdentityMapResult()
PUBLIC:
When unset means perform read normally and dont do refresh.
|
void |
dontUseDistinct()
ADVANCED:
If a distinct has been set the DISTINCT clause will be printed.
|
Object |
execute(AbstractSession session,
AbstractRecord translationRow)
INTERNAL:
Execute the query.
|
Object |
executeDatabaseQuery()
INTERNAL:
Execute the query
|
Object |
executeInUnitOfWork(UnitOfWorkImpl unitOfWork,
AbstractRecord translationRow)
INTERNAL:
At this point only the code has been copied over from UnitOfWork
internalExecuteQuery.
|
protected abstract Object |
executeObjectLevelReadQuery() |
Vector |
getAdditionalFields()
INTERNAL:
Additional fields can be added to a query.
|
int |
getCacheUsage()
PUBLIC:
Return the cache usage.
|
short |
getDistinctState()
ADVANCED:
If a distinct has been set the DISTINCT clause will be printed.
|
long |
getExecutionTime()
INTERNAL:
Return the time this query actually went to the database
|
ExpressionBuilder |
getExpressionBuilder()
REQUIRED:
Get the expression builder which should be used for this query.
|
FetchGroup |
getFetchGroup()
Return the fetch group set in the query.
|
String |
getFetchGroupName()
Return the fetch group name set in the query.
|
InMemoryQueryIndirectionPolicy |
getInMemoryQueryIndirectionPolicy()
PUBLIC:
Returns the InMemoryQueryIndirectionPolicy for this query
|
JoinedAttributeManager |
getJoinedAttributeManager()
INTERNAL:
Set the list of expressions that represent elements that are joined because of their
mapping for this query.
|
ClassDescriptor |
getLeafDescriptorFor(Expression expression,
ClassDescriptor rootDescriptor)
INTERNAL:
Lookup the descriptor for this item by traversing its expression recursively.
|
DatabaseMapping |
getLeafMappingFor(Expression expression,
ClassDescriptor rootDescriptor)
INTERNAL:
Lookup the mapping for this item by traversing its expression recursively.
|
ForUpdateClause |
getLockingClause()
INTERNAL:
It is not exactly as simple as a query being either locking or not.
|
short |
getLockMode()
PUBLIC:
Return the current locking mode.
|
Vector |
getNonFetchJoinAttributeExpressions()
INTERNAL:
Return the attributes that must be joined, but not fetched, that is,
do not trigger the value holder.
|
Class |
getReferenceClass()
PUBLIC:
Return the reference class of the query.
|
String |
getReferenceClassName()
INTERNAL:
Return the reference class of the query.
|
Vector |
getSelectionFields()
INTERNAL:
Return the fields selected by the query.
|
boolean |
hasAsOfClause()
PUBLIC:
Answers if the domain objects are to be read as of a past time.
|
boolean |
hasFetchGroupAttributeExpressions()
INTERNAL:
Return if fetch group attributes.
|
boolean |
hasNonFetchJoinedAttributeExpressions()
INTERNAL:
Return the attributes that must be joined.
|
boolean |
hasPartialAttributeExpressions()
INTERNAL:
Return if partial attributes.
|
protected void |
initializeDefaultBuilder()
Initialize the expression builder which should be used for this query.
|
void |
initializeFetchGroup()
INTERNAL:
Initialize fetch group
|
boolean |
isClonePessimisticLocked(Object clone,
UnitOfWorkImpl uow)
INTERNAL:
Helper method that checks if clone has been locked with uow.
|
boolean |
isDefaultLock()
INTERNAL: Helper method to determine the default mode.
|
boolean |
isDistinctComputed()
INTERNAL:
return true if this query has computed its distinct value already
|
boolean |
isFetchGroupAttribute(String attributeName)
INTERNAL:
Return if fetch group attribute.
|
boolean |
isLockQuery()
PUBLIC:
Answers if the query lock mode is known to be LOCK or LOCK_NOWAIT.
|
boolean |
isLockQuery(Session session)
ADVANCED:
Answers if this query will issue any pessimistic locks.
|
boolean |
isObjectLevelReadQuery()
PUBLIC:
Return if this is an object level read query.
|
protected boolean |
isPrePrepared()
PUBLIC:
Queries prepare common stated in themselves.
|
protected boolean |
isRegisteringResults()
INTERNAL:
Answers if we are executing through a UnitOfWork and registering results.
|
protected void |
prepare()
INTERNAL:
Prepare the receiver for execution in a session.
|
DatabaseQuery |
prepareOutsideUnitOfWork(AbstractSession session)
INTERNAL:
There is a very special case where a query may be a bean-level
pessimistic locking query.
|
protected void |
prepareQuery()
INTERNAL:
Prepare the receiver for execution in a session.
|
protected void |
prePrepare()
INTERNAL:
Prepare the receiver for execution in a session.
|
void |
recordCloneForPessimisticLocking(Object clone,
UnitOfWorkImpl uow)
INTERNAL:
Helper method that records clone with uow if query is pessimistic locking.
|
void |
refreshIdentityMapResult()
PUBLIC:
Refresh the attributes of the object(s) resulting from the query.
|
abstract Object |
registerResultInUnitOfWork(Object result,
UnitOfWorkImpl unitOfWork,
AbstractRecord arguments,
boolean buildDirectlyFromRows)
INTERNAL:
All objects queried via a UnitOfWork get registered here.
|
void |
resetDistinct()
ADVANCED:
If a distinct has been set the DISTINCT clause will be printed.
|
void |
setAdditionalFields(Vector additionalFields)
INTERNAL:
Additional fields can be added to a query.
|
void |
setCacheUsage(int cacheUsage)
PUBLIC:
Set the cache usage.
|
void |
setDescriptor(ClassDescriptor descriptor)
INTERNAL:
Set the descriptor for the query.
|
void |
setDistinctState(short distinctState)
ADVANCED:
If a distinct has been set the DISTINCT clause will be printed.
|
void |
setEJBQLString(String ejbqlString)
PUBLIC:
To any user of this object.
|
void |
setExecutionTime(long executionTime)
INTERNAL:
Set the the time this query went to the database.
|
void |
setExpressionBuilder(ExpressionBuilder builder)
INTERNAL
Sets the default expression builder for this query.
|
void |
setFetchGroup(FetchGroup newFetchGroup)
Set a dynamic (use case) fetch group to the query.
|
void |
setFetchGroupName(String groupName)
Set a descriptor-level pre-defined named fetch group to the query.
|
void |
setInMemoryQueryIndirectionPolicy(InMemoryQueryIndirectionPolicy inMemoryQueryIndirectionPolicy)
PUBLIC:
Set the InMemoryQueryIndirectionPolicy for this query
|
protected void |
setIsPrePrepared(boolean isPrePrepared)
INTERNAL:
If changes are made to the query that affect the derived SQL or Call
parameters the query needs to be prepared again.
|
void |
setLockingClause(ForUpdateClause clause)
INTERNAL:
The locking clause contains a list of expressions representing which
objects are to be locked by the query.
|
void |
setLockMode(short lockMode)
PUBLIC:
Sets whether this is a pessimistically locking query.
|
protected void |
setNonFetchJoinAttributeExpressions(Vector nonFetchJoinExpressions)
INTERNAL:
Return the attributes that must be joined, but not fetched, that is,
do not trigger the value holder.
|
void |
setReferenceClass(Class aClass)
REQUIRED:
Set the reference class for the query.
|
void |
setReferenceClassName(String aClass)
INTERNAL:
Set the reference class for the query.
|
void |
setSelectionCriteria(Expression expression)
PUBLIC:
To any user of this object.
|
void |
setShouldIncludeData(boolean shouldIncludeData)
INTERNAL:
Set if the rows for the result of the query should also be returned using a complex query result.
|
void |
setShouldProcessResultsInUnitOfWork(boolean processResultsInUnitOfWork)
ADVANCED:
Used for CMP only.
|
void |
setShouldRefreshIdentityMapResult(boolean shouldRefreshIdentityMapResult)
PUBLIC:
Set if the attributes of the object(s) resulting from the query should be refreshed.
|
void |
setShouldRegisterResultsInUnitOfWork(boolean shouldRegisterResultsInUnitOfWork)
INTERNAL:
Set to false to have queries conform to a UnitOfWork without registering
any additional objects not already in that UnitOfWork.
|
void |
setShouldUseDefaultFetchGroup(boolean shouldUseDefaultFetchGroup)
Set false if the user does not want to use the default fetch group defined in the descriptor level.
|
protected void |
setWasDefaultLockMode(boolean wasDefaultLockMode)
INTERNAL:
Set if this query originally used the default lock mode.
|
boolean |
shouldCheckCacheOnly()
PUBLIC:
Return if cache should be checked.
|
boolean |
shouldCheckDescriptorForCacheUsage()
PUBLIC:
Return whether the descriptor's disableCacheHits setting should be checked prior
to querying the cache.
|
boolean |
shouldConformResultsInUnitOfWork()
PUBLIC:
Should the results will be checked against the changes within the unit of work and object no longer matching or deleted will be remove, matching new objects will also be added..
|
boolean |
shouldDistinctBeUsed()
INTERNAL:
return true if this query should use a distinct
|
boolean |
shouldIncludeData()
INTERNAL:
Return if the rows for the result of the query should also be returned using a complex query result.
|
boolean |
shouldProcessResultsInUnitOfWork()
ADVANCED:
Used for CMP only.
|
boolean |
shouldReadAllMappings()
INTERNAL:
Return if this is a full object query, not partial nor fetch group.
|
boolean |
shouldReadMapping(DatabaseMapping mapping)
INTERNAL:
Check if the mapping is part of the partial attributes.
|
boolean |
shouldRefreshIdentityMapResult()
PUBLIC:
Set to a boolean.
|
boolean |
shouldRegisterResultsInUnitOfWork()
INTERNAL:
Allows one to do conforming in a UnitOfWork without registering.
|
boolean |
shouldUseDefaultFetchGroup()
Return false if the query does not use the default fetch group defined in the descriptor level.
|
String |
toString() |
void |
useDistinct()
ADVANCED:
If a distinct has been set the DISTINCT clause will be printed.
|
protected boolean |
wasDefaultLockMode()
INTERNAL:
Return if this query originally used the default lock mode.
|
convertClassNamesToClasses, dontRefreshRemoteIdentityMapResult, getDataResults, isAttributeJoined, isObjectBuildingQuery, refreshRemoteIdentityMapResult, registerIndividualResult, setShouldRefreshRemoteIdentityMapResult, shouldRefreshRemoteIdentityMapResult
clonedQueryExecutionComplete, getFirstResult, getMaxRows, getQueryId, isReadQuery, setFirstResult, setMaxRows, setQueryId
addArgument, addArgument, addArgument, addArgumentByTypeName, addArgumentValue, addArgumentValues, addCall, addStatement, bindAllParameters, buildSelectionCriteria, cacheStatement, cascadeAllParts, cascadeByMapping, cascadeOnlyDependentParts, cascadePrivateParts, checkForCustomQuery, deploymentSetShouldMaintainCache, deploymentShouldMaintainCache, dontBindAllParameters, dontCacheStatement, dontCascadeParts, dontMaintainCache, getAccessor, getArguments, getArgumentTypeNames, getArgumentTypes, getArgumentValues, getCall, getCascadePolicy, getDatasourceCall, getDatasourceCalls, getDescriptor, getEJBQLString, getFlushOnExecute, getName, getProperties, getProperty, getQueryMechanism, getSelectionCriteria, getSession, getSessionName, getShouldBindAllParameters, getSQLStatement, getSQLString, getSQLStrings, getTranslatedSQLString, getTranslatedSQLStrings, getTranslationRow, hasAccessor, hasProperties, hasQueryMechanism, hasSessionName, ignoreBindAllParameters, ignoreCacheStatement, isCallQuery, isCascadeOfAggregateDelete, isDataModifyQuery, isDataReadQuery, isDeleteAllQuery, isDeleteObjectQuery, isExpressionQuery, isInsertObjectQuery, isModifyAllQuery, isModifyQuery, isObjectLevelModifyQuery, isPrepared, isReadAllQuery, isReadObjectQuery, isReportQuery, isSQLCallQuery, isUpdateAllQuery, isUpdateObjectQuery, isUserDefined, isWriteObjectQuery, maintainCache, prepareCall, prepareCustomQuery, prepareForExecution, prepareForRemoteExecution, removeProperty, rowFromArguments, setAccessor, setArguments, setArgumentTypeNames, setArgumentTypes, setArgumentValues, setCall, setCascadePolicy, setDatasourceCall, setFlushOnExecute, setIsPrepared, setIsUserDefined, setName, setProperties, setProperty, setQueryMechanism, setSession, setSessionName, setShouldBindAllParameters, setShouldBindAllParameters, setShouldCacheStatement, setShouldMaintainCache, setShouldPrepare, setShouldUseWrapperPolicy, setSQLStatement, setSQLString, setTranslationRow, shouldBindAllParameters, shouldCacheStatement, shouldCascadeAllParts, shouldCascadeByMapping, shouldCascadeOnlyDependentParts, shouldCascadeParts, shouldCascadePrivateParts, shouldCloneCall, shouldIgnoreBindAllParameters, shouldIgnoreCacheStatement, shouldMaintainCache, shouldPrepare, shouldUseWrapperPolicy
protected ExpressionBuilder defaultBuilder
protected boolean shouldRefreshIdentityMapResult
protected int cacheUsage
public static final int UseDescriptorSetting
public static final int DoNotCheckCache
public static final int CheckCacheByExactPrimaryKey
public static final int CheckCacheByPrimaryKey
public static final int CheckCacheThenDatabase
public static final int CheckCacheOnly
public static final int ConformResultsInUnitOfWork
protected boolean shouldRegisterResultsInUnitOfWork
protected Vector additionalFields
protected boolean shouldIncludeData
protected boolean shouldProcessResultsInUnitOfWork
protected short distinctState
public static final short UNCOMPUTED_DISTINCT
public static final short USE_DISTINCT
public static final short DONT_USE_DISTINCT
protected InMemoryQueryIndirectionPolicy inMemoryQueryIndirectionPolicy
protected long executionTime
public static final String LOCK_RESULT_PROPERTY
protected FetchGroup fetchGroup
protected String fetchGroupName
protected boolean shouldUseDefaultFetchGroup
protected boolean wasDefaultLockMode
protected Vector nonFetchJoinAttributeExpressions
protected JoinedAttributeManager joinedAttributeManager
public ObjectLevelReadQuery()
protected boolean wasDefaultLockMode()
wasDefaultLockMode
in class ObjectBuildingQuery
protected void setWasDefaultLockMode(boolean wasDefaultLockMode)
setWasDefaultLockMode
in class ObjectBuildingQuery
public Object clone()
clone
in class DatabaseQuery
public Object deepClone()
Normally selection criteria are not cloned here as they are cloned later on during prepare.
public void acquireLocks()
public void acquireLocksWithoutWaiting()
public void addAdditionalField(DatabaseField field)
public void addAdditionalField(Expression fieldExpression)
public void addJoinedAttribute(String attributeName)
Note: This cannot be used for objects where it is possible not to have a part, as these objects will be ommited from the result set, unless an outer join is used through passing and expression using "getAllowingNull".
Example: query.addJoinedAttribute("address")
addJoinedAttribute(Expression)
public void addJoinedAttribute(Expression attributeExpression)
Note: This cannot be used for objects where it is possible not to have a part, as these objects will be ommited from the result set, unless an outer join is used through passing and expression using "getAllowingNull".
Example: The following will fetch along with Employee(s) "Jones" all projects they participate in along with teamLeaders and their addresses, teamMembers and their phones. query.setSelectionCriteria(query.getExpressionBuilder().get("lastName").equal("Jones")); Expression projects = query.getExpressionBuilder().anyOf("projects"); query.addJoinedAttribute(projects); Expression teamLeader = projects.get("teamLeader"); query.addJoinedAttribute(teamLeader); Expression teamLeaderAddress = teamLeader.getAllowingNull("address"); query.addJoinedAttribute(teamLeaderAddress); Expression teamMembers = projects.anyOf("teamMembers"); query.addJoinedAttribute(teamMembers); Expression teamMembersPhones = teamMembers.anyOfAllowingNone("phoneNumbers"); query.addJoinedAttribute(teamMembersPhones); Note that: the order is essential: an expression should be added before any expression derived from it; the object is built once - it won't be rebuilt if it to be read again as a joined attribute: in the example the query won't get phones for "Jones" - even though they are among teamMembers (for whom phones are read).
public void addNonFetchJoinedAttribute(String attributeName)
Note: This cannot be used for objects where it is possible not to have a part, as these objects will be ommited from the result set, unless an outer join is used through passing and expression using "getAllowingNull".
Example: query.addNonFetchJoinedAttribute("address")
addNonFetchJoinedAttribute(Expression)
public void addNonFetchJoinedAttribute(Expression attributeExpression)
Note: This cannot be used for objects where it is possible not to have a part, as these objects will be ommited from the result set, unless an outer join is used through passing and expression using "getAllowingNull".
Example: query.addNonFetchJoinedAttribute(query.getExpressionBuilder().get("teamLeader").get("address"))
addNonFetchJoinedAttribute(Expression)
protected void addSelectionFieldsForJoinedExpressions(List fields, List joinedExpressions)
public Object buildObject(AbstractRecord row)
buildObject
in class ReadQuery
public void checkCacheOnly()
setCacheUsage(int)
public void checkDescriptor(AbstractSession session) throws QueryException
checkDescriptor
in class DatabaseQuery
QueryException
protected abstract Object checkEarlyReturnImpl(AbstractSession session, AbstractRecord translationRow)
public Object checkEarlyReturn(AbstractSession session, AbstractRecord translationRow)
checkEarlyReturn
in class DatabaseQuery
public void checkPrepare(AbstractSession session, AbstractRecord translationRow)
checkPrepare
in class DatabaseQuery
protected void checkPrePrepare(AbstractSession session)
public void changeDescriptor(AbstractSession theSession)
protected Object conformIndividualResult(Object result, UnitOfWorkImpl unitOfWork, AbstractRecord arguments, Expression selectionCriteriaClone, IdentityHashtable alreadyReturned, boolean buildDirectlyFromRows)
A result needs to be registered before it can be conformed, so registerIndividualResult is called here.
Conforming on a result from the database is lenient. Since the object matched the query on the database we assume it matches here unless we can determine for sure that it was changed in this UnitOfWork not to conform.
result
- may be an original, or a raw database rowarguments
- the parameters this query was executed withselectionCriteriaClone
- the expression to conform to. If was a
selection object or key, null (which all conform to) is usedalreadyReturned
- a hashtable of objects already found by scanning
the UnitOfWork cache for conforming instances. Prevents duplicates.buildDirectlyFromRows
- whether result is an original or a raw database
rowpublic void conformResultsInUnitOfWork()
setCacheUsage(int)
public void dontAcquireLocks()
public void dontCheckCache()
public void dontRefreshIdentityMapResult()
dontRefreshIdentityMapResult
in class ObjectBuildingQuery
public void dontUseDistinct()
public DatabaseQuery prepareOutsideUnitOfWork(AbstractSession session)
If that is so, only queries executed inside of a UnitOfWork should have a locking clause. In the extremely rare case that we execute a locking query outside of a UnitOfWork, must disable locking so that we do not get a fetch out of sequence error.
public Object execute(AbstractSession session, AbstractRecord translationRow) throws DatabaseException, OptimisticLockException
execute
in class DatabaseQuery
session
- - the session in which the receiver will be executed.DatabaseException
- - an error has occurred on the database.OptimisticLockException
- - an error has occurred using the optimistic lock feature.public Object executeDatabaseQuery() throws DatabaseException
DatabaseQuery
executeDatabaseQuery
in class DatabaseQuery
DatabaseException
- - an error has occurred on the database.protected abstract Object executeObjectLevelReadQuery() throws DatabaseException
DatabaseException
public Object executeInUnitOfWork(UnitOfWorkImpl unitOfWork, AbstractRecord translationRow) throws DatabaseException, OptimisticLockException
executeInUnitOfWork
in class DatabaseQuery
unitOfWork
- translationRow
- DatabaseException
OptimisticLockException
public Vector getAdditionalFields()
public int getCacheUsage()
Valid values are:
public short getDistinctState()
public ExpressionBuilder getExpressionBuilder()
public void setExpressionBuilder(ExpressionBuilder builder)
public InMemoryQueryIndirectionPolicy getInMemoryQueryIndirectionPolicy()
public JoinedAttributeManager getJoinedAttributeManager()
public Vector getNonFetchJoinAttributeExpressions()
public DatabaseMapping getLeafMappingFor(Expression expression, ClassDescriptor rootDescriptor) throws QueryException
QueryException
public ClassDescriptor getLeafDescriptorFor(Expression expression, ClassDescriptor rootDescriptor) throws QueryException
expression
- rootDescriptor
- QueryException
public short getLockMode()
getLockMode
in class ObjectBuildingQuery
public ForUpdateClause getLockingClause()
public long getExecutionTime()
getExecutionTime
in class ObjectBuildingQuery
public Class getReferenceClass()
getReferenceClass
in class ObjectBuildingQuery
public String getReferenceClassName()
getReferenceClassName
in class ObjectBuildingQuery
public boolean hasAsOfClause()
#getAsOfClause()
public boolean hasNonFetchJoinedAttributeExpressions()
public boolean hasPartialAttributeExpressions()
hasPartialAttributeExpressions
in class ObjectBuildingQuery
public Vector getSelectionFields()
protected void initializeDefaultBuilder()
public boolean isDistinctComputed()
public boolean isLockQuery()
If a single joined attribute was configured for pessimistic locking then this will return true (after first execution) as the SQL contained a FOR UPDATE OF clause.
isLockQuery
in class ObjectBuildingQuery
public boolean isLockQuery(Session session)
If the lock mode is not known (DEFAULT_LOCK_MODE / descriptor specified fine-grained locking) the lock mode will be determined now, to be either LOCK, LOCK_NOWAIT, or NO_LOCK.
isLockQuery()
public boolean isObjectLevelReadQuery()
isObjectLevelReadQuery
in class DatabaseQuery
protected boolean isPrePrepared()
protected boolean isRegisteringResults()
isRegisteringResults
in class ObjectBuildingQuery
protected void setIsPrePrepared(boolean isPrePrepared)
Automatically called internally.
The early phase of preparation is to check if this is a pessimistic locking query.
protected void prepare() throws QueryException
prepare
in class DatabaseQuery
QueryException
protected void prePrepare() throws QueryException
QueryException
protected void prepareQuery() throws QueryException
QueryException
public void refreshIdentityMapResult()
refreshIdentityMapResult
in class ObjectBuildingQuery
public abstract Object registerResultInUnitOfWork(Object result, UnitOfWorkImpl unitOfWork, AbstractRecord arguments, boolean buildDirectlyFromRows)
Involves registering the query result individually and in totality, and hence refreshing / conforming is done here.
result
- may be collection (read all) or an object (read one),
or even a cursor. If in transaction the shared cache will
be bypassed, meaning the result may not be originals from the parent
but raw database rows.unitOfWork
- the unitOfWork the result is being registered in.arguments
- the original arguments/parameters passed to the query
execution. Used by conformingbuildDirectlyFromRows
- If in transaction must construct
a registered result from raw database rows.public void resetDistinct()
public void setAdditionalFields(Vector additionalFields)
public void setCacheUsage(int cacheUsage)
Valid values are:
public void setDescriptor(ClassDescriptor descriptor)
setDescriptor
in class DatabaseQuery
public void setDistinctState(short distinctState)
public void setExecutionTime(long executionTime)
setExecutionTime
in class ObjectBuildingQuery
public void setInMemoryQueryIndirectionPolicy(InMemoryQueryIndirectionPolicy inMemoryQueryIndirectionPolicy)
public void setLockMode(short lockMode)
Fine Grained Locking: On execution the reference class and those of all joined attributes will be checked. If any of these have a PessimisticLockingPolicy set on their descriptor, they will be locked in a SELECT ... FOR UPDATE OF ... {NO WAIT}. Issues fewer locks and avoids setting the lock mode on each query.
Example:readAllQuery.setSelectionCriteria(employee.get("address").equal("Ottawa"));
setLockMode
in class ObjectBuildingQuery
oracle.toplink.essentials.descriptors.PessimisticLockingPolicy
protected void setNonFetchJoinAttributeExpressions(Vector nonFetchJoinExpressions)
public void setLockingClause(ForUpdateClause clause)
Use for even finer grained control over what is and is not locked by a particular query.
public void setEJBQLString(String ejbqlString)
DatabaseQuery
setEJBQLString
in class DatabaseQuery
public void setReferenceClass(Class aClass)
setReferenceClass
in class ObjectBuildingQuery
public void setReferenceClassName(String aClass)
setReferenceClassName
in class ObjectBuildingQuery
public void setSelectionCriteria(Expression expression)
DatabaseQuery
setSelectionCriteria
in class DatabaseQuery
public void setShouldIncludeData(boolean shouldIncludeData)
ComplexQueryResult
public void setShouldRefreshIdentityMapResult(boolean shouldRefreshIdentityMapResult)
setShouldRefreshIdentityMapResult
in class ObjectBuildingQuery
public void setShouldRegisterResultsInUnitOfWork(boolean shouldRegisterResultsInUnitOfWork)
setShouldRegisterResultsInUnitOfWork
in class ObjectBuildingQuery
shouldRegisterResultsInUnitOfWork
public boolean shouldCheckCacheOnly()
public boolean shouldCheckDescriptorForCacheUsage()
public boolean shouldConformResultsInUnitOfWork()
public boolean shouldDistinctBeUsed()
public boolean shouldIncludeData()
ComplexQueryResult
public boolean shouldRegisterResultsInUnitOfWork()
Extreme care should be taken in using this feature, for a user will get back a mix of registered and original (unregistered) objects.
Best used with a WrapperPolicy where invoking on an object will trigger
its registration (CMP). Without a WrapperPolicy registerExistingObject
should be called on any object that you intend to change.
shouldRegisterResultsInUnitOfWork
in class ObjectBuildingQuery
setShouldRegisterResultsInUnitOfWork(boolean)
,
oracle.toplink.essentials.publicinterface.Descriptor#shouldRegisterResultsInUnitOfWork()
public boolean shouldReadAllMappings()
shouldReadAllMappings
in class ObjectBuildingQuery
public boolean shouldReadMapping(DatabaseMapping mapping)
shouldReadMapping
in class ObjectBuildingQuery
public boolean shouldRefreshIdentityMapResult()
shouldRefreshIdentityMapResult
in class ObjectBuildingQuery
public String toString()
toString
in class ObjectBuildingQuery
public void setShouldProcessResultsInUnitOfWork(boolean processResultsInUnitOfWork)
If set to false, then UnitOfWork allocation will be deferred until a business method (including creates/removes) or finder with shouldProcessResultsInUnitOfWork == true is invoked. Any finder executed before such a time, will do so against the underlying ServerSession. Forcing finder execution to always go through a UnitOfWork means the results will be cloned and cached in the UnitOfWork up front. This is desired when the results will be accessed in the same transaction.
Note that finders executed with an unspecified transaction context will never be executed against a UnitOfWork, even if this setting is true. This case may happen with the NotSupported, Never, and Supports attributes.
setShouldProcessResultsInUnitOfWork
in class ObjectBuildingQuery
public boolean shouldProcessResultsInUnitOfWork()
If set to false, then UnitOfWork allocation will be deferred until a business method (including creates/removes) or finder with shouldProcessResultsInUnitOfWork == true is invoked. Any finder executed before such a time, will do so against the underlying ServerSession. Forcing finder execution to always go through a UnitOfWork means the results will be cloned and cached in the UnitOfWork up front. This is desired when the results will be accessed in the same transaction.
Note that finders executed with an unspecified transaction context will never be executed against a UnitOfWork, even if this setting is true. This case may happen with the NotSupported, Never, and Supports attributes.
shouldProcessResultsInUnitOfWork
in class ObjectBuildingQuery
public void useDistinct()
public boolean isClonePessimisticLocked(Object clone, UnitOfWorkImpl uow)
isClonePessimisticLocked
in class ObjectBuildingQuery
public void recordCloneForPessimisticLocking(Object clone, UnitOfWorkImpl uow)
recordCloneForPessimisticLocking
in class ObjectBuildingQuery
public boolean isDefaultLock()
isDefaultLock
in class ObjectBuildingQuery
public FetchGroup getFetchGroup()
getFetchGroup
in class ObjectBuildingQuery
public void initializeFetchGroup()
public void setFetchGroup(FetchGroup newFetchGroup)
public void setFetchGroupName(String groupName)
public String getFetchGroupName()
public boolean shouldUseDefaultFetchGroup()
public void setShouldUseDefaultFetchGroup(boolean shouldUseDefaultFetchGroup)
public boolean hasFetchGroupAttributeExpressions()
public boolean isFetchGroupAttribute(String attributeName)
Copyright © 2022. All rights reserved.