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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Query.Result<R>
-
Constructor Summary
Constructors Constructor Description Query(Query<R> query)
Copy ConstructorQuery(Selectable<?>[] selects, Type<?> type, Condition condition)
Deprecated.UsenewQuery(Selectable[], Type, Condition)
insteadQuery(Selectable<? extends R> select)
Query(Selectable<? extends R> select, Condition condition)
Query(Selectable<? extends R> select, Query<?> query)
Copy ConstructorQuery(Selectable<R> select, Type<?> type, Condition condition)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addOrderBy(Function<?> orderBy)
void
addOrderBy(Function<?> orderBy, boolean ascending)
void
addOrderBy(Selectable<?> orderBy)
void
addOrderBy(Selectable<?> orderBy, boolean ascending)
void
addOrderByDescending(Function<?> orderBy)
void
addOrderByDescending(Selectable<?> orderBy)
int
countWithoutLimit()
Deprecated.Usetotal()
insteadstatic <R> Query.Result<R>
emptyResult()
Deprecated.UseQuery.Result.empty()
insteadCondition
getCondition()
List<Selectable<?>>
getGroupBy()
Condition
getHaving()
List<Join>
getJoins()
int
getLimit()
Deprecated.UsegetPageLimitOrMinusOne()
instead.int
getOffset()
Deprecated.UsegetPageOffset()
instead.List<Boolean>
getOrderByAscending()
List<Selectable<?>>
getOrderByFunctions()
int
getPageLimitOrMinusOne()
int
getPageOffset()
int
getSearchSizeCacheLimit()
int
getSearchSizeLimit()
Selectable<? extends R>
getSelectSingle()
Type<?>
getType()
boolean
isDistinct()
Join
join(Type<?> type)
Does an inner join with the given type without any join condition.Join
join(Type<?> type, Condition condition)
Does an inner join with the given type on the given join condition.Join
joinOuterLeft(Type<?> type, Condition condition)
Join
joinOuterRight(Type<?> type, Condition condition)
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))
.static Query<List<Object>>
newQuery(Selectable<?>[] selects, Type<?> type, Condition condition)
void
resetOrderBy()
List<R>
search()
Searches for items matching this query.Query.Result<R>
searchAndCountWithoutLimit()
Deprecated.UsesearchAndTotal()
insteadQuery.Result<R>
searchAndTotal()
Searches for items matching this query.R
searchSingleton()
Searches equivalently tosearch()
, but assumes that the search result has at most one element.R
searchSingletonStrict()
Searches equivalently tosearch()
, but assumes that the search result has exactly one element.R
searchUnique()
Deprecated.renamed tosearchSingleton()
.void
setCondition(Condition condition)
void
setDistinct(boolean distinct)
void
setGroupBy(Selectable<?>... groupBy)
void
setHaving(Condition having)
void
setLimit(int offset)
Deprecated.UsesetPageUnlimited(int)
instead.void
setLimit(int offset, int limit)
Deprecated.UsesetPage(int, int)
instead.void
setOrderBy(Function<?>[] orderBy, boolean[] ascending)
void
setOrderBy(Function<?> orderBy, boolean ascending)
void
setOrderBy(Selectable<?>[] orderBy, boolean[] ascending)
void
setOrderBy(Selectable<?> orderBy, boolean ascending)
void
setOrderByAndThis(Function<?> orderBy, boolean ascending)
void
setOrderByAndThis(Selectable<?> orderBy, boolean ascending)
void
setOrderByThis(boolean ascending)
void
setPage(int offset, int limit)
void
setPageUnlimited(int offset)
void
setSearchSizeCacheLimit(int searchSizeCacheLimit)
Sets the search size cache limit for this query.void
setSearchSizeLimit(int searchSizeLimit)
Sets the search size limit for this query.void
setSelect(Selectable<? extends R> select)
void
setSelects(Selectable<?>... selects)
String
toString()
int
total()
Counts the items matching this query.
-
-
-
Constructor Detail
-
Query
public Query(Selectable<? extends R> select)
-
Query
public Query(Selectable<? extends R> select, Condition condition)
-
Query
public Query(Selectable<? extends R> select, Query<?> query)
Copy Constructor
-
Query
public Query(Selectable<R> select, Type<?> type, Condition condition)
-
Query
@Deprecated public Query(Selectable<?>[] selects, Type<?> type, Condition condition)
Deprecated.UsenewQuery(Selectable[], Type, Condition)
instead
-
-
Method Detail
-
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.
-
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()
-
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
- iforderBy.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 usesetPageUnlimited(int)
instead.- Throws:
IllegalArgumentException
- if offset is a negative valueIllegalArgumentException
- if limit is a negative value- See Also:
setPageUnlimited(int)
-
setPageUnlimited
public void setPageUnlimited(int offset)
- Throws:
IllegalArgumentException
- if offset is a negative value- See Also:
setPage(int, int)
-
getSearchSizeLimit
public int getSearchSizeLimit()
- See Also:
setSearchSizeLimit(int)
-
setSearchSizeLimit
public void setSearchSizeLimit(int searchSizeLimit)
Sets the search size limit for this query.Method
search()
will fail with anIllegalStateException
as soon as the size of the result set exceeds the search size limit. Methodtotal()
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:
getSearchSizeLimit()
-
getSearchSizeCacheLimit
public int getSearchSizeCacheLimit()
- See Also:
setSearchSizeCacheLimit(int)
-
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. Methodtotal()
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:
getSearchSizeCacheLimit()
-
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 whatsearch()
would have returned for this query withsetPageUnlimited(int)
reset set to(0)
.
-
searchAndTotal
public Query.Result<R> searchAndTotal()
Searches for items matching this query.Returns a
Query.Result
containing thedata
and thetotal
. Thedata
is equal to whatsearch()
would have returned for this query. Thetotal
is equal to whattotal()
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 tosearch()
, 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 resultsize
is exactly one.- Throws:
IllegalArgumentException
- if the search result size is greater than one.- See Also:
searchSingletonStrict()
,Type.searchSingleton(Condition)
-
searchSingletonStrict
public R searchSingletonStrict()
Searches equivalently tosearch()
, 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:
searchSingleton()
,Type.searchSingletonStrict(Condition)
-
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.UsegetPageOffset()
instead.
-
getLimit
@Deprecated public int getLimit()
Deprecated.UsegetPageLimitOrMinusOne()
instead.
-
setLimit
@Deprecated public void setLimit(int offset, int limit)
Deprecated.UsesetPage(int, int)
instead.
-
setLimit
@Deprecated public void setLimit(int offset)
Deprecated.UsesetPageUnlimited(int)
instead.
-
searchAndCountWithoutLimit
@Deprecated public Query.Result<R> searchAndCountWithoutLimit()
Deprecated.UsesearchAndTotal()
instead
-
countWithoutLimit
@Deprecated public int countWithoutLimit()
Deprecated.Usetotal()
instead
-
searchUnique
@Deprecated public R searchUnique()
Deprecated.renamed tosearchSingleton()
.
-
emptyResult
@Deprecated public static <R> Query.Result<R> emptyResult()
Deprecated.UseQuery.Result.empty()
instead
-
-