exedio cope

com.exedio.cope
Class Query<R>

java.lang.Object
  extended by com.exedio.cope.Query<R>

public final class Query<R>
extends Object


Nested Class Summary
static class Query.Result<R>
           
 
Constructor Summary
Query(Selectable[] selects, Type type, Condition condition)
           
Query(Selectable<? extends R> select)
           
Query(Selectable<? extends R> select, Condition condition)
           
Query(Selectable<R> select, Type type, Condition condition)
           
 
Method Summary
 void addOrderBy(Function orderBy)
           
 void addOrderBy(Function orderBy, boolean ascending)
           
 void addOrderByDescending(Function orderBy)
           
 int countWithoutLimit()
          Deprecated. Use total() instead
static
<R> Query.Result<R>
emptyResult()
           
 Condition getCondition()
           
 List<Join> getJoins()
           
 List<Boolean> getOrderByAscending()
           
 List<Function> getOrderByFunctions()
           
 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 setCondition(getCondition().
 void resetOrderBy()
           
 List<R> search()
          Searches for items matching this query.
 Query.Result<R> searchAndCountWithoutLimit()
          Deprecated. Use searchAndTotal() instead
 Query.Result<R> searchAndTotal()
          Searches for items matching this query.
 R searchSingleton()
          Searches equivalently to search(), but assumes that the search result has at most one element.
 R searchSingletonStrict()
          Searches equivalently to search(), but assumes that the search result has exactly one element.
 R searchUnique()
          Deprecated. renamed to searchSingleton().
 void setCondition(Condition condition)
           
 void setDistinct(boolean distinct)
           
 void setLimit(int offset)
           
 void setLimit(int offset, int limit)
           
 void setOrderBy(Function[] orderBy, boolean[] ascending)
           
 void setOrderBy(Function orderBy, boolean ascending)
           
 void setOrderByAndThis(Function orderBy, boolean ascending)
           
 void setOrderByThis(boolean ascending)
           
 void setSelects(Selectable... selects)
           
 String toString()
           
 int total()
          Counts the items matching this query.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Query

public Query(Selectable<? extends R> select)

Query

public Query(Selectable<? extends R> select,
             Condition condition)

Query

public Query(Selectable<R> select,
             Type type,
             Condition condition)

Query

public Query(Selectable[] selects,
             Type type,
             Condition condition)
Method Detail

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 setCondition(getCondition().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()

getOrderByFunctions

public List<Function> getOrderByFunctions()

getOrderByAscending

public List<Boolean> getOrderByAscending()

setOrderByThis

public void setOrderByThis(boolean ascending)

setOrderBy

public void setOrderBy(Function orderBy,
                       boolean ascending)

setOrderByAndThis

public void setOrderByAndThis(Function orderBy,
                              boolean ascending)

setOrderBy

public void setOrderBy(Function[] orderBy,
                       boolean[] ascending)
Throws:
IllegalArgumentException - if orderBy.length!=ascending.length

addOrderBy

public void addOrderBy(Function orderBy)

addOrderByDescending

public void addOrderByDescending(Function orderBy)

addOrderBy

public void addOrderBy(Function orderBy,
                       boolean ascending)

resetOrderBy

public void resetOrderBy()

setLimit

public void setLimit(int offset,
                     int limit)
Parameters:
limit - the maximum number of items to be found.
Throws:
IllegalArgumentException - if offset is a negative value
IllegalArgumentException - if limit is a negative value
See Also:
setLimit(int)

setLimit

public void setLimit(int offset)
Throws:
IllegalArgumentException - if offset is a negative value
See Also:
setLimit(int, int)

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 setLimit(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.


emptyResult

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

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(), Type.searchSingleton(Condition)

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:
searchSingleton(), Type.searchSingletonStrict(Condition)

toString

public String toString()
Overrides:
toString in class Object

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().


Cope with
Object
Persistence

SourceForge.net LogoCopyright © 2004-2008 exedio Gesellschaft für Softwareentwicklung mbH. All rights reserved.
svn.12752 build.5319 20090312135114