Class ExpressionQueryMechanism

All Implemented Interfaces:
Serializable, 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
See Also:
  • Field Details

    • selectionCriteria

      protected Expression selectionCriteria
  • Constructor Details

    • 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 Details

    • aliasFields

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

      public 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, 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, 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, Map clonedExpressions)
      Return the appropriate select statement containing the fields in the table.
    • buildBaseSelectStatement

      public SQLSelectStatement buildBaseSelectStatement(boolean isSubSelect, 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, 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, Vector sourceFields, 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<SQLDeleteAllStatement>
    • buildDeleteAllStatementsForMappingsWithTempTable

      protected 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<SQLDeleteAllStatementForTempTable>
    • shouldBuildDeleteStatementForMapping

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

      protected static String getAliasTableName(SQLSelectStatement selectStatement, DatabaseTable table, DatasourcePlatform platform)
    • 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.
    • buildDeleteStatement

      protected SQLDeleteStatement buildDeleteStatement(DatabaseTable table)
      Return the appropriate delete statement
    • buildInsertStatement

      protected SQLInsertStatement buildInsertStatement(DatabaseTable table)
      Return the appropriate insert statement
    • 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.
    • buildUpdateAllStatement

      protected SQLUpdateAllStatement buildUpdateAllStatement(DatabaseTable table, HashMap databaseFieldsToValues, SQLCall selectCallForExist, SQLSelectStatement selectStatementForExist, Collection primaryKeyFields)
    • buildUpdateStatement

      protected SQLUpdateStatement buildUpdateStatement(DatabaseTable table)
      Return the appropriate update statement
      Returns:
      SQLInsertStatement
    • checkCacheForObject

      public Object checkCacheForObject(AbstractRecord translationRow, AbstractSession session)
      Perform a cache lookup for the query This is only called from read object query. The query has already checked that the cache should be checked.
      Overrides:
      checkCacheForObject in class DatabaseQueryMechanism
    • clearStatement

      public void clearStatement()
      The statement is no longer require after prepare so can be released.
      Overrides:
      clearStatement in class StatementQueryMechanism
    • clone

      public DatabaseQueryMechanism clone(DatabaseQuery queryClone)
      Clone the mechanism for the specified query clone. Should not try to clone statements.
      Overrides:
      clone in class StatementQueryMechanism
    • getExpressionBuilder

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

      public Expression getSelectionCriteria()
      Return the selection criteria of the query.
      Overrides:
      getSelectionCriteria in class StatementQueryMechanism
    • getSelectionFields

      public 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
    • isExpressionQueryMechanism

      public boolean isExpressionQueryMechanism()
      Return true if this is an expression query mechanism.
      Overrides:
      isExpressionQueryMechanism in class DatabaseQueryMechanism
    • isStatementQueryMechanism

      public boolean isStatementQueryMechanism()
      Return true if this is a statement query mechanism
      Overrides:
      isStatementQueryMechanism in class StatementQueryMechanism
    • prepare

      public void prepare() throws QueryException
      Override super to do nothing.
      Overrides:
      prepare in class StatementQueryMechanism
      Throws:
      QueryException
    • prepareCursorSelectAllRows

      public void prepareCursorSelectAllRows()
      Pre-build the SQL statement from the expression.
      Overrides:
      prepareCursorSelectAllRows in class StatementQueryMechanism
    • prepareDeleteAll

      public void prepareDeleteAll()
      Pre-build the SQL statement from the expression.
      Overrides:
      prepareDeleteAll in class StatementQueryMechanism
    • prepareDeleteAll

      protected void prepareDeleteAll(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 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<SQLDeleteAllStatement>
    • createSQLSelectStatementForModifyAll

      protected SQLSelectStatement createSQLSelectStatementForModifyAll(Expression whereClause)
    • 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)
    • prepareDeleteObject

      public void prepareDeleteObject()
      Pre-build the SQL statement from the expression.
      Overrides:
      prepareDeleteObject in class StatementQueryMechanism
    • prepareDoesExist

      public void prepareDoesExist(DatabaseField field)
      Pre-build the SQL statement from the expression.
      Overrides:
      prepareDoesExist in class StatementQueryMechanism
    • prepareInsertObject

      public void prepareInsertObject()
      Pre-build the SQL statement from the expression.
      Overrides:
      prepareInsertObject in class StatementQueryMechanism
    • prepareReportQuerySelectAllRows

      public void prepareReportQuerySelectAllRows()
      Pre-build the SQL statement from the expression.
      Overrides:
      prepareReportQuerySelectAllRows in class DatasourceCallQueryMechanism
    • 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
    • prepareSelectAllRows

      public void prepareSelectAllRows()
      Pre-build the SQL statement from the expression.
      Overrides:
      prepareSelectAllRows in class StatementQueryMechanism
    • prepareSelectOneRow

      public void prepareSelectOneRow()
      Pre-build the SQL statement from the expression.
      Overrides:
      prepareSelectOneRow in class StatementQueryMechanism
    • prepareUpdateObject

      public void prepareUpdateObject()
      Pre-build the SQL statement from the expression.
      Overrides:
      prepareUpdateObject in class StatementQueryMechanism
    • prepareUpdateAll

      public void prepareUpdateAll()
      Pre-build the SQL statement from the expressions.
      Overrides:
      prepareUpdateAll in class StatementQueryMechanism
    • createSQLSelectStatementForUpdateAllForOracleAnonymousBlock

      protected SQLSelectStatement createSQLSelectStatementForUpdateAllForOracleAnonymousBlock(HashMap tables_databaseFieldsToValues)
    • createSQLSelectStatementForModifyAllForTempTable

      protected SQLSelectStatement createSQLSelectStatementForModifyAllForTempTable(HashMap databaseFieldsToValues)
    • buildUpdateAllStatementForOracleAnonymousBlock

      protected SQLModifyStatement buildUpdateAllStatementForOracleAnonymousBlock(HashMap tables_databaseFieldsToValues, HashMap tablesToPrimaryKeyFields)
    • prepareUpdateAllUsingTempStorage

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

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

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

      protected Vector buildStatementsForDeleteAllForTempTables()
      Build SQLStatements for delete all using temporary table.
      Returns:
      Vector<SQLStatement>
    • buildStatementsForUpdateAllForTempTables

      protected Vector buildStatementsForUpdateAllForTempTables(DatabaseTable table, HashMap databaseFieldsToValues, List<DatabaseField> primaryKeyFields)
    • getPrimaryKeyFieldsForTable

      protected List<DatabaseField> getPrimaryKeyFieldsForTable(DatabaseTable table)
    • getPrimaryKeyFieldsForTable

      protected List<DatabaseField> getPrimaryKeyFieldsForTable(ClassDescriptor descriptor, DatabaseTable table)
    • selectAllReportQueryRows

      public Vector selectAllReportQueryRows() throws DatabaseException
      INTERNAL Read all rows from the database. The code to retrieve the full inheritance hierarchy was removed.
      Overrides:
      selectAllReportQueryRows in class DatasourceCallQueryMechanism
      Returns:
      Vector containing the database rows.
      Throws:
      DatabaseException - - an error has occurred on the database.
    • selectAllRows

      public Vector selectAllRows() throws DatabaseException
      Read all rows from the database.
      Overrides:
      selectAllRows in class DatasourceCallQueryMechanism
      Returns:
      Vector containing the database rows.
      Throws:
      DatabaseException - - an error has occurred on the database.
    • selectAllRowsFromConcreteTable

      public 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 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.
    • selectOneRow

      public AbstractRecord selectOneRow() 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.
      Overrides:
      selectOneRow in class DatasourceCallQueryMechanism
      Returns:
      row containing data
      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.