package gettasky.storage.mongodb;
import gettasky.storage.StorageException;
import java.net.UnknownHostException;
import com.mongodb.Mongo;
import com.mongodb.DB;
/**
* Single point of access to MongoDB database connections.
*/
public class ConnectionFactory
{
private static final String DATABASE_NAME = "gettasky";
private static Mongo mongo;
/**
* Return a connection to the database.
*/
public static DB getConnection() throws StorageException
{
try
{
return getMongoInstance().getDB(DATABASE_NAME);
}
catch (Exception e)
{
throw new StorageException(e);
}
}
/**
* Return the singleton instance of the Mongo connection pool.
*/
private static Mongo getMongoInstance() throws UnknownHostException
{
if (mongo == null)
{
mongo = new Mongo(); // localhost and default port
}
return mongo;
}
}