Class QueryByExampleMechanism

All Implemented Interfaces:
Serializable, Cloneable

public class QueryByExampleMechanism extends ExpressionQueryMechanism

Purpose: Mechanism used for all queries by example.

Responsibilities: Builds a selection criteria for this query given an example object and a QueryByExample policy. Works akin to EBQLMechanism which builds the selection criteria from an EJBQL string.

Since:
9.0.3.5
See Also:
  • Field Details

    • isParsed

      protected boolean isParsed
    • exampleObject

      protected Object exampleObject
      Used for Query By Example.
    • queryByExamplePolicy

      protected QueryByExamplePolicy queryByExamplePolicy
  • Constructor Details

    • QueryByExampleMechanism

      public QueryByExampleMechanism(DatabaseQuery query)
      Initialize the state of the query
      Parameters:
      query - - owner of mechanism
    • QueryByExampleMechanism

      public QueryByExampleMechanism(DatabaseQuery query, Expression expression)
      Initialize the state of the query
      Parameters:
      query - - owner of mechanism
      expression - - selection criteria
  • Method Details

    • buildSelectionCriteria

      public void buildSelectionCriteria(AbstractSession session)
      INTERNAL: In the case of EJBQL or query by example, an expression needs to be generated. Build the required expression.
      Overrides:
      buildSelectionCriteria in class DatabaseQueryMechanism
    • getExampleObject

      public Object getExampleObject()
      PUBLIC: This method returns the current example object. The "example" object is an actual domain object, provided by the client, from which an expression is generated. This expression is used for a query of all objects from the same class, that match the attribute values of the "example" object.
    • getQueryByExamplePolicy

      public QueryByExamplePolicy getQueryByExamplePolicy()
      PUBLIC: When using Query By Example, an instance of QueryByExamplePolicy is used to customize the query. The policy is useful when special operations are to be used for comparisons (notEqual, lessThan, greaterThan, like etc.), when a certain value is to be ignored, or when dealing with nulls.
    • isParsed

      public boolean isParsed()
      INTERNAL: Is this query Parsed
    • isQueryByExampleMechanism

      public boolean isQueryByExampleMechanism()
      Return true if this is a query by example mechanism
      Overrides:
      isQueryByExampleMechanism in class DatabaseQueryMechanism
    • setExampleObject

      public void setExampleObject(Object newExampleObject)
      PUBLIC: Set the example object of the query to be the newExampleObject. The example object is used for Query By Example. When doing a Query By Example, an instance of the desired object is created, and the fields are filled with the values that are required in the result set. From these values the corresponding expression is build by TopLink, and the query is executed, returning the set of results.
    • setIsParsed

      public void setIsParsed(boolean newIsParsed)
      INTERNAL: Set the isParsed state
    • setQueryByExamplePolicy

      public void setQueryByExamplePolicy(QueryByExamplePolicy queryByExamplePolicy)
      PUBLIC: The QueryByExamplePolicy, is a useful to customize the query when Query By Example is used. The pollicy will control what attributes should, or should not be included in the query. When dealing with nulls, using specail operations (notEqual, lessThan, like, etc.) for comparison, or chosing to include certain attributes at all times, it is useful to modify the policy accordingly.