Skip to content

Commit 793a07b

Browse files
committed
use ebean
1 parent a40500b commit 793a07b

8 files changed

Lines changed: 109 additions & 128 deletions

File tree

frameworks/Java/avaje-jex/benchmark_config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"platform": "httpserver",
1919
"database": "Postgres",
2020
"database_os": "Linux",
21-
"orm": "Raw",
21+
"orm": "Full",
2222
"webserver": "None",
2323
"os": "Linux",
2424
"notes": "avaje-jex using jdk.httpserver",
@@ -41,7 +41,7 @@
4141
"platform": "robaho",
4242
"database": "Postgres",
4343
"database_os": "Linux",
44-
"orm": "Raw",
44+
"orm": "Full",
4545
"webserver": "None",
4646
"os": "Linux",
4747
"notes": "avaje-jex using robaho's httpserver",
@@ -64,7 +64,7 @@
6464
"platform": "Jetty",
6565
"database": "Postgres",
6666
"database_os": "Linux",
67-
"orm": "Raw",
67+
"orm": "Full",
6868
"webserver": "None",
6969
"os": "Linux",
7070
"notes": "avaje-jex using Jetty",

frameworks/Java/avaje-jex/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
<artifactId>HikariCP</artifactId>
5656
<version>6.3.0</version>
5757
</dependency>
58+
59+
<dependency>
60+
<groupId>io.ebean</groupId>
61+
<artifactId>ebean-postgres</artifactId>
62+
</dependency>
63+
5864
<dependency>
5965
<groupId>org.postgresql</groupId>
6066
<artifactId>postgresql</artifactId>
@@ -89,6 +95,11 @@
8995
<artifactId>avaje-jsonb-generator</artifactId>
9096
<scope>provided</scope>
9197
</dependency>
98+
<dependency>
99+
<groupId>io.ebean</groupId>
100+
<artifactId>querybean-generator</artifactId>
101+
<scope>provided</scope>
102+
</dependency>
92103
</dependencies>
93104

94105
<build>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package benchmark.repository;
2+
3+
import benchmark.model.Fortune;
4+
import benchmark.model.World;
5+
import io.ebean.Database;
6+
import jakarta.inject.Named;
7+
import jakarta.inject.Singleton;
8+
import java.sql.SQLException;
9+
import java.util.ArrayList;
10+
import java.util.Comparator;
11+
import java.util.List;
12+
13+
@Singleton
14+
public class EbeanDbService implements DbService {
15+
16+
Database readOnly;
17+
Database updateOnly;
18+
19+
EbeanDbService(@Named("readOnly") Database readOnly, @Named("updateOnly") Database updateOnly) {
20+
this.readOnly = readOnly;
21+
this.updateOnly = updateOnly;
22+
}
23+
24+
@Override
25+
public List<World> getWorld(int num) {
26+
27+
String select = "select id, randomNumber from World where id IN (?)";
28+
29+
return readOnly.findDto(World.class, select).setParameter(getRandomNumberSet(num)).findList();
30+
}
31+
32+
@Override
33+
public List<Fortune> getFortune() throws SQLException {
34+
35+
String select = "select id, message from Fortune";
36+
List<Fortune> fortuneList = new ArrayList<>(readOnly.findDto(Fortune.class, select).findList());
37+
38+
fortuneList.add(new Fortune(defaultFortuneId, defaultFortuneMessage));
39+
40+
fortuneList.sort(Comparator.comparing(Fortune::message));
41+
return fortuneList;
42+
}
43+
44+
@Override
45+
public List<World> updateWorld(int num) throws SQLException {
46+
47+
String update = "update World set randomNumber = ? where id = ?";
48+
List<World> worldList = getWorld(num);
49+
var sqlUpdate = updateOnly.sqlUpdate(update);
50+
51+
for (World world : worldList) {
52+
int newRandomNumber;
53+
do {
54+
newRandomNumber = getRandomNumber();
55+
} while (newRandomNumber == world.getRandomNumber());
56+
57+
sqlUpdate.setParameter(1, newRandomNumber).setParameter(2, world.getId()).addBatch();
58+
59+
world.setRandomNumber(newRandomNumber);
60+
}
61+
62+
sqlUpdate.executeBatch();
63+
64+
return worldList;
65+
}
66+
}
Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
11
package benchmark.repository;
22

3-
import com.zaxxer.hikari.HikariConfig;
4-
import com.zaxxer.hikari.HikariDataSource;
5-
import io.avaje.config.Config;
63
import io.avaje.inject.Bean;
74
import io.avaje.inject.Factory;
8-
import javax.sql.DataSource;
5+
import io.ebean.Database;
6+
import io.ebean.DatabaseFactory;
7+
import io.ebean.config.DatabaseConfig;
8+
import io.ebean.datasource.DataSourceConfig;
9+
import jakarta.inject.Named;
910

1011
@Factory
1112
public class HikariFactory {
1213

1314
@Bean
14-
DataSource dataSource() {
15-
int maxPoolSize;
16-
var env = System.getenv("BENCHMARK_ENV");
17-
if (Config.get("physicalTag").equals(env)) {
18-
maxPoolSize = Config.getInt("postgresPhysicalPoolSize");
19-
} else if (Config.get("cloudTag").equals(env)) {
20-
maxPoolSize = Config.getInt("postgresCloudPoolSize");
21-
} else {
22-
maxPoolSize = Config.getInt("postgresDefaultPoolSize");
23-
}
15+
@Named("readOnly")
16+
Database readOnly() {
17+
var dataSourceConfig = new DataSourceConfig();
18+
dataSourceConfig.autoCommit(true);
19+
dataSourceConfig.readOnly(true);
20+
DatabaseConfig config = new DatabaseConfig();
21+
config.autoReadOnlyDataSource(true);
22+
config.readOnlyDatabase(true);
23+
config.setDataSourceConfig(dataSourceConfig);
24+
return DatabaseFactory.create(config);
25+
}
2426

25-
var hikari = new HikariDataSource(new HikariConfig("hikari.properties"));
26-
hikari.setMaximumPoolSize(maxPoolSize);
27-
return hikari;
27+
@Bean
28+
@Named("updateOnly")
29+
Database updateOnly() {
30+
var dataSourceConfig = new DataSourceConfig();
31+
dataSourceConfig.autoCommit(false);
32+
DatabaseConfig config = new DatabaseConfig();
33+
config.setDataSourceConfig(dataSourceConfig);
34+
return DatabaseFactory.create(config);
2835
}
2936
}

frameworks/Java/avaje-jex/src/main/java/benchmark/repository/JDBCDbService.java

Lines changed: 0 additions & 95 deletions
This file was deleted.

frameworks/Java/avaje-jex/src/main/java/module-info.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
requires java.sql;
77
requires org.postgresql.jdbc;
88
requires com.zaxxer.hikari;
9+
requires io.ebean.core;
10+
requires io.ebean.querybean;
911
// template engine
1012
requires io.jstach.jstachio;
1113
/// Configuration
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
physicalTag=Citrine
2-
cloudTag=Azure
3-
4-
postgresPhysicalPoolSize=56
5-
postgresCloudPoolSize=16
6-
postgresDefaultPoolSize=10
1+
datasource.db.username=benchmarkdbuser
2+
datasource.db.password=benchmarkdbpass
3+
datasource.db.url=jdbc:postgresql://${host:tfb-database}:5432/hello_world?user=${datasource.db.username}&password=${datasource.db.password}

frameworks/Java/avaje-jex/src/main/resources/hikari.properties

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)