Class AbstractMongodbQuery<K,​Q extends AbstractMongodbQuery<K,​Q>>

  • Type Parameters:
    K - result type
    Q - concrete subtype
    All Implemented Interfaces:
    Fetchable<K>, FilteredClause<Q>, SimpleQuery<Q>
    Direct Known Subclasses:
    MorphiaQuery

    public abstract class AbstractMongodbQuery<K,​Q extends AbstractMongodbQuery<K,​Q>>
    extends java.lang.Object
    implements SimpleQuery<Q>, Fetchable<K>
    AbstractMongodbQuery provides a base class for general Querydsl query implementation with a pluggable DBObject to Bean transformation
    Author:
    laimw
    • Constructor Detail

      • AbstractMongodbQuery

        public AbstractMongodbQuery​(com.mongodb.DBCollection collection,
                                    java.util.function.Function<com.mongodb.DBObject,​K> transformer,
                                    MongodbSerializer serializer)
        Create a new MongodbQuery instance
        Parameters:
        collection - collection
        transformer - result transformer
        serializer - serializer
    • Method Detail

      • join

        public <T> JoinBuilder<Q,​K,​T> join​(Path<T> ref,
                                                       Path<T> target)
        Define a join
        Parameters:
        ref - reference
        target - join target
        Returns:
        join builder
      • join

        public <T> JoinBuilder<Q,​K,​T> join​(CollectionPathBase<?,​T,​?> ref,
                                                       Path<T> target)
        Define a join
        Parameters:
        ref - reference
        target - join target
        Returns:
        join builder
      • anyEmbedded

        public <T> AnyEmbeddedBuilder<Q,​K> anyEmbedded​(Path<? extends java.util.Collection<T>> collection,
                                                             Path<T> target)
        Define a constraint for an embedded object
        Parameters:
        collection - collection
        target - target
        Returns:
        builder
      • getCollection

        protected abstract com.mongodb.DBCollection getCollection​(java.lang.Class<?> type)
      • getIds

        protected java.util.List<java.lang.Object> getIds​(java.lang.Class<?> targetType,
                                                          Predicate condition)
      • limit

        public Q limit​(long limit)
        Specified by:
        limit in interface SimpleQuery<K>
      • iterate

        public com.mysema.commons.lang.CloseableIterator<K> iterate​(Path<?>... paths)
        Iterate with the specific fields
        Parameters:
        paths - fields to return
        Returns:
        iterator
      • iterate

        public com.mysema.commons.lang.CloseableIterator<K> iterate()
        Specified by:
        iterate in interface Fetchable<K>
      • fetch

        public java.util.List<K> fetch​(Path<?>... paths)
        Fetch with the specific fields
        Parameters:
        paths - fields to return
        Returns:
        results
      • fetch

        public java.util.List<K> fetch()
        Specified by:
        fetch in interface Fetchable<K>
      • createCursor

        protected com.mongodb.DBCursor createCursor()
      • createCursor

        protected com.mongodb.DBCursor createCursor​(com.mongodb.DBCollection collection,
                                                    @Nullable
                                                    @Nullable Predicate where,
                                                    Expression<?> projection,
                                                    QueryModifiers modifiers,
                                                    java.util.List<OrderSpecifier<?>> orderBy)
      • fetchFirst

        public K fetchFirst​(Path<?>... paths)
        Fetch first with the specific fields
        Parameters:
        paths - fields to return
        Returns:
        first result
      • fetchOne

        public K fetchOne​(Path<?>... paths)
        Fetch one with the specific fields
        Parameters:
        paths - fields to return
        Returns:
        first result
      • fetchResults

        public QueryResults<K> fetchResults​(Path<?>... paths)
        Fetch results with the specific fields
        Parameters:
        paths - fields to return
        Returns:
        results
      • setReadPreference

        public void setReadPreference​(com.mongodb.ReadPreference readPreference)
        Sets the read preference for this query
        Parameters:
        readPreference - read preference
      • asDBObject

        public com.mongodb.DBObject asDBObject()
        Get the where definition as a DBObject instance
        Returns:
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object