com.mysema.query.mongodb
Class MongodbQuery<K>

java.lang.Object
  extended by com.mysema.query.mongodb.MongodbQuery<K>
Type Parameters:
K -
All Implemented Interfaces:
FilteredClause<MongodbQuery<K>>, SimpleProjectable<K>, SimpleQuery<MongodbQuery<K>>
Direct Known Subclasses:
MorphiaQuery

public abstract class MongodbQuery<K>
extends Object
implements SimpleQuery<MongodbQuery<K>>, SimpleProjectable<K>

MongodbQuery provides a general Querydsl query implementation with a pluugable DBObject to Bean transformation

Author:
laimw

Constructor Summary
MongodbQuery(com.mongodb.DBCollection collection, com.google.common.base.Function<com.mongodb.DBObject,K> transformer, MongodbSerializer serializer)
           
 
Method Summary
<T> AnyEmbeddedBuilder<K>
anyEmbedded(Path<? extends Collection<T>> collection, Path<T> target)
           
 long count()
          Get the count of matched elements
 long countDistinct()
          Get the count of distinct matched elements
protected  com.mongodb.DBCursor createCursor()
           
protected  com.mongodb.DBCursor createCursor(com.mongodb.DBCollection collection, Predicate where, QueryModifiers modifiers, List<OrderSpecifier<?>> orderBy)
           
protected  Predicate createFilter(QueryMetadata metadata)
           
protected  Predicate createJoinFilter(QueryMetadata metadata)
           
 MongodbQuery<K> distinct()
          Set the Query to return distinct results
 boolean exists()
           
protected abstract  com.mongodb.DBCollection getCollection(Class<?> type)
           
protected  List<Object> getIds(Class<?> targetType, Predicate condition)
           
 com.mysema.commons.lang.CloseableIterator<K> iterate()
          Get the projection as a typed closeable Iterator
 com.mysema.commons.lang.CloseableIterator<K> iterateDistinct()
          Get the projection as a typed closeable Iterator with distinct elements
<T> JoinBuilder<K,T>
join(Path<T> ref, Path<T> target)
           
 MongodbQuery<K> limit(long limit)
          Defines the limit / max results for the query results
 List<K> list()
          Get the projection as a typed List
 List<K> listDistinct()
          Get the projection as a typed List with distinct elements
 SearchResults<K> listDistinctResults()
          Get the projection in SearchResults form with distinct element
 SearchResults<K> listResults()
          Get the projection in SearchResults form
 boolean notExists()
           
 MongodbQuery<K> offset(long offset)
          Defines the offset for the query results
 MongodbQuery<K> orderBy(OrderSpecifier<?>... o)
          Defines the order expressions
 MongodbQuery<K> restrict(QueryModifiers modifiers)
          Defines both limit and offset of the query results
<T> MongodbQuery<K>
set(ParamExpression<T> param, T value)
          Set the given parameter to the given value
 K singleResult()
          Get the projection as a single result or null if no result is found
 String toString()
           
 K uniqueResult()
          Get the projection as a unique result or null if no result is found
 MongodbQuery<K> where(Predicate... e)
          Adds the given filter conditions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MongodbQuery

public MongodbQuery(com.mongodb.DBCollection collection,
                    com.google.common.base.Function<com.mongodb.DBObject,K> transformer,
                    MongodbSerializer serializer)
Method Detail

join

public <T> JoinBuilder<K,T> join(Path<T> ref,
                                 Path<T> target)

anyEmbedded

public <T> AnyEmbeddedBuilder<K> anyEmbedded(Path<? extends Collection<T>> collection,
                                             Path<T> target)

getCollection

protected abstract com.mongodb.DBCollection getCollection(Class<?> type)

exists

public boolean exists()
Specified by:
exists in interface SimpleProjectable<K>
Returns:
true, if rows matching the given criteria exist, otherwise false

createFilter

@Nullable
protected Predicate createFilter(QueryMetadata metadata)

createJoinFilter

@Nullable
protected Predicate createJoinFilter(QueryMetadata metadata)

getIds

protected List<Object> getIds(Class<?> targetType,
                              Predicate condition)

notExists

