Class AbstractSQLQuery<T,Q extends AbstractSQLQuery<T,Q>>

Type Parameters:
T - result type
Q - concrete subtype
All Implemented Interfaces:
Fetchable<T>, FetchableQuery<T,Q>, FilteredClause<Q>, Query<Q>, SimpleQuery<Q>, ExtendedSubQuery<T>, Expression<T>, SubQueryExpression<T>, SQLCommonQuery<Q>, Serializable
Direct Known Subclasses:
AbstractMySQLQuery, AbstractOracleQuery, AbstractPostgreSQLQuery, AbstractSQLServerQuery, AbstractTeradataQuery, SQLQuery

public abstract class AbstractSQLQuery<T,Q extends AbstractSQLQuery<T,Q>> extends ProjectableSQLQuery<T,Q>
AbstractSQLQuery is the base type for SQL query implementations
Author:
tiwe
See Also:
  • Field Details

    • PARENT_CONTEXT

      protected static final String PARENT_CONTEXT
    • listeners

      protected SQLListeners listeners
    • useLiterals

      protected boolean useLiterals
  • Constructor Details

  • Method Details

    • as

      public SimpleExpression<T> as(String alias)
      Create an alias for the expression
      Parameters:
      alias - alias
      Returns:
      this as alias
    • as

      public SimpleExpression<T> as(Path<?> alias)
      Create an alias for the expression
      Parameters:
      alias - alias
      Returns:
      this as alias
    • addListener

      public void addListener(SQLListener listener)
      Add a listener
      Parameters:
      listener - listener to add
    • fetchCount

      public long fetchCount()
      Specified by:
      fetchCount in interface Fetchable<T>
      Overrides:
      fetchCount in class ProjectableSQLQuery<T,Q extends AbstractSQLQuery<T,Q>>
    • forUpdate

      public Q forUpdate()
      If you use forUpdate() with a backend that uses page or row locks, rows examined by the query are write-locked until the end of the current transaction. Not supported for SQLite and CUBRID
      Returns:
      the current object
    • forShare

      public Q forShare()
      FOR SHARE causes the rows retrieved by the SELECT statement to be locked as though for update. Supported by MySQL, PostgreSQL, SQLServer.
      Returns:
      the current object
      Throws:
      QueryException - if the FOR SHARE is not supported.
    • forShare

      public Q forShare(boolean fallbackToForUpdate)
      FOR SHARE causes the rows retrieved by the SELECT statement to be locked as though for update. Supported by MySQL, PostgreSQL, SQLServer.
      Parameters:
      fallbackToForUpdate - if the FOR SHARE is not supported and this parameter is true, the forUpdate() functionality will be used.
      Returns:
      the current object
      Throws:
      QueryException - if the FOR SHARE is not supported and fallbackToForUpdate is set to false.
    • createSerializer

      protected SQLSerializer createSerializer()
      Specified by:
      createSerializer in class ProjectableSQLQuery<T,Q extends AbstractSQLQuery<T,Q>>
    • startContext

      protected SQLListenerContextImpl startContext(Connection connection, QueryMetadata metadata)
      Called to create and start a new SQL Listener context
      Parameters:
      connection - the database connection
      metadata - the meta data for that context
      Returns:
      the newly started context
    • onException

      protected void onException(SQLListenerContextImpl context, Exception e)
      Called to make the call back to listeners when an exception happens
      Parameters:
      context - the current context in play
      e - the exception
    • endContext

      protected void endContext(SQLListenerContext context)
      Called to end a SQL listener context
      Parameters:
      context - the listener context to end
    • getResults

      @Deprecated public ResultSet getResults(Expression<?>... exprs)
      Deprecated.
      Use @{code select(..)} to define the projection and getResults() to obtain the result set
      Get the results as a JDBC ResultSet
      Parameters:
      exprs - the expression arguments to retrieve
      Returns:
      results as ResultSet
    • getResults

      public ResultSet getResults()
      Get the results as a JDBC ResultSet
      Returns:
      results as ResultSet
    • getConfiguration

      protected Configuration getConfiguration()
    • iterate

      public com.mysema.commons.lang.CloseableIterator<T> iterate()
    • fetch

      public List<T> fetch()
      Specified by:
      fetch in interface Fetchable<T>
      Overrides:
      fetch in class FetchableQueryBase<T,Q extends AbstractSQLQuery<T,Q>>
    • fetchResults

      public QueryResults<T> fetchResults()
    • setParameters

      protected void setParameters(PreparedStatement stmt, List<?> objects, List<Path<?>> constantPaths, Map<ParamExpression<?>,?> params)
    • logQuery

      protected void logQuery(String queryString, Collection<Object> parameters)
    • setUseLiterals

      public void setUseLiterals(boolean useLiterals)
      Set whether literals are used in SQL strings instead of parameter bindings (default: false)

      Warning: When literals are used, prepared statement won't have any parameter bindings and also batch statements will only be simulated, but not executed as actual batch statements.

      Parameters:
      useLiterals - true for literals and false for bindings
    • clone

      protected void clone(Q query)
      Overrides:
      clone in class ProjectableSQLQuery<T,Q extends AbstractSQLQuery<T,Q>>
    • clone

      public Q clone()
      Specified by:
      clone in class ProjectableSQLQuery<T,Q extends AbstractSQLQuery<T,Q>>
    • clone

      public abstract Q clone(Connection connection)
    • setStatementOptions

      public void setStatementOptions(StatementOptions statementOptions)
      Set the options to be applied to the JDBC statements of this query
      Parameters:
      statementOptions - options to be applied to statements