Class SelectStatement
java.lang.Object
com.invirgance.convirgance.jdbc.sql.SelectStatement
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionSelectStatement(DatabaseSchemaLayout layout) Creates a new Statement using the provided database layout. -
Method Summary
Modifier and TypeMethodDescriptionAdds a column to the select query.Adds a column to the select clause with the specified result set namefrom(TabularStructure table) Creates a SelectStatement from the providedTable.from(TabularStructure table, String name) Creates a SelectStatement from the provided table, with optional aliasing.Gets the columns of the current statement.Sets a columns ordering to ascending.Sets a columns ordering.order(ExpressionStatement column) Sets a column's ordering to ascending.order(ExpressionStatement column, OrderBy order) Sets a columns ordering.render(SQLRenderer renderer) toString()where()Creates a WHERE clause for this SELECT statement to filter results.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.invirgance.convirgance.jdbc.sql.SQLStatement
getParent, query, query, setParent
-
Constructor Details
-
SelectStatement
Creates a new Statement using the provided database layout.- Parameters:
layout- The database layout.
-
-
Method Details
-
getColumns
Gets the columns of the current statement.- Returns:
- An array.
-
column
Adds a column to the select query.- Parameters:
column- Column to include.- Returns:
- this
-
column
Adds a column to the select clause with the specified result set name- Parameters:
column- Column to includename- to generate "as" clause- Returns:
- this
-
from
Creates a SelectStatement from the providedTable.- Parameters:
table- The table.- Returns:
- this.
-
from
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
Sets a column's ordering to ascending.- Parameters:
column- The column to order.- Returns:
- this.
-
order
Sets a columns ordering.- Parameters:
column- The column.order- The ordering to use.- Returns:
- this.
-
order
Sets a columns ordering to ascending.- Parameters:
column- The column.- Returns:
- this.
-
order
Sets a columns ordering.- Parameters:
column- The column.order- The ordering to use.- Returns:
- this.
-
render
- Specified by:
renderin interfaceSQLStatement
-
toString
-