mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-14 14:46:25 +00:00
Merge remote-tracking branch 'upstream/master'
# Conflicts: # ebean-bom/pom.xml # ebean-core/src/main/java/io/ebeaninternal/server/expression/platform/DbExpressionHandlerFactory.java # ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/InsertMeta.java # ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeNode.java # ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeBean.java # ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DdlPlugin.java # ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DefaultDbMigration.java # ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/MysqlGenerateMigrationTest.java # ebean-test/pom.xml # pom.xml # tests/pom.xml # tests/test-java16/pom.xml # tests/test-kotlin/pom.xml
This commit is contained in:
commit
5762a5bb9c
100 files changed
+1344
-747
No files matched your search
@@ -101,7 +101,7 @@ public class PlatformNoGeneratedKeysTest {
|
||||
config.setDatabasePlatform(platform);
|
||||
config.getDataSourceConfig().setUsername("sa");
|
||||
config.getDataSourceConfig().setPassword("");
|
||||
config.getDataSourceConfig().setUrl("jdbc:h2:mem:withPCQuery;");
|
||||
config.getDataSourceConfig().setUrl("jdbc:h2:mem:withPCQuery;MODE=LEGACY");
|
||||
config.getDataSourceConfig().setDriver("org.h2.Driver");
|
||||
|
||||
config.setDisableLazyLoading(true);
|
||||
|
||||
@@ -2,28 +2,34 @@ package io.ebean.config.dbplatform;
|
||||
|
||||
import io.ebean.config.PlatformConfig;
|
||||
import io.ebean.config.dbplatform.oracle.Oracle11Platform;
|
||||
import io.ebean.config.dbplatform.oracle.Oracle12Platform;
|
||||
import io.ebean.config.dbplatform.oracle.OraclePlatform;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class OraclePlatformTest {
|
||||
class OraclePlatformTest {
|
||||
|
||||
@Test
|
||||
public void columnAliasPrefix_Oracle11Platform() {
|
||||
void columnAliasPrefix_Oracle11Platform() {
|
||||
Oracle11Platform platform11 = new Oracle11Platform();
|
||||
assertThat(platform11.columnAliasPrefix).isEqualTo("c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void columnAliasPrefix_OraclePlatform() {
|
||||
OraclePlatform platform = new OraclePlatform();
|
||||
assertThat(platform.columnAliasPrefix).isEqualTo("c");
|
||||
void columnAliasPrefix_Oracle12Platform() {
|
||||
Oracle12Platform platform12 = new Oracle12Platform();
|
||||
assertThat(platform12.columnAliasPrefix).isEqualTo("c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uuid_default() {
|
||||
void columnAliasPrefix_OraclePlatform() {
|
||||
OraclePlatform platform = new OraclePlatform();
|
||||
assertThat(platform.columnAliasPrefix).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void uuid_default() {
|
||||
OraclePlatform platform = new OraclePlatform();
|
||||
platform.configure(new PlatformConfig(), false);
|
||||
DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID);
|
||||
@@ -31,8 +37,7 @@ public class OraclePlatformTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uuid_as_binary() {
|
||||
|
||||
void uuid_as_binary() {
|
||||
OraclePlatform platform = new OraclePlatform();
|
||||
PlatformConfig config = new PlatformConfig();
|
||||
config.setDbUuid(PlatformConfig.DbUuid.AUTO_BINARY);
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package io.ebean.test.config.platform;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class DockerHostTest {
|
||||
|
||||
@Test
|
||||
void runningInDocker_when_false_alwaysUseLocalhost() {
|
||||
DockerHost dockerHost = new DockerHost();
|
||||
assertFalse(dockerHost.runningInDocker());
|
||||
assertEquals("localhost", dockerHost.dockerHost("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void runningInDocker_when_true_useExplicit() {
|
||||
TDDockerHost dockerHost = new TDDockerHost();
|
||||
assertTrue(dockerHost.runningInDocker());
|
||||
|
||||
assertEquals("my-host", dockerHost.dockerHost("my-host"));
|
||||
}
|
||||
|
||||
@Disabled
|
||||
@Test
|
||||
void runningInDocker_when_trueAndLinux_useDefault() {
|
||||
TDDockerHost dockerHost = new TDDockerHost();
|
||||
assertTrue(dockerHost.runningInDocker());
|
||||
|
||||
assertEquals("172.17.0.1", dockerHost.dockerHost(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void runningInDocker_when_windowsDefault() {
|
||||
TDDockerHost dockerHost = new TDDockerHost();
|
||||
assertTrue(dockerHost.runningInDocker());
|
||||
|
||||
String origName = System.getProperty("os.name");
|
||||
System.setProperty("os.name", "win");
|
||||
try {
|
||||
assertEquals("host.docker.internal",dockerHost.defaultDockerHost());
|
||||
assertEquals("host.docker.internal", dockerHost.dockerHost(null));
|
||||
} finally {
|
||||
System.setProperty("os.name", origName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void runningInDocker_when_macDefault() {
|
||||
TDDockerHost dockerHost = new TDDockerHost();
|
||||
assertTrue(dockerHost.runningInDocker());
|
||||
|
||||
String origName = System.getProperty("os.name");
|
||||
System.setProperty("os.name", "mac");
|
||||
try {
|
||||
assertEquals("host.docker.internal",dockerHost.defaultDockerHost());
|
||||
assertEquals("host.docker.internal", dockerHost.dockerHost(null));
|
||||
} finally {
|
||||
System.setProperty("os.name", origName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void runningInDocker_when_linuxDefault() {
|
||||
TDDockerHost dockerHost = new TDDockerHost();
|
||||
assertTrue(dockerHost.runningInDocker());
|
||||
|
||||
String origName = System.getProperty("os.name");
|
||||
System.setProperty("os.name", "linux");
|
||||
try {
|
||||
assertEquals("172.17.0.1",dockerHost.defaultDockerHost());
|
||||
assertEquals("172.17.0.1", dockerHost.dockerHost(null));
|
||||
} finally {
|
||||
System.setProperty("os.name", origName);
|
||||
}
|
||||
}
|
||||
|
||||
static class TDDockerHost extends DockerHost {
|
||||
|
||||
@Override
|
||||
boolean initInDocker() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -24,8 +24,8 @@ public class DefaultServer_getReferenceTest extends BaseTestCase {
|
||||
ResetBasicData.reset();
|
||||
|
||||
DB.execute(() -> {
|
||||
Customer loaded = DB.find(Customer.class, 1);
|
||||
Customer reference = DB.reference(Customer.class, 1);
|
||||
Customer loaded = DB.find(Customer.class).where().eq("name", "Rob").findOne();
|
||||
Customer reference = DB.reference(Customer.class, loaded.getId());
|
||||
assertThat(loaded).isSameAs(reference);
|
||||
});
|
||||
}
|
||||
|
||||
+7
-4
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.bean.BeanCollection;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.common.BeanList;
|
||||
@@ -66,11 +67,13 @@ public class BeanPropertyAssocManyTest extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Object> customerIds = new ArrayList<>();
|
||||
customerIds.add(1L);
|
||||
customerIds.add(2L);
|
||||
List<Long> ids = DB.find(Customer.class).orderBy("id").setMaxRows(2).findIds();
|
||||
|
||||
List<Object> contactIdsForOne = contacts().findIdsByParentId(1L, null, null, null, true);
|
||||
List<Object> customerIds = new ArrayList<>();
|
||||
customerIds.add(ids.get(0));
|
||||
customerIds.add(ids.get(1));
|
||||
|
||||
List<Object> contactIdsForOne = contacts().findIdsByParentId(ids.get(0), null, null, null, true);
|
||||
|
||||
List<Object> contactIdsForMultiple = contacts().findIdsByParentId(null, customerIds, null, null, true);
|
||||
|
||||
|
||||
@@ -47,6 +47,14 @@ public class ScalarTypeLocalDateTest {
|
||||
assertTrue(o instanceof Date);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void olderDates_ToFromJdbcType() {
|
||||
LocalDate localDate = LocalDate.of(1850,12,1);
|
||||
Object o = type.toJdbcType(localDate);
|
||||
LocalDate localDate1 = type.toBeanType(o);
|
||||
assertThat(localDate1).isEqualTo(localDate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToBeanType() {
|
||||
|
||||
|
||||
@@ -6,13 +6,20 @@ import io.ebean.Database;
|
||||
import io.ebean.annotation.IgnorePlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.annotation.Transactional;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class TestBatchSaveWithGetBeanId extends BaseTestCase {
|
||||
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Making this transaction with batchSize means that the insert
|
||||
* below does not occur immediately ... and the getBeanId()
|
||||
@@ -22,7 +29,6 @@ public class TestBatchSaveWithGetBeanId extends BaseTestCase {
|
||||
@Test
|
||||
@IgnorePlatform(Platform.HANA) // HANA doesn't support insert batching
|
||||
public void test() {
|
||||
|
||||
Database server = DB.getDefault();
|
||||
Customer model = new Customer();
|
||||
model.setName("foo");
|
||||
|
||||
@@ -26,7 +26,7 @@ public class TestDefaults extends BaseTestCase {
|
||||
final List<String> current = LoggedSql.collect();
|
||||
|
||||
assertThat(current).isNotEmpty();
|
||||
if (isMySql() || isMariaDB()) {
|
||||
if (isMySql() || isMariaDB() || isOracle()) {
|
||||
assertThat(current.get(0)).contains("insert into defaults_model_draft values (default);");
|
||||
} else if (isDb2()) {
|
||||
assertThat(current.get(0)).contains("insert into defaults_model_draft (id) values (default)");
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.tests.inheritance.abstrakt;
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "block")
|
||||
@Table(name = "blockt")
|
||||
@Inheritance
|
||||
@DiscriminatorColumn(name = "case_type", discriminatorType = DiscriminatorType.INTEGER)
|
||||
public abstract class AbstractBaseBlock {
|
||||
|
||||
@@ -2,8 +2,10 @@ package org.tests.insert;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -12,9 +14,13 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestInsertCollection extends BaseTestCase {
|
||||
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Customer cust1 = new Customer();
|
||||
cust1.setName("jim");
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.tests.model.basic;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.Transaction;
|
||||
import org.tests.model.basic.Order.Status;
|
||||
|
||||
import java.sql.Date;
|
||||
@@ -47,6 +48,7 @@ public class ResetBasicData {
|
||||
// the test rely on the products being in there
|
||||
return;
|
||||
}
|
||||
Transaction.current().setBatchMode(false);
|
||||
//me.deleteAll();
|
||||
me.insertCountries();
|
||||
me.insertProducts();
|
||||
@@ -56,100 +58,55 @@ public class ResetBasicData {
|
||||
}
|
||||
|
||||
|
||||
public void deleteAll() {
|
||||
DB.execute(() -> {
|
||||
private void insertCountries() {
|
||||
Country c = new Country();
|
||||
c.setCode("NZ");
|
||||
c.setName("New Zealand");
|
||||
server.save(c);
|
||||
|
||||
// orm update use bean name and bean properties
|
||||
server.sqlUpdate("delete from o_cached_bean_child").execute();
|
||||
server.sqlUpdate("delete from o_cached_bean_country").execute();
|
||||
server.sqlUpdate("delete from o_cached_bean").execute();
|
||||
|
||||
server.createUpdate(OrderShipment.class, "delete from orderShipment").execute();
|
||||
|
||||
server.createUpdate(OrderDetail.class, "delete from orderDetail").execute();
|
||||
|
||||
server.createUpdate(Order.class, "delete from order").execute();
|
||||
|
||||
server.createUpdate(Contact.class, "delete from contact").execute();
|
||||
|
||||
server.createUpdate(Customer.class, "delete from Customer").execute();
|
||||
|
||||
server.createUpdate(Address.class, "delete from address").execute();
|
||||
|
||||
// sql update uses table and column names
|
||||
server.sqlUpdate("delete from o_country").execute();
|
||||
server.sqlUpdate("delete from o_product").execute();
|
||||
|
||||
});
|
||||
Country au = new Country();
|
||||
au.setCode("AU");
|
||||
au.setName("Australia");
|
||||
server.save(au);
|
||||
}
|
||||
|
||||
|
||||
public void insertCountries() {
|
||||
private void insertProducts() {
|
||||
Product p = new Product();
|
||||
p.setName("Chair");
|
||||
p.setSku("C001");
|
||||
server.save(p);
|
||||
|
||||
if (server.find(Country.class).findCount() > 0) {
|
||||
return;
|
||||
}
|
||||
p = new Product();
|
||||
p.setName("Desk");
|
||||
p.setSku("DSK1");
|
||||
server.save(p);
|
||||
|
||||
server.execute(() -> {
|
||||
Country c = new Country();
|
||||
c.setCode("NZ");
|
||||
c.setName("New Zealand");
|
||||
server.save(c);
|
||||
p = new Product();
|
||||
p.setName("Computer");
|
||||
p.setSku("C002");
|
||||
server.save(p);
|
||||
|
||||
Country au = new Country();
|
||||
au.setCode("AU");
|
||||
au.setName("Australia");
|
||||
server.save(au);
|
||||
});
|
||||
p = new Product();
|
||||
p.setName("Printer");
|
||||
p.setSku("C003");
|
||||
server.save(p);
|
||||
}
|
||||
|
||||
private void insertTestCustAndOrders() {
|
||||
Customer cust1 = insertCustomer("Rob");
|
||||
Customer cust2 = insertCustomerNoAddress();
|
||||
insertCustomerFiona();
|
||||
insertCustomerNoContacts("NocCust");
|
||||
|
||||
public void insertProducts() {
|
||||
|
||||
if (server.find(Product.class).findCount() > 0) {
|
||||
return;
|
||||
}
|
||||
server.execute(() -> {
|
||||
Product p = new Product();
|
||||
p.setName("Chair");
|
||||
p.setSku("C001");
|
||||
server.save(p);
|
||||
|
||||
p = new Product();
|
||||
p.setName("Desk");
|
||||
p.setSku("DSK1");
|
||||
server.save(p);
|
||||
|
||||
p = new Product();
|
||||
p.setName("Computer");
|
||||
p.setSku("C002");
|
||||
server.save(p);
|
||||
|
||||
p = new Product();
|
||||
p.setName("Printer");
|
||||
p.setSku("C003");
|
||||
server.save(p);
|
||||
});
|
||||
}
|
||||
|
||||
public void insertTestCustAndOrders() {
|
||||
|
||||
DB.execute(() -> {
|
||||
Customer cust1 = insertCustomer("Rob");
|
||||
Customer cust2 = insertCustomerNoAddress();
|
||||
insertCustomerFiona();
|
||||
insertCustomerNoContacts("NocCust");
|
||||
|
||||
createOrder1(cust1);
|
||||
createOrder2(cust2);
|
||||
createOrder3(cust1);
|
||||
createOrder4(cust1);
|
||||
createOrder5(cust2);
|
||||
});
|
||||
createOrder1(cust1);
|
||||
createOrder2(cust2);
|
||||
createOrder3(cust1);
|
||||
createOrder4(cust1);
|
||||
createOrder5(cust2);
|
||||
}
|
||||
|
||||
public static Customer createCustAndOrder(String custName) {
|
||||
|
||||
ResetBasicData me = new ResetBasicData();
|
||||
Customer cust1 = insertCustomer(custName);
|
||||
me.createOrder1(cust1);
|
||||
@@ -157,7 +114,6 @@ public class ResetBasicData {
|
||||
}
|
||||
|
||||
public static Order createOrderCustAndOrder(String custName) {
|
||||
|
||||
ResetBasicData me = new ResetBasicData();
|
||||
Customer cust1 = insertCustomer(custName);
|
||||
return me.createOrder1(cust1);
|
||||
@@ -166,10 +122,8 @@ public class ResetBasicData {
|
||||
private static int contactEmailNum = 1;
|
||||
|
||||
private Customer insertCustomerFiona() {
|
||||
|
||||
Customer c = createCustomer("Fiona", "12 Apple St", "West Coast Rd", 1, "2009-08-31");
|
||||
c.setStatus(Customer.Status.ACTIVE);
|
||||
|
||||
c.addContact(createContact("Fiona", "Black"));
|
||||
c.addContact(createContact("Tracy", "Red"));
|
||||
|
||||
@@ -185,22 +139,18 @@ public class ResetBasicData {
|
||||
}
|
||||
|
||||
private Customer insertCustomerNoContacts(String name) {
|
||||
|
||||
Customer c = createCustomer("Roger", "15 Kumera Way", "Bos town", 1, "2010-04-10");
|
||||
c.setName(name);
|
||||
c.setStatus(Customer.Status.ACTIVE);
|
||||
|
||||
DB.save(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
private Customer insertCustomerNoAddress() {
|
||||
|
||||
Customer c = new Customer();
|
||||
c.setName("Cust NoAddress");
|
||||
c.setStatus(Customer.Status.NEW);
|
||||
c.addContact(createContact("Jack", "Black"));
|
||||
|
||||
DB.save(c);
|
||||
return c;
|
||||
}
|
||||
@@ -216,7 +166,6 @@ public class ResetBasicData {
|
||||
}
|
||||
|
||||
public static Customer createCustomer(String name, String shippingStreet, String billingStreet, int contactSuffix, String annDate) {
|
||||
|
||||
Customer c = new Customer();
|
||||
c.setName(name);
|
||||
c.setStatus(Customer.Status.NEW);
|
||||
@@ -251,17 +200,14 @@ public class ResetBasicData {
|
||||
|
||||
c.setBillingAddress(billingAddr);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
private Order createOrder1(Customer customer) {
|
||||
|
||||
Product product1 = DB.reference(Product.class, 1);
|
||||
Product product2 = DB.reference(Product.class, 2);
|
||||
Product product3 = DB.reference(Product.class, 3);
|
||||
|
||||
|
||||
Order order = new Order();
|
||||
order.setCustomer(customer);
|
||||
order.setOrderDate(Date.valueOf("2018-07-01"));
|
||||
@@ -271,16 +217,12 @@ public class ResetBasicData {
|
||||
details.add(new OrderDetail(product2, 3, 1.10));
|
||||
details.add(new OrderDetail(product3, 1, 2.00));
|
||||
order.setDetails(details);
|
||||
|
||||
|
||||
order.addShipment(new OrderShipment());
|
||||
|
||||
DB.save(order);
|
||||
return order;
|
||||
}
|
||||
|
||||
private void createOrder2(Customer customer) {
|
||||
|
||||
Product product1 = DB.reference(Product.class, 1);
|
||||
|
||||
Order order = new Order();
|
||||
@@ -291,14 +233,11 @@ public class ResetBasicData {
|
||||
List<OrderDetail> details = new ArrayList<>();
|
||||
details.add(new OrderDetail(product1, 4, 10.50));
|
||||
order.setDetails(details);
|
||||
|
||||
order.addShipment(new OrderShipment());
|
||||
|
||||
DB.save(order);
|
||||
}
|
||||
|
||||
private void createOrder3(Customer customer) {
|
||||
|
||||
Product product1 = DB.reference(Product.class, 1);
|
||||
Product product3 = DB.reference(Product.class, 3);
|
||||
|
||||
@@ -312,30 +251,23 @@ public class ResetBasicData {
|
||||
details.add(new OrderDetail(product3, 40, 2.10));
|
||||
details.add(new OrderDetail(product1, 5, 10.00));
|
||||
order.setDetails(details);
|
||||
|
||||
order.addShipment(new OrderShipment());
|
||||
|
||||
DB.save(order);
|
||||
}
|
||||
|
||||
private void createOrder4(Customer customer) {
|
||||
|
||||
Order order = new Order();
|
||||
order.setCustomer(customer);
|
||||
order.setOrderDate(Date.valueOf("2018-07-04"));
|
||||
|
||||
order.addShipment(new OrderShipment());
|
||||
|
||||
DB.save(order);
|
||||
}
|
||||
|
||||
private void createOrder5(Customer customer) {
|
||||
|
||||
Order order = new Order();
|
||||
order.setCustomer(customer);
|
||||
order.setOrderDate(Date.valueOf("2018-06-28"));
|
||||
order.addShipment(new OrderShipment());
|
||||
|
||||
DB.save(order);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package org.tests.model.elementcollection;
|
||||
|
||||
import io.ebean.annotation.Cache;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Cache
|
||||
@Entity
|
||||
public class EcblPerson2 {
|
||||
|
||||
@Id
|
||||
long id;
|
||||
|
||||
String name;
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable(joinColumns = @JoinColumn(name = "person_id"))
|
||||
List<EcPhone> phoneNumbers = new ArrayList<>();
|
||||
|
||||
@Version
|
||||
long version;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "person id:" + id + " name:" + name + " phs:" + phoneNumbers;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<EcPhone> getPhoneNumbers() {
|
||||
return phoneNumbers;
|
||||
}
|
||||
|
||||
public void setPhoneNumbers(List<EcPhone> phoneNumbers) {
|
||||
this.phoneNumbers = phoneNumbers;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(long version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -9,10 +9,10 @@ import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestElementCollectionEmbeddedListCache extends BaseTestCase {
|
||||
class TestElementCollectionEmbeddedListCache extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
void test() {
|
||||
|
||||
EcblPerson person = new EcblPerson("CacheL");
|
||||
person.getPhoneNumbers().add(new EcPhone("64", "021","1234"));
|
||||
@@ -86,12 +86,10 @@ public class TestElementCollectionEmbeddedListCache extends BaseTestCase {
|
||||
assertThat(four.getPhoneNumbers().toString()).contains("61-07-11");
|
||||
assertThat(four.getPhoneNumbers()).hasSize(1);
|
||||
|
||||
|
||||
DB.delete(four);
|
||||
sql = LoggedSql.collect();
|
||||
assertThat(sql).hasSize(2);
|
||||
|
||||
|
||||
LoggedSql.stop();
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package org.tests.model.elementcollection;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.test.LoggedSql;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class TestElementCollectionEmbeddedListCache2 extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
|
||||
EcblPerson2 person = new EcblPerson2();
|
||||
person.setName("CacheL");
|
||||
person.getPhoneNumbers().add(new EcPhone("64", "021","1234"));
|
||||
person.getPhoneNumbers().add(new EcPhone("64","021","4321"));
|
||||
DB.save(person);
|
||||
|
||||
EcblPerson2 one = DB.find(EcblPerson2.class)
|
||||
.setId(person.getId())
|
||||
.fetch("phoneNumbers")
|
||||
.findOne();
|
||||
|
||||
LoggedSql.start();
|
||||
|
||||
one.getPhoneNumbers().size();
|
||||
|
||||
List<String> sql = LoggedSql.collect();
|
||||
assertThat(sql).isEmpty();
|
||||
|
||||
EcblPerson2 two = DB.find(EcblPerson2.class )
|
||||
.setId(person.getId())
|
||||
.findOne();
|
||||
|
||||
two.getPhoneNumbers().size();
|
||||
assertThat(two.getPhoneNumbers().toString()).contains("64-021-1234", "64-021-4321");
|
||||
|
||||
sql = LoggedSql.collect();
|
||||
assertThat(sql).isEmpty(); // cache hit
|
||||
|
||||
two.getPhoneNumbers().add(new EcPhone("61", "07", "11"));
|
||||
two.getPhoneNumbers().remove(1);
|
||||
|
||||
DB.save(two);
|
||||
|
||||
sql = LoggedSql.collect();
|
||||
if (isPersistBatchOnCascade()) {
|
||||
assertThat(sql).hasSize(5); // update of collection only
|
||||
assertSql(sql.get(0)).contains("delete from ecbl_person2_phone_numbers where person_id=?");
|
||||
assertSqlBind(sql.get(1));
|
||||
assertSql(sql.get(2)).contains("insert into ecbl_person2_phone_numbers (person_id,country_code,area,phnum) values (?,?,?,?)");
|
||||
assertSqlBind(sql, 3, 4);
|
||||
} else {
|
||||
assertThat(sql).hasSize(3); // update of collection only
|
||||
assertSql(sql.get(0)).contains("delete from ecbl_person2_phone_numbers where person_id=?");
|
||||
assertSql(sql.get(1)).contains("insert into ecbl_person2_phone_numbers (person_id,country_code,area,phnum) values (?,?,?,?)");
|
||||
assertSql(sql.get(2)).contains("insert into ecbl_person2_phone_numbers (person_id,country_code,area,phnum) values (?,?,?,?)");
|
||||
}
|
||||
|
||||
EcblPerson2 three = DB.find(EcblPerson2.class )
|
||||
.setId(person.getId())
|
||||
.findOne();
|
||||
|
||||
assertThat(three.getPhoneNumbers().toString()).contains("61-07-11", "64-021-1234");
|
||||
assertThat(three.getPhoneNumbers()).hasSize(2);
|
||||
|
||||
sql = LoggedSql.collect();
|
||||
assertThat(sql).isEmpty(); // cache hit
|
||||
|
||||
|
||||
three.setName("mod-3");
|
||||
three.getPhoneNumbers().remove(0);
|
||||
|
||||
DB.save(three);
|
||||
|
||||
sql = LoggedSql.collect();
|
||||
assertThat(sql).hasSize(5);
|
||||
|
||||
EcblPerson2 four = DB.find(EcblPerson2.class )
|
||||
.setId(person.getId())
|
||||
.findOne();
|
||||
|
||||
assertThat(four.getPhoneNumbers().toString()).contains("61-07-11");
|
||||
assertThat(four.getPhoneNumbers()).hasSize(1);
|
||||
|
||||
|
||||
DB.delete(four);
|
||||
sql = LoggedSql.collect();
|
||||
assertThat(sql).hasSize(2);
|
||||
|
||||
|
||||
LoggedSql.stop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.tests.model.embedded;
|
||||
|
||||
import io.ebean.annotation.DbArray;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class EmbArrayMaster {
|
||||
|
||||
@Embeddable
|
||||
public static class EmbArrayDetail {
|
||||
@DbArray
|
||||
List<String> vals;
|
||||
|
||||
public EmbArrayDetail(List<String> vals) {
|
||||
this.vals = vals;
|
||||
}
|
||||
}
|
||||
|
||||
@Id
|
||||
int id;
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "test_array_detail", joinColumns = {@JoinColumn(name = "master_id")})
|
||||
List<EmbArrayDetail> details;
|
||||
|
||||
public EmbArrayMaster(List<EmbArrayDetail> details) {
|
||||
this.details = details;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.tests.model.embedded;
|
||||
|
||||
import io.ebean.DB;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
class TestEmbeddedDbArray {
|
||||
|
||||
/**
|
||||
* Failing test case for #2477
|
||||
*/
|
||||
@Disabled
|
||||
@Test
|
||||
void testArrayInsert() {
|
||||
EmbArrayMaster t = new EmbArrayMaster(singletonList(new EmbArrayMaster.EmbArrayDetail(emptyList())));
|
||||
DB.insert(t);
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class MnyNode {
|
||||
joinColumns = @JoinColumn(name = "from_id", referencedColumnName = "id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "to_id", referencedColumnName = "id"))
|
||||
@Where(clause = "${mta}.flags & 1 != 0")
|
||||
@Where(clause = "BITAND(${mta}.flags, 1) != 0", platforms = Platform.H2)
|
||||
@Where(clause = "BITAND(${mta}.flags, 1) != 0", platforms = {Platform.H2, Platform.ORACLE})
|
||||
List<MnyNode> bit1Relations;
|
||||
|
||||
@ManyToMany
|
||||
@@ -41,7 +41,7 @@ public class MnyNode {
|
||||
joinColumns = @JoinColumn(name = "to_id", referencedColumnName = "id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "from_id", referencedColumnName = "id"))
|
||||
@Where(clause = "${mta}.flags & 1 != 0")
|
||||
@Where(clause = "BITAND(${mta}.flags, 1) != 0", platforms = Platform.H2)
|
||||
@Where(clause = "BITAND(${mta}.flags, 1) != 0", platforms = {Platform.H2, Platform.ORACLE})
|
||||
List<MnyNode> bit1ReverseRelations;
|
||||
|
||||
@ManyToMany
|
||||
@@ -49,7 +49,7 @@ public class MnyNode {
|
||||
joinColumns = @JoinColumn(name = "from_id", referencedColumnName = "id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "to_id", referencedColumnName = "id"))
|
||||
@Where(clause = "${mta}.flags & 2 != 0")
|
||||
@Where(clause = "BITAND(${mta}.flags, 2) != 0", platforms = Platform.H2)
|
||||
@Where(clause = "BITAND(${mta}.flags, 2) != 0", platforms = {Platform.H2, Platform.ORACLE})
|
||||
List<MnyNode> bit2Relations;
|
||||
|
||||
@ManyToMany
|
||||
@@ -57,7 +57,7 @@ public class MnyNode {
|
||||
joinColumns = @JoinColumn(name = "to_id", referencedColumnName = "id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "from_id", referencedColumnName = "id"))
|
||||
@Where(clause = "${mta}.flags & 2 != 0")
|
||||
@Where(clause = "BITAND(${mta}.flags, 2) != 0", platforms = Platform.H2)
|
||||
@Where(clause = "BITAND(${mta}.flags, 2) != 0", platforms = {Platform.H2, Platform.ORACLE})
|
||||
List<MnyNode> bit2ReverseRelations;
|
||||
|
||||
@ManyToMany
|
||||
|
||||
@@ -131,7 +131,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
|
||||
|
||||
Query<Customer> query = DB.find(Customer.class)
|
||||
.select("name")
|
||||
.where().eq("id", 1).query();
|
||||
.where().eq("name", "Rob").query();
|
||||
|
||||
String name = query.findSingleAttribute();
|
||||
|
||||
@@ -248,7 +248,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
|
||||
|
||||
String name = DB.find(Customer.class)
|
||||
.select("name")
|
||||
.where().eq("id", 1)
|
||||
.where().eq("name", "Rob")
|
||||
.findSingleAttribute();
|
||||
|
||||
assertThat(name).isNotNull();
|
||||
@@ -646,7 +646,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
|
||||
.findSingleAttributeList();
|
||||
assertThat(list1.get(0)).isInstanceOf(CountedValue.class);
|
||||
//assertThat(list1.toString()).isEqualTo("[1: Tracy, 3: Jim1, 1: Jack, 3: Fred1, 1: Fiona, 3: Bugs1]");
|
||||
|
||||
|
||||
query = DB.find(Contact.class).select("firstName");
|
||||
list1 = query
|
||||
.setCountDistinct(CountDistinctOrder.NO_ORDERING)
|
||||
|
||||
@@ -12,14 +12,12 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class ParentQueryTest extends BaseTestCase {
|
||||
class ParentQueryTest extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void QueryParentCollectionFetch() {
|
||||
|
||||
void queryParentCollectionFetch() {
|
||||
List<Data> exampleData = new ArrayList<>();
|
||||
exampleData.add(new Data(0));
|
||||
exampleData.add(new Data(1));
|
||||
@@ -40,7 +38,7 @@ public class ParentQueryTest extends BaseTestCase {
|
||||
List<Parent> partial = DB.find(Parent.class).where().ge("val", 1001).findList();
|
||||
assertNotNull(partial.get(0).getData());
|
||||
assertThat(partial.get(0).getMore()).startsWith("PQT-");
|
||||
assertEquals(partial.get(0).getData().get(0).getVal().intValue(), 0);
|
||||
assertThat(partial.get(0).getData()).hasSize(3);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class TestSqlUpdateUpsert extends BaseTestCase {
|
||||
.setParameter("online", false);
|
||||
|
||||
Object key2 = sqlUpdate2.executeGetKey();
|
||||
assertThat(key2).isNull();
|
||||
assertThat(key2).isEqualTo(key);
|
||||
|
||||
|
||||
EPersonOnline found2 = DB.find(EPersonOnline.class).where().eq("email", email).findOne();
|
||||
|
||||
@@ -3,11 +3,13 @@ package org.tests.update;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.TransactionalTestCase;
|
||||
import io.ebean.test.LoggedSql;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.EBasic;
|
||||
import org.tests.model.basic.EBasic.Status;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import java.util.*;
|
||||
@@ -17,6 +19,11 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestStatelessUpdate extends TransactionalTestCase {
|
||||
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
|
||||
@@ -3,14 +3,21 @@ package org.tests.update;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.SqlRow;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestUpdatePartial extends BaseTestCase {
|
||||
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ datasource.db.databaseDriver=org.h2.Driver
|
||||
|
||||
datasource.h2.username=sa
|
||||
datasource.h2.password=
|
||||
datasource.h2.url=jdbc:h2:mem:testsMem;DB_CLOSE_ON_EXIT=FALSE
|
||||
datasource.h2.url=jdbc:h2:mem:testsMem;DB_CLOSE_ON_EXIT=FALSE;NON_KEYWORDS=KEY,VALUE
|
||||
datasource.h2.poolListener=org.tests.basic.MyTestDataSourcePoolListener
|
||||
#datasource.h2.minConnections=1
|
||||
#datasource.h2.maxConnections=25
|
||||
|
||||
@@ -8,5 +8,5 @@ ebean.jodaLocalTimeMode=normal
|
||||
|
||||
datasource.someotherdb.username=sa
|
||||
datasource.someotherdb.password=
|
||||
datasource.someotherdb.databaseUrl=jdbc:h2:mem:someotherdb
|
||||
datasource.someotherdb.databaseUrl=jdbc:h2:mem:someotherdb;NON_KEYWORDS=KEY,VALUE
|
||||
datasource.someotherdb.databaseDriver=org.h2.Driver
|
||||
Reference in new issue
Block a user