Skip to content

Commit 08de5e8

Browse files
authored
jooby: upgrade to 4.0 (#10008)
- major dependencies upgrade
1 parent 8741815 commit 08de5e8

File tree

14 files changed

+119
-188
lines changed

14 files changed

+119
-188
lines changed

frameworks/Java/jooby/pom.xml

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
<name>jooby</name>
1212

1313
<properties>
14-
<jooby.version>3.4.0</jooby.version>
15-
<netty.version>4.1.113.Final</netty.version>
14+
<jooby.version>4.0.2</jooby.version>
1615
<dsl-json.version>2.0.2</dsl-json.version>
1716
<postgresql.version>42.7.7</postgresql.version>
1817
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -38,13 +37,6 @@
3837
<version>${jooby.version}</version>
3938
</dependency>
4039

41-
<!-- mySQL -->
42-
<dependency>
43-
<groupId>com.mysql</groupId>
44-
<artifactId>mysql-connector-j</artifactId>
45-
<version>8.4.0</version>
46-
</dependency>
47-
4840
<!-- postgresql -->
4941
<dependency>
5042
<groupId>org.postgresql</groupId>
@@ -55,7 +47,7 @@
5547
<dependency>
5648
<groupId>io.vertx</groupId>
5749
<artifactId>vertx-pg-client</artifactId>
58-
<version>4.5.7</version>
50+
<version>5.0.1</version>
5951
</dependency>
6052

6153
<!-- json -->
@@ -72,7 +64,7 @@
7264
<plugin>
7365
<groupId>org.codehaus.mojo</groupId>
7466
<artifactId>build-helper-maven-plugin</artifactId>
75-
<version>3.6.0</version>
67+
<version>3.6.1</version>
7668
<executions>
7769
<execution>
7870
<id>add-source</id>
@@ -91,7 +83,7 @@
9183
<plugin>
9284
<groupId>com.fizzed</groupId>
9385
<artifactId>rocker-maven-plugin</artifactId>
94-
<version>1.4.0</version>
86+
<version>2.2.1</version>
9587
<executions>
9688
<execution>
9789
<id>generate-rocker-templates</id>
@@ -110,7 +102,7 @@
110102
<plugin>
111103
<groupId>org.apache.maven.plugins</groupId>
112104
<artifactId>maven-compiler-plugin</artifactId>
113-
<version>3.13.0</version>
105+
<version>3.14.0</version>
114106
<configuration>
115107
<annotationProcessorPaths>
116108
<path>
@@ -174,14 +166,10 @@
174166
</os>
175167
</activation>
176168
<dependencies>
177-
<dependency>
178-
<groupId>com.ongres.scram</groupId>
179-
<artifactId>client</artifactId>
180-
<version>2.1</version>
181-
</dependency>
182169
<dependency>
183170
<groupId>io.netty</groupId>
184171
<artifactId>netty-resolver-dns-native-macos</artifactId>
172+
<classifier>osx-aarch_64</classifier>
185173
</dependency>
186174
</dependencies>
187175
</profile>
@@ -221,14 +209,6 @@
221209

222210
<dependencyManagement>
223211
<dependencies>
224-
<dependency>
225-
<groupId>io.netty</groupId>
226-
<artifactId>netty-bom</artifactId>
227-
<version>${netty.version}</version>
228-
<type>pom</type>
229-
<scope>import</scope>
230-
</dependency>
231-
232212
<dependency>
233213
<groupId>io.jooby</groupId>
234214
<artifactId>jooby-bom</artifactId>

frameworks/Java/jooby/src/main/java/com/techempower/App.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.techempower;
22

3+
import static com.techempower.Util.boxedRandomWorld;
34
import static com.techempower.Util.randomWorld;
45
import static io.jooby.ExecutionMode.EVENT_LOOP;
56
import static io.jooby.MediaType.JSON;
@@ -29,16 +30,18 @@ public class App extends Jooby {
2930
private static final byte[] MESSAGE_BYTES = MESSAGE.getBytes(StandardCharsets.US_ASCII);
3031

3132
{
32-
var bufferFactory = getBufferFactory();
3333
/** Database: */
3434
install(new HikariModule());
3535
DataSource ds = require(DataSource.class);
3636

3737
/** Template engine: */
3838
install(new RockerModule());
3939

40+
var outputFactory = getOutputFactory();
41+
Json.configure(outputFactory);
42+
var message = outputFactory.wrap(MESSAGE_BYTES);
4043
get("/plaintext", ctx ->
41-
ctx.send(bufferFactory.wrap(MESSAGE_BYTES))
44+
ctx.send(message)
4245
);
4346

4447
get("/json", ctx -> ctx
@@ -99,7 +102,7 @@ public class App extends Jooby {
99102
statement.setInt(1, randomWorld());
100103
try (ResultSet rs = statement.executeQuery()) {
101104
rs.next();
102-
result[i] = new World(rs.getInt("id"), randomWorld());
105+
result[i] = new World(rs.getInt("id"), boxedRandomWorld());
103106
}
104107
// prepare update query
105108
updateSql.add("(?, ?)");

frameworks/Java/jooby/src/main/java/com/techempower/Json.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.dslplatform.json.DslJson;
77
import com.dslplatform.json.JsonWriter;
88
import com.dslplatform.json.runtime.Settings;
9+
import io.jooby.output.Output;
10+
import io.jooby.output.OutputFactory;
911

1012
public class Json {
1113
private final static DslJson<Object> dslJson = new DslJson<>(Settings.basicSetup());
@@ -15,36 +17,41 @@ public class Json {
1517
return dslJson.newWriter(1024);
1618
}
1719
};
20+
private static OutputFactory outputFactory;
1821

19-
public static ByteBuffer encode(Message data) {
22+
public static void configure(OutputFactory outputFactory) {
23+
Json.outputFactory =outputFactory.getContextFactory();
24+
}
25+
26+
public static Output encode(Message data) {
2027
JsonWriter writer = pool.get();
2128
writer.reset();
2229
var converter = new _Message_DslJsonConverter.ObjectFormatConverter(dslJson);
2330
converter.write(writer, data);
24-
return ByteBuffer.wrap(writer.getByteBuffer(), 0, writer.size());
31+
return outputFactory.wrap(writer.getByteBuffer(), 0, writer.size());
2532
}
2633

27-
public static ByteBuffer encode(World data) {
34+
public static Output encode(World data) {
2835
JsonWriter writer = pool.get();
2936
writer.reset();
3037
var converter = new _World_DslJsonConverter.ObjectFormatConverter(dslJson);
3138
converter.write(writer, data);
32-
return ByteBuffer.wrap(writer.getByteBuffer(), 0, writer.size());
39+
return outputFactory.wrap(writer.getByteBuffer(), 0, writer.size());
3340
}
3441

35-
public static ByteBuffer encode(World[] data) {
42+
public static Output encode(World[] data) {
3643
JsonWriter writer = pool.get();
3744
writer.reset();
3845
var converter = new _World_DslJsonConverter.ObjectFormatConverter(dslJson);
3946
writer.serialize(data, converter);
40-
return ByteBuffer.wrap(writer.getByteBuffer(), 0, writer.size());
47+
return outputFactory.wrap(writer.getByteBuffer(), 0, writer.size());
4148
}
4249

43-
public static ByteBuffer encode(List<World> data) {
50+
public static Output encode(List<World> data) {
4451
JsonWriter writer = pool.get();
4552
writer.reset();
4653
var converter = new _World_DslJsonConverter.ObjectFormatConverter(dslJson);
4754
writer.serialize(data, converter);
48-
return ByteBuffer.wrap(writer.getByteBuffer(), 0, writer.size());
55+
return outputFactory.wrap(writer.getByteBuffer(), 0, writer.size());
4956
}
5057
}

frameworks/Java/jooby/src/main/java/com/techempower/MvcApp.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ public static void main(String[] args) {
1717
/** Template engine: */
1818
app.install(new RockerModule());
1919

20-
app.mvc(new Resource_(app.require(DataSource.class)));
20+
Json.configure(app.getOutputFactory());
21+
22+
app.mvc(new Resource_(app.require(DataSource.class), app.getOutputFactory()));
2123
});
2224
}
2325
}

frameworks/Java/jooby/src/main/java/com/techempower/PgClient.java

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,45 @@ private static class DbConnection {
4040
private PreparedQuery<RowSet<Row>> UPDATE_WORLD_QUERY;
4141
private SqlClientInternal updates;
4242
@SuppressWarnings("unchecked")
43-
private PreparedQuery<RowSet<Row>>[] AGGREGATED_UPDATE_WORLD_QUERY = new PreparedQuery[128];
43+
private PreparedQuery<RowSet<Row>>[] AGGREGATED_UPDATE_WORLD_QUERY = new PreparedQuery[500];
44+
}
45+
46+
public static class PgUpdate {
47+
private DbConnection connection;
48+
49+
public PgUpdate(DbConnection connection) {
50+
this.connection = connection;
51+
}
52+
53+
public void selectWorldForUpdate(int queries, BiConsumer<Integer, PreparedQuery<RowSet<Row>>> consumer) {
54+
connection.queries.group(c -> {
55+
PreparedQuery<RowSet<Row>> statement = c.preparedQuery(SELECT_WORLD);
56+
for (int i = 0; i < queries; i++) {
57+
consumer.accept(i, statement);
58+
}
59+
});
60+
}
61+
62+
public void updateWorld(World[] worlds, Handler<AsyncResult<RowSet<Row>>> handler) {
63+
Arrays.sort(worlds);
64+
int len = worlds.length;
65+
if (0 < len && len <= connection.AGGREGATED_UPDATE_WORLD_QUERY.length) {
66+
List<Object> arguments = new ArrayList<>();
67+
for (World world : worlds) {
68+
arguments.add(world.getId());
69+
arguments.add(world.getRandomNumber());
70+
}
71+
Tuple tuple = Tuple.tuple(arguments);
72+
PreparedQuery<RowSet<Row>> query = connection.AGGREGATED_UPDATE_WORLD_QUERY[len - 1];
73+
query.execute(tuple).onComplete(handler);
74+
} else {
75+
List<Tuple> batch = new ArrayList<>();
76+
for (World world : worlds) {
77+
batch.add(Tuple.of(world.getRandomNumber(), world.getId()));
78+
}
79+
connection.UPDATE_WORLD_QUERY.executeBatch(batch).onComplete(handler);
80+
}
81+
}
4482
}
4583

4684
private static class DbConnectionFactory extends ThreadLocal<DbConnection> {
@@ -129,51 +167,23 @@ public PgClient(Config config) {
129167
}
130168

131169
public void selectWorld(Tuple row, Handler<AsyncResult<RowSet<Row>>> handler) {
132-
this.sqlClient.get().SELECT_WORLD_QUERY.execute(row, handler);
170+
this.sqlClient.get().SELECT_WORLD_QUERY.execute(row).onComplete(handler);
133171
}
134172

135173
public void selectWorlds(int queries, Handler<AsyncResult<RowSet<Row>>> handler) {
136174
this.sqlClient.get().queries.group(c -> {
137175
for (int i = 0; i < queries; i++) {
138-
c.preparedQuery(SELECT_WORLD).execute(Tuple.of(Util.randomWorld()), handler);
176+
c.preparedQuery(SELECT_WORLD).execute(Tuple.of(Util.boxedRandomWorld())).onComplete(handler);
139177
}
140178
});
141179
}
142180

143181
public void fortunes(Handler<AsyncResult<RowSet<Row>>> handler) {
144-
this.sqlClient.get().SELECT_FORTUNE_QUERY.execute(handler);
145-
}
146-
147-
public void selectWorldForUpdate(int queries,
148-
BiConsumer<Integer, PreparedQuery<RowSet<Row>>> consumer) {
149-
this.sqlClient.get().queries.group(c -> {
150-
PreparedQuery<RowSet<Row>> statement = c.preparedQuery(SELECT_WORLD);
151-
for (int i = 0; i < queries; i++) {
152-
consumer.accept(i, statement);
153-
}
154-
});
182+
this.sqlClient.get().SELECT_FORTUNE_QUERY.execute().onComplete(handler);
155183
}
156184

157-
public void updateWorld(World[] worlds, Handler<AsyncResult<RowSet<Row>>> handler) {
158-
Arrays.sort(worlds);
159-
int len = worlds.length;
160-
var connection = this.sqlClient.get();
161-
if (0 < len && len <= connection.AGGREGATED_UPDATE_WORLD_QUERY.length) {
162-
List<Object> arguments = new ArrayList<>();
163-
for (World world : worlds) {
164-
arguments.add(world.getId());
165-
arguments.add(world.getRandomNumber());
166-
}
167-
Tuple tuple = Tuple.tuple(arguments);
168-
PreparedQuery<RowSet<Row>> query = connection.AGGREGATED_UPDATE_WORLD_QUERY[len - 1];
169-
query.execute(tuple, handler);
170-
} else {
171-
List<Tuple> batch = new ArrayList<>();
172-
for (World world : worlds) {
173-
batch.add(Tuple.of(world.getRandomNumber(), world.getId()));
174-
}
175-
connection.UPDATE_WORLD_QUERY.executeBatch(batch, handler);
176-
}
185+
public PgUpdate updater() {
186+
return new PgUpdate(sqlClient.get());
177187
}
178188

179189
private PgConnectOptions pgPoolOptions(Config config) {

0 commit comments

Comments
 (0)