Last active
August 29, 2017 20:40
-
-
Save amgohan/8252487 to your computer and use it in GitHub Desktop.
Mongo Connection Manager using Morphia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.UnknownHostException; | |
import org.mongodb.morphia.Datastore; | |
import org.mongodb.morphia.Morphia; | |
import com.mongodb.MongoClient; | |
public class MongoConnectionManager { | |
private static final MongoConnectionManager INSTANCE = new MongoConnectionManager(); | |
private static final String DB_NAME = "dbtest"; | |
private Morphia morphia = null; | |
private Datastore datastore = null; | |
private MongoClient mongoClient = null; | |
private MongoConnectionManager() { | |
morphia = new Morphia(); | |
try { | |
mongoClient = new MongoClient(); | |
} catch (UnknownHostException e) { | |
e.printStackTrace(); | |
} | |
datastore = morphia.createDatastore(mongoClient, DB_NAME); | |
} | |
public static MongoConnectionManager getInstance() { | |
return INSTANCE; | |
} | |
public Morphia getMorphia() { | |
return morphia; | |
} | |
public void setMorphia(Morphia morphia) { | |
this.morphia = morphia; | |
} | |
public Datastore getDatastore() { | |
return datastore; | |
} | |
public void setDatastore(Datastore datastore) { | |
this.datastore = datastore; | |
} | |
public MongoClient getMongoClient() { | |
return mongoClient; | |
} | |
public void setMongoClient(MongoClient mongoClient) { | |
this.mongoClient = mongoClient; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment