Class Select
java.lang.Object
com.northconcepts.datapipeline.jdbc.sql.SqlPart
com.northconcepts.datapipeline.jdbc.sql.select.QuerySource
com.northconcepts.datapipeline.jdbc.sql.select.Select
Builds a SELECT statement with its parameter values; as a
QuerySource it can also be nested in another query.-
Constructor Summary
ConstructorsConstructorDescriptionSelect(QuerySource... querySources) Creates a query over the given sources, such as tables, nested queries orUnions; at least one is required.Creates a query over the given tables; null entries are skipped, but at least one table is required.Creates a query over the given tables; null entries are skipped, but at least one table is required. -
Method Summary
Modifier and TypeMethodDescriptionvoidcollectParameterValues(List<Object> values) Appends the values for this part's?parameters to the list in order; adds nothing by default.protected voidcollectQuerySourceSqlFragment(CodeWriter writer, QuerySource querySource) Writes a FROM source, in parentheses ifQuerySource.shouldWrapWhenNested()is true, followed by its nested alias if any.voidcollectSqlFragment(CodeWriter writer) Writes this part's SQL to the writer; used bySqlPart.getSqlFragment()and by enclosing parts.booleancontainsTable(String table) Returns true if this source, a nested source or a join refers to the table (ignoring case).getCount()Returns the maximum number of rows to return ornullif unlimited.Deprecated.Returns the GROUP BY fields (nevernull).Returns the HAVING criteria (nevernull).getJoins()Returns the number of rows to skip ornullif not set.getOrder()Returns the ORDER BY fields (nevernull).Returns the SELECT column list (nevernull).getTable()Returns the first table in the list of tables.Returns the tables this source reads from, including those of nested sources but not joined tables.getWhere()Returns the WHERE criteria (nevernull).Adds a condition and its parameter values to the HAVING clause with AND (ifandConjunctionis true) or OR.having(QueryCriteriaPart criteria) Replaces all HAVING conditions with the given part.ANDs a condition, such as"SUM(total) > ?", and its parameter values with the existing HAVING conditions.limit(int count) Limits the result tocountrows and clears any offset; a negative count removes the limit.Sets the rows to skip (OFFSET) and the maximum to return (LIMIT); a null or negative value omits that clause.Appends the fields to the ORDER BY clause in ascending order.Appends the fields to the ORDER BY clause in ascending order.Appends a field to the ORDER BY clause, addingNULLS FIRSTorNULLS LASTunlessnullsFirstis null.page(int page, int pageSize) Limits the result to the given 0-based page ofpageSizerows.Adds columns or expressions to the SELECT list;*is selected if none are added.setGrouping(QueryGrouping grouping) Replaces the GROUP BY fields;nullinstalls an empty grouping.setHaving(QueryCriteria having) Replaces the HAVING criteria, changing its type to HAVING;nullinstalls empty criteria.setNestedAlias(String nestedAlias) Sets the alias written after this source in a FROM clause (nullfor none).setOrder(QueryOrder order) Replaces the ORDER BY fields;nullinstalls an empty ordering.setPretty(boolean pretty) Indicates ifSqlPart.getSqlFragment()adds line breaks and indentation instead of using one line (default is false).setSelection(QuerySelection selection) Replaces the SELECT column list;nullinstalls an empty one, which selects*.setWhere(QueryCriteria where) Replaces the WHERE criteria, changing its type to WHERE;nullinstalls empty criteria.Adds a condition and its parameter values to the WHERE clause with AND (ifandConjunctionis true) or OR.where(QueryCriteriaPart criteria) Replaces all WHERE conditions with the given part.ANDs a condition, such as"id = ?", and its parameter values with the existing WHERE conditions.Methods inherited from class com.northconcepts.datapipeline.jdbc.sql.select.QuerySource
getNestedAlias, shouldWrapWhenNestedMethods inherited from class com.northconcepts.datapipeline.jdbc.sql.SqlPart
getParameterValues, getSqlFragment, isPretty, printSqlParts, toString
-
Constructor Details
-
Select
Creates a query over the given tables; null entries are skipped, but at least one table is required. -
Select
Creates a query over the given tables; null entries are skipped, but at least one table is required. -
Select
Creates a query over the given sources, such as tables, nested queries orUnions; at least one is required.
-
-
Method Details
-
setPretty
Description copied from class:SqlPartIndicates ifSqlPart.getSqlFragment()adds line breaks and indentation instead of using one line (default is false).- Overrides:
setPrettyin classQuerySource
-
setNestedAlias
Description copied from class:QuerySourceSets the alias written after this source in a FROM clause (nullfor none).- Overrides:
setNestedAliasin classQuerySource
-
getQuerySources
-
getTables
Description copied from class:QuerySourceReturns the tables this source reads from, including those of nested sources but not joined tables.- Specified by:
getTablesin classQuerySource
-
getTable
Returns the first table in the list of tables.
If this select query involves more than one table, usegetTables()instead of this method.- Specified by:
getTablein classQuerySource
-
getJoins
-
containsTable
Description copied from class:QuerySourceReturns true if this source, a nested source or a join refers to the table (ignoring case).- Specified by:
containsTablein classQuerySource
-
getSelection
Returns the SELECT column list (nevernull). -
setSelection
Replaces the SELECT column list;nullinstalls an empty one, which selects*. -
select
Adds columns or expressions to the SELECT list;*is selected if none are added. -
innerJoin
-
leftJoin
-
rightJoin
-
fullJoin
-
getCriteria
Deprecated.usegetWhere() -
getWhere
Returns the WHERE criteria (nevernull). -
setWhere
Replaces the WHERE criteria, changing its type to WHERE;nullinstalls empty criteria. -
where
ANDs a condition, such as"id = ?", and its parameter values with the existing WHERE conditions. -
where
Adds a condition and its parameter values to the WHERE clause with AND (ifandConjunctionis true) or OR. -
where
Replaces all WHERE conditions with the given part. -
clearWhere
-
getGrouping
Returns the GROUP BY fields (nevernull). -
setGrouping
Replaces the GROUP BY fields;nullinstalls an empty grouping. -
groupBy
-
getHaving
Returns the HAVING criteria (nevernull). -
setHaving
Replaces the HAVING criteria, changing its type to HAVING;nullinstalls empty criteria. -
having
ANDs a condition, such as"SUM(total) > ?", and its parameter values with the existing HAVING conditions. -
having
Adds a condition and its parameter values to the HAVING clause with AND (ifandConjunctionis true) or OR. -
having
Replaces all HAVING conditions with the given part. -
clearHaving
-
getOrder
Returns the ORDER BY fields (nevernull). -
setOrder
Replaces the ORDER BY fields;nullinstalls an empty ordering. -
orderBy
Appends the fields to the ORDER BY clause in ascending order. -
orderBy
Appends the fields to the ORDER BY clause in ascending order. -
orderBy
-
orderBy
Appends a field to the ORDER BY clause, addingNULLS FIRSTorNULLS LASTunlessnullsFirstis null. -
limit
Limits the result tocountrows and clears any offset; a negative count removes the limit. -
limit
Sets the rows to skip (OFFSET) and the maximum to return (LIMIT); a null or negative value omits that clause. -
clearLimit
-
page
Limits the result to the given 0-based page ofpageSizerows. -
getOffset
Returns the number of rows to skip ornullif not set. -
getCount
Returns the maximum number of rows to return ornullif unlimited. -
collectSqlFragment
Description copied from class:SqlPartWrites this part's SQL to the writer; used bySqlPart.getSqlFragment()and by enclosing parts.- Specified by:
collectSqlFragmentin classSqlPart
-
collectQuerySourceSqlFragment
Writes a FROM source, in parentheses ifQuerySource.shouldWrapWhenNested()is true, followed by its nested alias if any. -
collectParameterValues
Description copied from class:SqlPartAppends the values for this part's?parameters to the list in order; adds nothing by default.- Overrides:
collectParameterValuesin classSqlPart
-
getWhere()