mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1521 - Add API for using explicit transaction for UpdateQuery - e.g. ebeanServer.update(Customer.class)...update(activeTransaction);
This commit is contained in:
@@ -215,6 +215,67 @@ public class UpdateQueryTest extends BaseTestCase {
|
||||
assertThat(rows).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateQuery_withExplicitTransaction() {
|
||||
|
||||
EbeanServer server = server();
|
||||
|
||||
int rowsExprList;
|
||||
int rowsQuery;
|
||||
|
||||
try (Transaction transaction = server.beginTransaction()) {
|
||||
|
||||
rowsExprList = server
|
||||
.update(Customer.class)
|
||||
.setRaw("status = coalesce(status, ?)", Customer.Status.ACTIVE)
|
||||
.where()
|
||||
.gt("id", 10000)
|
||||
.update(transaction);
|
||||
|
||||
rowsQuery = server
|
||||
.update(Customer.class)
|
||||
.setRaw("status = coalesce(status, ?)", Customer.Status.ACTIVE)
|
||||
.where()
|
||||
.gt("id", 10001)
|
||||
.query().update(transaction);
|
||||
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
assertThat(rowsExprList).isEqualTo(0);
|
||||
assertThat(rowsQuery).isEqualTo(0);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void deleteQuery_withExplicitTransaction() {
|
||||
|
||||
EbeanServer server = server();
|
||||
|
||||
int rowsExprList;
|
||||
int rowsQuery;
|
||||
|
||||
try (Transaction transaction = server.beginTransaction()) {
|
||||
|
||||
rowsExprList = server
|
||||
.update(Customer.class)
|
||||
.where()
|
||||
.gt("id", 10000)
|
||||
.delete(transaction);
|
||||
|
||||
rowsQuery = server
|
||||
.update(Customer.class)
|
||||
.where()
|
||||
.gt("id", 10001)
|
||||
.query().delete(transaction);
|
||||
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
assertThat(rowsExprList).isEqualTo(0);
|
||||
assertThat(rowsQuery).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useViaEbean() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user