Class BaseQuery<T>

java.lang.Object
org.infinispan.commons.query.BaseQuery<T>
All Implemented Interfaces:
Iterable<T>, Query<T>, Query<T>

public abstract class BaseQuery<T> extends Object implements Query<T>
Since:
7.2
Author:
anistor@redhat.com
  • Field Details

    • queryString

      protected final String queryString
    • namedParameters

      protected Map<String,Object> namedParameters
    • projection

      protected final String[] projection
    • startOffset

      protected int startOffset
    • maxResults

      protected int maxResults
    • hitCountAccuracy

      protected Integer hitCountAccuracy
    • local

      protected boolean local
    • scoreRequired

      protected boolean scoreRequired
    • timeout

      protected long timeout
      Optional timeout in nanoseconds.
  • Constructor Details

    • BaseQuery

      protected BaseQuery(String queryString, Map<String,Object> namedParameters, String[] projection, long startOffset, int maxResults, boolean local)
    • BaseQuery

      protected BaseQuery(String queryString)
  • Method Details

    • getQueryString

      public String getQueryString()
      Returns the Ickle query string.
      Specified by:
      getQueryString in interface Query<T>
      Returns:
      the Ickle query string
    • getParameters

      public Map<String,Object> getParameters()
      Description copied from interface: Query
      Returns the named parameters Map.
      Specified by:
      getParameters in interface Query<T>
      Returns:
      the named parameters (unmodifiable) or null if the query does not have parameters
    • setParameter

      public Query<T> setParameter(String paramName, Object paramValue)
      Description copied from interface: Query
      Sets the value of a named parameter.
      Specified by:
      setParameter in interface Query<T>
      Specified by:
      setParameter in interface Query<T>
      Parameters:
      paramName - the parameters name (non-empty and not null)
      paramValue - a non-null value
      Returns:
      itself
    • setParameters

      public Query<T> setParameters(Map<String,Object> paramValues)
      Description copied from interface: Query
      Sets multiple named parameters at once. Parameter names cannot be empty or null. Parameter values must not be null.
      Specified by:
      setParameters in interface Query<T>
      Specified by:
      setParameters in interface Query<T>
      Parameters:
      paramValues - a Map of parameters
      Returns:
      itself
    • resetQuery

      public abstract void resetQuery()
      Reset internal state after pagination or query parameters are modified. This is needed to ensure the next execution of the query uses the new values.
    • validateNamedParameters

      public void validateNamedParameters()
      Ensure all named parameters have non-null values.
    • getProjection

      public String[] getProjection()
      Specified by:
      getProjection in interface Query<T>
      Returns:
      the values for query projections or null if the query does not have projections.
    • hasProjections

      public boolean hasProjections()
      Description copied from interface: Query
      Indicates if the parsed query has projections (a SELECT clause) and consequently, the returned results will actually be Object[] containing the projected values rather than the target entity.
      Specified by:
      hasProjections in interface Query<T>
      Returns:
      true if it has projections, false otherwise.
    • getStartOffset

      public long getStartOffset()
      Description copied from interface: Query
      Returns the start offset configured for this query.
      Specified by:
      getStartOffset in interface Query<T>
      Returns:
      the start offset
    • getMaxResults

      public int getMaxResults()
      Description copied from interface: Query
      Returns the maximum number of results configured for this query.
      Specified by:
      getMaxResults in interface Query<T>
      Returns:
      the maximum number of results
    • startOffset

      public Query<T> startOffset(long startOffset)
      Description copied from interface: Query
      Sets the starting offset into the overall result set. Must be equal or greater than 0. Use it in combination with Query.maxResults(int) to implement pagination.
      Specified by:
      startOffset in interface Query<T>
      Specified by:
      startOffset in interface Query<T>
      Parameters:
      startOffset - the start offset
      Returns:
      this, for method chaining
    • maxResults

      public Query<T> maxResults(int maxResults)
      Description copied from interface: Query
      Sets the maximum number of results to return. Must be equal or greater than 0. When 0 is set, the execution of the query will not return any results, but will still information about the total number of hits. Use it in combination with Query.startOffset(long) to implement pagination.
      Specified by:
      maxResults in interface Query<T>
      Specified by:
      maxResults in interface Query<T>
      Parameters:
      maxResults - the maximum number of results to return
      Returns:
      this, for method chaining
    • hitCountAccuracy

      public Integer hitCountAccuracy()
      Specified by:
      hitCountAccuracy in interface Query<T>
      Returns:
      the current hitCountAccuracy if present
      See Also:
    • hitCountAccuracy

      public Query<T> hitCountAccuracy(int hitCountAccuracy)
      Description copied from interface: Query
      Limits the required accuracy of the hit count for the indexed queries to an upper-bound. Setting the hit-count-accuracy could improve the performance of queries targeting large data sets.
      Specified by:
      hitCountAccuracy in interface Query<T>
      Specified by:
      hitCountAccuracy in interface Query<T>
      Parameters:
      hitCountAccuracy - The value to apply
      Returns:
      this, for method chaining
    • local

      public Query<T> local(boolean local)
      Description copied from interface: Query
      Set the query execution scope
      Specified by:
      local in interface Query<T>
      Parameters:
      local - if true, query will be restricted to the data present in the local node, ignoring the other members of the clusters
    • isLocal

      public boolean isLocal()
    • scoreRequired

      public Query<T> scoreRequired(boolean scoreRequired)
      Specified by:
      scoreRequired in interface Query<T>
    • timeout

      public Query<T> timeout(long timeout, TimeUnit timeUnit)
      Description copied from interface: Query
      Set the timeout for this query. If the query hasn't finished processing before the timeout, a timeout will be thrown. For queries that use the index, the timeout is handled on a best effort basis, and the supplied time is rounded to the nearest millisecond.
      Specified by:
      timeout in interface Query<T>
      Specified by:
      timeout in interface Query<T>
    • entryIterator

      public <K> ClosableIteratorWithCount<EntityEntry<K,T>> entryIterator(boolean withMetadata)
      Description copied from interface: Query
      Returns a ClosableIteratorWithCount over the results, including both key and value. Close the iterator when you are done with processing the results. The query cannot use projections.
      Specified by:
      entryIterator in interface Query<T>
      Parameters:
      withMetadata - Whether the cache entry metadata needs to be retrieved
      Returns:
      the results of the query as an iterator.
    • executeStatement

      public int executeStatement()
      Description copied from interface: Query
      Executes a data modifying statement (typically a DELETE) that does not return results; instead it returns the count of affected entries. This method cannot be used to execute a SELECT.

      NOTE: Paging parameters (firstResult/maxResults) are NOT allowed.

      Specified by:
      executeStatement in interface Query<T>
      Returns:
      the number of affected (deleted) entries