Package org.fugerit.java.core.db.daogen
Class SelectHelper
- java.lang.Object
-
- org.fugerit.java.core.db.daogen.BasicHelper
-
- org.fugerit.java.core.db.daogen.QueryHelper
-
- org.fugerit.java.core.db.daogen.SelectHelper
-
- All Implemented Interfaces:
Serializable
public class SelectHelper extends QueryHelper
Query helper for select operations.QueryHelper
for basic informations.- Author:
- Matteo Franci a.k.a. Fugerit
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
COMPARE_DIFFERENT
Constant for '<>'static String
COMPARE_EQUAL
Constant for '='static String
COMPARE_GT
Constant for '>'static String
COMPARE_GT_EQUAL
Constant for '>='static String
COMPARE_LIKE
Constant for 'LIKE'static String
COMPARE_LT
Constant for '<'static String
COMPARE_LT_EQUAL
Constant for '<='static String
MODE_AND
Constant for 'AND'static String
MODE_NONE
Constant for empty stringstatic String
MODE_OR
Constant for 'OR'static String
ORDER_ASC
Constant for 'ASC'static String
ORDER_DESC
Constant for 'DESC'-
Fields inherited from class org.fugerit.java.core.db.daogen.QueryHelper
CLOSE_PARA, OPEN_PARA, QUESTION_MARK, WHITESPACE
-
Fields inherited from class org.fugerit.java.core.db.daogen.BasicHelper
UNSOPPORTED_OPERATION
-
-
Constructor Summary
Constructors Constructor Description SelectHelper(String table, FieldList fl)
Constructor for a SelectHelper
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addNullComparison(String columnName, String mode, boolean isNull)
Add a NULL check to the query.void
addOrderBy(String orderBy)
Directly add ORDER BY to the query.void
addOrderBy(String columnName, String orderByMode)
Add ORDER BY to the query.boolean
addParam(String columnName, Object value, String mode, String compare)
Add a parameter to the query.boolean
addParam(String columnName, Object value, String mode, String compare, String parameter)
Add a parameter to the query.boolean
addWhereOrMode(String mode)
If no field has been set, WHERE will be added, otherwise 'mode' will be added.boolean
andEqualParam(String columnName, Object value)
Add a parameter to the query.boolean
andLikeParam(String columnName, Object value)
Add a parameter to the query.String
getQueryContent()
Builds the query context of all query buffer.void
initSelectEntity()
Initialize this helper.static SelectHelper
newCustomSelectHelper(String table, FieldList fl, boolean firstParam, String queryView)
Creates a new SelectHelper NOTE : initSelectEntity() should not be invoked.boolean
orEqualParam(String columnName, Object value)
Add a parameter to the query.boolean
orLikeParam(String columnName, Object value)
Add a parameter to the query.-
Methods inherited from class org.fugerit.java.core.db.daogen.QueryHelper
append, appendToQuery, appendToQueryWithSpace, appendWithSpace, closePara, getFields, getQuery, getTable, openPara
-
Methods inherited from class org.fugerit.java.core.db.daogen.BasicHelper
throwUnsupported
-
-
-
-
Field Detail
-
MODE_NONE
public static final String MODE_NONE
Constant for empty string- See Also:
- Constant Field Values
-
MODE_AND
public static final String MODE_AND
Constant for 'AND'- See Also:
- Constant Field Values
-
MODE_OR
public static final String MODE_OR
Constant for 'OR'- See Also:
- Constant Field Values
-
COMPARE_EQUAL
public static final String COMPARE_EQUAL
Constant for '='- See Also:
- Constant Field Values
-
COMPARE_DIFFERENT
public static final String COMPARE_DIFFERENT
Constant for '<>'- See Also:
- Constant Field Values
-
COMPARE_LT
public static final String COMPARE_LT
Constant for '<'- See Also:
- Constant Field Values
-
COMPARE_GT
public static final String COMPARE_GT
Constant for '>'- See Also:
- Constant Field Values
-
COMPARE_LIKE
public static final String COMPARE_LIKE
Constant for 'LIKE'- See Also:
- Constant Field Values
-
COMPARE_LT_EQUAL
public static final String COMPARE_LT_EQUAL
Constant for '<='- See Also:
- Constant Field Values
-
COMPARE_GT_EQUAL
public static final String COMPARE_GT_EQUAL
Constant for '>='- See Also:
- Constant Field Values
-
ORDER_ASC
public static final String ORDER_ASC
Constant for 'ASC'- See Also:
- Constant Field Values
-
ORDER_DESC
public static final String ORDER_DESC
Constant for 'DESC'- See Also:
- Constant Field Values
-
-
Method Detail
-
newCustomSelectHelper
public static SelectHelper newCustomSelectHelper(String table, FieldList fl, boolean firstParam, String queryView)
Creates a new SelectHelper NOTE : initSelectEntity() should not be invoked.- Parameters:
table
- the entity this select helper is meant for.fl
- the list of fieldsfirstParam
-true
if WHERE must be set,false
othewise.queryView
- the query to use instead of default query build on TABLE name.- Returns:
- a new SelectHelper
-
initSelectEntity
public void initSelectEntity()
Initialize this helper.
-
addWhereOrMode
public boolean addWhereOrMode(String mode)
If no field has been set, WHERE will be added, otherwise 'mode' will be added.- Parameters:
mode
- the mode to be added ( AND, OR )- Returns:
true
if WHERE has been added,false
otherwise.- Since:
- 8.0.1
-
addParam
public boolean addParam(String columnName, Object value, String mode, String compare, String parameter)
Add a parameter to the query. The parameter is added if and only if the value is not null. If you want to add a null comparison use addNullComparison() method()- Parameters:
columnName
- the name of the columnvalue
- the valuemode
- the mode (AND, OR)compare
- the comparison type ( = , <>, >, <, <=, >=, LIKE )parameter
- the parameter (for example section '?' or 'UPPER(?)')- Returns:
true
if the parameter has been added,false
otherwise.- Since:
- 8.0.1
-
addNullComparison
public boolean addNullComparison(String columnName, String mode, boolean isNull)
Add a NULL check to the query.- Parameters:
columnName
- the name of the columnisNull
-true
to add 'IS NULL' check,false
to add 'IS NOT NULL' check.mode
- the mode (AND, OR)- Returns:
true
if the parameter has been added,false
otherwise.- Since:
- 8.0.1
-
addParam
public boolean addParam(String columnName, Object value, String mode, String compare)
Add a parameter to the query. The parameter is added if and only if the value is not null. If you want to add a null comparison use addNullComparison() method() The parameter will be added as a parameter (?) for prepared statement- Parameters:
columnName
- the name of the columnvalue
- the valuemode
- the mode (AND, OR)compare
- the comparison type ( = , <>, >, <, <=, >=, LIKE )- Returns:
true
if the parameter has been added,false
otherwise.
-
orEqualParam
public boolean orEqualParam(String columnName, Object value)
Add a parameter to the query. The parameter is added if and only if the value is not null. If you want to add a null comparison use addNullComparison() method(). The parameter will be added as a parameter (?) for prepared statement. The mode will be OR and the comparison =- Parameters:
columnName
- the name of the columnvalue
- the value- Returns:
true
if the parameter has been added,false
otherwise.
-
orLikeParam
public boolean orLikeParam(String columnName, Object value)
Add a parameter to the query. The parameter is added if and only if the value is not null. If you want to add a null comparison use addNullComparison() method(). The parameter will be added as a parameter (?) for prepared statement. The mode will be OR and the comparison LIKE- Parameters:
columnName
- the name of the columnvalue
- the value- Returns:
true
if the parameter has been added,false
otherwise.
-
andEqualParam
public boolean andEqualParam(String columnName, Object value)
Add a parameter to the query. The parameter is added if and only if the value is not null. If you want to add a null comparison use addNullComparison() method(). The parameter will be added as a parameter (?) for prepared statement. The mode will be AND and the comparison =- Parameters:
columnName
- the name of the columnvalue
- the value- Returns:
true
if the parameter has been added,false
otherwise.
-
andLikeParam
public boolean andLikeParam(String columnName, Object value)
Add a parameter to the query. The parameter is added if and only if the value is not null. If you want to add a null comparison use addNullComparison() method(). The parameter will be added as a parameter (?) for prepared statement. The mode will be AND and the comparison LIKE- Parameters:
columnName
- the name of the columnvalue
- the value- Returns:
true
if the parameter has been added,false
otherwise.
-
addOrderBy
public void addOrderBy(String columnName, String orderByMode)
Add ORDER BY to the query.- Parameters:
columnName
- the column nameorderByMode
- the order mode (ASC, DESC)
-
addOrderBy
public void addOrderBy(String orderBy)
Directly add ORDER BY to the query.- Parameters:
orderBy
- string "ORDER BY ${orderBy}" will be added to the query buffer.
-
getQueryContent
public String getQueryContent()
Description copied from class:QueryHelper
Builds the query context of all query buffer. (To be preferred to getQuery().toString() method).- Overrides:
getQueryContent
in classQueryHelper
- Returns:
- the current query content
-
-