Package com.gengoai.sql.statement
Class Select
- java.lang.Object
-
- com.gengoai.sql.statement.QueryStatement
-
- com.gengoai.sql.statement.Select
-
- All Implemented Interfaces:
Copyable<QueryStatement>
,SQLElement
,Serializable
public class Select extends QueryStatement
SQL statement for selecting data from a table
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Select
columns(@NonNull SQLElement... columns)
Sets the columns being selected.Select
columns(@NonNull Collection<? extends SQLElement> columns)
Sets the columns being selected.Select
distinct()
Performs a select distinctSelect
distinct(boolean distinct)
Sets whether or not the selct will be distinctstatic Select
from(@NonNull SQLElement table)
Creates a new Select statement with the given table for the from clausestatic Select
from(@NonNull String table)
Creates a new Select statement with the given table for the from clauseSelect
groupBy(@NonNull SQLElement... groupBy)
Sets the group by clause to the given strings.Select
groupBy(@NonNull String... groupBy)
Sets the group by clause to the given strings.Select
groupBy(@NonNull Collection<? extends SQLElement> groupBy)
Sets the group by clause to the given strings.Select
having(SQLElement havingClause)
Sets the criteria for group bys (i.e.Select
having(String havingClause)
Sets the criteria for group bys (i.e.Select
innerJoin(@NonNull SQLElement table, @NonNull SQLElement criteria)
Adds an inner join with the given table on the given criteria to the from clauseSelect
join(@NonNull JoinType type, @NonNull SQLElement table, @NonNull SQLElement criteria)
Adds a join with the given table on the given criteria to the from clauseSelect
leftOuterJoin(@NonNull SQLElement table, @NonNull SQLElement criteria)
Adds a left outer join with the given table on the given criteria to the from clauseSelect
limit(SQLElement limitClause)
Sets the limit clause for selectionSelect
orderBy(@NonNull SQLElement... orderBy)
Sets the order by clause to the given strings.Select
orderBy(@NonNull String... orderBy)
Sets the order by clause to the given strings.Select
orderBy(@NonNull Collection<? extends SQLElement> orderBy)
Sets the order by clause to the given strings.<T> Stream<T>
queryParallel(@NonNull SQLContext context, @NonNull ResultSetMapper<? extends T> mapper, @NonNull String partitionColumn)
Performs this Select query using the givenSQLContext
using the givenResultSetMapper
to map ResultSet to objects.<T> Stream<T>
queryParallel(@NonNull SQLContext context, @NonNull ResultSetMapper<? extends T> mapper, @NonNull String partitionColumn, int numPartitions)
Performs this Select query using the givenSQLContext
using the givenResultSetMapper
to map ResultSet to objects.<T> Stream<T>
queryParallel(@NonNull SQLContext context, @NonNull List<?> values, @NonNull ResultSetMapper<? extends T> mapper, @NonNull String partitionColumn, int numPartitions)
Performs this Select query using the givenSQLContext
filling in indexed value placeholders using the given Map of values and returning the results as aResultSetIterator
using the givenResultSetMapper
* to map ResultSet to objects.<T> Stream<T>
queryParallel(@NonNull SQLContext context, @NonNull List<Object> values, @NonNull ResultSetMapper<? extends T> mapper, @NonNull String partitionColumn)
Performs this Select query using the givenSQLContext
filling in indexed value placeholders using the given Map of values and returning the results as aResultSetIterator
using the givenResultSetMapper
to map ResultSet to objects.<T> Stream<T>
queryParallel(@NonNull SQLContext context, @NonNull Map<String,?> values, @NonNull ResultSetMapper<? extends T> mapper, @NonNull String partitionColumn)
Performs this Select query using the givenSQLContext
filling in named value placeholders using the given Map of values and returning the results as aResultSetIterator
using the givenResultSetMapper
* to map ResultSet to objects.<T> Stream<T>
queryParallel(@NonNull SQLContext context, @NonNull Map<String,?> values, @NonNull ResultSetMapper<? extends T> mapper, @NonNull String partitionColumn, int numPartitions)
Performs this Select query using the givenSQLContext
filling in named value placeholders using the given Map of values and returning the results as aResultSetIterator
using the givenResultSetMapper
to map ResultSet to objects.Select
rightOuterJoin(@NonNull SQLElement table, @NonNull SQLElement criteria)
Adds a right outer join with the given table on the given criteria to the from clauseSelect
where(SQLElement whereClause)
Sets the criteria (i.e.Select
where(String whereClause)
Sets the criteria (i.e.Select
window(SQLElement window)
Sets the Window function for the selection.Select
window(String window)
Sets the Window function for the selection.-
Methods inherited from class com.gengoai.sql.statement.QueryStatement
copy, except, exists, intersect, query, query, query, query, queryScalar, queryScalarDouble, queryScalarLong, queryScalarString, union, unionAll
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.gengoai.sql.SQLElement
getClassName
-
-
-
-
Method Detail
-
from
public static Select from(@NonNull @NonNull SQLElement table)
Creates a new Select statement with the given table for the from clause- Parameters:
table
- the table to select from- Returns:
- this Select object
-
from
public static Select from(@NonNull @NonNull String table)
Creates a new Select statement with the given table for the from clause- Parameters:
table
- the table to select from- Returns:
- this Select object
-
columns
public Select columns(@NonNull @NonNull SQLElement... columns)
Sets the columns being selected. Note that this clears any previously specified columns.- Parameters:
columns
- the columns being selected- Returns:
- this Select object
-
columns
public Select columns(@NonNull @NonNull Collection<? extends SQLElement> columns)
Sets the columns being selected. Note that this clears any previously specified columns.- Parameters:
columns
- the columns being selected- Returns:
- this Select object
-
distinct
public Select distinct()
Performs a select distinct- Returns:
- this Select object
-
distinct
public Select distinct(boolean distinct)
Sets whether or not the selct will be distinct- Parameters:
distinct
- true - select distinct, false - normal select- Returns:
- this Select object
-
groupBy
public Select groupBy(@NonNull @NonNull String... groupBy)
Sets the group by clause to the given strings. Note that this clears any previously specified groupBy.- Parameters:
groupBy
- the group by statements- Returns:
- this Select object
-
groupBy
public Select groupBy(@NonNull @NonNull SQLElement... groupBy)
Sets the group by clause to the given strings. Note that this clears any previously specified groupBy.- Parameters:
groupBy
- the group by statements- Returns:
- this Select object
-
groupBy
public Select groupBy(@NonNull @NonNull Collection<? extends SQLElement> groupBy)
Sets the group by clause to the given strings. Note that this clears any previously specified groupBy.- Parameters:
groupBy
- the group by statements- Returns:
- this Select object
-
having
public Select having(SQLElement havingClause)
Sets the criteria for group bys (i.e. HAVING) for the selection.- Parameters:
havingClause
- the having clause- Returns:
- this Select object
-
having
public Select having(String havingClause)
Sets the criteria for group bys (i.e. HAVING) for the selection.- Parameters:
havingClause
- the having clause- Returns:
- this Select object
-
innerJoin
public Select innerJoin(@NonNull @NonNull SQLElement table, @NonNull @NonNull SQLElement criteria)
Adds an inner join with the given table on the given criteria to the from clause- Parameters:
table
- the table or expression to join withcriteria
- the criteria for joining- Returns:
- this Select object
-
join
public Select join(@NonNull @NonNull JoinType type, @NonNull @NonNull SQLElement table, @NonNull @NonNull SQLElement criteria)
Adds a join with the given table on the given criteria to the from clause- Parameters:
type
- the join typetable
- the table or expression to join withcriteria
- the criteria for joining- Returns:
- this Select object
-
leftOuterJoin
public Select leftOuterJoin(@NonNull @NonNull SQLElement table, @NonNull @NonNull SQLElement criteria)
Adds a left outer join with the given table on the given criteria to the from clause- Parameters:
table
- the table or expression to join withcriteria
- the criteria for joining- Returns:
- this Select object
-
limit
public Select limit(SQLElement limitClause)
Sets the limit clause for selection- Parameters:
limitClause
- the limit clause- Returns:
- this Select object
-
orderBy
public Select orderBy(@NonNull @NonNull String... orderBy)
Sets the order by clause to the given strings. Note that this clears any previously specified orderBy.- Parameters:
orderBy
- the order by statements- Returns:
- this Select object
-
orderBy
public Select orderBy(@NonNull @NonNull SQLElement... orderBy)
Sets the order by clause to the given strings. Note that this clears any previously specified orderBy.- Parameters:
orderBy
- the order by statements- Returns:
- this Select object
-
orderBy
public Select orderBy(@NonNull @NonNull Collection<? extends SQLElement> orderBy)
Sets the order by clause to the given strings. Note that this clears any previously specified orderBy.- Parameters:
orderBy
- the order by statements- Returns:
- this Select object
-
queryParallel
public final <T> Stream<T> queryParallel(@NonNull @NonNull SQLContext context, @NonNull @NonNull ResultSetMapper<? extends T> mapper, @NonNull @NonNull String partitionColumn) throws SQLException
Performs this Select query using the givenSQLContext
using the givenResultSetMapper
to map ResultSet to objects. This query method returns a parallel stream using 2 * the number processors as the partition count.- Type Parameters:
T
- the Iterator type parameter- Parameters:
context
- the context to perform the select overmapper
- the mapper from ResultSet to ObjectpartitionColumn
- the column to use for portioning (should be numeric)- Returns:
- the ResultSetIterator over the results of the given
QueryStatement
- Throws:
SQLException
- something happened trying to query
-
queryParallel
public final <T> Stream<T> queryParallel(@NonNull @NonNull SQLContext context, @NonNull @NonNull Map<String,?> values, @NonNull @NonNull ResultSetMapper<? extends T> mapper, @NonNull @NonNull String partitionColumn) throws SQLException
Performs this Select query using the givenSQLContext
filling in named value placeholders using the given Map of values and returning the results as aResultSetIterator
using the givenResultSetMapper
* to map ResultSet to objects. This query method returns a parallel stream using 2 * the number processors as the partition count.- Type Parameters:
T
- the Iterator type parameter- Parameters:
context
- the context to perform the select overvalues
- the values to use to fill the query statement (by Name)mapper
- the mapper from ResultSet to ObjectpartitionColumn
- the column to use for portioning (should be numeric)- Returns:
- the ResultSetIterator over the results of the given
QueryStatement
- Throws:
SQLException
- something happened trying to query
-
queryParallel
public final <T> Stream<T> queryParallel(@NonNull @NonNull SQLContext context, @NonNull @NonNull ResultSetMapper<? extends T> mapper, @NonNull @NonNull String partitionColumn, int numPartitions) throws SQLException
Performs this Select query using the givenSQLContext
using the givenResultSetMapper
to map ResultSet to objects. This query method returns a parallel stream.- Type Parameters:
T
- the Iterator type parameter- Parameters:
context
- the context to perform the select overmapper
- the mapper from ResultSet to ObjectpartitionColumn
- the column to use for portioning (should be numeric)numPartitions
- the number of partitions (controls the parallelization- Returns:
- the ResultSetIterator over the results of the given
QueryStatement
- Throws:
SQLException
- something happened trying to query
-
queryParallel
public final <T> Stream<T> queryParallel(@NonNull @NonNull SQLContext context, @NonNull @NonNull List<Object> values, @NonNull @NonNull ResultSetMapper<? extends T> mapper, @NonNull @NonNull String partitionColumn) throws SQLException
Performs this Select query using the givenSQLContext
filling in indexed value placeholders using the given Map of values and returning the results as aResultSetIterator
using the givenResultSetMapper
to map ResultSet to objects. This query method returns a parallel stream using 2 times the number processors as the partition count.- Type Parameters:
T
- the Iterator type parameter- Parameters:
context
- the context to perform the select overvalues
- the values to use to fill the query statement (by Name)mapper
- the mapper from ResultSet to ObjectpartitionColumn
- the column to use for portioning (should be numeric)- Returns:
- the ResultSetIterator over the results of the given
QueryStatement
- Throws:
SQLException
- something happened trying to query
-
queryParallel
public <T> Stream<T> queryParallel(@NonNull @NonNull SQLContext context, @NonNull @NonNull Map<String,?> values, @NonNull @NonNull ResultSetMapper<? extends T> mapper, @NonNull @NonNull String partitionColumn, int numPartitions) throws SQLException
Performs this Select query using the givenSQLContext
filling in named value placeholders using the given Map of values and returning the results as aResultSetIterator
using the givenResultSetMapper
to map ResultSet to objects. This query method returns a parallel stream.- Type Parameters:
T
- the Iterator type parameter- Parameters:
context
- the context to perform the select overvalues
- the values to use to fill the query statement (by Name)mapper
- the mapper from ResultSet to ObjectpartitionColumn
- the column to use for portioning (should be numeric)numPartitions
- the number of partitions (controls the parallelization- Returns:
- the ResultSetIterator over the results of the given
QueryStatement
- Throws:
SQLException
- something happened trying to query
-
queryParallel
public final <T> Stream<T> queryParallel(@NonNull @NonNull SQLContext context, @NonNull @NonNull List<?> values, @NonNull @NonNull ResultSetMapper<? extends T> mapper, @NonNull @NonNull String partitionColumn, int numPartitions) throws SQLException
Performs this Select query using the givenSQLContext
filling in indexed value placeholders using the given Map of values and returning the results as aResultSetIterator
using the givenResultSetMapper
* to map ResultSet to objects. This query method returns a parallel stream.- Type Parameters:
T
- the Iterator type parameter- Parameters:
context
- the context to perform the select overvalues
- the values to use to fill the query statement (by Name)mapper
- the mapper from ResultSet to ObjectpartitionColumn
- the column to use for portioning (should be numeric)numPartitions
- the number of partitions (controls the parallelization- Returns:
- the ResultSetIterator over the results of the given
QueryStatement
- Throws:
SQLException
- something happened trying to query
-
rightOuterJoin
public Select rightOuterJoin(@NonNull @NonNull SQLElement table, @NonNull @NonNull SQLElement criteria)
Adds a right outer join with the given table on the given criteria to the from clause- Parameters:
table
- the table or expression to join withcriteria
- the criteria for joining- Returns:
- this Select object
-
where
public Select where(SQLElement whereClause)
Sets the criteria (i.e. WHERE) for the selection.- Parameters:
whereClause
- the where clause- Returns:
- this Select object
-
where
public Select where(String whereClause)
Sets the criteria (i.e. WHERE) for the selection.- Parameters:
whereClause
- the where clause- Returns:
- this Select object
-
window
public Select window(SQLElement window)
Sets the Window function for the selection.- Parameters:
window
- the window clause- Returns:
- this Select object
-
-