deps: Refactor dependencies (#3224)

* remove spring dep
move junit, logging, mockito under dep mgmt

* upgrade anti-corruption-layer deps

* async method invocation

* balking, bloc

* bridge to bytecode

* caching

* callback - cqrs

* component - health check

* hexagonal - metadata mapping

* rest of the patterns

* remove checkstyle, take spotless into use
This commit is contained in:
Ilkka Seppälä
2025-03-29 19:34:27 +02:00
committed by GitHub
parent 371439aeaa
commit 0ca162a55c
1863 changed files with 14408 additions and 17637 deletions
@@ -29,30 +29,22 @@ import javax.sql.DataSource;
import lombok.extern.slf4j.Slf4j;
import org.h2.jdbcx.JdbcDataSource;
/**
* Table Module pattern is a domain logic pattern.
* In Table Module a single class encapsulates all the domain logic for all
* records stored in a table or view. It's important to note that there is no
* translation of data between objects and rows, as it happens in Domain Model,
* hence implementation is relatively simple when compared to the Domain
* Model pattern.
* Table Module pattern is a domain logic pattern. In Table Module a single class encapsulates all
* the domain logic for all records stored in a table or view. It's important to note that there is
* no translation of data between objects and rows, as it happens in Domain Model, hence
* implementation is relatively simple when compared to the Domain Model pattern.
*
* <p>In this example we will use the Table Module pattern to implement register
* and login methods for the records stored in the user table. The main
* method will initialise an instance of {@link UserTableModule} and use it to
* handle the domain logic for the user table.</p>
* <p>In this example we will use the Table Module pattern to implement register and login methods
* for the records stored in the user table. The main method will initialise an instance of {@link
* UserTableModule} and use it to handle the domain logic for the user table.
*/
@Slf4j
public final class App {
private static final String DB_URL = "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1";
/**
* Private constructor.
*/
private App() {
}
/** Private constructor. */
private App() {}
/**
* Program entry point.
@@ -80,18 +72,16 @@ public final class App {
deleteSchema(dataSource);
}
private static void deleteSchema(final DataSource dataSource)
throws SQLException {
private static void deleteSchema(final DataSource dataSource) throws SQLException {
try (var connection = dataSource.getConnection();
var statement = connection.createStatement()) {
var statement = connection.createStatement()) {
statement.execute(UserTableModule.DELETE_SCHEMA_SQL);
}
}
private static void createSchema(final DataSource dataSource)
throws SQLException {
private static void createSchema(final DataSource dataSource) throws SQLException {
try (var connection = dataSource.getConnection();
var statement = connection.createStatement()) {
var statement = connection.createStatement()) {
statement.execute(UserTableModule.CREATE_SCHEMA_SQL);
}
}
@@ -30,10 +30,7 @@ import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* A user POJO that represents the data that will be read from the data source.
*/
/** A user POJO that represents the data that will be read from the data source. */
@Setter
@Getter
@ToString
@@ -43,5 +40,4 @@ public class User {
private int id;
private String username;
private String password;
}
@@ -29,26 +29,21 @@ import java.sql.SQLException;
import javax.sql.DataSource;
import lombok.extern.slf4j.Slf4j;
/**
* This class organizes domain logic with the user table in the
* database. A single instance of this class contains the various
* procedures that will act on the data.
* This class organizes domain logic with the user table in the database. A single instance of this
* class contains the various procedures that will act on the data.
*/
@Slf4j
public class UserTableModule {
/**
* Public element for creating schema.
*/
/** Public element for creating schema. */
public static final String CREATE_SCHEMA_SQL =
"CREATE TABLE IF NOT EXISTS USERS (ID NUMBER, USERNAME VARCHAR(30) "
+ "UNIQUE,PASSWORD VARCHAR(30))";
/**
* Public element for deleting schema.
*/
public static final String DELETE_SCHEMA_SQL = "DROP TABLE USERS IF EXISTS";
private final DataSource dataSource;
"CREATE TABLE IF NOT EXISTS USERS (ID NUMBER, USERNAME VARCHAR(30) "
+ "UNIQUE,PASSWORD VARCHAR(30))";
/** Public element for deleting schema. */
public static final String DELETE_SCHEMA_SQL = "DROP TABLE USERS IF EXISTS";
private final DataSource dataSource;
/**
* Public constructor.
@@ -59,7 +54,6 @@ public class UserTableModule {
this.dataSource = userDataSource;
}
/**
* Login using username and password.
*
@@ -68,14 +62,11 @@ public class UserTableModule {
* @return the execution result of the method
* @throws SQLException if any error
*/
public int login(final String username, final String password)
throws SQLException {
public int login(final String username, final String password) throws SQLException {
var sql = "select count(*) from USERS where username=? and password=?";
ResultSet resultSet = null;
try (var connection = dataSource.getConnection();
var preparedStatement =
connection.prepareStatement(sql)
) {
var preparedStatement = connection.prepareStatement(sql)) {
var result = 0;
preparedStatement.setString(1, username);
preparedStatement.setString(2, password);
@@ -106,9 +97,7 @@ public class UserTableModule {
public int registerUser(final User user) throws SQLException {
var sql = "insert into USERS (username, password) values (?,?)";
try (var connection = dataSource.getConnection();
var preparedStatement =
connection.prepareStatement(sql)
) {
var preparedStatement = connection.prepareStatement(sql)) {
preparedStatement.setString(1, user.getUsername());
preparedStatement.setString(2, user.getPassword());
var result = preparedStatement.executeUpdate();
@@ -24,17 +24,15 @@
*/
package com.iluwatar.tablemodule;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
/**
* Tests that the table module example runs without errors.
*/
import org.junit.jupiter.api.Test;
/** Tests that the table module example runs without errors. */
class AppTest {
@Test
void shouldExecuteWithoutException() {
assertDoesNotThrow(() -> App.main(new String[]{}));
assertDoesNotThrow(() -> App.main(new String[] {}));
}
}
@@ -24,16 +24,16 @@
*/
package com.iluwatar.tablemodule;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.h2.jdbcx.JdbcDataSource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import javax.sql.DataSource;
import java.sql.DriverManager;
import java.sql.SQLException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
class UserTableModuleTest {
private static final String DB_URL = "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1";
@@ -47,7 +47,7 @@ class UserTableModuleTest {
@BeforeEach
void setUp() throws SQLException {
try (var connection = DriverManager.getConnection(DB_URL);
var statement = connection.createStatement()) {
var statement = connection.createStatement()) {
statement.execute(UserTableModule.DELETE_SCHEMA_SQL);
statement.execute(UserTableModule.CREATE_SCHEMA_SQL);
}
@@ -56,7 +56,7 @@ class UserTableModuleTest {
@AfterEach
void tearDown() throws SQLException {
try (var connection = DriverManager.getConnection(DB_URL);
var statement = connection.createStatement()) {
var statement = connection.createStatement()) {
statement.execute(UserTableModule.DELETE_SCHEMA_SQL);
}
}
@@ -66,8 +66,7 @@ class UserTableModuleTest {
var dataSource = createDataSource();
var userTableModule = new UserTableModule(dataSource);
var user = new User(1, "123456", "123456");
assertEquals(0, userTableModule.login(user.getUsername(),
user.getPassword()));
assertEquals(0, userTableModule.login(user.getUsername(), user.getPassword()));
}
@Test
@@ -76,8 +75,7 @@ class UserTableModuleTest {
var userTableModule = new UserTableModule(dataSource);
var user = new User(1, "123456", "123456");
userTableModule.registerUser(user);
assertEquals(1, userTableModule.login(user.getUsername(),
user.getPassword()));
assertEquals(1, userTableModule.login(user.getUsername(), user.getPassword()));
}
@Test
@@ -96,4 +94,4 @@ class UserTableModuleTest {
var user = new User(1, "123456", "123456");
assertEquals(1, userTableModule.registerUser(user));
}
}
}
@@ -24,104 +24,89 @@
*/
package com.iluwatar.tablemodule;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class UserTest {
@Test
void testCanEqual() {
assertFalse((new User(1, "janedoe", "iloveyou"))
.canEqual("Other"));
assertFalse((new User(1, "janedoe", "iloveyou")).canEqual("Other"));
}
@Test
void testCanEqual2() {
var user = new User(1, "janedoe", "iloveyou");
assertTrue(user.canEqual(new User(1, "janedoe",
"iloveyou")));
assertTrue(user.canEqual(new User(1, "janedoe", "iloveyou")));
}
@Test
void testEquals1() {
var user = new User(1, "janedoe", "iloveyou");
assertNotEquals(user, new User(123, "abcd",
"qwerty"));
assertNotEquals(user, new User(123, "abcd", "qwerty"));
}
@Test
void testEquals2() {
var user = new User(1, "janedoe", "iloveyou");
assertEquals(user, new User(1, "janedoe",
"iloveyou"));
assertEquals(user, new User(1, "janedoe", "iloveyou"));
}
@Test
void testEquals3() {
var user = new User(123, "janedoe", "iloveyou");
assertNotEquals(user, new User(1, "janedoe",
"iloveyou"));
assertNotEquals(user, new User(1, "janedoe", "iloveyou"));
}
@Test
void testEquals4() {
var user = new User(1, null, "iloveyou");
assertNotEquals(user, new User(1, "janedoe",
"iloveyou"));
assertNotEquals(user, new User(1, "janedoe", "iloveyou"));
}
@Test
void testEquals5() {
var user = new User(1, "iloveyou", "iloveyou");
assertNotEquals(user, new User(1, "janedoe",
"iloveyou"));
assertNotEquals(user, new User(1, "janedoe", "iloveyou"));
}
@Test
void testEquals6() {
var user = new User(1, "janedoe", "janedoe");
assertNotEquals(user, new User(1, "janedoe",
"iloveyou"));
assertNotEquals(user, new User(1, "janedoe", "iloveyou"));
}
@Test
void testEquals7() {
var user = new User(1, "janedoe", null);
assertNotEquals(user, new User(1, "janedoe",
"iloveyou"));
assertNotEquals(user, new User(1, "janedoe", "iloveyou"));
}
@Test
void testEquals8() {
var user = new User(1, null, "iloveyou");
assertEquals(user, new User(1, null,
"iloveyou"));
assertEquals(user, new User(1, null, "iloveyou"));
}
@Test
void testEquals9() {
var user = new User(1, "janedoe", null);
assertEquals(user, new User(1, "janedoe",
null));
assertEquals(user, new User(1, "janedoe", null));
}
@Test
void testHashCode1() {
assertEquals(-1758941372, (new User(1, "janedoe",
"iloveyou")).hashCode());
assertEquals(-1758941372, (new User(1, "janedoe", "iloveyou")).hashCode());
}
@Test
void testHashCode2() {
assertEquals(-1332207447, (new User(1, null,
"iloveyou")).hashCode());
assertEquals(-1332207447, (new User(1, null, "iloveyou")).hashCode());
}
@Test
void testHashCode3() {
assertEquals(-426522485, (new User(1, "janedoe",
null)).hashCode());
assertEquals(-426522485, (new User(1, "janedoe", null)).hashCode());
}
@Test
@@ -148,9 +133,10 @@ class UserTest {
@Test
void testToString() {
var user = new User(1, "janedoe", "iloveyou");
assertEquals(String.format("User(id=%s, username=%s, password=%s)",
assertEquals(
String.format(
"User(id=%s, username=%s, password=%s)",
user.getId(), user.getUsername(), user.getPassword()),
user.toString());
user.toString());
}
}