Class JoinedAttributeManager

java.lang.Object
org.eclipse.persistence.internal.queries.JoinedAttributeManager
All Implemented Interfaces:
Serializable, Cloneable

public class JoinedAttributeManager extends Object implements Cloneable, Serializable

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 Details

    • joinedAggregateMappings

      protected transient List<DatabaseMapping> joinedAggregateMappings
      Stores AggregateObjectMapping expressions used within local join expressions
    • joinedAttributeMappings

      protected transient List<DatabaseMapping> joinedAttributeMappings
      indexed list of mappings corresponding to
    • joinedAttributeExpressions

      protected List<Expression> joinedAttributeExpressions
      Stores the joined attributes added through the query
    • joinedMappingExpressions

      protected List<Expression> joinedMappingExpressions
      Stores the joined attributes as specified in the descriptor
    • joinedAttributes

      protected List<Expression> joinedAttributes
      PERF: Cache the local joined attribute expressions.
    • isToManyJoin

      protected boolean isToManyJoin
      Used to determine if -m joining has been used.
    • hasOuterJoinedAttribute

      protected boolean hasOuterJoinedAttribute
      PERF: Used to avoid null checks for inner attribute joining.
    • joinedMappingIndexes

      protected transient Map<DatabaseMapping,Object> joinedMappingIndexes
      Used internally for joining.
    • joinedMappingQueries

      protected transient Map<DatabaseMapping,ObjectLevelReadQuery> joinedMappingQueries
      Used internally for joining.
    • joinedMappingQueryClones

      protected transient Map<DatabaseMapping,ObjectLevelReadQuery> joinedMappingQueryClones
      PERF: Stores the cloned joinedMappingQueries.
    • dataResults

      protected transient List<AbstractRecord> dataResults
      Stored all row results to -m joining.
    • dataResultsByPrimaryKey

      protected transient Map<Object,List<AbstractRecord>> dataResultsByPrimaryKey
      Stored all row results to -m joining by cache key.
    • descriptor

      protected transient ClassDescriptor descriptor
      Stores the descriptor that these joins apply on
    • baseExpressionBuilder

      protected ExpressionBuilder baseExpressionBuilder
      Stores the base builder for resolving joined attributes by name.
    • lastJoinedAttributeBaseExpression

      protected Expression lastJoinedAttributeBaseExpression
      Stores the last used base expression while adding joined attribute expression.
    • baseQuery

      protected ObjectBuildingQuery baseQuery
      Stores the base query.
    • parentResultIndex

      protected int parentResultIndex
      Stores the result index of the parent, used for oneToMany joins.
    • shouldFilterDuplicates

      protected boolean shouldFilterDuplicates
      Determine if duplicate rows should be filter when using 1-m joining.
    • orderByExpressions

      protected transient List<Expression> orderByExpressions
    • additionalFieldExpressions

      protected transient List<Expression> additionalFieldExpressions
  • Constructor Details

  • 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

      public void addJoinedAttribute(Expression attributeExpression)
    • addJoinedAttributeExpression

      public void addJoinedAttributeExpression(Expression attributeExpression)
    • addJoinedMappingExpression

      public void addJoinedMappingExpression(Expression mappingExpression)
      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

      public void addJoinedMapping(String attributeName)
      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

      public JoinedAttributeManager clone()
      Clones the Joined Attribute Manager. Generally called from Query.clone().
      Overrides:
      clone in class Object
    • copyFrom

      public void copyFrom(JoinedAttributeManager otherJoinManager)
      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

      public void computeJoiningMappingQueries(AbstractSession session)
      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. Method computeNestedQueriesForJoinedExpressions(List, AbstractSession, ObjectLevelReadQuery) must be already called.
      Parameters:
      joinedExpressions - Join expressions List.
      currentIndex - Current joined mapping index.
      session - Current session.
      Returns:
      Current joined mapping index updated.
    • getAdditionalFieldExpressions

      public List<Expression> getAdditionalFieldExpressions()
      Get the list of additional field expressions.
    • getAdditionalFieldExpressions_

      public List<Expression> getAdditionalFieldExpressions_()
      Get the list of additional field expressions.
    • getBaseExpressionBuilder

      public ExpressionBuilder getBaseExpressionBuilder()
      Returns the base expression builder for this query.
    • getBaseQuery

      public ObjectBuildingQuery getBaseQuery()
      Returns the base query.
    • getDataResults_

      public List<AbstractRecord> getDataResults_()
      Return all of the rows fetched by the query, used for 1-m joining.
    • getDescriptor

      public ClassDescriptor getDescriptor()
    • hasAdditionalFieldExpressions

      public boolean hasAdditionalFieldExpressions()
      Return if there are additional field expressions.
    • setAdditionalFieldExpressions_

      public void setAdditionalFieldExpressions_(List<Expression> expressions)
      Set the list of additional field expressions.
    • getJoinedAggregateMappings

      public List<DatabaseMapping> getJoinedAggregateMappings()
      Return the attributes that must be joined.
    • getJoinedAttributeExpressions

      public List<Expression> getJoinedAttributeExpressions()
      Return the attributes that must be joined.
    • getJoinedAttributeMappings

      public List<DatabaseMapping> getJoinedAttributeMappings()
      Return the attributes that must be joined.
    • getJoinedAttributes

      public List<Expression> getJoinedAttributes()
      Return the attributes that must be joined.
    • getJoinedMappingExpressions

      public List<Expression> 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

      public List<Expression> getOrderByExpressions()
      Get the list of orderBy expressions.
    • getOrderByExpressions_

      public List<Expression> 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_

      public void setOrderByExpressions_(List<Expression> expressions)
      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

      protected boolean isAttributeExpressionJoined(DatabaseMapping attributeMapping)
      Return if the attribute is specified for joining.
    • isAttributeMappingJoined

      protected boolean isAttributeMappingJoined(DatabaseMapping attributeMapping)
      Return whether the given attribute is joined as a result of a join on a mapping
    • setJoinedAttributeExpressions_

      public void setJoinedAttributeExpressions_(List joinedExpressions)
      Set the list of expressions that represent elements that are joined because of their mapping for this query.
    • setJoinedMappingExpressions_

      public void setJoinedMappingExpressions_(List joinedMappingExpressions)
      Set the list of expressions that represent elements that are joined because of their mapping for this query.
    • getJoinedMappingIndexes_

      public Map<DatabaseMapping,Object> getJoinedMappingIndexes_()
      Return the joined mapping indexes, used to compute mapping row partitions.
    • getJoinedMappingQueries_

      public Map<DatabaseMapping,ObjectLevelReadQuery> getJoinedMappingQueries_()
      Return the joined mapping queries, used optimize joining, only compute the nested queries once.
    • getNestedJoinedMappingQuery

      public ObjectLevelReadQuery getNestedJoinedMappingQuery(Expression expression)
      INTERNAL: Returns the nested query corresponding to the expression. The passed expression should be either join mapping or joined attribute expression.
    • setJoinedMappingQueries_

      public void setJoinedMappingQueries_(Map joinedMappingQueries)
      Set the joined mapping queries, used optimize joining, only compute the nested queries once.
    • setJoinedMappingIndexes_

      public void setJoinedMappingIndexes_(Map joinedMappingIndexes)
      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

      public void prepareJoinExpressions(AbstractSession session)
      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

      protected Expression prepareJoinExpression(Expression expression, AbstractSession session)
      Validate and prepare the join expression.
    • processJoinedMappings

      public void processJoinedMappings(AbstractSession session)
      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

      public void setBaseQuery(ObjectLevelReadQuery query)
      This method is called from within this package it is used when initializing a report Item
    • setBaseExpressionBuilder

      protected void setBaseExpressionBuilder(ExpressionBuilder builder)
      This method is called from within this package, it is used when initializing a ReportItem
    • getDataResultsByPrimaryKey

      public Map<Object,List<AbstractRecord>> getDataResultsByPrimaryKey()
      Return all of the rows fetched by the query by cache-key, used for 1-m joining.
    • setDataResultsByPrimaryKey

      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.
    • setDataResults

      public void setDataResults(List dataResults, AbstractSession session)
      Set all of the rows fetched by the query, used for 1-m joining.
    • processDataResults

      protected void processDataResults(AbstractSession session)
      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

      public AbstractRecord processDataResults(AbstractRecord row, Cursor cursor, boolean forward)
      Process the data-results for joined data for a 1-m join. This allows incremental processing for a cursor.
    • setDescriptor

      public void setDescriptor(ClassDescriptor descriptor)
      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

      public Map<DatabaseMapping,ObjectLevelReadQuery> getJoinedMappingQueryClones()
    • setJoinedMappingQueryClones

      public void setJoinedMappingQueryClones(Map joinedMappingQueryClones)