Interface IQueryHelper


public interface IQueryHelper
A helper class for query manipulation. Helps in composing queries in a correct way.

Note: This class also serves as an 'entry point' to track all usages of such logic, so that the object model for queries can be introduced later. Therefore it is strongly recommended to use this helper for query manipulation.

Author:
POLARION SOFTWARE
  • Field Details

    • FIELD_SQL

      @NotNull static final String FIELD_SQL
      Virtual index field for SQL queries. Works only for work items and baseline collections and its parameter must be enclosed in "()" parentheses, e.g. "SQL:(SELECT * FROM WORKITEM WHERE C_TYPE='issue')"
      Since:
      3.8.2
      See Also:
    • HAS_VALUE

      static final String HAS_VALUE
      Search field that contains ids of all object fields that have non-empty value.
      Since:
      3.7.1
      See Also:
    • UNASSIGNED_VALUE

      @Deprecated static final String UNASSIGNED_VALUE
      Deprecated.
      Constant (######NULL) used for unassigned value queries.
      See Also:
    • FIELD_IS_LOCAL

      @Deprecated static final String FIELD_IS_LOCAL
      Deprecated.
      The 2010 Live Documents are deprecated.
      Search field, which can be used to include or eliminate objects with local id (the ones coming from live-documents) from the query results.

      By default (if not mentioned), the objects with local id are NOT included in the result.

      See Also:
    • IS_LOCAL_TRUE

      @Deprecated static final String IS_LOCAL_TRUE
      Deprecated.
      The 2010 Live Documents are deprecated.
      FIELD_IS_LOCAL value for objects with local id.
      See Also:
    • IS_LOCAL_FALSE

      @Deprecated static final String IS_LOCAL_FALSE
      Deprecated.
      The 2010 Live Documents are deprecated.
      FIELD_IS_LOCAL value for objects with global id.
      See Also:
    • ALL_QUERY

      static final String ALL_QUERY
      Nonempty query matching all objects. Used when one needs to start query with NOT condition.
      Since:
      3.1.2
      See Also:
  • Method Details

    • andQuery

      String andQuery(String firstQuery, String secondQuery)
      Composes the given queries using AND. If one of the queries is empty or null, the other query is returned. If both queries are empty or null, empty string is returned.
      Parameters:
      firstQuery -
      secondQuery -
      Returns:
      new query
    • orQuery

      String orQuery(String firstQuery, String secondQuery)
      Composes the given queries using OR. If one of the queries is empty or null, the other query is returned. If both queries are empty or null, empty string is returned.
      Parameters:
      firstQuery -
      secondQuery -
      Returns:
      new query
    • escapeQueryPart

      String escapeQueryPart(String part)
      Escapes special characters in query part. See http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
      Parameters:
      part -
      Returns:
      the escaped query
    • escapeQueryForSQL

      @NotNull String escapeQueryForSQL(@NotNull String query)
      Escapes characters in Lucene query so that it can be used in an SQL query as argument of the LUCENE_QUERY function.
      Since:
      3.9.2
    • fieldQuery

      String fieldQuery(String field, String term)
      Creates a field query for the specified term that will be enclosed in double quotes and contained special characters will be escaped. If field is null, the field part will be omitted, so the query will target the default field.
      Parameters:
      field -
      term -
      Returns:
      the field query
      Since:
      3.3.1
    • formatDateOnly

      String formatDateOnly(Date date)
      Convert date to string used in queries from...to
      Parameters:
      date - cannot be null
      Returns:
      the formated Date, only the part indicating time is ignored
    • formatDate

      String formatDate(Date date)
      Convert date to string used in queries from...to
      Parameters:
      date - cannot be null
      Returns:
      the formated date
    • fromToDateOnlyQuery

      String fromToDateOnlyQuery(Date from, Date to)
      Compose [from TO to] query fragments using the DATE_NO_TIME_FORMAT format.
      Parameters:
      from - can be null if to is not null
      to - can be null if from is not null
      Returns:
      the query
    • expandKeywords

      String expandKeywords(String query)
      Expands keywords in simple query using asterisks.
      Parameters:
      query -
      Returns:
      query with expanded keywords
      Since:
      3.5.2
    • negateQuery

      @NotNull String negateQuery(@NotNull String query)
      Adds NOT to the whole query
      Returns:
      the given query with a leading NOT and brackets (e.g. negateQuery(a or b) => NOT (a or b)). Will return empty String if given query is empty
      Since:
      3.10.1