Class SelectStatement

java.lang.Object
com.invirgance.convirgance.jdbc.sql.SelectStatement
All Implemented Interfaces:
SQLStatement

public class SelectStatement extends Object implements SQLStatement
Represents a SQL SELECT statement builder. This class implements the builder pattern to construct SQL SELECT queries through method chaining. It manages columns, tables, filtering conditions, and ordering specifications, automatically tracking table dependencies when columns are added.

 DatabaseSchemaLayout layout = new DatabaseSchemaLayout(driver, getHSQLDataSource())
 Table table = layout.getCurrentSchema().getTable("customer");
 
 SelectStatement query = new SelectStatement(layout)
     .select()
     .column(table.getColumn("name"))
     .column(table.getColumn("email"), "contact_email")
     .from(table, "c");
 
Author:
jbanes
  • Constructor Details

    • SelectStatement

      public SelectStatement(DatabaseSchemaLayout layout)
      Creates a new Statement using the provided database layout.
      Parameters:
      layout - The database layout.
  • Method Details

    • getColumns

      public ExpressionStatement[] getColumns()
      Gets the columns of the current statement.
      Returns:
      An array.
    • column

      public SelectStatement column(Column column)
      Adds a column to the select query.
      Parameters:
      column - Column to include.
      Returns:
      this
    • column

      public SelectStatement column(Column column, String name)
      Adds a column to the select clause with the specified result set name
      Parameters:
      column - Column to include
      name - to generate "as" clause
      Returns:
      this
    • from

      public SelectStatement from(TabularStructure table)
      Creates a SelectStatement from the provided Table.
      Parameters:
      table - The table.
      Returns:
      this.
    • from

      public SelectStatement from(TabularStructure table, String name)
      Creates a SelectStatement from the provided table, with optional aliasing.
      Parameters:
      table - The table/view to use.
      name - The name.
      Returns:
      this.
    • where

      Creates a WHERE clause for this SELECT statement to filter results. This method begins a new context for adding filter conditions. After adding all desired conditions, you must call .done() on the returned WhereStatement to return to the SelectStatement context.
      
       selectStatement
           .where()  // Enter WHERE context
               .equals(customerTable.getColumn("id"), 1)
           .done(); // Return to SELECT context
       
      Returns:
      A WhereStatement builder attached to this SelectStatement
    • order

      public SelectStatement order(ExpressionStatement column)
      Sets a column's ordering to ascending.
      Parameters:
      column - The column to order.
      Returns:
      this.
    • order

      public SelectStatement order(ExpressionStatement column, OrderBy order)
      Sets a columns ordering.
      Parameters:
      column - The column.
      order - The ordering to use.
      Returns:
      this.
    • order

      public SelectStatement order(Column column)
      Sets a columns ordering to ascending.
      Parameters:
      column - The column.
      Returns:
      this.
    • order

      public SelectStatement order(Column column, OrderBy order)
      Sets a columns ordering.
      Parameters:
      column - The column.
      order - The ordering to use.
      Returns:
      this.
    • render

      public SQLRenderer render(SQLRenderer renderer)
      Specified by:
      render in interface SQLStatement
    • toString

      public String toString()
      Overrides:
      toString in class Object