Class PreparedQuery<T>

java.lang.Object
com.evolveum.midpoint.schema.query.AbstractTypedQuery<T,PreparedQuery<T>>
com.evolveum.midpoint.schema.query.PreparedQuery<T>
Type Parameters:
T - Resulting item type

public class PreparedQuery<T> extends AbstractTypedQuery<T,PreparedQuery<T>>
Prepared Query represents query with filter with placeholders, which can be used for search. Prepared Query differs from TypedQuery that original query contained placeholders, which needs to be bound to actual values before query is used. Values could be bound using bindValue(Object) method for binding first unbound values or by using bind(Object...) method which binds multiple unbound values in order of their appeareance. Prepared Query can be converted to TypedQuery by binding values using bind(Object...) method. Once prepared query is successfully bound, filter is cached and new typed queries could be generated using toTypedQuery().
  • Method Details

    • parse

      public static <T> PreparedQuery<T> parse(Class<T> type, String query) throws SchemaException
      Parses supplied query string for type with placeholder support.
      Type Parameters:
      T - Type of the items which query should return
      Parameters:
      type - Type of the items which query should return
      query - Midpoint Query string without placeholders
      Returns:
      new Prepared Query which contains partially parsed filter, type information and allows for values to be bound to placeholders.
      Throws:
      SchemaException - when supplied query string was syntactically or logically incorrect
    • parse

      public static <T> PreparedQuery<T> parse(Class<T> type, ItemDefinition<?> def, String query) throws SchemaException
      Throws:
      SchemaException
    • bindValue

      public PreparedQuery<T> bindValue(Object realValue) throws SchemaException
      Binds next unbound value in filter to provided value. IMPORTANT: Current behavior is strict in checking value types for bound values, user must supply correct class for realValue (eg. PolyString, XMLGregorianCalendar
      Parameters:
      realValue - Real Value to be bound
      Throws:
      SchemaException - If provided value is invalid according to schema definition (type of value)
      IllegalStateException - If there is no positional value to be bound
    • set

      public PreparedQuery<T> set(String name, Object realValue) throws SchemaException
      Parameters:
      name -
      realValue -
      Returns:
      Throws:
      SchemaException
    • bind

      public TypedQuery<T> bind(Object... args) throws SchemaException
      Binds multiple values and returns final Typed Query which will contain filter.
      Parameters:
      args - Real values to be bound to unbound placeholders in order of appearance. See bindValue(Object) for more details.
      Returns:
      Typed Query which contains final filter and configuration of paging and ordering.
      Throws:
      IllegalStateException - If not all placeholders were bound to values
      SchemaException - If provided values are invalid according to schema definition (type of value) resulting filter with bound values is invalid.
    • toTypedQuery

      public TypedQuery<T> toTypedQuery()
      Creates new TypedQuery based on type, filter, bound values and configuration of paging and ordering.
      Returns:
      New Typed Query based on bound values and configuration of paging and ordering.
      Throws:
      IllegalStateException - If query was not successfully bound before using bind(Object...) or build().
    • toObjectQuery

      public ObjectQuery toObjectQuery()
    • build

      public TypedQuery<T> build() throws SchemaException
      Returns:
      Throws:
      SchemaException
    • allPlaceholdersBound

      public boolean allPlaceholdersBound()
      Returns:
      True if all placeholders were bound to value.
    • self

      protected PreparedQuery<T> self()
      Specified by:
      self in class AbstractTypedQuery<T,PreparedQuery<T>>