-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0038501
commit 13f682f
Showing
5 changed files
with
99 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package test.mysql; | ||
|
||
import com.github.fantasy0v0.swift.jdbc.JDBC; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import test.container.ContainerUtil; | ||
import test.container.JdbcContainer; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.Connection; | ||
|
||
import static com.github.fantasy0v0.swift.jdbc.JDBC.*; | ||
|
||
public class TransactionTest { | ||
|
||
private final Logger log = LoggerFactory.getLogger(TransactionTest.class); | ||
|
||
private final static JdbcContainer container = JdbcContainer.create( | ||
ContainerUtil.MYSQL, ContainerUtil.MYSQL_LOCATIONS | ||
); | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
DataSource dataSource = container.start(); | ||
JDBC.configuration(dataSource); | ||
} | ||
|
||
@AfterAll | ||
static void afterAll() { | ||
container.stop(); | ||
} | ||
|
||
@Test | ||
void test() { | ||
transaction(() -> { | ||
select("select * from student").fetch(); | ||
transaction(Connection.TRANSACTION_READ_UNCOMMITTED, () -> { | ||
select("select * from student").fetch(); | ||
transaction(Connection.TRANSACTION_READ_COMMITTED, () -> { | ||
modify("update student set name = ? where id = ?") | ||
.execute("修改", 1L); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
@Test | ||
void rollback() { | ||
transaction(() -> { | ||
modify("update student set name = ? where id = ?") | ||
.execute("修改", 1L); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
CREATE TABLE student ( | ||
id bigint NOT NULL, | ||
name text NOT NULL, | ||
status INT NOT NULL, | ||
ext text | ||
); | ||
CREATE TABLE datetime_test ( | ||
id bigint NOT NULL, | ||
date timestamp NOT NULL | ||
); | ||
insert into student(id, name, status) values | ||
(1, '小明', 0), (2, '张三', 1), | ||
(3, '李四', 2), (4, '董超', 2), | ||
(5, '薛霸', 2); |