Class SelectQueryBuilder
java.lang.Object
io.github.blyznytsiaorg.bibernate.dao.jdbc.dsl.QueryBuilder
io.github.blyznytsiaorg.bibernate.dao.jdbc.dsl.SelectQueryBuilder
Represents a SQL SELECT query builder for constructing SELECT statements with optional clauses
such as JOIN, WHERE, GROUP BY, HAVING, and UNION.
Extends the base class QueryBuilder.
Example usage:
```java
SelectQueryBuilder.from("users")
.selectField("*")
.join("orders", "users.id = orders.user_id", JoinType.LEFT)
.whereCondition("age > ?")
.groupBy("name")
.havingCondition("COUNT(*) > 1")
.buildSelectStatement();
Result will be:
SELECT * FROM users LEFT JOIN orders ON users.id = orders.user_id WHERE age > ? GROUP BY name HAVING COUNT(*) > 1;
```
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
-
Field Summary
Modifier and TypeFieldDescriptionprivate String
The field to be used for GROUP BY clauses.private String
The condition for HAVING clauses.private final List
<JoinClause> The list of JOIN clauses to be included in the SELECT statement.The list of fields to be selected in the SELECT statement.private final List
<SelectQueryBuilder> The list of SELECT queries to be combined using UNION.Fields inherited from class io.github.blyznytsiaorg.bibernate.dao.jdbc.dsl.QueryBuilder
ALL_FIELDS, AND, AS, BETWEEN_S_AND_S, CLOSE_BRACKET, COMA, DELETE, DOT, EQ, FROM, GROUP_BY, HAVING, IN, INSERT_INTO, OPEN_BRACKET, OR, PARAMETER, SELECT, SEMICOLON, SET, SPACE, tableName, UNDERSCORE, UNION, UPDATE, WHERE, whereConditions
-
Constructor Summary
ConstructorDescriptionSelectQueryBuilder
(String tableName) Constructs a new SelectQueryBuilder with the specified table name. -
Method Summary
Modifier and TypeMethodDescriptionandCondition
(String condition) Adds an AND condition to the existing WHERE conditions.betweenCondition
(String field, Object lowerBound, Object upperBound) Adds a BETWEEN condition to the existing WHERE conditions.Builds the SELECT SQL statement based on the configured conditions and clauses.static SelectQueryBuilder
Creates a new SelectQueryBuilder with the specified table name.Sets the field for GROUP BY clauses in the SELECT statement.havingCondition
(String havingCondition) Sets the condition for HAVING clauses in the SELECT statement.Adds a JOIN clause to the SELECT statement.join
(List<JoinClause> joinClausesList) Adds a list of join clauses to the current select query builder.orCondition
(String condition) Adds an OR condition to the existing WHERE conditions.selectField
(String fieldName) Adds a field to the list of fields to be selected in the SELECT statement.selectFieldFromTable
(String tableName, String fieldName) Adds a specific field from a specified table to the list of fields to be selected.selectFields
(List<String> fieldNames) selectFieldsFromTable
(String tableName) Adds all fields from a specified table to the list of fields to be selected.union
(SelectQueryBuilder otherQuery) Combines the current SELECT query with another query using the UNION operator.whereCondition
(String condition) Adds a WHERE condition to the SELECT statement.Methods inherited from class io.github.blyznytsiaorg.bibernate.dao.jdbc.dsl.QueryBuilder
handleWhereCondition
-
Field Details
-
groupByField
The field to be used for GROUP BY clauses. -
havingCondition
The condition for HAVING clauses. -
selectedFields
The list of fields to be selected in the SELECT statement. -
joinClauses
The list of JOIN clauses to be included in the SELECT statement. -
unionQueries
The list of SELECT queries to be combined using UNION.
-
-
Constructor Details
-
SelectQueryBuilder
Constructs a new SelectQueryBuilder with the specified table name.- Parameters:
tableName
- The name of the table from which to select records.
-
-
Method Details
-
from
Creates a new SelectQueryBuilder with the specified table name.- Parameters:
tableName
- The name of the table from which to select records.- Returns:
- A new instance of SelectQueryBuilder.
-
selectField
Adds a field to the list of fields to be selected in the SELECT statement.- Parameters:
fieldName
- The name of the field to be selected.- Returns:
- The current SelectQueryBuilder instance for method chaining.
-
selectFields
-
selectFieldsFromTable
Adds all fields from a specified table to the list of fields to be selected.- Parameters:
tableName
- The name of the table from which to select all fields.- Returns:
- The current SelectQueryBuilder instance for method chaining.
-
selectFieldFromTable
Adds a specific field from a specified table to the list of fields to be selected.- Parameters:
tableName
- The name of the table from which to select the field.fieldName
- The name of the field to be selected.- Returns:
- The current SelectQueryBuilder instance for method chaining.
-
join
Adds a JOIN clause to the SELECT statement.- Parameters:
joinedTable
- The name of the table to be joined.onCondition
- The ON condition specifying how the tables should be joined.joinType
- The type of JOIN (INNER, LEFT, RIGHT, FULL).- Returns:
- The current SelectQueryBuilder instance for method chaining.
-
join
Adds a list of join clauses to the current select query builder.- Parameters:
joinClausesList
- The list of join clauses to be added.- Returns:
- The updated SelectQueryBuilder instance with the specified join clauses.
-
whereCondition
Adds a WHERE condition to the SELECT statement.- Parameters:
condition
- The WHERE condition to be added.- Returns:
- The current SelectQueryBuilder instance for method chaining.
-
andCondition
Adds an AND condition to the existing WHERE conditions.- Parameters:
condition
- The AND condition to be added.- Returns:
- The current SelectQueryBuilder instance for method chaining.
-
orCondition
Adds an OR condition to the existing WHERE conditions.- Parameters:
condition
- The OR condition to be added.- Returns:
- The current SelectQueryBuilder instance for method chaining.
-
betweenCondition
Adds a BETWEEN condition to the existing WHERE conditions.- Parameters:
field
- The field to which the BETWEEN condition applies.lowerBound
- The lower bound of the range.upperBound
- The upper bound of the range.- Returns:
- The current SelectQueryBuilder instance for method chaining.
-
groupBy
Sets the field for GROUP BY clauses in the SELECT statement.- Parameters:
groupByField
- The field to be used for GROUP BY clauses.- Returns:
- The current SelectQueryBuilder instance for method chaining.
-
havingCondition
Sets the condition for HAVING clauses in the SELECT statement.- Parameters:
havingCondition
- The condition for HAVING clauses.- Returns:
- The current SelectQueryBuilder instance for method chaining.
-
union
Combines the current SELECT query with another query using the UNION operator.- Parameters:
otherQuery
- The SelectQueryBuilder representing the other query.- Returns:
- The current SelectQueryBuilder instance for method chaining.
-
buildSelectStatement
Builds the SELECT SQL statement based on the configured conditions and clauses.- Returns:
- The generated SELECT SQL statement as a string.
-