Class Criteria

java.lang.Object
overit.geocall.sql.code.criterion.Criterion
overit.geocall.sql.code.criterion.Criteria
All Implemented Interfaces:
Cloneable

public class Criteria extends Criterion
The class extends Criterion and aims to create a criterion's set to define how the values should be treated and what clauses must be created for specific fields.
  • Field Details

    • START

      public static final Criteria START
      Defines an empty Criteria used as starting point for your custom criteria.
    • INSERT_ASSIGN

      public static final Criteria INSERT_ASSIGN
      It's a predefined Criteria and it's used to define the content of the INSERT's SET clause.
      This Criteria discard control fields and empty or null values.
      For the others uses the EQUALS criterion.
    • UPDATE_ASSIGN

      public static final Criteria UPDATE_ASSIGN
      It's a predefined Criteria and it's used to define the content of the UPDATE?s SET clause.
      This Criteria discard control fields and reset empty set.
      For the others uses the EQUALS criterion.
      For example given this "AUSENAME,null" key-value pair, will be treated like "AUSENAME = NULL" in the SET clause.
    • SEARCH_WEAK

      public static final Criteria SEARCH_WEAK
      It's a predefined Criteria and it's used to define the content of the SELECT's WHERE clause.
      This Criteria discard control fields and empty or null values.

      Depending on the possible prefix of the field name, the corresponding SQL clause is created, supporting the following types:

      Collection's values is treated with IN clause, Like string is treated with LIKE clause and for the others uses the EQUALS criterion.
      For example, given this AUSEUSERNAME - admin%, AUSENAME - null, AUSEID_TUSE - [1,2,3], like:AUSESURNAME - 'Ross%', gte:AUSEBIRTHDATE - '2001-02-03' key-value pairs will be treated like WHERE AUSEUSERNAME LIKE 'admin%' AND AUSEID_TUSE IN (1,2,3) AND AUSESURNAME LIKE 'Ross%' AND AUSEBIRTHDATE >= '2001-02-03'.

    • SEARCH_STRONG

      public static final Criteria SEARCH_STRONG
      It's a predefined Criteria and it's used to define the content of the SELECT's WHERE clause.
      This Criteria discard control fields.

      Depending on the possible prefix of the field name, the corresponding SQL clause is created, supporting the following types:

      Empty or null values and empty collections are treated with IS NULL clause.

      Collection's values is treated with IN clause and for the others uses the EQUALS criterion.
      For example given this AUSEUSERNAME - admin, AUSENAME - null, AUSEID_TUSE - [1,2,3], like:AUSESURNAME - 'Ross%', gte:AUSEBIRTHDATE - '2001-02-03', isnotnull:AUSEEMAIL key-value pairs will be treated like WHERE AUSEUSERNAME='admin' AND AUSEID_TUSE IN (1,2,3) AND AUSENAME IS NULL AND AUSESURNAME LIKE 'Ross%' AND AUSEBIRTHDATE >= '2001-02-03' AND AUSEEMAIL IS NOT NULL.

    • _onMatch

      protected Criterion _onMatch
    • _otherwise

      protected Criterion _otherwise
  • Constructor Details

    • Criteria

      public Criteria()
      The Default constructor.
    • Criteria

      public Criteria(Criterion primary)
    • Criteria

      public Criteria(Criterion primary, Criterion secondary)
      The class's constructor. It defines a Criteria with a primary and secondary Criterion passed by parameters.
      Parameters:
      primary - The predefined Criterion used as primary.
      secondary - The predefined Criterion used as secondary.
  • Method Details

    • start

      public static Criteria start(Criterion c)
      Creates a new Criteria with a specific Criterion passed by parameters.
      Parameters:
      c - The specific Criterion.
      Returns:
      The new Criteria created with a specific Criterion passed by parameters.
    • isEmpty

      public boolean isEmpty()
      If no criteria matched so far and there are no other criteria to check, then there are no criteria that matched with a given key-value pair. return true otherwise return false
      Returns:
      true if no criteria matched so far and there are no other criteria to check, false otherwise.
    • ifNot

      public Criteria ifNot(Criterion criterion)
      It creates a Criteria with a primary Criterion passed by parameter and a secondary Criterion which depends on the criterion passed by parameter.
      Parameters:
      criterion - The predefined Criterion used as primary.
      Returns:
      A Criteria with a primary Criterion that is the criterion object passed by parameter and (as secondary criterion) null if criterion is empty or criterion itself if it's not empty.
    • otherwise

      public Criteria otherwise(Criterion other)
      This method allows to add a decision criterion to the set of criteria defined by the current criteria.
      It's very used to add a customized decision criterion, for example it's used in this way:

      Criteria. START
        .otherwise(new Decision(new Clause("@AUSEAGE >= 18")).forName("adult").forPattern(Boolean.class,true))
        .otherwise(new Decision(new Clause("@AUSEAGE < 18")).forName("adult").forPattern(Boolean.class,false))
        .otherwise(Criteria.SEARCH_WEAK);
      Parameters:
      other - The decision criterion to add.
      Returns:
      A new Criteria with the decision criterion, passed by parameter, added.
    • define

      public Parts define(String name, Object value)
      Description copied from class: Criterion
      defines the Parts of the operation with all the information to become a fragment.
      Specified by:
      define in class Criterion
      Parameters:
      name - the nome of the context field
      value - the current value of the context field
      Returns:
      return null if the Criterion don't find an information, a Parts otherwise. Then Parts con also contain empty strings if the decision is to discard the name and the value
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object