Skip to content

Commit 08635cb

Browse files
committed
Format
1 parent 5e076d2 commit 08635cb

File tree

25 files changed

+871
-893
lines changed

25 files changed

+871
-893
lines changed

jakarta-ee/src/main/java/com/example/ProgrammingLanguage.java

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,62 @@
99
@NamedQuery(name = "topProgrammingLanguages", query = "from ProgrammingLanguage pl where pl.rating > :rating")
1010
public class ProgrammingLanguage {
1111

12-
@Id
13-
@GeneratedValue(strategy = GenerationType.IDENTITY)
14-
@Column(name = "pl_id")
15-
private Integer id;
16-
17-
@Column(name = "pl_name")
18-
private String name;
19-
20-
@Column(name = "pl_rating")
21-
private Integer rating;
22-
23-
public ProgrammingLanguage() {
24-
}
25-
26-
public ProgrammingLanguage(String name, Integer rating) {
27-
this.name = name;
28-
this.rating = rating;
29-
}
30-
31-
@Override
32-
public boolean equals(Object o) {
33-
if (this == o)
34-
return true;
35-
if (o == null || getClass() != o.getClass())
36-
return false;
37-
ProgrammingLanguage that = (ProgrammingLanguage) o;
38-
return Objects.equals(id, that.id);
39-
}
40-
41-
@Override
42-
public int hashCode() {
43-
return Objects.hash(id);
44-
}
45-
46-
public Integer getId() {
47-
return id;
48-
}
49-
50-
public void setId(Integer id) {
51-
this.id = id;
52-
}
53-
54-
public String getName() {
55-
return name;
56-
}
57-
58-
public void setName(String name) {
59-
this.name = name;
60-
}
61-
62-
public Integer getRating() {
63-
return rating;
64-
}
65-
66-
public void setRating(Integer rating) {
67-
this.rating = rating;
68-
}
12+
@Id
13+
@GeneratedValue(strategy = GenerationType.IDENTITY)
14+
@Column(name = "pl_id")
15+
private Integer id;
16+
17+
@Column(name = "pl_name")
18+
private String name;
19+
20+
@Column(name = "pl_rating")
21+
private Integer rating;
22+
23+
public ProgrammingLanguage() {
24+
}
25+
26+
public ProgrammingLanguage(String name, Integer rating) {
27+
this.name = name;
28+
this.rating = rating;
29+
}
30+
31+
@Override
32+
public boolean equals(Object o) {
33+
if (this == o)
34+
return true;
35+
if (o == null || getClass() != o.getClass())
36+
return false;
37+
ProgrammingLanguage that = (ProgrammingLanguage) o;
38+
return Objects.equals(id, that.id);
39+
}
40+
41+
@Override
42+
public int hashCode() {
43+
return Objects.hash(id);
44+
}
45+
46+
public Integer getId() {
47+
return id;
48+
}
49+
50+
public void setId(Integer id) {
51+
this.id = id;
52+
}
53+
54+
public String getName() {
55+
return name;
56+
}
57+
58+
public void setName(String name) {
59+
this.name = name;
60+
}
61+
62+
public Integer getRating() {
63+
return rating;
64+
}
65+
66+
public void setRating(Integer rating) {
67+
this.rating = rating;
68+
}
6969

7070
}

jdbc/mariadb-pool/pom.xml

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,48 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<modelVersion>4.0.0</modelVersion>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
64

7-
<groupId>org.example</groupId>
8-
<artifactId>mariadb-pool</artifactId>
9-
<version>1.0-SNAPSHOT</version>
5+
<groupId>org.example</groupId>
6+
<artifactId>mariadb-pool</artifactId>
7+
<version>1.0-SNAPSHOT</version>
108

11-
<properties>
12-
<maven.compiler.source>17</maven.compiler.source>
13-
<maven.compiler.target>17</maven.compiler.target>
14-
</properties>
9+
<properties>
10+
<maven.compiler.source>17</maven.compiler.source>
11+
<maven.compiler.target>17</maven.compiler.target>
12+
</properties>
1513

16-
<dependencies>
17-
<dependency>
18-
<groupId>org.mariadb.jdbc</groupId>
19-
<artifactId>mariadb-java-client</artifactId>
20-
<version>2.7.4</version>
21-
</dependency>
22-
</dependencies>
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.mariadb.jdbc</groupId>
17+
<artifactId>mariadb-java-client</artifactId>
18+
<version>2.7.4</version>
19+
</dependency>
20+
</dependencies>
2321

24-
<build>
25-
<plugins>
26-
<!-- Creates an Uber JAR (with the JDBC driver) -->
27-
<plugin>
28-
<artifactId>maven-shade-plugin</artifactId>
29-
<version>3.2.4</version>
30-
<executions>
31-
<execution>
32-
<phase>package</phase>
33-
<goals>
34-
<goal>shade</goal>
35-
</goals>
36-
<configuration>
37-
<createDependencyReducedPom>false</createDependencyReducedPom>
38-
<transformers>
39-
<transformer
40-
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
41-
<mainClass>com.example.Application</mainClass>
42-
</transformer>
43-
</transformers>
44-
</configuration>
45-
</execution>
46-
</executions>
47-
</plugin>
48-
</plugins>
49-
</build>
22+
<build>
23+
<plugins>
24+
<!-- Creates an Uber JAR (with the JDBC driver) -->
25+
<plugin>
26+
<artifactId>maven-shade-plugin</artifactId>
27+
<version>3.2.4</version>
28+
<executions>
29+
<execution>
30+
<phase>package</phase>
31+
<goals>
32+
<goal>shade</goal>
33+
</goals>
34+
<configuration>
35+
<createDependencyReducedPom>false</createDependencyReducedPom>
36+
<transformers>
37+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
38+
<mainClass>com.example.Application</mainClass>
39+
</transformer>
40+
</transformers>
41+
</configuration>
42+
</execution>
43+
</executions>
44+
</plugin>
45+
</plugins>
46+
</build>
5047

