Module org.eclipse.persistence.core
Class JoinedAttributeManager
java.lang.Object
org.eclipse.persistence.internal.queries.JoinedAttributeManager
- All Implemented Interfaces:
Serializable
,Cloneable
Purpose: A common class to be used by ObjectLevelReadQueries and ReportItems. This Class will be used to store Joined Attribute Expressions. It will also store the indexes for object construction.
- Since:
- EJB3.0 RI
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected List
<Expression> protected ExpressionBuilder
Stores the base builder for resolving joined attributes by name.protected ObjectBuildingQuery
Stores the base query.protected List
<AbstractRecord> Stored all row results to -m joining.protected Map
<Object, List<AbstractRecord>> Stored all row results to -m joining by cache key.protected ClassDescriptor
Stores the descriptor that these joins apply onprotected boolean
PERF: Used to avoid null checks for inner attribute joining.protected boolean
Used to determine if -m joining has been used.protected List
<DatabaseMapping> Stores AggregateObjectMapping expressions used within local join expressionsprotected List
<Expression> Stores the joined attributes added through the queryprotected List
<DatabaseMapping> indexed list of mappings corresponding toprotected List
<Expression> PERF: Cache the local joined attribute expressions.protected List
<Expression> Stores the joined attributes as specified in the descriptorprotected Map
<DatabaseMapping, Object> Used internally for joining.protected Map
<DatabaseMapping, ObjectLevelReadQuery> Used internally for joining.protected Map
<DatabaseMapping, ObjectLevelReadQuery> PERF: Stores the cloned joinedMappingQueries.protected Expression
Stores the last used base expression while adding joined attribute expression.protected List
<Expression> protected int
Stores the result index of the parent, used for oneToMany joins.protected boolean
Determine if duplicate rows should be filter when using 1-m joining. -
Constructor Summary
ConstructorDescriptionJoinedAttributeManager
(ClassDescriptor descriptor, ExpressionBuilder baseBuilder, ObjectBuildingQuery baseQuery) -
Method Summary
Modifier and TypeMethodDescriptionaddAndPrepareJoinedMapping
(ForeignReferenceMapping mapping, AbstractSession session) Add the mapping for join fetch, prepare and return the join expression being used.protected Expression
addExpressionAndBaseToGroupedList
(Expression expression, List expressionlist, Expression lastJoinedAttributeBaseExpression) adds expression and its base expressions recursively to the expressionList in groups, so that an expression is never listed before its base expressionvoid
addJoinedAttribute
(Expression attributeExpression) void
addJoinedAttributeExpression
(Expression attributeExpression) void
addJoinedMapping
(String attributeName) Add an attribute represented by the given attribute name to the list of joins for this query.void
addJoinedMappingExpression
(Expression mappingExpression) Add an attribute represented by the given attribute name to the list of joins for this query.void
clear()
Clear the joining state.void
Clear the data-results for joined data for a 1-m join.clone()
Clones the Joined Attribute Manager.protected int
computeIndexesForJoinedExpressions
(List joinedExpressions, int currentIndex, AbstractSession session) This method is used when computing the indexes for joined mappings.int
computeJoiningMappingIndexes
(boolean includeAllSubclassFields, AbstractSession session, int offset) For joining the resulting rows include the field/values for many objects.void
Used to optimize joining by pre-computing the nested join queries for the mappings.protected void
computeNestedQueriesForJoinedExpressions
(List joinedExpressions, AbstractSession session, ObjectLevelReadQuery readQuery) This method is used when computing the nested queries for joined mappings.void
copyFrom
(JoinedAttributeManager otherJoinManager) Copies settings from another manager.Get the list of additional field expressions.Get the list of additional field expressions.Returns the base expression builder for this query.Returns the base query.Return all of the rows fetched by the query, used for 1-m joining.Return all of the rows fetched by the query by cache-key, used for 1-m joining.Return the attributes that must be joined.Return the attributes that must be joined.Return the attributes that must be joined.Return the attributes that must be joined.Get the list of expressions that represent elements that are joined because of their mapping for this query.Return the joined mapping indexes, used to compute mapping row partitions.Return the joined mapping queries, used optimize joining, only compute the nested queries once.getNestedJoinedMappingQuery
(Expression expression) INTERNAL: Returns the nested query corresponding to the expression.Get the list of orderBy expressions.Get the list of orderBy expressions.int
getValueFromObjectForExpression
(AbstractSession session, Object clone, ObjectExpression expression) INTERNAL: Helper method to get the value from the clone for the expression passed in, triggering joins on all intermediate steps.boolean
Return if there are additional field expressions.boolean
Return the attributes that must be joined.boolean
Return if any attributes are joined.boolean
This method checks both attribute expressions and mapping expressions and determines if there are any joins to be made.boolean
Return the attributes that must be joined.boolean
Return if there are orderBy expressions.boolean
PERF: Return if the query uses any outer attribute joins, used to avoid null checks in building objects.protected boolean
isAttributeExpressionJoined
(DatabaseMapping attributeMapping) Return if the attribute is specified for joining.boolean
isAttributeJoined
(ClassDescriptor mappingDescriptor, DatabaseMapping attributeMapping) Return if the attribute is specified for joining.protected boolean
isAttributeMappingJoined
(DatabaseMapping attributeMapping) Return whether the given attribute is joined as a result of a join on a mappingprotected boolean
isAttributeNameInJoinedExpressionList
(String attributeName, List joinedExpressionList) Iterate through a list of expressions searching for the given attribute name.protected boolean
isMappingInJoinedExpressionList
(DatabaseMapping attributeMapping, List joinedExpressionList) Iterate through a list of expressions searching for the given attribute name.boolean
Return if the query uses any -m joins, and thus return duplicate/multiple rows.protected Expression
prepareJoinExpression
(Expression expression, AbstractSession session) Validate and prepare the join expression.void
prepareJoinExpressions
(AbstractSession session) Validate and prepare join expressions.processDataResults
(AbstractRecord row, Cursor cursor, boolean forward) Process the data-results for joined data for a 1-m join.protected void
processDataResults
(AbstractSession session) Process the data-results for joined data for a 1-m join.void
processJoinedMappings
(AbstractSession session) This method collects the Joined Mappings from the descriptor and initializes them.void
reset()
Reset the JoinedAttributeManager.void
setAdditionalFieldExpressions_
(List<Expression> expressions) Set the list of additional field expressions.protected void
This method is called from within this package, it is used when initializing a ReportItemvoid
setBaseQuery
(ObjectLevelReadQuery query) This method is called from within this package it is used when initializing a report Itemvoid
setDataResults
(List dataResults, AbstractSession session) Set all of the rows fetched by the query, used for 1-m joining.protected void
setDataResultsByPrimaryKey
(Map<Object, List<AbstractRecord>> dataResultsByPrimaryKey) Set all of the rows fetched by the query by cache-key, used for 1-m joining.void
setDescriptor
(ClassDescriptor descriptor) Called to set the descriptor on a Join Managerwith in a ReportItem, durring initialization, and durring DatabaseQuery.checkDescriptor.protected void
setIsOuterJoinedAttributeQuery
(boolean isOuterJoinedAttribute) PERF: Set if the query uses any outer attribute joins, used to avoid null checks in building objects.void
setIsToManyJoinQuery
(boolean isToManyJoin) Set if the query uses any -m joins, and thus return duplicate/multiple rows.void
setJoinedAttributeExpressions_
(List joinedExpressions) Set the list of expressions that represent elements that are joined because of their mapping for this query.void
setJoinedMappingExpressions_
(List joinedMappingExpressions) Set the list of expressions that represent elements that are joined because of their mapping for this query.void
setJoinedMappingIndexes_
(Map joinedMappingIndexes) Set the joined mapping indexes, used to compute mapping row partitions.void
setJoinedMappingQueries_
(Map joinedMappingQueries) Set the joined mapping queries, used optimize joining, only compute the nested queries once.void
setJoinedMappingQueryClones
(Map joinedMappingQueryClones) void
setOrderByExpressions_
(List<Expression> expressions) Set the list of orderBy expressions.void
setParentResultIndex
(int parentsResultIndex) void
setShouldFilterDuplicates
(boolean shouldFilterDuplicates) Set if duplicate rows should be filter when using 1-m joining.setupLockingClauseForJoinedExpressions
(ForUpdateOfClause lockingClause, AbstractSession session) Used for joining in conjunction with pessimistic locking.boolean
Return if duplicate rows should be filter when using 1-m joining.
-
Field Details
-
joinedAggregateMappings
Stores AggregateObjectMapping expressions used within local join expressions -
joinedAttributeMappings
indexed list of mappings corresponding to -
joinedAttributeExpressions
Stores the joined attributes added through the query -
joinedMappingExpressions
Stores the joined attributes as specified in the descriptor -
joinedAttributes
PERF: Cache the local joined attribute expressions. -
isToManyJoin
protected boolean isToManyJoinUsed to determine if -m joining has been used. -
hasOuterJoinedAttribute
protected boolean hasOuterJoinedAttributePERF: Used to avoid null checks for inner attribute joining. -
joinedMappingIndexes
Used internally for joining. -
joinedMappingQueries
Used internally for joining. -
joinedMappingQueryClones
PERF: Stores the cloned joinedMappingQueries. -
dataResults
Stored all row results to -m joining. -
dataResultsByPrimaryKey
Stored all row results to -m joining by cache key. -
descriptor
Stores the descriptor that these joins apply on -
baseExpressionBuilder
Stores the base builder for resolving joined attributes by name. -
lastJoinedAttributeBaseExpression
Stores the last used base expression while adding joined attribute expression. -
baseQuery
Stores the base query. -
parentResultIndex
protected int parentResultIndexStores the result index of the parent, used for oneToMany joins. -
shouldFilterDuplicates
protected boolean shouldFilterDuplicatesDetermine if duplicate rows should be filter when using 1-m joining. -
orderByExpressions
-
additionalFieldExpressions
-
-
Constructor Details
-
JoinedAttributeManager
public JoinedAttributeManager() -
JoinedAttributeManager
public JoinedAttributeManager(ClassDescriptor descriptor, ExpressionBuilder baseBuilder, ObjectBuildingQuery baseQuery)
-
-
Method Details
-
shouldFilterDuplicates
public boolean shouldFilterDuplicates()Return if duplicate rows should be filter when using 1-m joining. -
setShouldFilterDuplicates
public void setShouldFilterDuplicates(boolean shouldFilterDuplicates) Set if duplicate rows should be filter when using 1-m joining. -
addJoinedAttribute
-
addJoinedAttributeExpression
-
addJoinedMappingExpression
Add an attribute represented by the given attribute name to the list of joins for this query. Note: Mapping level joins are represented separately from query level joins. -
addJoinedMapping
Add an attribute represented by the given attribute name to the list of joins for this query. Note: Mapping level joins are represented separately from query level joins. -
clone
Clones the Joined Attribute Manager. Generally called from Query.clone(). -
copyFrom
Copies settings from another manager. Should copy all the attributes that clone method clones. -
clear
public void clear()Clear the joining state. This is used to redefine a queries joins for nested joins. -
computeJoiningMappingIndexes
public int computeJoiningMappingIndexes(boolean includeAllSubclassFields, AbstractSession session, int offset) For joining the resulting rows include the field/values for many objects. As some of the objects may have the same field names, these row partitions need to be calculated. The indexes are stored in the query and used later when building the objects. -
computeNestedQueriesForJoinedExpressions
protected void computeNestedQueriesForJoinedExpressions(List joinedExpressions, AbstractSession session, ObjectLevelReadQuery readQuery) This method is used when computing the nested queries for joined mappings. It recurses computing the nested mapping queries and their join indexes. -
computeJoiningMappingQueries
Used to optimize joining by pre-computing the nested join queries for the mappings. -
computeIndexesForJoinedExpressions
protected int computeIndexesForJoinedExpressions(List joinedExpressions, int currentIndex, AbstractSession session) This method is used when computing the indexes for joined mappings. It iterates through a list of join expressions and adds an index that represents where the fields represented by that expression will appear in the row returned by a read query. MethodcomputeNestedQueriesForJoinedExpressions(List, AbstractSession, ObjectLevelReadQuery)
must be already called.- Parameters:
joinedExpressions
- Join expressionsList
.currentIndex
- Current joined mapping index.session
- Current session.- Returns:
- Current joined mapping index updated.
-
getAdditionalFieldExpressions
Get the list of additional field expressions. -
getAdditionalFieldExpressions_
Get the list of additional field expressions. -
getBaseExpressionBuilder
Returns the base expression builder for this query. -
getBaseQuery
Returns the base query. -
getDataResults_
Return all of the rows fetched by the query, used for 1-m joining. -
getDescriptor
-
hasAdditionalFieldExpressions
public boolean hasAdditionalFieldExpressions()Return if there are additional field expressions. -
setAdditionalFieldExpressions_
Set the list of additional field expressions. -
getJoinedAggregateMappings
Return the attributes that must be joined. -
getJoinedAttributeExpressions
Return the attributes that must be joined. -
getJoinedAttributeMappings
Return the attributes that must be joined. -
getJoinedAttributes
Return the attributes that must be joined. -
getJoinedMappingExpressions
Get the list of expressions that represent elements that are joined because of their mapping for this query. -
hasJoinedAttributeExpressions
public boolean hasJoinedAttributeExpressions()Return the attributes that must be joined. -
hasJoinedExpressions
public boolean hasJoinedExpressions()This method checks both attribute expressions and mapping expressions and determines if there are any joins to be made. -
hasJoinedMappingExpressions
public boolean hasJoinedMappingExpressions()Return the attributes that must be joined. -
hasJoinedAttributes
public boolean hasJoinedAttributes()Return if any attributes are joined. This is a convience method that is only valid after prepare. -
hasOuterJoinedAttributeQuery
public boolean hasOuterJoinedAttributeQuery()PERF: Return if the query uses any outer attribute joins, used to avoid null checks in building objects. -
getOrderByExpressions
Get the list of orderBy expressions. -
getOrderByExpressions_
Get the list of orderBy expressions. -
getValueFromObjectForExpression
public Object getValueFromObjectForExpression(AbstractSession session, Object clone, ObjectExpression expression) INTERNAL: Helper method to get the value from the clone for the expression passed in, triggering joins on all intermediate steps. Example expression "emp.project.pk" with a clone Employee will trigger indirection and return the project pk value. -
hasOrderByExpressions
public boolean hasOrderByExpressions()Return if there are orderBy expressions. -
setOrderByExpressions_
Set the list of orderBy expressions. -
isToManyJoin
public boolean isToManyJoin()Return if the query uses any -m joins, and thus return duplicate/multiple rows. -
isAttributeJoined
public boolean isAttributeJoined(ClassDescriptor mappingDescriptor, DatabaseMapping attributeMapping) Return if the attribute is specified for joining. -
isMappingInJoinedExpressionList
protected boolean isMappingInJoinedExpressionList(DatabaseMapping attributeMapping, List joinedExpressionList) Iterate through a list of expressions searching for the given attribute name. Return true if it is found, false otherwise. Only use if the query was preprepared so that join expressions were processed. -
isAttributeNameInJoinedExpressionList
protected boolean isAttributeNameInJoinedExpressionList(String attributeName, List joinedExpressionList) Iterate through a list of expressions searching for the given attribute name. Return true if it is found, false otherwise. -
isAttributeExpressionJoined
Return if the attribute is specified for joining. -
isAttributeMappingJoined
Return whether the given attribute is joined as a result of a join on a mapping -
setJoinedAttributeExpressions_
Set the list of expressions that represent elements that are joined because of their mapping for this query. -
setJoinedMappingExpressions_
Set the list of expressions that represent elements that are joined because of their mapping for this query. -
getJoinedMappingIndexes_
Return the joined mapping indexes, used to compute mapping row partitions. -
getJoinedMappingQueries_
Return the joined mapping queries, used optimize joining, only compute the nested queries once. -
getNestedJoinedMappingQuery
INTERNAL: Returns the nested query corresponding to the expression. The passed expression should be either join mapping or joined attribute expression. -
setJoinedMappingQueries_
Set the joined mapping queries, used optimize joining, only compute the nested queries once. -
setJoinedMappingIndexes_
Set the joined mapping indexes, used to compute mapping row partitions. -
setIsOuterJoinedAttributeQuery
protected void setIsOuterJoinedAttributeQuery(boolean isOuterJoinedAttribute) PERF: Set if the query uses any outer attribute joins, used to avoid null checks in building objects. -
setIsToManyJoinQuery
public void setIsToManyJoinQuery(boolean isToManyJoin) Set if the query uses any -m joins, and thus return duplicate/multiple rows. -
prepareJoinExpressions
Validate and prepare join expressions. -
addExpressionAndBaseToGroupedList
protected Expression addExpressionAndBaseToGroupedList(Expression expression, List expressionlist, Expression lastJoinedAttributeBaseExpression) adds expression and its base expressions recursively to the expressionList in groups, so that an expression is never listed before its base expression -
prepareJoinExpression
Validate and prepare the join expression. -
processJoinedMappings
This method collects the Joined Mappings from the descriptor and initializes them. Excludes the mapping that are not in the passed mappingsAllowedToJoin set (if it's not null). -
addAndPrepareJoinedMapping
public Expression addAndPrepareJoinedMapping(ForeignReferenceMapping mapping, AbstractSession session) Add the mapping for join fetch, prepare and return the join expression being used. -
reset
public void reset()Reset the JoinedAttributeManager. This will be called when the Query is re-prepared -
setBaseQuery
This method is called from within this package it is used when initializing a report Item -
setBaseExpressionBuilder
This method is called from within this package, it is used when initializing a ReportItem -
getDataResultsByPrimaryKey
Return all of the rows fetched by the query by cache-key, used for 1-m joining. -
setDataResultsByPrimaryKey
Set all of the rows fetched by the query by cache-key, used for 1-m joining. -
setDataResults
Set all of the rows fetched by the query, used for 1-m joining. -
processDataResults
Process the data-results for joined data for a 1-m join. This allows all the data to be processed once, instead of n times for each object. -
clearDataResults
public void clearDataResults()Clear the data-results for joined data for a 1-m join. -
processDataResults
Process the data-results for joined data for a 1-m join. This allows incremental processing for a cursor. -
setDescriptor
Called to set the descriptor on a Join Managerwith in a ReportItem, durring initialization, and durring DatabaseQuery.checkDescriptor. -
setupLockingClauseForJoinedExpressions
public ForUpdateOfClause setupLockingClauseForJoinedExpressions(ForUpdateOfClause lockingClause, AbstractSession session) Used for joining in conjunction with pessimistic locking. Iterate through a list of joined expressions and ensure expression is set on the locking clause for each expression that represents a pessimisically locked descriptor. -
setParentResultIndex
public void setParentResultIndex(int parentsResultIndex) -
getParentResultIndex
public int getParentResultIndex() -
getJoinedMappingQueryClones
-
setJoinedMappingQueryClones
-