Class SelectBuilder

java.lang.Object
com.ptsmods.mysqlw.query.builder.SelectBuilder

public class SelectBuilder extends Object
  • Method Details

    • create

      public static SelectBuilder create(Database db, String table)
      Create a new SelectBuilder selecting data from the given table on the given Database.
      Parameters:
      db - The database to select from
      table - The table to select from
      Returns:
      A new SelectBuilder
    • create

      public static SelectBuilder create(Database db, SelectBuilder select)
      Create a new SelectBuilder selecting data from another select query on the given Database.
      Parameters:
      db - The database to select from
      select - The query to select from
      Returns:
      A new SelectBuilder
    • create

      public static SelectBuilder create(String table)
      Create a new SelectBuilder for use in BlockBuilders.
      Parameters:
      table - The table to select from
      Returns:
      A new SelectBuilder
    • create

      public static SelectBuilder create(SelectBuilder select)
      Create a new SelectBuilder for use in BlockBuilders.
      Parameters:
      select - The query to select from
      Returns:
      A new SelectBuilder
    • select

      public SelectBuilder select(CharSequence column)
      Select a column or QueryFunction.
      Parameters:
      column - The column or QueryFunction to select
      Returns:
      This SelectBuilder
    • select

      public SelectBuilder select(CharSequence column, String name)
      Select a column or QueryFunction with a specific name.
      Parameters:
      column - The column or QueryFunction to select
      name - The name to select the column as
      Returns:
      This SelectBuilder
    • select

      public SelectBuilder select(CharSequence... columns)
      Select columns or QueryFunctions or any combination.
      Parameters:
      columns - The columns or QueryFunctions or any combination to select
      Returns:
      This SelectBuilder
    • select

      public SelectBuilder select(Iterable<? extends CharSequence> columns)
      Select columns or QueryFunctions or any combination.
      Parameters:
      columns - The columns or QueryFunctions or any combination to select
      Returns:
      This SelectBuilder
    • alias

      public SelectBuilder alias(String alias)
      Sets the alias of the table to select from used when selecting.
      Mostly only useful in combination with join(Join)
      Parameters:
      alias - The alias to use
      Returns:
      This SelectBuilder
    • join

      public SelectBuilder join(String table, QueryCondition condition)
      Add a new INNER join.
      Parameters:
      table - The table to join with
      condition - The condition to join on, required unless chaining multiple joins on MySQL.
      Returns:
      This select builder
    • join

      public SelectBuilder join(JoinType type, String table, QueryCondition condition)
      Add a new join.
      Parameters:
      type - The type of the new join
      table - The table to join with
      condition - The condition to join on, required unless chaining multiple joins on MySQL.
      Returns:
      This SelectBuilder
    • join

      public SelectBuilder join(Join.Builder join)
      Add a new join formed with a builder.
      Parameters:
      join - The join to add
      Returns:
      This SelectBuilder
    • join

      public SelectBuilder join(Join join)
      Add a new prebuilt join.
      Parameters:
      join - The join to add
      Returns:
      This SelectBuilder
    • removeJoin

      public SelectBuilder removeJoin(Join join)
    • into

      public SelectBuilder into(String target)
      Sets the table or variable to store the selected data into.
      Parameters:
      target - The target to select into
      Returns:
      This SelectBuilder
    • where

      public SelectBuilder where(QueryCondition condition)
      Sets the condition that rows must comply with to be selected.
      Parameters:
      condition - The condition that rows must comply with
      Returns:
      This SelectBuilder
    • groupBy

      public SelectBuilder groupBy(String... columns)
      Groups this query by the specified columns, especially useful in combination with aggregate functions.
      Parameters:
      columns - The columns to group by
      Returns:
      This SelectBuilder
    • groupBy

      public SelectBuilder groupBy(GroupBy.Builder groupBy)
      Groups this query by the given group by.
      Parameters:
      groupBy - The group by to group by
      Returns:
      This Select Builder
    • groupBy

      public SelectBuilder groupBy(GroupBy groupBy)
      Groups this query by the given group by.
      Parameters:
      groupBy - The group by to group by
      Returns:
      This Select Builder
    • order

      public SelectBuilder order(QueryOrder order)
      Sets the order in which the data should be returned.
      Parameters:
      order - The order in which the data should be returned
      Returns:
      This SelectBuilder
    • order

      public SelectBuilder order(String column)
      Sets the order in which the data should be returned.
      Convenient shorthand for order(QueryOrder) and QueryOrder.by(String).
      Parameters:
      column - The order in which the data should be returned
      Returns:
      This SelectBuilder
    • order

      public SelectBuilder order(String column, QueryOrder.OrderDirection direction)
      Sets the order in which the data should be returned.
      Convenient shorthand for order(QueryOrder) and QueryOrder.by(String, QueryOrder.OrderDirection).
      Parameters:
      column - The order in which the data should be returned
      direction - The direction to order in
      Returns:
      This SelectBuilder
    • limit

      public SelectBuilder limit(QueryLimit limit)
      Set the maximum amount of rows that should be returned.
      Parameters:
      limit - The maximum amount of rows to return
      Returns:
      This SelectBuilder
    • limit

      public SelectBuilder limit(int limit)
      Set the maximum amount of rows that should be returned.
      Convenience method for limit(QueryLimit) and QueryLimit.limit(int).
      Parameters:
      limit - The maximum amount of rows to return
      Returns:
      This SelectBuilder
    • limit

      public SelectBuilder limit(int limit, int offset)
      Set the maximum amount of rows that should be returned.
      Convenience method for limit(QueryLimit) and QueryLimit.limit(int, int).
      Parameters:
      limit - The maximum amount of rows to return
      offset - The offset at which to start
      Returns:
      This SelectBuilder
    • buildQuery

      public String buildQuery()
      Builds a SELECT query from this builder.
      Returns:
      The built query
    • executeRaw

      public ResultSet executeRaw()
      Executes the built query and returns the raw ResultSet.
      Returns:
      The raw ResultSet
    • executeRawAsync

      public CompletableFuture<ResultSet> executeRawAsync()
      executeRaw() but asynchronous.
      Returns:
      A CompletableFuture containing the raw ResultSet
    • execute

      public SelectResults execute()
      Executes the built query and parses it into an instance of SelectResults.
      Returns:
      The parsed results
    • executeAsync

      public CompletableFuture<SelectResults> executeAsync()
      Asynchronously executes the built query and parses it into an instance of SelectResults.
      Returns:
      A CompletableFuture contain the parsed results
    • executeCount

      public long executeCount()
      Counts the rows this select builder will select.
      Returns:
      The amount of rows counted
    • executeCountAsync

      public CompletableFuture<Long> executeCountAsync()
      Counts the rows this select builder will select asynchronously.
      Returns:
      A CompletableFuture containing the counted rows
    • executeCountMultiple

      public <T> Map<T,Long> executeCountMultiple(Class<T> type)
      Counts the rows this select builder will select.
      Parameters:
      type - The type of the column this query will be grouped by.
      Returns:
      The amount of rows counted
    • executeCountMultipleAsync

      public <T> CompletableFuture<Map<T,Long>> executeCountMultipleAsync(Class<T> type)
      Counts the rows this select builder will select asynchronously.
      Parameters:
      type - The type of the column this query will be grouped by.
      Returns:
      A CompletableFuture containing the counted rows
    • executeCountRaw

      public SelectResults executeCountRaw()
    • executeCountRawAsync

      public CompletableFuture<SelectResults> executeCountRawAsync()
    • getDb

      public Database getDb()
      Returns:
      The database this builder will select from
    • getTable

      @Deprecated public String getTable()
      Deprecated.
      Has been renamed to account for different usages. Use getSelectionTarget() instead.
      Returns:
      The table this builder will select from
    • getSelectionTarget

      public String getSelectionTarget()
      Returns:
      The table or query this builder will select from
    • getColumns

      public List<Pair<CharSequence,String>> getColumns()
      Returns:
      The columns this builder will select, mainly for internal purposes.
    • getAlias

      public String getAlias()
      Returns:
      The alias of this table used when selecting
    • getTarget

      public String getTarget()
      Returns:
      The target this builder will select into
    • getCondition

      public QueryCondition getCondition()
      Returns:
      The condition rows will have to comply with to be selected
    • getLimit

      public QueryLimit getLimit()
      Returns:
      The maximum amount of rows this builder will return upon selecting
    • getOrder

      public QueryOrder getOrder()
      Returns:
      The order in which the rows will be sorted upon selecting
    • getJoins

      public Set<Join> getJoins()
      Returns:
      The joins added to this builder
    • getGroupBy

      public GroupBy getGroupBy()
      Returns:
      The group by statement of this builder
    • clone

      public SelectBuilder clone()
      Overrides:
      clone in class Object