Class Criteria

java.lang.Object
com.jbstrap.core.dao.Criteria

public class Criteria extends Object

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 Details

    • Criteria

      public Criteria(String columnName, OperatorType operator, Object value)
      Creates a simple Criteria
      Parameters:
      columnName - Name of the column that will be examined
      operator - The Criteria operator type
      value - The operator value
      Throws:
      NullPointerException - If the column name or operator is null
    • Criteria

      public Criteria(OperatorType operator, Criteria... criteria)
      Creates a complex Criteria
      Parameters:
      operator - The operator type. Only the 'AND' or 'OR' operators can be used here
      criteria - The other Criteria, that we want to connect with the operators
      Throws:
      NullPointerException - If the operator is null
  • Method Details

    • getColumnName

      public String getColumnName()
      Gets the Criteria column name
      Returns:
      The column name
    • getOperator

      public OperatorType getOperator()
      Gets the Criteria operator
      Returns:
      The Criteria operator
    • getReferencedColumnName

      public final String getReferencedColumnName()
      Gets the referenced column name
      Returns:
      The referenced column name. If there is no referenced column in the criteria, returns with null
    • isReferencedColumn

      public boolean isReferencedColumn(String columnName)
      Determines if the specified column is referenced in the criteria
      Parameters:
      columnName - The column name
      Returns:
      true, if the column is referenced, otherwise false
    • getValue

      public Object 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

      public final Criteria setRecord(Record data)
      Parameters:
      data - The record containing the data
      Returns:
      The criteria
    • getSubCriteria

      public List<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, otherwise false
    • addSubCriteria

      public Criteria addSubCriteria(Criteria criteria)
      Adds a new sub criteria to the complex Criteria
      Parameters:
      criteria - The new sub criteria. If specified as null nothing will be added
      Returns:
      The criteria
    • containsCriteria

      public boolean containsCriteria(Criteria criteria)

      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 with false
      See Also:
    • toString

      public String toString()

      Converts the Criteria to String

      The converted Criteria can be converted back, by using the CriteriaUtils.fromString() method

      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)

      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
      Overrides:
      equals in class Object
    • 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 with false
    • isReferencedColumnFilled

      public boolean isReferencedColumnFilled(String columnName)
      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 with false
    • getReferencedColumnNames

      public final List<String> 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

      public Criteria copy()
      Creates a copy of the Criteria
      Returns:
      A new instance of the Criteria, which is a perfect copy of the original Criteria
    • test

      public boolean test(Record record)

      Checks if the specified Record passes the Criteria

      Parameters:
      record - The Record that will be checked
      Returns:
      true if the record passes, otherwise false