Class ExpressionQueryMechanism

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable
    Direct Known Subclasses:
    JPQLCallQueryMechanism, QueryByExampleMechanism

    public class ExpressionQueryMechanism
    extends StatementQueryMechanism

    Purpose: Mechanism used for all expression read queries. ExpressionQueryInterface understands how to deal with expressions.

    Responsibilities: Translates the expression and creates the appropriate SQL statements. Retrieves the data from the database and return the results to the query.

    Since:
    TOPLink/Java 1.0
    Author:
    Yvon Lavoie
    See Also:
    Serialized Form
    • Field Detail

      • selectionCriteria

        protected Expression selectionCriteria
    • Constructor Detail

      • ExpressionQueryMechanism

        public ExpressionQueryMechanism()
      • ExpressionQueryMechanism

        public ExpressionQueryMechanism​(DatabaseQuery query)
        Initialize the state of the query
        Parameters:
        query - - owner of mechanism
      • ExpressionQueryMechanism

        public ExpressionQueryMechanism​(DatabaseQuery query,
                                        Expression expression)
        Initialize the state of the query
        Parameters:
        query - - owner of mechanism
        expression - - selection criteria
    • Method Detail

      • aliasFields

        protected java.util.Vector aliasFields​(ObjectExpression node,
                                               java.util.Vector fields)
        Alias the supplied fields with respect to the expression node. Return copies of the fields
      • aliasPresetFields

        public java.util.Vector aliasPresetFields​(SQLSelectStatement statement)
        If the fields in the statement have breen pre-set, e.g. for a subset of the fields in a partial attribute read, report query, or just a query for the class indicator, then try to alias those. Right now this just guesses that they're all from the base.
      • buildBaseSelectionCriteria

        public Expression buildBaseSelectionCriteria​(boolean isSubSelect,
                                                     java.util.Map clonedExpressions)
        Create the appropriate where clause. Since this is where the selection criteria gets cloned for the first time (long after the owning query has been) many interesting things happen here.
      • buildBaseSelectionCriteria

        public Expression buildBaseSelectionCriteria​(boolean isSubSelect,
                                                     java.util.Map clonedExpressions,
                                                     boolean shouldUseAdditionalJoinExpression)
        Create the appropriate where clause. Since this is where the selection criteria gets cloned for the first time (long after the owning query has been) many interesting things happen here. Ability to switch off AdditionalJoinExpression is required for DeleteAllQuery.
      • buildBaseSelectStatement

        public SQLSelectStatement buildBaseSelectStatement​(boolean isSubSelect,
                                                           java.util.Map clonedExpressions)
        Return the appropriate select statement containing the fields in the table.
      • buildBaseSelectStatement

        public SQLSelectStatement buildBaseSelectStatement​(boolean isSubSelect,
                                                           java.util.Map clonedExpressions,
                                                           boolean shouldUseAdditionalJoinExpression)
        Return the appropriate select statement containing the fields in the table. Ability to switch off AdditionalJoinExpression is required for DeleteAllQuery.
      • buildConcreteSelectStatement

        protected SQLSelectStatement buildConcreteSelectStatement()
        Return the appropriate select statement containing the fields in the table. This is used as a second read to a concrete class with subclasses in an abstract-multiple table read.
      • buildDeleteAllStatement

        protected SQLDeleteStatement buildDeleteAllStatement​(DatabaseTable table,
                                                             Expression inheritanceExpression,
                                                             SQLCall selectCallForExist,
                                                             SQLSelectStatement selectStatementForExist,
                                                             SQLCall selectCallForNotExist,
                                                             SQLSelectStatement selectStatementForNotExist,
                                                             java.util.Collection primaryKeyFields)
        Return the appropriate delete statement Passing of a call/ statement pair is used because the same pair may be used several times. More elegant orangement of passing just a statement and creating the call in the method was rejected because the same call would've been potentially re-created several times. Preconditions: if selectCallForExist != null then selectStatementForExist != null; if selectCallForNotExist != null then selectStatementForNotExist != null.
        Returns:
        SQLDeleteStatement
      • buildDeleteAllStatementForMapping

        protected SQLDeleteStatement buildDeleteAllStatementForMapping​(SQLCall selectCallForExist,
                                                                       SQLSelectStatement selectStatementForExist,
                                                                       java.util.Vector sourceFields,
                                                                       java.util.Vector targetFields)
        Create SQLDeleteAllStatements for mappings that may be responsible for references to the objects to be deleted in the tables NOT mapped to any class: ManyToManyMapping and DirectCollectionMapping NOTE: A similar pattern also used in method buildDeleteAllStatementsForMappingsWithTempTable(): if you are updating this method consider applying a similar update to that method as well.
        Returns:
        Vector
      • buildDeleteAllStatementsForMappingsWithTempTable

        protected java.util.Vector buildDeleteAllStatementsForMappingsWithTempTable​(ClassDescriptor descriptor,
                                                                                    DatabaseTable rootTable,
                                                                                    boolean dontCheckDescriptor)
        Build delete statements with temporary table for ManyToMany and DirectCollection mappings. NOTE: A similar pattern also used in method buildDeleteAllStatementsForMappings(): if you are updating this method consider applying a similar update to that method as well.
        Returns:
        Vector
      • shouldBuildDeleteStatementForMapping

        protected boolean shouldBuildDeleteStatementForMapping​(ForeignReferenceMapping frMapping,
                                                               boolean dontCheckDescriptor,
                                                               ClassDescriptor descriptor)
      • buildDeleteStatementForDeleteAllQuery

        protected SQLDeleteStatement buildDeleteStatementForDeleteAllQuery​(DatabaseTable table)
        Used by DeleteAllQuery to create DeleteStatement in a simple case when selectionCriteria==null.
      • buildDeleteStatementForDeleteAllQuery

        protected SQLDeleteStatement buildDeleteStatementForDeleteAllQuery​(DatabaseTable table,
                                                                           Expression inheritanceExpression)
        Used by DeleteAllQuery to create DeleteStatement in a simple case when selectionCriteria==null.
      • buildNormalSelectStatement

        protected SQLSelectStatement buildNormalSelectStatement()
        Return the appropriate select statement containing the fields in the table.
      • shouldIncludeAllSubclassFields

        protected boolean shouldIncludeAllSubclassFields​(SQLSelectStatement selectStatement)
        Return whether to include all subclass fields in select statement or not.
      • buildReportQuerySelectStatement

        protected SQLSelectStatement buildReportQuerySelectStatement​(boolean isSubSelect)
        Return the appropriate select statement containing the fields in the table. Similar to super except the buildBaseSelectStatement will look after setting the fields to select.
      • buildReportQuerySelectStatement

        protected SQLSelectStatement buildReportQuerySelectStatement​(boolean isSubSelect,
                                                                     boolean useCustomaryInheritanceExpression,
                                                                     Expression inheritanceExpression,
                                                                     boolean shouldUseAdditionalJoinExpression)
        Customary inheritance expression is required for DeleteAllQuery and UpdateAllQuery preparation. Ability to switch off AdditionalJoinExpression is required for DeleteAllQuery.
      • buildSelectStatementForDoesExist

        protected SQLSelectStatement buildSelectStatementForDoesExist​(DatabaseField field)
        Return the appropriate select statement to perform a does exist check
        Parameters:
        field - fields for does exist check.
      • buildUpdateStatement

        protected SQLUpdateStatement buildUpdateStatement​(DatabaseTable table)
        Return the appropriate update statement with return update columns (if any)
        Returns:
        SQLUpdateStatement
      • getExpressionBuilder

        public ExpressionBuilder getExpressionBuilder()
        Return an expression builder which is valid for us
      • getSelectionFields

        public java.util.Vector getSelectionFields​(SQLSelectStatement statement,
                                                   boolean includeAllSubclassFields)
        Return the fields required in the select clause. This must now be called after normalization, so it will get the aliased fields
      • prepareDeleteAll

        protected void prepareDeleteAll​(java.util.List<DatabaseTable> tablesToIgnore,
                                        boolean isWhereClauseRequired)
        Pre-build the SQL statement from the expression. NOTE: A similar pattern also used in method buildDeleteAllStatementsForTempTable(): if you are updating this method consider applying a similar update to that method as well.
      • prepareDeleteAllUsingTempStorage

        protected void prepareDeleteAllUsingTempStorage()
      • prepareDeleteAllUsingTempTables

        protected void prepareDeleteAllUsingTempTables()
      • buildDeleteAllStatementsForMappings

        protected java.util.Vector buildDeleteAllStatementsForMappings​(SQLCall selectCallForExist,
                                                                       SQLSelectStatement selectStatementForExist,
                                                                       boolean dontCheckDescriptor)
        NOTE: A similar pattern also used in method buildDeleteAllStatementsForMappingsWithTempTable: if you are updating this method consider applying a similar update to that method as well.
        Returns:
        Vector
      • createSQLSelectStatementForModifyAll

        protected SQLSelectStatement createSQLSelectStatementForModifyAll​(Expression whereClause,
                                                                          Expression inheritanceExpression,
                                                                          ClassDescriptor desc,
                                                                          boolean useCustomaryInheritanceExpression,
                                                                          boolean shouldUseAdditionalJoinExpression)
        Customary inheritance expression is required for DeleteAllQuery and UpdateAllQuery preparation. Ability to switch off AdditionalJoinExpression is required for DeleteAllQuery.
      • createSQLSelectStatementForAssignedExpressionForUpdateAll

        protected SQLSelectStatement createSQLSelectStatementForAssignedExpressionForUpdateAll​(Expression value)
      • prepareReportQuerySubSelect

        public void prepareReportQuerySubSelect()
        Pre-build the SQL statement from the expression. This is used for subselects, so does not normalize or generate the SQL as it needs the outer expression for this.
        Overrides:
        prepareReportQuerySubSelect in class DatasourceCallQueryMechanism
      • createSQLSelectStatementForUpdateAllForOracleAnonymousBlock

        protected SQLSelectStatement createSQLSelectStatementForUpdateAllForOracleAnonymousBlock​(java.util.HashMap tables_databaseFieldsToValues)
      • createSQLSelectStatementForModifyAllForTempTable

        protected SQLSelectStatement createSQLSelectStatementForModifyAllForTempTable​(java.util.HashMap databaseFieldsToValues)
      • buildUpdateAllStatementForOracleAnonymousBlock

        protected SQLModifyStatement buildUpdateAllStatementForOracleAnonymousBlock​(java.util.HashMap tables_databaseFieldsToValues,
                                                                                    java.util.HashMap tablesToPrimaryKeyFields)
      • prepareUpdateAllUsingTempStorage

        protected void prepareUpdateAllUsingTempStorage​(java.util.HashMap tables_databaseFieldsToValues,
                                                        java.util.HashMap<DatabaseTable,​java.util.List<DatabaseField>> tablesToPrimaryKeyFields)
      • prepareUpdateAllUsingOracleAnonymousBlock

        protected void prepareUpdateAllUsingOracleAnonymousBlock​(java.util.HashMap tables_databaseFieldsToValues,
                                                                 java.util.HashMap tablesToPrimaryKeyFields)
        Pre-build the SQL statement from the expressions.
      • prepareUpdateAllUsingTempTables

        protected void prepareUpdateAllUsingTempTables​(java.util.HashMap tables_databaseFieldsToValues,
                                                       java.util.HashMap<DatabaseTable,​java.util.List<DatabaseField>> tablesToPrimaryKeyFields)
        Pre-build the SQL statement from the expressions.
      • buildStatementsForDeleteAllForTempTables

        protected java.util.Vector buildStatementsForDeleteAllForTempTables()
        Build SQLStatements for delete all using temporary table.
        Returns:
        Vector
      • buildStatementsForUpdateAllForTempTables

        protected java.util.Vector buildStatementsForUpdateAllForTempTables​(DatabaseTable table,
                                                                            java.util.HashMap databaseFieldsToValues,
                                                                            java.util.List<DatabaseField> primaryKeyFields)
      • selectAllRowsFromConcreteTable

        public java.util.Vector selectAllRowsFromConcreteTable()
                                                        throws DatabaseException
        Read all rows from the database. This is used only from query mechanism on a abstract-multiple table read.
        Throws:
        DatabaseException
      • selectAllRowsFromTable

        public java.util.Vector selectAllRowsFromTable()
                                                throws DatabaseException
        Read all rows from the database.
        Returns:
        Vector containing the database rows.
        Throws:
        DatabaseException - - an error has occurred on the database.
      • selectOneRowFromConcreteTable

        public AbstractRecord selectOneRowFromConcreteTable()
                                                     throws DatabaseException
        Read a single row from the database. This is used from query mechanism during an abstract-multiple table read.
        Throws:
        DatabaseException
      • selectOneRowFromTable

        public AbstractRecord selectOneRowFromTable()
                                             throws DatabaseException
        Read a single row from the database. Create an SQL statement object, use it to create an SQL command string, and delegate row building responsibility to the accessor.
        Throws:
        DatabaseException
      • setSelectionCriteria

        public void setSelectionCriteria​(Expression expression)
        Set the selection criteria of the query.
      • getHighestDescriptorMappingTable

        protected ClassDescriptor getHighestDescriptorMappingTable​(DatabaseTable table)
        Pass to this method a table mapped by query's descriptor. Returns the highest descriptor in inheritance hierarchy that mapps this table.