Search in sources :

Example 1 with World

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

the class WorldHibernateImpl method findAndModify.

@Override
public World findAndModify(int id, int newRandomNumber) {
    final World world = get(id);
    world.setRandomNumber(newRandomNumber);
    return persist(world);
}
Also used : World(com.example.helloworld.db.model.World)

Example 2 with World

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

the class WorldHibernateImpl method updatesQueries.

/**
 * Using manual transaction handling and JDBC batch updates
 */
@Override
public World[] updatesQueries(int totalQueries) {
    final World[] worlds = new World[totalQueries];
    Transaction txn = null;
    try {
        txn = currentSession().beginTransaction();
        // using write batching. See the data source properties provided in the
        // configuration .yml file
        int[] ids = Helper.getRandomInts(totalQueries);
        int i = 0;
        for (int id : ids) {
            int newNumber;
            World world = findById(id);
            do {
                newNumber = Helper.randomWorld();
            } while (world.getRandomNumber() == newNumber);
            worlds[i++] = modify(world, newNumber);
        }
        currentSession().flush();
        currentSession().clear();
        txn.commit();
    } catch (RuntimeException e) {
        if (txn != null && txn.isActive())
            txn.rollback();
        throw e;
    }
    return worlds;
}
Also used : Transaction(org.hibernate.Transaction) World(com.example.helloworld.db.model.World)

Example 3 with World

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

the class WorldRepository method updatesQueries.

@Override
public World[] updatesQueries(int totalQueries) {
    try (Handle handle = jdbi.open()) {
        WorldJDBIImpl dao = handle.attach(WorldJDBIImpl.class);
        final World[] updates = new World[totalQueries];
        for (int i = 0; i < totalQueries; i++) {
            final World world = dao.findById(Helper.randomWorld());
            world.setRandomNumber(Helper.randomWorld());
            updates[i] = world;
        }
        // Reason for sorting : https://github.com/TechEmpower/FrameworkBenchmarks/pull/2684
        Arrays.sort(updates, Comparator.comparingInt(World::getId));
        dao.update(updates);
        handle.commit();
        return updates;
    }
}
Also used : World(com.example.helloworld.db.model.World) Handle(org.jdbi.v3.core.Handle)

Example 4 with World

use of com.example.helloworld.db.model.World 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 5 with World

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

the class WorldMongoImpl method findAndModify.

@Override
public World findAndModify(int worldId, int newRandomNumber) {
    World theOne = findById(worldId);
    theOne.setRandomNumber(newRandomNumber);
    worldCollection.updateById(theOne.getId(), DBUpdate.set("randomNumber", theOne.getRandomNumber()));
    return theOne;
}
Also used : World(com.example.helloworld.db.model.World)

Aggregations

World (com.example.helloworld.db.model.World)5 Fortune (com.example.helloworld.db.model.Fortune)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 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DB (com.mongodb.DB)1 MongoClient (com.mongodb.MongoClient)1 Transaction (org.hibernate.Transaction)1 Handle (org.jdbi.v3.core.Handle)1