Class Criteria
This class represents the query criteria, that are used within JBStrap
The Criteria object can be divided into two categories. The criteria can be simple or complex. The simple criteria only checks a certain value. The complex criteria is made up of multiple simple, or multiple other complex ones, and they can have an and/or relationship to each other. This means that with this class, the complexity of the criteria can be fully customized. For a more detailed explanation, please refer to the JBStrap guide
These can be used for multiple purposes. They are mainly used during filtering queries from databases. This can be done during a direct query, or used with data query components. In every case, this criteria class is used.
They are also used when a Record
is available (which can come from a database query or a
newly created record), and we want to do a check on it with certain criteria.
In this case, a Criteria class can be created, and using the test
method's
parameter to specify the record, which specifies if the record meets the criteria or not.
When creating criteria, we can reference a column that is part of a Record.
In this case, the referenced column's name can be used as a value, if the column's name is specified like this:
${anotherColumnName}
If you would like to create a Criteria, in which 'column1' must be equal with 'column2', it would look like this:
new Criteria("column1", OperatorType.EQUALS, "${column2}");
Use cases:
- Since:
- 4.0
- Author:
- JBStrap
- See Also:
-
Constructor Summary
ConstructorDescriptionCriteria
(OperatorType operator, Criteria... criteria) Creates a complex CriteriaCriteria
(String columnName, OperatorType operator, Object value) Creates a simple Criteria -
Method Summary
Modifier and TypeMethodDescriptionaddSubCriteria
(Criteria criteria) Adds a new sub criteria to the complex Criteriaboolean
containsCriteria
(Criteria criteria) Determines if the complex Criteria contains the specified criteriacopy()
Creates a copy of the Criteriaboolean
Determines if the Criteria is equal with the specified ObjectGets the Criteria column nameGets the Criteria operatorfinal String
Gets the referenced column nameGets a list of the name of every referenced column, that the criteria usesIf the criteria is complex, gets a list of every sub criteriagetValue()
Gets the Criteria valueboolean
Determines if the Criteria is complexboolean
isReferencedColumn
(String columnName) Determines if the specified column is referenced in the criteriaboolean
isReferencedColumnFilled
(String columnName) Determines if the criteria's specified referenced columm was filled by the set Recordboolean
Determines if the criteria's referenced columms were filled by the set Recordfinal Criteria
boolean
Checks if the specified Record passes the CriteriatoString()
Converts the Criteria to String
-
Constructor Details
-
Criteria
Creates a simple Criteria- Parameters:
columnName
- Name of the column that will be examinedoperator
- The Criteria operator typevalue
- The operator value- Throws:
NullPointerException
- If the column name or operator isnull
-
Criteria
Creates a complex Criteria- Parameters:
operator
- The operator type. Only the 'AND' or 'OR' operators can be used herecriteria
- The other Criteria, that we want to connect with the operators- Throws:
NullPointerException
- If the operator isnull
-
-
Method Details
-
getColumnName
Gets the Criteria column name- Returns:
- The column name
-
getOperator
Gets the Criteria operator- Returns:
- The Criteria operator
-
getReferencedColumnName
Gets the referenced column name- Returns:
- The referenced column name. If there is no referenced column in the criteria, returns with
null
-
isReferencedColumn
Determines if the specified column is referenced in the criteria- Parameters:
columnName
- The column name- Returns:
true
, if the column is referenced, otherwisefalse
-
getValue
Gets the Criteria value- Returns:
- The criteria value or
null
, if the criteria doesn't have a value specified, or if the criteria is complex
-
setRecord
- Parameters:
data
- The record containing the data- Returns:
- The criteria
-
getSubCriteria
If the criteria is complex, gets a list of every sub criteria- Returns:
- A list of every sub criteria or
null
, if not found, or if it's a simple criteria
-
isComplex
public boolean isComplex()Determines if the Criteria is complex- Returns:
true
, if complex, otherwisefalse
-
addSubCriteria
Adds a new sub criteria to the complex Criteria- Parameters:
criteria
- The new sub criteria. If specified asnull
nothing will be added- Returns:
- The criteria
-
containsCriteria
Determines if the complex Criteria contains the specified criteria
During the search, the method considers criteria to be the same, if their type is identical, and their contents are also identical. This means that differing instances can be identical instances.
- Parameters:
criteria
- The Criteria that will be examined- Returns:
true
, if the criteria is complex, and contains the specified criteria. Otherwise, returns withfalse
- See Also:
-
toString
Converts the Criteria to String
The converted Criteria can be converted back, by using the
CriteriaUtils.fromString()
method -
equals
Determines if the Criteria is equal with the specified Object
They are considered to be equal if:
- the specified object isn't
null
- The specified object is a Criteria class, or a descendant of one
- In the case of simple criteria, the specified criteria's column name, operator type and operator value is the same as the criteria's column name, operator type and operator value
- In the case of complex criteria, the specified criteria's operator is the same as the criteria's operator and the specified criteria has the same criteria's linked as the criteria
- the specified object isn't
-
isReferencedColumnsFilled
public boolean isReferencedColumnsFilled()Determines if the criteria's referenced columms were filled by the set Record- Returns:
true
if the criteria doesn't reference a column, or the columns are filled. Otherwise returns withfalse
-
isReferencedColumnFilled
Determines if the criteria's specified referenced columm was filled by the set Record- Parameters:
columnName
- The referenced column name- Returns:
true
, if the criteria doesn't reference the specified column, or if the column was filled. Otherwise returns withfalse
-
getReferencedColumnNames
Gets a list of the name of every referenced column, that the criteria uses- Returns:
- A list of the name of every referenced column. If there are none, returns with an empty list
-
copy
Creates a copy of the Criteria- Returns:
- A new instance of the Criteria, which is a perfect copy of the original Criteria
-
test
Checks if the specified Record passes the Criteria
- Parameters:
record
- The Record that will be checked- Returns:
true
if the record passes, otherwisefalse
-