|
1 | 1 | package io.quarkus.benchmark.repository; |
2 | 2 |
|
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import io.quarkus.benchmark.model.World; |
| 7 | +import io.quarkus.benchmark.utils.LocalRandom; |
| 8 | +import io.quarkus.benchmark.utils.Randomizer; |
3 | 9 | import jakarta.inject.Inject; |
4 | 10 | import jakarta.inject.Singleton; |
5 | 11 | import jakarta.transaction.Transactional; |
6 | | - |
7 | | -import org.hibernate.FlushMode; |
8 | | -import org.hibernate.Session; |
9 | 12 | import org.hibernate.SessionFactory; |
10 | 13 | import org.hibernate.StatelessSession; |
11 | 14 |
|
12 | | -import io.quarkus.benchmark.model.World; |
13 | | -import io.quarkus.benchmark.utils.LocalRandom; |
14 | | -import io.quarkus.benchmark.utils.Randomizer; |
15 | | - |
16 | 15 | @Singleton |
17 | 16 | public class WorldRepository { |
18 | 17 |
|
@@ -57,23 +56,22 @@ public World[] loadNWorlds(final int count) { |
57 | 56 |
|
58 | 57 | public World[] updateNWorlds(final int count) { |
59 | 58 | //We're again forced to use the "individual load" pattern by the rules: |
60 | | - final World[] list = loadNWorlds(count); |
| 59 | + final World[] worlds = loadNWorlds(count); |
| 60 | + final List<World> worldList = new ArrayList<>(worlds.length); |
61 | 61 | final LocalRandom random = Randomizer.current(); |
62 | | - try (Session s = sf.openSession()) { |
63 | | - s.setJdbcBatchSize(count); |
64 | | - s.setHibernateFlushMode(FlushMode.MANUAL); |
65 | | - for (World w : list) { |
| 62 | + try (StatelessSession s = sf.openStatelessSession()) { |
| 63 | + for (World w : worlds) { |
66 | 64 | //Read the one field, as required by the following rule: |
67 | 65 | // # vi. At least the randomNumber field must be read from the database result set. |
68 | 66 | final int previousRead = w.getRandomNumber(); |
69 | 67 | //Update it, but make sure to exclude the current number as Hibernate optimisations would otherwise |
70 | 68 | // skip the write operation: |
71 | 69 | w.setRandomNumber(random.getNextRandomExcluding(previousRead)); |
72 | | - s.update(w); |
| 70 | + worldList.add(w); |
73 | 71 | } |
74 | | - s.flush(); |
| 72 | + s.updateMultiple(worldList); |
75 | 73 | } |
76 | | - return list; |
| 74 | + return worlds; |
77 | 75 | } |
78 | 76 |
|
79 | 77 | } |
0 commit comments