!
https://github.com/mongodb/morphia
factory, Mongo Morphia Datastore. Datastore MongoDB.
public class DatastoreFactory {
private static Datastore ds;
public static Datastore getDatastore() {
if(ds == null) {
try {
Morphia morphia = new Morphia();
ds = morphia.createDatastore(
new MongoClient("server", port, "database"));
} catch(Exception e) {
}
}
return ds;
}
, MongoDB, Datastore factory
Datastore ds = DatastoreFactory.getDatastore();
CDI , ,
@Singleton
public class DatastoreFactory {
private Datastore ds;
@Produces
public Datastore getDatastore() {
if(ds == null) {
try {
Morphia morphia = new Morphia();
ds = morphia.createDatastore(
new MongoClient("server", port, "database"));
} catch(Exception e) {
}
}
return ds;
}
:
@Inject
Datastore ds;
BONUS
MongoDB, (DAO) , Morphia Datastore. DAO , (, , , ). , MongoDB, DAO, !