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;
|
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 {
|
public static void main(String[] args) throws SQLException, InterruptedException {
|
||||||
try (
|
try (
|
||||||
final Connection connection = Repository.getConnection();
|
final Connection connection = Repository.getConnectionH2();
|
||||||
final Statement statement = connection.createStatement()
|
final Statement statement = connection.createStatement()
|
||||||
) {
|
) {
|
||||||
connection.setAutoCommit(false);
|
connection.setAutoCommit(false);
|
||||||
connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
|
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();
|
new OtherTransaction().start();
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
@ -30,7 +30,7 @@ public class DirtyReadExample {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try (
|
try (
|
||||||
final Connection connection = Repository.getConnection();
|
final Connection connection = Repository.getConnectionH2();
|
||||||
final Statement statement = connection.createStatement()
|
final Statement statement = connection.createStatement()
|
||||||
) {
|
) {
|
||||||
connection.setAutoCommit(false);
|
connection.setAutoCommit(false);
|
||||||
|
5
pom.xml
5
pom.xml
@ -39,5 +39,10 @@
|
|||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.7.36</version>
|
<version>1.7.36</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<version>2.1.214</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user