Class AbstractRDBMSAction

java.lang.Object
com.kingsrook.qqq.backend.module.rdbms.actions.AbstractRDBMSAction
Direct Known Subclasses:
RDBMSAggregateAction, RDBMSCountAction, RDBMSDeleteAction, RDBMSInsertAction, RDBMSQueryAction, RDBMSUpdateAction

public abstract class AbstractRDBMSAction extends Object
Base class for all core actions in the RDBMS module.
  • Field Details

    • queryStat

      protected QueryStat queryStat
    • statement

      protected PreparedStatement statement
    • isCancelled

      protected boolean isCancelled
  • Constructor Details

    • AbstractRDBMSAction

      public AbstractRDBMSAction()
  • Method Details

    • getTableName

      public static String getTableName(QTableMetaData table)
      Get the table name to use in the RDBMS from a QTableMetaData. That is, table.backendDetails.tableName if set -- else, table.name
    • getColumnName

      public static String getColumnName(QFieldMetaData field)
      Get the column name to use for a field in the RDBMS, from the fieldMetaData. That is, field.backendName if set -- else, field.name
    • getConnection

      public static Connection getConnection(AbstractTableActionInput tableActionInput) throws SQLException
      Get a database connection, per the backend in the request. Note that it may be a connection to a read-only backend, per query-hints, and backend settings.
      Throws:
      SQLException
    • scrubValue

      protected Serializable scrubValue(QFieldMetaData field, Serializable value)
      Handle obvious problems with values - like empty string for integer should be null, and type conversions that we can do "better" than jdbc...
    • setValueIfTableHasField

      protected void setValueIfTableHasField(QRecord record, QTableMetaData table, String fieldName, Serializable value)
      If the table has a field with the given name, then set the given value in the given record.
    • makeFromClause

      protected String makeFromClause(QInstance instance, String tableName, JoinsContext joinsContext, List<Serializable> params)
    • makeWhereClause

      protected String makeWhereClause(JoinsContext joinsContext, QQueryFilter filter, List<Serializable> params) throws IllegalArgumentException
      Method to make a full WHERE clause. Note that criteria for security are assumed to have been added to the filter during the construction of the JoinsContext.
      Throws:
      IllegalArgumentException
    • escapeIdentifier

      protected String escapeIdentifier(String id)
      Escape an identifier (table name, column name) with the appropriate quote character for the database vendor. Uses the action strategy's getIdentifierQuoteString() method to determine the appropriate quote character. Falls back to backtick if strategy not available.
    • getFieldValueFromResultSet

      protected Serializable getFieldValueFromResultSet(QFieldType type, ResultSet resultSet, int i) throws SQLException
      Throws:
      SQLException
    • getFieldValueFromResultSet

      protected Serializable getFieldValueFromResultSet(QFieldMetaData qFieldMetaData, ResultSet resultSet, int i) throws SQLException
      Throws:
      SQLException
    • makeOrderByClause

      protected String makeOrderByClause(QTableMetaData table, List<QFilterOrderBy> orderBys, JoinsContext joinsContext)
    • getSingleGroupByClause

      protected String getSingleGroupByClause(GroupBy groupBy, JoinsContext joinsContext)
    • setLogSQL

      public static void setLogSQL(boolean on, boolean doReformat, String loggerOrSystemOut)
      Make it easy (e.g., for tests) to turn on logging of SQL
    • setLogSQL

      public static void setLogSQL(boolean on)
      Make it easy (e.g., for tests) to turn on logging of SQL
    • setLogSQLOutput

      public static void setLogSQLOutput(String loggerOrSystemOut)
      Make it easy (e.g., for tests) to turn on logging of SQL
    • setLogSQLReformat

      public static void setLogSQLReformat(boolean doReformat)
      Make it easy (e.g., for tests) to turn on poor-man's formatting of SQL
    • logSQL

      protected void logSQL(CharSequence sql, List<?> params, Long mark)
    • doesSelectClauseRequireDistinct

      protected boolean doesSelectClauseRequireDistinct(QTableMetaData table)
      method that looks at security lock joins, and if a one-to-many is found where the specified field name is on the 'right side' of the join, then a distinct needs added to select clause. Memoized because it's a lot of gyrations, and it never ever changes for a running server.
    • setSqlAndJoinsInQueryStat

      protected void setSqlAndJoinsInQueryStat(CharSequence sql, JoinsContext joinsContext)
    • getQueryStat

      public QueryStat getQueryStat()
      Getter for queryStat
    • setQueryStat

      public void setQueryStat(QueryStat queryStat)
      Setter for queryStat
    • doCancelQuery

      protected void doCancelQuery()
    • clonedOrNewFilter

      protected QQueryFilter clonedOrNewFilter(QQueryFilter filter)
      Either clone the input filter (so we can change it safely), or return a new blank filter.
    • setBackendMetaData

      protected void setBackendMetaData(QBackendMetaData backendMetaData)
      Setter for backendMetaData
    • getActionStrategy

      protected RDBMSActionStrategyInterface getActionStrategy()