Package com.rosivanyshyn.utils
Class MySQLQueryBuilder
java.lang.Object
com.rosivanyshyn.utils.MySQLQueryBuilder
MySQL Query Builder.
It contains methods to build dynamic query depends on business requirements.
It contains methods to build dynamic query depends on business requirements.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCombine several filtersvoidclear()Clear query buildervoidexcludeJoin(String table, String label, String tableField, String field) Returns rows of current table, that are not exist in table BgetQuery()Build the query from all the previous added parts.voidReturns rows of current table, that are existed in table BvoidSpecify the number of records to return.voidSort records by field in ascending or descending order.voidSettervoidsubcondition(Boolean state) Open or close new sub-condition in WHERE clausevoidwhere(String field, MySQLQueryBuilder.LogicalOperation logicalOperation, boolean and) Filter the table by the specified field
-
Field Details
-
label
-
where
-
-
Constructor Details
-
MySQLQueryBuilder
public MySQLQueryBuilder()
-
-
Method Details
-
setLabel
Setter- Parameters:
label- name of DB table
-
join
Returns rows of current table, that are existed in table B- Parameters:
table- table to comparisonslabel- abbreviation of the compared table nametableField- field name of the compared tablefield- field name of current table
-
excludeJoin
Returns rows of current table, that are not exist in table B- Parameters:
table- table to comparisonslabel- abbreviation of the compared table nametableField- field name of the compared tablefield- field name of current table
-
where
Filter the table by the specified field- Parameters:
field- field by which to filterand- combining with previous condition. True -> the preconditions, including the new one, must be true to return records. False -> return a records if any of the conditions is true.
-
addWhere
Combine several filters- Parameters:
clause- new filterand- Combining with previous condition. True -> the preconditions, including the new one, must be true to return records. False -> return a records if any of the conditions is true.
-
subcondition
Open or close new sub-condition in WHERE clause- Parameters:
state- - State of condition. True - open new sub-condition. False - close previous sub-condition
-
limit
Specify the number of records to return.- Parameters:
offset- which record to start sampling fromlimit- records count to get
-
order
Sort records by field in ascending or descending order.- Parameters:
field- field by which to sortdesc- if true -> sort in descending order
-
getQuery
Build the query from all the previous added parts.- Returns:
- string represent of query.
-
clear
public void clear()Clear query builder
-