Package dev.morphia

Interface AdvancedDatastore

  • All Superinterfaces:
    Datastore
    All Known Implementing Classes:
    DatastoreImpl

    public interface AdvancedDatastore
    extends Datastore
    This interface exposes advanced Datastore features, like interacting with DBObject and low-level options. It implements matching methods from the Datastore interface but with a specified kind (collection name), or raw types (DBObject).
    Author:
    ScottHernandez
    • Method Detail

      • getDecoderFact

        @Deprecated
        com.mongodb.DBDecoderFactory getDecoderFact()
        Deprecated.
        unused in 2.0 and will be removed
        Returns the DBDecoderFactory used by this Datastore
        Returns:
        the decoder factory
        See Also:
        DBDecoderFactory
        Developer note. This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • setDecoderFact

        @Deprecated
        void setDecoderFact​(com.mongodb.DBDecoderFactory fact)
        Deprecated.
        unused in 2.0 and will be removed
        Sets the DBDecoderFactory to use in this Datastore
        Parameters:
        fact - the DBDecoderFactory to use
        Developer note. This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • createAggregation

        AggregationPipeline createAggregation​(java.lang.String collection,
                                              java.lang.Class<?> clazz)
        Returns an AggregationPipeline bound to the given collection and class.
        Parameters:
        collection - the collection to query
        clazz - The class to create aggregation against
        Returns:
        the aggregation pipeline
      • createQuery

        @Deprecated
        <T> Query<T> createQuery​(java.lang.String collection,
                                 java.lang.Class<T> clazz)
        Deprecated.
        this feature is being removed. no replacement is planned. see issue #1331
        Type Parameters:
        T - The type of the entity
        Parameters:
        collection - the collection to query
        clazz - the class of objects to be returned
        Returns:
        Query for the specified class clazz
      • createQuery

        <T> Query<T> createQuery​(java.lang.Class<T> clazz,
                                 com.mongodb.DBObject q)
        Type Parameters:
        T - The type of the entity
        Parameters:
        clazz - the class of objects to be returned
        q - the query which will be passed to a QueryFactory
        Returns:
        Query for the specified class clazz
      • createQuery

        @Deprecated
        <T> Query<T> createQuery​(java.lang.String collection,
                                 java.lang.Class<T> clazz,
                                 com.mongodb.DBObject q)
        Deprecated.
        this feature is being removed. no replacement is planned. see issue #1331
        Type Parameters:
        T - The type of the entity
        Parameters:
        collection - the collection to query
        clazz - the class of objects to be returned
        q - the query which will be passed to a QueryFactory
        Returns:
        Query for the specified class clazz
      • createRef

        <T,​V> com.mongodb.DBRef createRef​(java.lang.Class<T> clazz,
                                                V id)
        Creates a reference to the entity (using the current DB -can be null-, the collectionName, and id)
        Type Parameters:
        T - The type of the entity
        V - The type of the ID value
        Parameters:
        clazz - The type of the entity
        id - The ID value of the entity
        Returns:
        the DBRef for the entity
      • createRef

        <T> com.mongodb.DBRef createRef​(T entity)
        Creates a reference to the entity (using the current DB -can be null-, the collectionName, and id)
        Type Parameters:
        T - The type of the entity
        Parameters:
        entity - the entity to create a DBRef for
        Returns:
        the DBRef for the entity
      • createUpdateOperations

        <T> UpdateOperations<T> createUpdateOperations​(java.lang.Class<T> type,
                                                       com.mongodb.DBObject ops)
        Creates an UpdateOperations instance for the given type.
        Type Parameters:
        T - The type of the entity
        Parameters:
        type - The type of the entity
        ops - The operations to perform
        Returns:
        the UpdateOperations instance
      • delete

        @Deprecated
        <T,​V> com.mongodb.WriteResult delete​(java.lang.String kind,
                                                   java.lang.Class<T> clazz,
                                                   V id)
        Deprecated.
        Deletes an entity of the given type T, with the given id, from the collection with the name in the kind param. Validates the id, checking it's the correct type for an ID for entities of type T. The entity type clazz is used only for validation, not for filtering, therefore if you have entities of different types in the same collection ( kind), this method will delete any entity with the given id, regardless of its type.
        Type Parameters:
        T - the entity type
        V - is the type of the ID, for example ObjectId
        Parameters:
        kind - the collection name
        clazz - the Class of the entity to delete
        id - the value of the ID
        Returns:
        the result of this delete operation.
        Developer note. Inline this method to update to the new usage
      • delete

        @Deprecated
        <T,​V> com.mongodb.WriteResult delete​(java.lang.String kind,
                                                   java.lang.Class<T> clazz,
                                                   V id,
                                                   DeleteOptions options)
        Deletes an entity of the given type T, with the given id, from the collection with the name in the kind param. Validates the id, checking it's the correct type for an ID for entities of type T. The entity type clazz is used only for validation, not for filtering, therefore if you have entities of different types in the same collection ( kind), this method will delete any entity with the given id, regardless of its type.
        Type Parameters:
        T - the entity type
        V - is the type of the ID, for example ObjectId
        Parameters:
        kind - the collection name
        clazz - the Class of the entity to delete
        id - the value of the ID
        options - the options to use when deleting
        Returns:
        the result of this delete operation.
        Since:
        1.3
        Developer note. Inline this method to update to the new usage
      • delete

        @Deprecated
        <T,​V> com.mongodb.WriteResult delete​(java.lang.String kind,
                                                   java.lang.Class<T> clazz,
                                                   V id,
                                                   com.mongodb.WriteConcern wc)
        Deletes an entity of the given type T, with the given id, from the collection with the name in the kind param. Validates the id, checking it's the correct type for an ID for entities of type T. The entity type clazz is used only for validation, not for filtering, therefore if you have entities of different types in the same collection ( kind), this method will delete any entity with the given id, regardless of its type.
        Type Parameters:
        T - the entity type
        V - is the type of the ID, for example ObjectId
        Parameters:
        kind - the collection name
        clazz - the Class of the entity to delete
        id - the value of the ID
        wc - the WriteConcern for this operation
        Returns:
        the result of this delete operation.
      • ensureIndex

        @Deprecated
        <T> void ensureIndex​(java.lang.String collection,
                             java.lang.Class<T> clazz,
                             java.lang.String fields)
        Deprecated.
        This method uses the legacy approach for defining indexes. Switch to using annotations on entity classes or the methods in the Java driver itself.
        Ensures (creating if necessary) the index including the field(s) + directions on the given collection name; eg fields = "field1, -field2" ({field1:1, field2:-1})
        Type Parameters:
        T - the type to index
        Parameters:
        collection - the collection to update
        clazz - the class from which to get the index definitions
        fields - the fields to index
        See Also:
        MongoCollection.createIndex(org.bson.conversions.Bson, com.mongodb.client.model.IndexOptions), ensureIndexes(String, Class)
      • ensureIndex

        @Deprecated
        <T> void ensureIndex​(java.lang.String collection,
                             java.lang.Class<T> clazz,
                             java.lang.String name,
                             java.lang.String fields,
                             boolean unique,
                             boolean dropDupsOnCreate)
        Deprecated.
        This method uses the legacy approach for defining indexes. Switch to using annotations on entity classes or the methods in the Java driver itself.
        Ensures (creating if necessary) the index including the field(s) + directions on the given collection name; eg fields = "field1, -field2" ({field1:1, field2:-1})
        Type Parameters:
        T - the type to index
        Parameters:
        collection - the collection to update
        clazz - the class from which to get the index definitions
        name - the name of the index to create
        fields - the fields to index
        unique - true if the index should enforce uniqueness on the fields indexed
        dropDupsOnCreate - This value is no longer supported. Tells the unique index to drop duplicates silently when creating; only the first will be kept
        See Also:
        MongoCollection.createIndex(org.bson.conversions.Bson, com.mongodb.client.model.IndexOptions), ensureIndexes(String, Class)
      • ensureIndexes

        @Deprecated
        <T> void ensureIndexes​(java.lang.String collection,
                               java.lang.Class<T> clazz)
        Deprecated.
        this feature is being removed. no replacement is planned. see issue #1331
        Ensures (creating if necessary) the indexes found during class mapping (using @Indexed, @Indexes) on the given collection name.
        Type Parameters:
        T - the type to index
        Parameters:
        collection - the collection to update
        clazz - the class from which to get the index definitions
      • ensureIndexes

        @Deprecated
        <T> void ensureIndexes​(java.lang.String collection,
                               java.lang.Class<T> clazz,
                               boolean background)
        Deprecated.
        use ensureIndexes(String, Class) instead and specify background true or false in the annotations
        Ensures (creating if necessary) the indexes found during class mapping (using @Indexed, @Indexes) on the given collection name, possibly in the background
        Type Parameters:
        T - the type to index
        Parameters:
        collection - the collection to update
        clazz - the class from which to get the index definitions
        background - if true, the index will be built in the background. If false, the method will block until the index is created.
      • exists

        @Deprecated
        Key<?> exists​(java.lang.Object keyOrEntity,
                      com.mongodb.ReadPreference readPreference)
        Deprecated.
        use MongoIterable.first() instead
        Checks that an entity exists for the given key or entity
        Parameters:
        keyOrEntity - the value to check for
        readPreference - Uses the supplied ReadPreference for the check. If readPreference is null the preference is taken from the annotation or uses the default preference.
        Returns:
        the key if the entity exists
        See Also:
        Datastore.exists(Object)
        Developer note. Inline this method to update to the new usage
      • find

        @Deprecated
        <T> Query<T> find​(java.lang.String collection,
                          java.lang.Class<T> clazz)
        Deprecated.
        this feature is being removed. no replacement is planned. see issue #1331
        Find all instances by type in a different collection than what is mapped on the class given.
        Type Parameters:
        T - the type to query
        Parameters:
        collection - the collection to query against
        clazz - the class to use for mapping the results
        Returns:
        the query
      • find

        @Deprecated
        <T,​V> Query<T> find​(java.lang.String collection,
                                  java.lang.Class<T> clazz,
                                  java.lang.String property,
                                  V value,
                                  int offset,
                                  int size)
        Deprecated.
        use find(String, Class) and apply the options to the com.mongodb.client.model.FindOptions parameter
        Find all instances by type in a different collection than what is mapped on the class given skipping some documents and returning a fixed number of the remaining.
        Type Parameters:
        T - the type to query
        V - the type to filter value
        Parameters:
        collection - the collection to query against
        clazz - the class to use for mapping the results
        property - the document property to query against
        value - the value to check for
        offset - the number of results to skip
        size - the maximum number of results to return
        Returns:
        the query
        Developer note. Inline this method to update to the new usage
      • get

        @Deprecated
        <T> T get​(java.lang.Class<T> clazz,
                  com.mongodb.DBRef ref)
        Deprecated.
        Find the given entity (by collectionName/id);
        Type Parameters:
        T - the type to fetch
        Parameters:
        clazz - the class to use for mapping
        ref - the DBRef to use when querying
        Returns:
        the entity referenced in the DBRef. May be null.
        Developer note. Inline this method to update to the new usage
      • get

        @Deprecated
        <T,​V> T get​(java.lang.String collection,
                          java.lang.Class<T> clazz,
                          V id)
        Deprecated.
        Finds an entity in the named collection whose id matches the value given.
        Type Parameters:
        T - the type to fetch
        V - the type of the ID
        Parameters:
        collection - the collection to query
        clazz - the class to use for mapping
        id - the ID to query
        Returns:
        the entity with the id. May be null.
        Developer note. Inline this method to update to the new usage
      • getCount

        @Deprecated
        long getCount​(java.lang.String collection)
        Deprecated.
        use Query.count() instead
        Gets the count this collection
        Parameters:
        collection - the collection to count
        Returns:
        the collection size
        Developer note. Inline this method to update to the new usage
      • insert

        <T> Key<T> insert​(T entity)
        Inserts an entity in to the mapped collection. The return type will change in 2.0
        Type Parameters:
        T - the type of the entity
        Parameters:
        entity - the entity to insert
        Returns:
        the new key of the inserted entity
      • insert

        @Deprecated
        <T> Key<T> insert​(T entity,
                          com.mongodb.WriteConcern wc)
        Inserts an entity in to the mapped collection.
        Type Parameters:
        T - the type of the entity
        Parameters:
        entity - the entity to insert
        wc - the WriteConcern to use when inserting
        Returns:
        the new key of the inserted entity
        See Also:
        WriteConcern
        Developer note. Inline this method to update to the new usage
      • insert

        <T> Key<T> insert​(T entity,
                          InsertOptions options)
        Inserts an entity in to the mapped collection. The return type will change in 2.0
        Type Parameters:
        T - the type of the entity
        Parameters:
        entity - the entity to insert
        options - the options to apply to the insert operation
        Returns:
        the new key of the inserted entity
        Since:
        1.3
        Developer note. Inline this method to update to the new usage
      • insert

        @Deprecated
        <T> Key<T> insert​(java.lang.String collection,
                          T entity)
        Deprecated.
        this feature is being removed. no replacement is planned. see issue #1331
        Inserts an entity in to the named collection.
        Type Parameters:
        T - the type of the entity
        Parameters:
        collection - the collection to update
        entity - the entity to insert
        Returns:
        the new key of the inserted entity
      • insert

        @Deprecated
        <T> Key<T> insert​(java.lang.String collection,
                          T entity,
                          InsertOptions options)
        Deprecated.
        this feature is being removed. no replacement is planned. see issue #1331
        Inserts an entity in to the named collection.
        Type Parameters:
        T - the type of the entity
        Parameters:
        collection - the collection to update
        entity - the entity to insert
        options - the options to apply to the insert operation
        Returns:
        the new key of the inserted entity
        Since:
        1.3
        Developer note. Inline this method to update to the new usage
      • insert

        @Deprecated
        <T> java.lang.Iterable<Key<T>> insert​(T... entities)
        Deprecated.
        use insert(Iterable) instead
        Inserts entities in to the mapped collection.
        Type Parameters:
        T - the type of the entity
        Parameters:
        entities - the entities to insert
        Returns:
        the new keys of the inserted entities
        Developer note. Inline this method to update to the new usage
      • insert

        @Deprecated
        <T> java.lang.Iterable<Key<T>> insert​(java.lang.Iterable<T> entities)
        Deprecated.
        Inserts entities in to the mapped collection. The return type will change in 2.0
        Type Parameters:
        T - the type of the entities
        Parameters:
        entities - the entities to insert
        Returns:
        the new keys of the inserted entities
      • insert

        <T> java.lang.Iterable<Key<T>> insert​(java.util.List<T> entities)
        Inserts entities in to the mapped collection. The return type will change in 2.0
        Type Parameters:
        T - the type of the entities
        Parameters:
        entities - the entities to insert
        Returns:
        the new keys of the inserted entities
        Since:
        1.6
      • insert

        @Deprecated
        <T> java.lang.Iterable<Key<T>> insert​(java.lang.Iterable<T> entities,
                                              com.mongodb.WriteConcern wc)
        Inserts entities in to the mapped collection.
        Type Parameters:
        T - the type of the entity
        Parameters:
        entities - the entities to insert
        wc - the WriteConcern to use when inserting
        Returns:
        the new keys of the inserted entities
      • insert

        @Deprecated
        <T> java.lang.Iterable<Key<T>> insert​(java.lang.Iterable<T> entities,
                                              InsertOptions options)
        Inserts entities in to the mapped collection. The return type will change in 2.0
        Type Parameters:
        T - the type of the entity
        Parameters:
        entities - the entities to insert
        options - the options to apply to the insert operation
        Returns:
        the new keys of the inserted entities
        Since:
        1.3
      • insert

        <T> java.lang.Iterable<Key<T>> insert​(java.util.List<T> entities,
                                              InsertOptions options)
        Inserts entities in to the mapped collection. The return type will change in 2.0
        Type Parameters:
        T - the type of the entity
        Parameters:
        entities - the entities to insert
        options - the options to apply to the insert operation
        Returns:
        the new keys of the inserted entities
        Since:
        1.6
      • insert

        @Deprecated
        <T> java.lang.Iterable<Key<T>> insert​(java.lang.String collection,
                                              java.lang.Iterable<T> entities)
        Deprecated.
        this feature is being removed. no replacement is planned. see issue #1331
        Inserts an entity in to the named collection.
        Type Parameters:
        T - the type of the entity
        Parameters:
        collection - the collection to update
        entities - the entities to insert
        Returns:
        the new keys of the inserted entities
      • insert

        @Deprecated
        <T> java.lang.Iterable<Key<T>> insert​(java.lang.String collection,
                                              java.lang.Iterable<T> entities,
                                              com.mongodb.WriteConcern wc)
        Inserts an entity in to the named collection.
        Type Parameters:
        T - the type of the entity
        Parameters:
        collection - the collection to update
        entities - the entities to insert
        wc - the WriteConcern to use when inserting
        Returns:
        the new keys of the inserted entities
        See Also:
        WriteConcern
      • insert

        @Deprecated
        <T> java.lang.Iterable<Key<T>> insert​(java.lang.String collection,
                                              java.lang.Iterable<T> entities,
                                              InsertOptions options)
        Deprecated.
        this feature is being removed. no replacement is planned. see issue #1331
        Inserts entities in to the named collection.
        Type Parameters:
        T - the type of the entity
        Parameters:
        collection - the collection to update
        entities - the entities to insert
        options - the options to apply to the insert operation
        Returns:
        the new keys of the inserted entities
        Since:
        1.3
      • queryByExample

        <T> Query<T> queryByExample​(java.lang.String collection,
                                    T example)
        Returns a new query based on the example object
        Type Parameters:
        T - the type of the entity
        Parameters:
        collection - the collection to query
        example - the example entity to use when building the query
        Returns:
        the query
      • save

        @Deprecated
        <T> Key<T> save​(java.lang.String collection,
                        T entity)
        Deprecated.
        this feature is being removed. no replacement is planned. see issue #1331
        Saves an entity in to the named collection.
        Type Parameters:
        T - the type of the entity
        Parameters:
        collection - the collection to update
        entity - the entity to save
        Returns:
        the new key of the inserted entity
      • save

        @Deprecated
        <T> Key<T> save​(java.lang.String collection,
                        T entity,
                        com.mongodb.WriteConcern wc)
        Deprecated.
        Saves an entity in to the named collection.
        Type Parameters:
        T - the type of the entity
        Parameters:
        collection - the collection to update
        entity - the entity to save
        wc - the WriteConcern to use when inserting
        Returns:
        the new key of the inserted entity
      • save

        @Deprecated
        <T> Key<T> save​(java.lang.String collection,
                        T entity,
                        InsertOptions options)
        Deprecated.
        this feature is being removed. no replacement is planned. see issue #1331
        Saves an entity in to the named collection.
        Type Parameters:
        T - the type of the entity
        Parameters:
        collection - the collection to update
        entity - the entity to save
        options - the options to apply to the save operation
        Returns:
        the new key of the inserted entity