mirror of
https://github.com/Example-uPagge/transactional.git
synced 2024-06-14 11:52:55 +03:00
Заменил бд на H2
This commit is contained in:
parent
b4c0d30bba
commit
0ab798cb5f
@ -24,4 +24,16 @@ public final class Repository {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Connection getConnectionH2() {
|
||||
try {
|
||||
final String url = "jdbc:h2:file:/Users/upagge/IdeaProjects/struchkov/example/spring-boot/spring-boot-transaction/db/test";
|
||||
final String user = "sa";
|
||||
final String passwd = "pass";
|
||||
return DriverManager.getConnection(url, user, passwd);
|
||||
} catch (SQLException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,13 +11,13 @@ public class DirtyReadExample {
|
||||
|
||||
public static void main(String[] args) throws SQLException, InterruptedException {
|
||||
try (
|
||||
final Connection connection = Repository.getConnection();
|
||||
final Connection connection = Repository.getConnectionH2();
|
||||
final Statement statement = connection.createStatement()
|
||||
) {
|
||||
connection.setAutoCommit(false);
|
||||
connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
|
||||
|
||||
statement.execute("UPDATE person SET balance = 100000 WHERE id = 1");
|
||||
statement.executeUpdate("UPDATE person SET balance = 100000 WHERE id = 1");
|
||||
|
||||
new OtherTransaction().start();
|
||||
Thread.sleep(2000);
|
||||
@ -30,7 +30,7 @@ public class DirtyReadExample {
|
||||
@Override
|
||||
public void run() {
|
||||
try (
|
||||
final Connection connection = Repository.getConnection();
|
||||
final Connection connection = Repository.getConnectionH2();
|
||||
final Statement statement = connection.createStatement()
|
||||
) {
|
||||
connection.setAutoCommit(false);
|
||||
|
Loading…
Reference in New Issue
Block a user