5148
</project>

jdbc/mariadb-pool/src/main/java/com/example/Application.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@
1414
*/
1515
public class Application {
1616

17-
public static void main(String[] args) throws InterruptedException {
18-
ExecutorService executorService = Executors.newFixedThreadPool(200);
19-
20-
IntStream.range(0, 1000)
21-
.mapToObj(i -> (Runnable) () -> requestService())
22-
.forEach(executorService::submit);
23-
24-
executorService.shutdown();
25-
executorService.awaitTermination(1, TimeUnit.MINUTES);
26-
}
27-
28-
public static void requestService() {
29-
try {
30-
Service service = Service.getInstance();
31-
List<String> list = service.getAllProgrammingLanguages();
32-
list.forEach(System.out::println);
33-
34-
} catch (SQLException e) {
35-
e.printStackTrace();
36-
}
37-
}
17+
public static void main(String[] args) throws InterruptedException {
18+
ExecutorService executorService = Executors.newFixedThreadPool(200);
19+
20+
IntStream.range(0, 1000)
21+
.mapToObj(i -> (Runnable) () -> requestService())
22+
.forEach(executorService::submit);
23+
24+
executorService.shutdown();
25+
executorService.awaitTermination(1, TimeUnit.MINUTES);
26+
}
27+
28+
public static void requestService() {
29+
try {
30+
Service service = Service.getInstance();
31+
List<String> list = service.getAllProgrammingLanguages();
32+
list.forEach(System.out::println);
33+
34+
} catch (SQLException e) {
35+
e.printStackTrace();
36+
}
37+
}
3838

3939
}

jdbc/mariadb-pool/src/main/java/com/example/Service.java

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,40 @@
2727
*/
2828
public class Service {
2929

30-
private static Service instance;
30+
private static Service instance;
3131

32-
private DataSource dataSource;
32+
private DataSource dataSource;
3333

34-
private Service() throws SQLException {
35-
// First try with a DataSource without pooling:
36-
MariaDbDataSource dataSource = new MariaDbDataSource();
37-
// That should fail (SQLException: too many connections)
38-
// Try now commenting the previous executable line
39-
// and using the following DataSource that supports pooling:
40-
//MariaDbPoolDataSource dataSource = new MariaDbPoolDataSource();
41-
// That should work!
42-
dataSource.setUrl("jdbc:mariadb://localhost:3306/jdbc_demo");
43-
dataSource.setUser("user");
44-
dataSource.setPassword("password");
45-
this.dataSource = dataSource;
46-
}
34+
private Service() throws SQLException {
35+
// First try with a DataSource without pooling:
36+
MariaDbDataSource dataSource = new MariaDbDataSource();
37+
// That should fail (SQLException: too many connections)
38+
// Try now commenting the previous executable line
39+
// and using the following DataSource that supports pooling:
40+
// MariaDbPoolDataSource dataSource = new MariaDbPoolDataSource();
41+
// That should work!
42+
dataSource.setUrl("jdbc:mariadb://localhost:3306/jdbc_demo");
43+
dataSource.setUser("user");
44+
dataSource.setPassword("password");
45+
this.dataSource = dataSource;
46+
}
4747

48-
public static synchronized Service getInstance() throws SQLException {
49-
return instance == null ? instance = new Service() : instance;
50-
}
48+
public static synchronized Service getInstance() throws SQLException {
49+
return instance == null ? instance = new Service() : instance;
50+
}
5151

52-
public List<String> getAllProgrammingLanguages() throws SQLException {
53-
var list = new ArrayList<String>();
54-
try (Connection connection = dataSource.getConnection()) {
55-
try (PreparedStatement statement = connection.prepareStatement(
56-
"SELECT name FROM programming_language"
57-
)) {
58-
ResultSet resultSet = statement.executeQuery();
59-
while (resultSet.next()) {
60-
list.add(resultSet.getString("name"));
61-
}
62-
}
63-
}
64-
return list;
65-
}
52+
public List<String> getAllProgrammingLanguages() throws SQLException {
53+
var list = new ArrayList<String>();
54+
try (Connection connection = dataSource.getConnection()) {
55+
try (PreparedStatement statement = connection.prepareStatement(
56+
"SELECT name FROM programming_language")) {
57+
ResultSet resultSet = statement.executeQuery();
58+
while (resultSet.next()) {
59+
list.add(resultSet.getString("name"));
60+
}
61+
}
62+
}
63+
return list;
64+
}
6665

6766
}

0 commit comments

Comments
 (0)