mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
FIX: Reuse of io.ebean.Update with collection parameters did not work correctly
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package org.tests.basic;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Update;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Testcase identified a bug when collections are used as bind parameters
|
||||
*
|
||||
* @author Roland Praml, FOCONIS AG
|
||||
*/
|
||||
public class TestUpdate extends BaseTestCase {
|
||||
|
||||
@BeforeEach
|
||||
public void createCustomers() {
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
Customer cust = new Customer();
|
||||
cust.setName("testUpdate" + i);
|
||||
DB.save(cust);
|
||||
}
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void deleteCustomers() {
|
||||
DB.createUpdate(Customer.class, "delete from customer where name like 'testUpdate%'").execute();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormal() {
|
||||
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
Update<Customer> update = DB.createUpdate(Customer.class,
|
||||
"update customer set smallnote = :smallnote where name in (:name)");
|
||||
update.setParameter("name", Arrays.asList("testUpdate" + i)).setParameter("smallnote", "Note #" + i).execute();
|
||||
}
|
||||
Customer cust = DB.find(Customer.class).where().eq("name", "testUpdate3").findOne();
|
||||
assertThat(cust.getSmallnote()).isEqualTo("Note #3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReuse() {
|
||||
|
||||
Update<Customer> update = DB.createUpdate(Customer.class,
|
||||
"update customer set smallnote = :smallnote where name in (:name)");
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
update.setParameter("name", Arrays.asList("testUpdate" + i)).setParameter("smallnote", "Note #" + i).execute();
|
||||
}
|
||||
Customer cust = DB.find(Customer.class).where().eq("name", "testUpdate3").findOne();
|
||||
assertThat(cust.getSmallnote()).isEqualTo("Note #3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReuseNoArray() {
|
||||
|
||||
Update<Customer> update = DB.createUpdate(Customer.class,
|
||||
"update customer set smallnote = :smallnote where name = :name");
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
update.setParameter("name", "testUpdate" + i).setParameter("smallnote", "Note #" + i).execute();
|
||||
}
|
||||
Customer cust = DB.find(Customer.class).where().eq("name", "testUpdate3").findOne();
|
||||
assertThat(cust.getSmallnote()).isEqualTo("Note #3");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user