Class QueryByExampleMechanism

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.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
    Author:
    Stephen McRitchie
    See Also:
    Serialized Form
    • Field Detail

      • isParsed

        protected boolean isParsed
      • exampleObject

        protected java.lang.Object exampleObject
        Used for Query By Example.
    • Constructor Detail

      • 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 Detail

      • getExampleObject

        public java.lang.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
      • setExampleObject

        public void setExampleObject​(java.lang.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.