All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.dheid.roperty.mongodb.KeyDocumentDAO Maven / Gradle / Ivy

There is a newer version: 1.1
Show newest version
package io.github.dheid.roperty.mongodb;

import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import org.apache.commons.lang3.Validate;
import org.bson.Document;

import static com.mongodb.client.model.Filters.eq;

public class KeyDocumentDAO {

    private CollectionProvider collectionProvider;

    public Document findKey(String key) {
        Validate.notNull(collectionProvider, "Collection provider must not be null");
        MongoCollection collection = collectionProvider.getCollection();
        Validate.notNull(collection, "Collection must not be null");
        return collection.find(eq(RopertyMongoDbAttribute.KEY.getName(), key)).first();
    }

    public void setCollectionProvider(CollectionProvider collectionProvider) {
        Validate.notNull(collectionProvider, "Collection provider must not be null");
        this.collectionProvider = collectionProvider;
    }

    public FindIterable findAllKeys() {
        Validate.notNull(collectionProvider, "Collection provider must not be null");
        MongoCollection collection = collectionProvider.getCollection();
        Validate.notNull(collection, "Collection must not be null");
        return collection.find();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy