io.github.dheid.roperty.mongodb.CollectionProvider 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.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.apache.commons.lang3.Validate;
import org.bson.Document;
public class CollectionProvider {
private String databaseName;
private String collectionName;
private MongoClient mongo;
public MongoCollection getCollection() {
MongoDatabase database = mongo.getDatabase(databaseName);
return database.getCollection(collectionName);
}
public void setDatabaseName(String databaseName) {
Validate.notBlank(databaseName, "Database name must not be blank");
this.databaseName = databaseName;
}
public void setMongo(MongoClient mongo) {
Validate.notNull(mongo, "Mongo client must not be null");
this.mongo = mongo;
}
public void setCollectionName(String collectionName) {
Validate.notBlank(collectionName, "Collection name must not be blank");
this.collectionName = collectionName;
}
}