Class SpringDataMongodbQuery<T>

java.lang.Object
com.querydsl.mongodb.document.AbstractMongodbQuery<Q>
org.springframework.data.mongodb.repository.support.SpringDataMongodbQuery<T>
All Implemented Interfaces:
com.querydsl.core.Fetchable<T>, com.querydsl.core.FilteredClause<SpringDataMongodbQuery<T>>, com.querydsl.core.SimpleQuery<SpringDataMongodbQuery<T>>

public class SpringDataMongodbQuery<T> extends com.querydsl.mongodb.document.AbstractMongodbQuery<Q> implements com.querydsl.core.Fetchable<T>
Spring Data specific simple Fetchable Query implementation.
Author:
Oliver Gierke, Mark Paluch, Christoph Strobl
  • Constructor Summary

    Constructors
    Constructor
    Description
    SpringDataMongodbQuery(MongoOperations operations, Class<? extends T> type)
    Creates a new SpringDataMongodbQuery.
    SpringDataMongodbQuery(MongoOperations operations, Class<? extends T> type, String collectionName)
    Creates a new SpringDataMongodbQuery to query the given collection.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.bson.Document
    Get the where definition as a Document instance
    protected Query
     
    protected Query
    createQuery(com.querydsl.core.types.Predicate filter, com.querydsl.core.types.Expression<?> projection, com.querydsl.core.QueryModifiers modifiers, List<com.querydsl.core.types.OrderSpecifier<?>> orderBy)
     
    protected org.bson.Document
    createSort(List<com.querydsl.core.types.OrderSpecifier<?>> orderSpecifiers)
    Compute the sort Document from the given list of order specifiers.
     
    long
     
     
     
    org.springframework.data.domain.Page<T>
    fetchPage(org.springframework.data.domain.Pageable pageable)
    Fetch a Page.
    com.querydsl.core.QueryResults<T>
     
    protected List<Object>
    getIds(Class<?> targetType, com.querydsl.core.types.Predicate condition)
    Fetch the list of ids matching a given condition.
    com.mysema.commons.lang.CloseableIterator<T>
     
    org.springframework.data.domain.Window<T>
    scroll(org.springframework.data.domain.ScrollPosition scrollPosition)
     
     
    Obtain the Mongo Shell json query representation.
    toJson(org.bson.json.JsonWriterSettings settings)
    Obtain the json query representation applying given settings.
    Returns the Mongo Shell representation of the query.

    Methods inherited from class com.querydsl.mongodb.document.AbstractMongodbQuery

    anyEmbedded, createFilter, createJoinFilter, createProjection, createQuery, distinct, getQueryMixin, getReadPreference, getSerializer, join, join, limit, offset, orderBy, orderBy, restrict, set, setReadPreference, where, where

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SpringDataMongodbQuery

      public SpringDataMongodbQuery(MongoOperations operations, Class<? extends T> type)
      Creates a new SpringDataMongodbQuery.
      Parameters:
      operations - must not be null.
      type - must not be null.
    • SpringDataMongodbQuery

      public SpringDataMongodbQuery(MongoOperations operations, Class<? extends T> type, String collectionName)
      Creates a new SpringDataMongodbQuery to query the given collection.
      Parameters:
      operations - must not be null.
      type - must not be null.
      collectionName - must not be null or empty.
  • Method Details

    • iterate

      public com.mysema.commons.lang.CloseableIterator<T> iterate()
      Specified by:
      iterate in interface com.querydsl.core.Fetchable<T>
    • scroll

      public org.springframework.data.domain.Window<T> scroll(org.springframework.data.domain.ScrollPosition scrollPosition)
    • stream

      public Stream<T> stream()
      Specified by:
      stream in interface com.querydsl.core.Fetchable<T>
    • fetch

      public List<T> fetch()
      Specified by:
      fetch in interface com.querydsl.core.Fetchable<T>
    • fetchPage

      public org.springframework.data.domain.Page<T> fetchPage(org.springframework.data.domain.Pageable pageable)
      Fetch a Page.
      Parameters:
      pageable -
      Returns:
    • fetchFirst

      public T fetchFirst()
      Specified by:
      fetchFirst in interface com.querydsl.core.Fetchable<T>
    • fetchOne

      public T fetchOne()
      Specified by:
      fetchOne in interface com.querydsl.core.Fetchable<T>
    • fetchResults

      public com.querydsl.core.QueryResults<T> fetchResults()
      Specified by:
      fetchResults in interface com.querydsl.core.Fetchable<T>
    • fetchCount

      public long fetchCount()
      Specified by:
      fetchCount in interface com.querydsl.core.Fetchable<T>
    • createQuery

      protected Query createQuery()
    • createQuery

      protected Query createQuery(@Nullable com.querydsl.core.types.Predicate filter, @Nullable com.querydsl.core.types.Expression<?> projection, com.querydsl.core.QueryModifiers modifiers, List<com.querydsl.core.types.OrderSpecifier<?>> orderBy)
    • getIds

      protected List<Object> getIds(Class<?> targetType, com.querydsl.core.types.Predicate condition)
      Fetch the list of ids matching a given condition.
      Specified by:
      getIds in class com.querydsl.mongodb.document.AbstractMongodbQuery<SpringDataMongodbQuery<T>>
      Parameters:
      targetType - must not be null.
      condition - must not be null.
      Returns:
      empty List if none found.
    • toString

      public String toString()
      Returns the Mongo Shell representation of the query.
      The following query
      
       where(p.lastname.eq("Matthews")).orderBy(p.firstname.asc()).offset(1).limit(5);
       
      results in
      
       find({"lastname" : "Matthews"}).sort({"firstname" : 1}).skip(1).limit(5)
       
      Note that encoding to String may fail when using data types that cannot be encoded or DBRef's without an identifier.
      Overrides:
      toString in class com.querydsl.mongodb.document.AbstractMongodbQuery<Q extends org.springframework.data.mongodb.repository.support.SpringDataMongodbQuerySupport<Q>>
      Returns:
      never null.
    • asDocument

      public org.bson.Document asDocument()
      Get the where definition as a Document instance
      Overrides:
      asDocument in class com.querydsl.mongodb.document.AbstractMongodbQuery<Q extends org.springframework.data.mongodb.repository.support.SpringDataMongodbQuerySupport<Q>>
      Returns:
    • toJson

      public String toJson()
      Obtain the Mongo Shell json query representation.
      Returns:
      never null.
    • toJson

      public String toJson(org.bson.json.JsonWriterSettings settings)
      Obtain the json query representation applying given settings.
      Parameters:
      settings - must not be null.
      Returns:
      never null.
    • createSort

      protected org.bson.Document createSort(List<com.querydsl.core.types.OrderSpecifier<?>> orderSpecifiers)
      Compute the sort Document from the given list of order specifiers.
      Parameters:
      orderSpecifiers - can be null.
      Returns:
      an empty Document if predicate is null.
      See Also:
      • MongodbDocumentSerializer.toSort(List)