package framework;

import com.mongodb.*;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;

/**
 * Created with IntelliJ IDEA.
 * User: jhasmanyquiroz
 * Date: 12/9/15
 * Time: 7:44 PM
 * To change this template use File | Settings | File Templates.
 */
public class DBManager {
    private MongoClient mongoClient;
    private MongoDatabase database;
    private static DBManager instance;

    private DBManager() {
        initialize();
    }

    public static DBManager getInstance() {
        if (instance == null)
            instance = new DBManager();
        return instance;
    }

    public void quitMongoDB() {
        mongoClient.close();
    }

    private void initialize() {
        mongoClient = new MongoClient(new MongoClientURI(CredentialsManager.getInstance().getMongoServer()));
        database = mongoClient.getDatabase(CredentialsManager.getInstance().getMongoDataBase());
    }
}
@@ -75,16 +75,59 @@
 erable;%0A
+import com.mongodb.client.MongoCollection;%0A
 import c
@@ -492,21 +492,23 @@
 %0A%0A    pr
-ivate
+otected
  DBManag
@@ -704,17 +704,148 @@
 lic 
-void quit
+MongoCollection%3CDocument%3E getCollection(String collection) %7B%0A        return database.getCollection(collection);%0A    %7D%0A%0A    public void close
 Mong
@@ -916,24 +916,42 @@
 tialize() %7B%0A
+        try %7B%0A    
         mong
@@ -1044,24 +1044,28 @@
 Server()));%0A
+    
         data
@@ -1145,19 +1145,141 @@
 ataBase());%0A
+        %7D catch (Exception e) %7B%0A            System.err.println(e.getClass().getName() + %22: %22 + e.getMessage());%0A        %7D%0A
     %7D%0A%7D

Create the DBManager.java file for make the connections to MongoDB database