Class SelectAdapter
- java.lang.Object
-
- com.ibm.fhir.database.utils.query.SelectAdapter
-
- Direct Known Subclasses:
FromSubQueryAdapter
public class SelectAdapter extends Object
An abstract representation of a select statement which can be translated into an executable select statement. Keeps track of bind variables (parameter markers) and hopefully is a bit easier to use (and is more reliable) than constructing SQL with StringBuilder. The goal is to support two main use-cases (which drive the API design):- 1. Simplify construction of hand-written SQL statements
- 2. Support code-generated SQL where a statement is constructed from another model (e.g. FHIR search queries).
-
-
Constructor Summary
Constructors Constructor Description SelectAdapter(boolean distinct, String... columns)
SelectAdapter(Select select)
Adapter this select statementSelectAdapter(String... columns)
Public constructor taking a collection of string column names
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SelectAdapter
addColumn(String source, String name, Alias alias)
Select
build()
Get the statement we've been constructingSelectAdapter
column(String source, String name)
FromAdapter
from()
Create aFromAdapter
associated with the current select statement.FromAdapter
from(Select sub, Alias alias)
Add the sub-query select to the FROM clauseFromAdapter
from(String table)
Create a from clause for this select statementFromAdapter
from(String tableName, Alias alias)
Create a from clause for this select statementSelect
getSelect()
Getter for the select statement we are managingvoid
pagination(int offset, int rowsPerPage)
Add pagination offset/limit to the query
-
-
-
Constructor Detail
-
SelectAdapter
public SelectAdapter(Select select)
Adapter this select statement- Parameters:
select
-
-
SelectAdapter
public SelectAdapter(String... columns)
Public constructor taking a collection of string column names- Parameters:
columns
-
-
SelectAdapter
public SelectAdapter(boolean distinct, String... columns)
-
-
Method Detail
-
column
public SelectAdapter column(String source, String name)
-
addColumn
public SelectAdapter addColumn(String source, String name, Alias alias)
-
from
public FromAdapter from(String tableName, Alias alias)
Create a from clause for this select statement- Returns:
-
from
public FromAdapter from(Select sub, Alias alias)
Add the sub-query select to the FROM clause- Parameters:
sub
- the sub-query select statementalias
-- Returns:
-
from
public FromAdapter from(String table)
Create a from clause for this select statement- Returns:
-
from
public FromAdapter from()
Create aFromAdapter
associated with the current select statement. No row sources are added to the query. The FROM will only be added to the statement if rows sources are subsequently added to the returnedFromAdapter
.- Returns:
-
getSelect
public Select getSelect()
Getter for the select statement we are managing- Returns:
-
pagination
public void pagination(int offset, int rowsPerPage)
Add pagination offset/limit to the query- Parameters:
translator
-offset
-rowsPerPage
-
-
build
public Select build()
Get the statement we've been constructing- Returns:
-
-