io.github.dheid.roperty.mongodb.KeyDocumentDAO Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of roperty-mongodb Show documentation
Show all versions of roperty-mongodb Show documentation
A MongoDB persistence implementation for Roperty
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();
}
}