Class Query<R>

java.lang.Object
com.exedio.cope.Query<R>
All Implemented Interfaces:
Serializable

public final class Query<R> extends Object implements Serializable
See Also:
  • Constructor Details

  • Method Details

    • newQuery

      public static Query<List<Object>> newQuery(Selectable<?>[] selects, Type<?> type, Condition condition)
    • getSelectSingle

      public Selectable<? extends R> getSelectSingle()
    • setSelect

      public void setSelect(Selectable<? extends R> select)
    • setSelects

      public void setSelects(Selectable<?>... selects)
    • isDistinct

      public boolean isDistinct()
    • setDistinct

      public void setDistinct(boolean distinct)
    • getType

      public Type<?> getType()
    • setCondition

      public void setCondition(Condition condition)
    • getCondition

      public Condition getCondition()
    • narrow

      public void narrow(Condition narrowingCondition)
      If there is already a condition set for this query, this is equivalent to {@link #setCondition(Condition) setCondition}({@link #getCondition()}.{@link Condition#and(Condition) and}(narrowingCondition)).
    • join

      public Join join(Type<?> type)
      Does an inner join with the given type without any join condition.
    • join

      public Join join(Type<?> type, Condition condition)
      Does an inner join with the given type on the given join condition.
    • joinOuterLeft

      public Join joinOuterLeft(Type<?> type, Condition condition)
    • joinOuterRight

      public Join joinOuterRight(Type<?> type, Condition condition)
    • getJoins

      public List<Join> getJoins()
    • getGroupBy

      public List<Selectable<?>> getGroupBy()
    • setGroupBy

      public void setGroupBy(Selectable<?>... groupBy)
    • setHaving

      public void setHaving(Condition having)
    • getHaving

      public Condition getHaving()
    • getOrderByFunctions

      public List<Selectable<?>> getOrderByFunctions()
    • getOrderByAscending

      public List<Boolean> getOrderByAscending()
    • setOrderByThis

      public void setOrderByThis(boolean ascending)
    • setOrderBy

      public void setOrderBy(Selectable<?> orderBy, boolean ascending)
    • setOrderByAndThis

      public void setOrderByAndThis(Selectable<?> orderBy, boolean ascending)
    • setOrderBy

      public void setOrderBy(Selectable<?>[] orderBy, boolean[] ascending)
      Throws:
      IllegalArgumentException - if orderBy.length!=ascending.length
    • addOrderBy

      public void addOrderBy(Selectable<?> orderBy)
    • addOrderByDescending

      public void addOrderByDescending(Selectable<?> orderBy)
    • addOrderBy

      public void addOrderBy(Selectable<?> orderBy, boolean ascending)
    • resetOrderBy

      public void resetOrderBy()
    • getPageOffset

      public int getPageOffset()
    • getPageLimitOrMinusOne

      public int getPageLimitOrMinusOne()
    • setPage

      public void setPage(int offset, int limit)
      Parameters:
      limit - the maximum number of items to be found. For specifying offset but no limit use setPageUnlimited(int) instead.
      Throws:
      IllegalArgumentException - if offset is a negative value
      IllegalArgumentException - if limit is a negative value
      See Also:
    • setPageUnlimited

      public void setPageUnlimited(int offset)
      Throws:
      IllegalArgumentException - if offset is a negative value
      See Also:
    • getSearchSizeLimit

      public int getSearchSizeLimit()
      See Also:
    • setSearchSizeLimit

      public void setSearchSizeLimit(int searchSizeLimit)
      Sets the search size limit for this query.

      Method search() will fail with an IllegalStateException as soon as the size of the result set exceeds the search size limit. Method total() is not affected by this limit.

      Setting the search size limit does not guarantee, that search() actually fails when exceeding the limit. But it is guaranteed, that it does not fail when not exceeding the limit. In particular, it may not fail, if the result is fetched from the query cache.

      If search size limit is not set, it defaults to ConnectProperties.getQuerySearchSizeLimit().

      See Also:
    • getSearchSizeCacheLimit

      public int getSearchSizeCacheLimit()
      See Also:
    • setSearchSizeCacheLimit

      public void setSearchSizeCacheLimit(int searchSizeCacheLimit)
      Sets the search size cache limit for this query.

      Results of method search() will not be considered for inclusion into query cache as soon as the size of the result set exceeds the search size cache limit. Method total() is not affected by this limit.

      Setting the search size cache limit does not guarantee, that search() is not satisfied from the cache.

      If search size cache limit is not set, it defaults to ConnectProperties.getQueryCacheSizeLimit().

      See Also:
    • search

      public List<R> search()
      Searches for items matching this query.

      Returns an unmodifiable collection. Any attempts to modify the returned collection, whether direct or via its iterator, result in an UnsupportedOperationException.

    • total

      public int total()
      Counts the items matching this query.

      Returns the size of what search() would have returned for this query with setPageUnlimited(int) reset set to (0).

    • searchAndTotal

      public Query.Result<R> searchAndTotal()
      Searches for items matching this query.

      Returns a Query.Result containing the data and the total. The data is equal to what search() would have returned for this query. The total is equal to what total() would have returned for this query.

      This method does it's best to avoid issuing two queries for searching and totaling.

    • searchSingleton

      public R searchSingleton()
      Searches equivalently to search(), but assumes that the search result has at most one element.

      Returns null, if the search result is empty, returns the only element of the search result, if the result size is exactly one.

      Throws:
      IllegalArgumentException - if the search result size is greater than one.
      See Also:
    • searchSingletonStrict

      public R searchSingletonStrict()
      Searches equivalently to search(), but assumes that the search result has exactly one element.

      Returns the only element of the search result, if the result size is exactly one.

      Throws:
      IllegalArgumentException - if the search result size is not exactly one.
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setOrderBy

      public void setOrderBy(Function<?> orderBy, boolean ascending)
    • setOrderByAndThis

      public void setOrderByAndThis(Function<?> orderBy, boolean ascending)
    • setOrderBy

      public void setOrderBy(Function<?>[] orderBy, boolean[] ascending)
    • addOrderBy

      public void addOrderBy(Function<?> orderBy)
    • addOrderByDescending

      public void addOrderByDescending(Function<?> orderBy)
    • addOrderBy

      public void addOrderBy(Function<?> orderBy, boolean ascending)
    • getOffset

      @Deprecated public int getOffset()
      Deprecated.
      Use getPageOffset() instead.
    • getLimit

      @Deprecated public int getLimit()
      Deprecated.
    • setLimit

      @Deprecated public void setLimit(int offset, int limit)
      Deprecated.
      Use setPage(int, int) instead.
    • setLimit

      @Deprecated public void setLimit(int offset)
      Deprecated.
    • searchAndCountWithoutLimit

      @Deprecated public Query.Result<R> searchAndCountWithoutLimit()
      Deprecated.
      Use searchAndTotal() instead
    • countWithoutLimit

      @Deprecated public int countWithoutLimit()
      Deprecated.
      Use total() instead
    • searchUnique

      @Deprecated public R searchUnique()
      Deprecated.
      renamed to searchSingleton().
    • emptyResult

      @Deprecated public static <R> Query.Result<R> emptyResult()
      Deprecated.