|
@@ -13,7 +13,6 @@ import io.quarkus.benchmark.model.World;
|
|
|
import io.quarkus.benchmark.utils.LocalRandom;
|
|
|
import io.quarkus.benchmark.utils.Randomizer;
|
|
|
|
|
|
-
|
|
|
@Singleton
|
|
|
public class WorldRepository {
|
|
|
|
|
@@ -38,39 +37,43 @@ public class WorldRepository {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public World findSingleAndStateless(Integer id) {
|
|
|
+ public World loadSingleWorldById(Integer id) {
|
|
|
try (StatelessSession ss = sf.openStatelessSession()) {
|
|
|
- return singleStatelessWorldLoad(ss,id);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional
|
|
|
- public void updateAll(World[] worlds) {
|
|
|
- try (Session s = sf.openSession()) {
|
|
|
- s.setJdbcBatchSize(worlds.length);
|
|
|
- s.setHibernateFlushMode(FlushMode.MANUAL);
|
|
|
- for (World w : worlds) {
|
|
|
- s.update(w);
|
|
|
- }
|
|
|
- s.flush();
|
|
|
+ return (World) ss.get(World.class, id);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public World[] findReadonly(int count) {
|
|
|
- try (StatelessSession s = sf.openStatelessSession()) {
|
|
|
+ public World[] loadNWorlds(final int count) {
|
|
|
+ final World[] list = new World[count];
|
|
|
+ final LocalRandom random = Randomizer.current();
|
|
|
+ try (StatelessSession ss = sf.openStatelessSession()) {
|
|
|
//The rules require individual load: we can't use the Hibernate feature which allows load by multiple IDs as one single operation
|
|
|
- World[] list = new World[count];
|
|
|
- final LocalRandom random = Randomizer.current();
|
|
|
for (int i=0;i<count;i++) {
|
|
|
- Integer idToLoad = random.getNextRandom();
|
|
|
- list[i] = singleStatelessWorldLoad(s,idToLoad);
|
|
|
+ list[i] = (World) ss.get(World.class, random.getNextRandom());
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static World singleStatelessWorldLoad(final StatelessSession ss, final Integer id) {
|
|
|
- return (World) ss.get(World.class, id);
|
|
|
+ public World[] updateNWorlds(final int count) {
|
|
|
+ //We're again forced to use the "individual load" pattern by the rules:
|
|
|
+ final World[] list = loadNWorlds(count);
|
|
|
+ final LocalRandom random = Randomizer.current();
|
|
|
+ try (Session s = sf.openSession()) {
|
|
|
+ s.setJdbcBatchSize(count);
|
|
|
+ s.setHibernateFlushMode(FlushMode.MANUAL);
|
|
|
+ for (World w : list) {
|
|
|
+ //Read the one field, as required by the following rule:
|
|
|
+ // # vi. At least the randomNumber field must be read from the database result set.
|
|
|
+ final int previousRead = w.getRandomNumber();
|
|
|
+ //Update it, but make sure to exclude the current number as Hibernate optimisations would otherwise
|
|
|
+ //skip the write operation:
|
|
|
+ w.setRandomNumber(random.getNextRandomExcluding(previousRead));
|
|
|
+ s.update(w);
|
|
|
+ }
|
|
|
+ s.flush();
|
|
|
+ }
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
}
|