public boolean notExists()
Specified by:
notExists in interface SimpleProjectable<K>
Returns:
true, if no rows matching the given criteria exist, otherwise false

distinct

public MongodbQuery<K> distinct()
Description copied from interface: SimpleQuery
Set the Query to return distinct results

Specified by:
distinct in interface SimpleQuery<MongodbQuery<K>>
Returns:

where

public MongodbQuery<K> where(Predicate... e)
Description copied from interface: FilteredClause
Adds the given filter conditions

Specified by:
where in interface FilteredClause<MongodbQuery<K>>
Parameters:
e - filter conditions to be added
Returns:

limit

public MongodbQuery<K> limit(long limit)
Description copied from interface: SimpleQuery
Defines the limit / max results for the query results

Specified by:
limit in interface SimpleQuery<MongodbQuery<K>>
Returns:

offset

public MongodbQuery<K> offset(long offset)
Description copied from interface: SimpleQuery
Defines the offset for the query results

Specified by:
offset in interface SimpleQuery<MongodbQuery<K>>
Returns:

restrict

public MongodbQuery<K> restrict(QueryModifiers modifiers)
Description copied from interface: SimpleQuery
Defines both limit and offset of the query results

Specified by:
restrict in interface SimpleQuery<MongodbQuery<K>>
Returns:

orderBy

public MongodbQuery<K> orderBy(OrderSpecifier<?>... o)
Description copied from interface: SimpleQuery
Defines the order expressions

Specified by:
orderBy in interface SimpleQuery<MongodbQuery<K>>
Returns:

set

public <T> MongodbQuery<K> set(ParamExpression<T> param,
                               T value)
Description copied from interface: SimpleQuery
Set the given parameter to the given value

Specified by:
set in interface SimpleQuery<MongodbQuery<K>>
Returns:

iterate

public com.mysema.commons.lang.CloseableIterator<K> iterate()
Description copied from interface: SimpleProjectable
Get the projection as a typed closeable Iterator

Specified by:
iterate in interface SimpleProjectable<K>
Returns:

iterateDistinct

public com.mysema.commons.lang.CloseableIterator<K> iterateDistinct()
Description copied from interface: SimpleProjectable
Get the projection as a typed closeable Iterator with distinct elements

Specified by:
iterateDistinct in interface SimpleProjectable<K>
Returns:

list

public List<K> list()
Description copied from interface: SimpleProjectable
Get the projection as a typed List

Specified by:
list in interface SimpleProjectable<K>
Returns:

createCursor

protected com.mongodb.DBCursor createCursor()

createCursor

protected com.mongodb.DBCursor createCursor(com.mongodb.DBCollection collection,
                                            @Nullable
                                            Predicate where,
                                            QueryModifiers modifiers,
                                            List<OrderSpecifier<?>> orderBy)

listDistinct

public List<K> listDistinct()
Description copied from interface: SimpleProjectable
Get the projection as a typed List with distinct elements

Specified by:
listDistinct in interface SimpleProjectable<K>
Returns:

singleResult

public K singleResult()
Description copied from interface: SimpleProjectable
Get the projection as a single result or null if no result is found

for multiple results only the first one is returned

Specified by:
singleResult in interface SimpleProjectable<K>
Returns:

uniqueResult

public K uniqueResult()
Description copied from interface: SimpleProjectable
Get the projection as a unique result or null if no result is found

Specified by:
uniqueResult in interface SimpleProjectable<K>
Returns:

listResults

public SearchResults<K> listResults()
Description copied from interface: SimpleProjectable
Get the projection in SearchResults form

Specified by:
listResults in interface SimpleProjectable<K>
Returns:

listDistinctResults

public SearchResults<K> listDistinctResults()
Description copied from interface: SimpleProjectable
Get the projection in SearchResults form with distinct element

Specified by:
listDistinctResults in interface SimpleProjectable<K>
Returns:

count

public long count()
Description copied from interface: SimpleProjectable
Get the count of matched elements

Specified by:
count in interface SimpleProjectable<K>
Returns:

countDistinct

public long countDistinct()
Description copied from interface: SimpleProjectable
Get the count of distinct matched elements

Specified by:
countDistinct in interface SimpleProjectable<K>
Returns:

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2007-2012 Mysema Ltd. All Rights Reserved.