/** * DataWriter constructor * * @throws IllegalStateException if database configuration is not set */ private DatabaseWriter() { try { final MongoClient mongoClient = MongoClients.create(PROPERTIES_MANAGER.getProperty("database.host")); final MongoDatabase mongoDatabase = mongoClient.getDatabase(PROPERTIES_MANAGER.getProperty("database.datasource")); this.mongoCollection = mongoDatabase.getCollection(PROPERTIES_MANAGER.getProperty("database.collection")); } catch (IllegalArgumentException e) { LOGGER.error(e.getMessage()); throw new IllegalStateException(e.getMessage()); } LOGGER.info("DatabaseWriter has been instantiate"); }
/** * Get or create the MongoDB client * @return the MongoDB client */ private MongoClient getMongoClient() { if (mongoClient == null) { mongoClient = MongoClients.create(connectionString); } return mongoClient; }
public void setMongoClient(MongoClient mongoClient) { this.mongoClient = mongoClient; }
public MongoChanFetcher(Set<Port> localInputs, MongoClient mongoClient, String database, String collection) { this.localInputs = localInputs; this.mongoClient = mongoClient; this.collection = collection; this.database = database; }
/** * Returns the {@code MongoCollection} which contains the oplog. * * @param client The {@link MongoClient} * @return The {@code MongoCollection} which contains the oplog */ public static MongoCollection<BsonDocument> getCollection(MongoClient client) { return client.getDatabase(OPLOG_DATABASE).getCollection(OPLOG_COLLECTION, BsonDocument.class); }