Skip to content

Commit 8c007fa

Browse files
authored
[Java] Update Solon Version To 3.0.3 (#9401)
* Update Solon Version To 2.9.1 * Update Solon Version To 2.9.1 * Update Solon Jdk To 21 * Update Solon Jdk To 21 * Update Solon Jdk To 21 * Update Solon Jdk To 21 * Update Solon Jdk To 21 * Update Solon Version To 2.9.2 * Add Solon-Virtual * Remove solon-virtual * Update Solon Version To 3.0.2 * Add Solon-Vertx * Tweak description * Tweak the dockerfile * Tweak the dockerfile * Tweak config * Tweak dockefile name * Add FilterImpl * Add FilterImpl * The json plugin is changed to jackson * Update Solon Jdk To 23 * Update Solon-Vertx Jdk To 23 * Solon-vertx is restored to jdk 21 * Solon is restored to jdk 21 * Solon-vertx adjusts the Date output format * Solon is restored to jdk 21 * Remove solon-vertx * [Java] Update Solon Version To 3.0.3
1 parent 56e5498 commit 8c007fa

File tree

17 files changed

+349
-53
lines changed

17 files changed

+349
-53
lines changed

frameworks/Java/solon/pom.xml

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.noear</groupId>
77
<artifactId>solon-parent</artifactId>
8-
<version>3.0.2</version>
8+
<version>3.0.3</version>
99
</parent>
1010

1111
<groupId>hello</groupId>
@@ -15,24 +15,70 @@
1515

1616
<properties>
1717
<java.version>21</java.version>
18+
<jstachio.version>1.3.6</jstachio.version>
1819
</properties>
1920

2021
<dependencies>
2122
<dependency>
2223
<groupId>org.noear</groupId>
23-
<artifactId>solon-boot-smarthttp</artifactId>
24+
<artifactId>solon-web</artifactId>
2425
</dependency>
2526

2627
<dependency>
2728
<groupId>org.noear</groupId>
2829
<artifactId>solon-serialization-jackson</artifactId>
2930
</dependency>
31+
32+
<dependency>
33+
<groupId>org.noear</groupId>
34+
<artifactId>solon-data-sqlutils</artifactId>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>io.jstach</groupId>
39+
<artifactId>jstachio</artifactId>
40+
<version>${jstachio.version}</version>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>io.jstach</groupId>
45+
<artifactId>jstachio-apt</artifactId>
46+
<version>${jstachio.version}</version>
47+
<scope>provided</scope>
48+
<optional>true</optional>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>com.zaxxer</groupId>
53+
<artifactId>HikariCP</artifactId>
54+
<version>6.0.0</version>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>org.postgresql</groupId>
59+
<artifactId>postgresql</artifactId>
60+
<version>42.7.4</version>
61+
</dependency>
3062
</dependencies>
3163

3264
<build>
3365
<finalName>${project.artifactId}</finalName>
3466

3567
<plugins>
68+
<plugin>
69+
<groupId>org.apache.maven.plugins</groupId>
70+
<artifactId>maven-compiler-plugin</artifactId>
71+
<configuration>
72+
<annotationProcessorPaths>
73+
<path>
74+
<groupId>io.jstach</groupId>
75+
<artifactId>jstachio-apt</artifactId>
76+
<version>${jstachio.version}</version>
77+
</path>
78+
</annotationProcessorPaths>
79+
</configuration>
80+
</plugin>
81+
3682
<plugin>
3783
<groupId>org.apache.maven.plugins</groupId>
3884
<artifactId>maven-assembly-plugin</artifactId>

frameworks/Java/solon/src/main/java/hello/Main.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
import org.noear.solon.Solon;
44

5-
/**
6-
* @author pmg1991
7-
* @version V1.0
8-
*/
95
public class Main {
106
public static void main(String[] args) {
117
Solon.start(Main.class, args);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package hello;
2+
3+
import java.util.concurrent.ThreadLocalRandom;
4+
import java.util.stream.IntStream;
5+
6+
abstract public class Utils {
7+
private static final int MIN_WORLD_NUMBER = 1;
8+
private static final int MAX_WORLD_NUMBER_PLUS_ONE = 10_001;
9+
10+
public static int randomWorldNumber() {
11+
return ThreadLocalRandom.current().nextInt(MIN_WORLD_NUMBER, MAX_WORLD_NUMBER_PLUS_ONE);
12+
}
13+
14+
public static IntStream randomWorldNumbers() {
15+
return ThreadLocalRandom.current().ints(MIN_WORLD_NUMBER, MAX_WORLD_NUMBER_PLUS_ONE).distinct();
16+
}
17+
}

frameworks/Java/solon/src/main/java/hello/controller/HelloController.java

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package hello.model;
2+
3+
public final class Fortune implements Comparable<Fortune>{
4+
public final int id;
5+
public final String message;
6+
7+
public Fortune(int id, String message) {
8+
this.id = id;
9+
this.message = message;
10+
}
11+
12+
@Override
13+
public int compareTo(final Fortune other) {
14+
return message.compareTo(other.message);
15+
}
16+
}

frameworks/Java/solon/src/main/java/hello/model/Message.java

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package hello.model;
2+
3+
4+
public final class World {
5+
public int id;
6+
public int randomNumber;
7+
public World(int id, int randomNumber) {
8+
this.id = id;
9+
this.randomNumber = randomNumber;
10+
}
11+
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package hello.repository;
2+
3+
import hello.model.Fortune;
4+
import hello.model.World;
5+
6+
import java.util.List;
7+
8+
public interface DbRepository {
9+
10+
World getWorld(int id) throws Exception;
11+
12+
void updateWorlds(List<World> worlds) throws Exception;
13+
14+
List<Fortune> fortunes() throws Exception;
15+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package hello.repository;
2+
3+
import hello.model.Fortune;
4+
import hello.model.World;
5+
import org.noear.solon.annotation.Component;
6+
import org.noear.solon.annotation.Inject;
7+
import org.noear.solon.data.sql.SqlUtils;
8+
9+
import java.sql.SQLException;
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
@Component
14+
public class JdbcDbRepository implements DbRepository {
15+
@Inject
16+
SqlUtils sqlUtils;
17+
18+
@Override
19+
public World getWorld(int id) {
20+
try {
21+
return sqlUtils.sql("SELECT id, randomnumber FROM world WHERE id = ?", id)
22+
.queryRow()
23+
.toBean(World.class, (r, t) -> new World((int) r.getObject(1), (int) r.getObject(2)));
24+
} catch (Exception e) {
25+
return null;
26+
}
27+
}
28+
29+
@Override
30+
public void updateWorlds(List<World> worlds) throws SQLException {
31+
List<Object[]> values = new ArrayList<>();
32+
for (World w : worlds) {
33+
values.add(new Object[]{w.randomNumber, w.id});
34+
}
35+
36+
sqlUtils.sql("UPDATE world SET randomnumber = ? WHERE id = ?")
37+
.updateBatch(values);
38+
}
39+
40+
@Override
41+
public List<Fortune> fortunes() throws SQLException {
42+
return sqlUtils.sql("SELECT id, message FROM fortune")
43+
.queryRowList()
44+
.toBeanList(Fortune.class, (r, t) -> new Fortune((int) r.getObject(1), (String) r.getObject(2)));
45+
}
46+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package hello.web;
2+
3+
import hello.Utils;
4+
import hello.model.Fortune;
5+
import hello.model.World;
6+
import hello.repository.JdbcDbRepository;
7+
import org.noear.solon.annotation.Component;
8+
import org.noear.solon.annotation.Inject;
9+
import org.noear.solon.core.handle.Context;
10+
11+
import java.util.Collections;
12+
import java.util.Comparator;
13+
import java.util.List;
14+
15+
@Component
16+
public class DbHandler {
17+
@Inject
18+
JdbcDbRepository dbRepository;
19+
20+
public void db(Context ctx) throws Throwable {
21+
ctx.render(dbRepository.getWorld(Utils.randomWorldNumber()));
22+
}
23+
24+
public void queries(Context ctx) throws Throwable {
25+
int queries = ctx.paramAsInt("queries", 0);
26+
27+
World[] worlds = Utils.randomWorldNumbers()
28+
.mapToObj(dbRepository::getWorld).limit(queries)
29+
.toArray(World[]::new);
30+
31+
ctx.render(worlds);
32+
}
33+
34+
public void updates(Context ctx) throws Throwable {
35+
int queries = ctx.paramAsInt("queries", 0);
36+
37+
List<World> worlds = Utils.randomWorldNumbers()
38+
.mapToObj(id -> {
39+
World world = dbRepository.getWorld(id);
40+
int randomNumber;
41+
do {
42+
randomNumber = Utils.randomWorldNumber();
43+
} while (randomNumber == world.randomNumber);
44+
world.randomNumber = randomNumber;
45+
return world;
46+
}).limit(queries)
47+
.sorted(Comparator.comparingInt(w -> w.id))
48+
.toList();
49+
dbRepository.updateWorlds(worlds);
50+
51+
ctx.render(worlds);
52+
}
53+
54+
public void fortunes(Context ctx) throws Throwable {
55+
List<Fortune> fortunes = dbRepository.fortunes();
56+
fortunes.add(new Fortune(0, "Additional fortune added at request time."));
57+
Collections.sort(fortunes);
58+
59+
ctx.render(new Fortunes(fortunes));
60+
}
61+
}

0 commit comments

Comments
 (0)