Search in sources :

Example 1 with Fortune

use of com.example.helloworld.db.model.Fortune in project FrameworkBenchmarks by TechEmpower.

the class HelloMongoService method run.

@Override
public void run(HelloMongoConfiguration config, Environment environment) throws UnknownHostException {
    final MongoClient mongoClient = config.getMongo().build();
    environment.lifecycle().manage(new MongoManaged(mongoClient));
    final DB db = mongoClient.getDB(config.getMongo().getDb());
    final ObjectMapper mongoJackMapper = MongoJackModule.configure(Jackson.newObjectMapper());
    final JacksonDBCollection<World, Integer> worlds = JacksonDBCollection.wrap(db.getCollection("world"), World.class, Integer.class, mongoJackMapper);
    final JacksonDBCollection<Fortune, Integer> fortunes = JacksonDBCollection.wrap(db.getCollection("fortune"), Fortune.class, Integer.class, mongoJackMapper);
    // Test types 2, 3 & 5: Single database query, Multiple database queries & Database updates
    environment.jersey().register(new WorldResource(new WorldMongoImpl(worlds)));
    // Test type 4: Fortunes
    environment.jersey().register(new FortuneResource(new FortuneMongoImpl(fortunes)));
}
Also used : WorldResource(com.example.helloworld.resources.WorldResource) World(com.example.helloworld.db.model.World) FortuneMongoImpl(com.example.helloworld.db.mongo.FortuneMongoImpl) MongoClient(com.mongodb.MongoClient) FortuneResource(com.example.helloworld.resources.FortuneResource) MongoManaged(com.example.helloworld.db.mongo.MongoManaged) Fortune(com.example.helloworld.db.model.Fortune) WorldMongoImpl(com.example.helloworld.db.mongo.WorldMongoImpl) DB(com.mongodb.DB) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with Fortune

use of com.example.helloworld.db.model.Fortune in project FrameworkBenchmarks by TechEmpower.

the class FortuneResource method dbTest.

@GET
// Needed only for Hibernate - not for Mongo or JDBI
@UnitOfWork
public FortuneView dbTest() {
    final List<Fortune> fortunes = fortuneDAO.list();
    fortunes.add(new Fortune("Additional fortune added at request time."));
    Collections.sort(fortunes);
    return new FortuneView(fortunes);
}
Also used : Fortune(com.example.helloworld.db.model.Fortune) FortuneView(com.example.helloworld.resources.views.FortuneView) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) GET(javax.ws.rs.GET)

Aggregations

Fortune (com.example.helloworld.db.model.Fortune)2 World (com.example.helloworld.db.model.World)1 FortuneMongoImpl (com.example.helloworld.db.mongo.FortuneMongoImpl)1 MongoManaged (com.example.helloworld.db.mongo.MongoManaged)1 WorldMongoImpl (com.example.helloworld.db.mongo.WorldMongoImpl)1 FortuneResource (com.example.helloworld.resources.FortuneResource)1 WorldResource (com.example.helloworld.resources.WorldResource)1 FortuneView (com.example.helloworld.resources.views.FortuneView)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DB (com.mongodb.DB)1 MongoClient (com.mongodb.MongoClient)1 UnitOfWork (io.dropwizard.hibernate.UnitOfWork)1 GET (javax.ws.rs.GET)1