Class ObjectExpression

    • Field Detail

      • shouldUseOuterJoinForMultitableInheritance

        protected boolean shouldUseOuterJoinForMultitableInheritance
        indicates whether subclasses should be joined
      • shouldUseOuterJoin

        protected boolean shouldUseOuterJoin
        Is this query key to be resolved using an outer join or not. Does not apply to attributes.
      • castClass

        protected Class castClass
        Allow an expression node to be cast to a subclass or implementation class.
      • joinSource

        protected Expression joinSource
        Defines that this expression has been joined to the source expression.
      • onClause

        protected Expression onClause
        Allow for an ON clause to be specified on a join condition.
      • hasBeenAliased

        protected boolean hasBeenAliased
        Allow hasBeenAliased to be marked independently from the existence of the tableAliases collection.
    • Constructor Detail

      • ObjectExpression

        public ObjectExpression()
    • Method Detail

      • treat

        public Expression treat​(Class castClass)
        Return an expression that allows you to treat its base as if it were a subclass of the class returned by the base This can only be called on an ExpressionBuilder, the result of expression.get(String), expression.getAllowingNull(String), the result of expression.anyOf("String") or the result of expression.anyOfAllowingNull("String") downcast uses Expression.type() internally to guarantee the results are of the specified class.

        Example:

             Expression: employee.get("project").as(LargeProject.class).get("budget").equal(1000)
             Java: ((LargeProject)employee.getProjects().get(0)).getBudget() == 1000
             SQL: LPROJ.PROJ_ID (+)= PROJ.PROJ_ID AND L_PROJ.BUDGET = 1000 AND PROJ.TYPE = "L"
         
        Overrides:
        treat in class Expression
      • equals

        public boolean equals​(Object expression)
        INTERNAL: Return if the expression is equal to the other. This is used to allow dynamic expression's SQL to be cached.
        Overrides:
        equals in class DataExpression
      • addDerivedExpression

        public void addDerivedExpression​(Expression addThis)
        INTERNAL: Add the expression as a derived child of this expression. i.e. e.get("name"), "name" is a derived child of "e".
      • additionalExpressionCriteria

        public Expression additionalExpressionCriteria()
        INTERNAL: Return the expression to join the main table of this node to any auxiliary tables.
      • additionalExpressionCriteriaMap

        public Map additionalExpressionCriteriaMap()
        INTERNAL: Used in case outer joins should be printed in FROM clause. Each of the additional tables mapped to expressions that joins it.
      • assignTableAliasesStartingAt

        public int assignTableAliasesStartingAt​(int initialValue)
        INTERNAL: Assign aliases to any tables which I own. Start with t(initialValue), and return the new value of the counter , i.e. if initialValue is one and I have tables ADDRESS and EMPLOYEE I will assign them t1 and t2 respectively, and return 3.
        Overrides:
        assignTableAliasesStartingAt in class Expression
      • anyOf

        public Expression anyOf​(String attributeName,
                                boolean shouldJoinBeIndependent)
        PUBLIC: Return an expression representing traversal of a 1:many or many:many relationship. This allows you to query whether any of the "many" side of the relationship satisfies the remaining criteria.

        Example:

             Expression: employee.anyOf("managedEmployees").get("firstName").equal("Bob")
             Java: no direct equivalent
             SQL: SELECT DISTINCT ... WHERE (t2.MGR_ID = t1.ID) AND (t2.F_NAME = 'Bob')
         
        Overrides:
        anyOf in class Expression
        Parameters:
        shouldJoinBeIndependent - indicates whether a new expression should be created.
      • anyOfAllowingNone

        public Expression anyOfAllowingNone​(String attributeName,
                                            boolean shouldJoinBeIndependent)
        ADVANCED: Return an expression representing traversal of a 1:many or many:many relationship. This allows you to query whether any of the "many" side of the relationship satisfies the remaining criteria.

        Example:

             Expression: employee.anyOf("managedEmployees").get("firstName").equal("Bob")
             Java: no direct equivalent
             SQL: SELECT DISTINCT ... WHERE (t2.MGR_ID (+) = t1.ID) AND (t2.F_NAME = 'Bob')
         
        Overrides:
        anyOfAllowingNone in class Expression
        Parameters:
        shouldJoinBeIndependent - indicates whether a new expression should be created.
      • isDowncast

        public boolean isDowncast​(ClassDescriptor rootDescriptor,
                                  AbstractSession session)
        INTERNAL Return true if it uses a cast class and query is downcasting. It will look into inheritance hierarchy of the root descriptor.
      • isTreatUsed

        public boolean isTreatUsed()
        INTERNAL Return true if treat was used on this expression
      • convertToCastDescriptor

        public ClassDescriptor convertToCastDescriptor​(ClassDescriptor rootDescriptor,
                                                       AbstractSession session)
        INTERNAL Return the descriptor which contains this query key, look in the inheritance hierarchy of rootDescriptor for the descriptor.
      • copyDerivedExpressions

        public List<Expression> copyDerivedExpressions​(Map alreadyDone)
      • doNotUseOuterJoin

        public void doNotUseOuterJoin()
      • doUseOuterJoin

        public void doUseOuterJoin()
      • get

        public Expression get​(String attributeName,
                              boolean forceInnerJoin)
        Return the expression from the attribute dervied from this expression.
        Overrides:
        get in class Expression
        forceInnerJoin - - allows the get to not force an inner-join (if getAllowingNull was used elsewhere).
      • getAllowingNull

        public Expression getAllowingNull​(String attributeName)
        Description copied from class: Expression
        ADVANCED: Return an expression that wraps the attribute or query key name. This is only applicable to 1:1 relationships, and allows the target of the relationship to be null if there is no corresponding relationship in the database. Implemented via an outer join in the database.

        Example:

          builder.getAllowingNull("address").get("city").equal("Ottawa");
         
        Overrides:
        getAllowingNull in class Expression
      • getCastClass

        public Class getCastClass()
      • type

        public Expression type()
        PUBLIC: Return an expression that wraps the inheritance type field in an expression.

        Example:

          builder.getClassForInheritance().equal(SmallProject.class);
         
        Overrides:
        type in class Expression
      • getFields

        public Vector getFields()
        INTERNAL: Not to be confused with the public getField(String) This returns a collection of all fields associated with this object. Really only applies to query keys representing an object or to expression builders.
        Overrides:
        getFields in class Expression
      • getForUpdateOfFields

        protected Vector getForUpdateOfFields()
        INTERNAL: Returns the first field from each of the owned tables, used for fine-grained pessimistic locking.
      • getAdditionalTables

        public List<DatabaseTable> getAdditionalTables()
        Return any tables in addition to the descriptor's tables, such as the mappings join table.
      • hasBeenAliased

        public boolean hasBeenAliased()
        Description copied from class: Expression
        INTERNAL: Answers if the database tables associated with this expression have been aliased. This insures the same tables are not aliased twice.
        Overrides:
        hasBeenAliased in class DataExpression
      • hasDerivedExpressions

        protected boolean hasDerivedExpressions()
      • isUsingOuterJoinForMultitableInheritance

        public boolean isUsingOuterJoinForMultitableInheritance()
        INTERNAL: indicates whether additional expressions for multitable inheritance should be used and are available
      • postCopyIn

        protected void postCopyIn​(Map alreadyDone)
        INTERNAL: Used for cloning.
        Overrides:
        postCopyIn in class DataExpression
      • getRelationTable

        public DatabaseTable getRelationTable()
        Return null by default, only QueryKeyExpression can have a relation table.
      • isDirectCollection

        public boolean isDirectCollection()
        Return false by default, only possible for QueryKeyExpression.
      • setOnClause

        public void setOnClause​(Expression onClause)
      • setCastClass

        public void setCastClass​(Class castClass)
      • setShouldUseOuterJoinForMultitableInheritance

        public void setShouldUseOuterJoinForMultitableInheritance​(boolean shouldUseOuterJoinForMultitableInheritance)
        INTERNAL: set the flag indicating whether subclasses should be joined
      • shouldUseOuterJoin

        public boolean shouldUseOuterJoin()
      • shouldUseOuterJoinForMultitableInheritance

        public boolean shouldUseOuterJoinForMultitableInheritance()
      • writeForUpdateOfFields

        protected void writeForUpdateOfFields​(ExpressionSQLPrinter printer,
                                              SQLSelectStatement statement)
        INTERNAL: writes the first field from each of the owned tables, used for fine-grained pessimistic locking.
      • getJoinSource

        public Expression getJoinSource()
      • setJoinSource

        public void setJoinSource​(Expression joinSource)
      • getOuterJoinExpIndex

        public Integer getOuterJoinExpIndex()
      • setOuterJoinExpIndex

        public void setOuterJoinExpIndex​(Integer outerJoinExpIndex)
      • getFirstNonAggregateExpressionAfterExpressionBuilder

        public ObjectExpression getFirstNonAggregateExpressionAfterExpressionBuilder​(List aggregateMappingsEncountered)
        INTERNAL: Parses an expression to return the first non-AggregateObjectMapping expression after the base ExpressionBuilder. This is used by joining and batch fetch to get the list of mappings that really need to be processed (non-aggregates).
        Parameters:
        aggregateMappingsEncountered - - collection of aggregateObjectMapping expressions encountered in the returned expression between the first expression and the ExpressionBuilder
        Returns:
        first non-AggregateObjectMapping expression after the base ExpressionBuilder from the fullExpression