Package org.mongojack

Class DbReferenceManager


  • public class DbReferenceManager
    extends Object
    • Constructor Detail

      • DbReferenceManager

        public DbReferenceManager​(com.mongodb.client.MongoClient mongoClient,
                                  com.fasterxml.jackson.databind.ObjectMapper objectMapper,
                                  String defaultDatabaseName,
                                  org.bson.UuidRepresentation uuidRepresentation)
      • DbReferenceManager

        public DbReferenceManager​(com.mongodb.client.MongoClient mongoClient,
                                  String defaultDatabaseName,
                                  org.bson.UuidRepresentation uuidRepresentation)
    • Method Detail

      • getReferenceCollection

        public <CT> JacksonMongoCollection<CT> getReferenceCollection​(String databaseName,
                                                                      String collectionName,
                                                                      Class<CT> valueClass)
        Get a collection for loading a reference of the given type
        Type Parameters:
        CT - The type of the values in the collection
        Parameters:
        databaseName - Name of the DB that holds the collection
        collectionName - The name of the collection
        valueClass - The type of the values in the collection
        Returns:
        The collection
      • getReferenceCollection

        public <CT> JacksonMongoCollection<CT> getReferenceCollection​(JacksonCollectionKey<CT> collectionKey)
        Get a collection for loading a reference of the given type
        Type Parameters:
        CT - The type of values in the collection
        Parameters:
        collectionKey - The key for the collection
        Returns:
        The collection
      • fetch

        public <R,​RK> R fetch​(DBRef<R,​RK> ref)
        Fetches the underlying value for a single DBRef.
        Type Parameters:
        R - The type the ref points to.
        RK - The type of ID the ref points to
        Parameters:
        ref - The reference
        Returns:
        A ref, or null if the underlying value is nto found
      • fetch

        public <R,​RK> R fetch​(DBRef<R,​RK> ref,
                                    org.bson.conversions.Bson fields)
        Fetches the underlying value for a single DBRef.
        Type Parameters:
        R - The type the ref points to.
        RK - The type of ID the ref points to
        Parameters:
        ref - The reference
        fields - A Bson representing the projection to be used.
        Returns:
        A ref, or null if the underlying value is nto found
      • fetch

        public <R,​RK> List<R> fetch​(Collection<DBRef<R,​RK>> refs)
        Fetch a refs of dbrefs. This is more efficient than fetching one at a time.
        Type Parameters:
        R - The type of the reference
        RK - The identifier type
        Parameters:
        refs - the refs to fetch
        Returns:
        The refs of referenced objcets
      • fetch

        public <R,​RK> List<R> fetch​(Collection<DBRef<R,​RK>> refs,
                                          org.bson.conversions.Bson fields)
        Fetch a refs of dbrefs. This is more efficient than fetching one at a time.
        Type Parameters:
        R - The type of the reference
        RK - The identifier type
        Parameters:
        refs - the refs to fetch
        fields - The fields to retrieve for each of the documents
        Returns:
        The refs of referenced objects
      • registerCollection

        public void registerCollection​(JacksonMongoCollection<?> collection)
        Register a collection so that it will be used (as opposed to an internally built one) when retrieving references.
        Parameters:
        collection - The collection to register