mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-09-20 03:16:42 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -8,13 +8,14 @@ import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.EBasicClobNoVer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestBasicClobNoVer extends BaseTestCase {
|
||||
class TestBasicClobNoVer extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
void test() {
|
||||
|
||||
EBasicClobNoVer entity = new EBasicClobNoVer();
|
||||
entity.setName("test");
|
||||
@@ -65,4 +66,36 @@ public class TestBasicClobNoVer extends BaseTestCase {
|
||||
assertThat(entity.getDescription()).isEqualTo("modified");
|
||||
}
|
||||
|
||||
@Test
|
||||
void refresh_withSoftDelete() {
|
||||
|
||||
EBasicClobNoVer bean = new EBasicClobNoVer();
|
||||
bean.setDescription("hello");
|
||||
DB.save(bean);
|
||||
|
||||
DB.refresh(bean);
|
||||
|
||||
LoggedSql.start();
|
||||
bean.children().forEach(System.out::println);
|
||||
List<String> sql = LoggedSql.stop();
|
||||
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains(" and t0.deleted =");
|
||||
}
|
||||
|
||||
@Test
|
||||
void largeValueInsert() {
|
||||
EBasicClobNoVer bean = new EBasicClobNoVer();
|
||||
bean.setDescription(largeContent());
|
||||
DB.save(bean);
|
||||
}
|
||||
|
||||
private String largeContent() {
|
||||
Random random = new Random();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 1048577; i++) {
|
||||
sb.append((char) (random.nextInt(26) + 'a'));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.tests.inheritance.bothsides;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Inheritance;
|
||||
|
||||
@Entity
|
||||
public class Target1 extends TargetBase {
|
||||
|
||||
@@ -3,6 +3,9 @@ package org.tests.model.basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class EBasicClobNoVer {
|
||||
@@ -18,6 +21,9 @@ public class EBasicClobNoVer {
|
||||
@Lob
|
||||
private String description;
|
||||
|
||||
@OneToMany
|
||||
private List<EBasicClobNoVerChild> children = new ArrayList<>();
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
@@ -41,4 +47,13 @@ public class EBasicClobNoVer {
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public List<EBasicClobNoVerChild> children() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public EBasicClobNoVer children(List<EBasicClobNoVerChild> children) {
|
||||
this.children = children;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import io.ebean.annotation.SoftDelete;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Entity
|
||||
public class EBasicClobNoVerChild {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@ManyToOne
|
||||
private final EBasicClobNoVer parent;
|
||||
|
||||
private final String child;
|
||||
|
||||
@SoftDelete
|
||||
private boolean deleted;
|
||||
|
||||
public EBasicClobNoVerChild(EBasicClobNoVer parent, String child) {
|
||||
this.parent = parent;
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
public Long id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public EBasicClobNoVerChild id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String child() {
|
||||
return child;
|
||||
}
|
||||
|
||||
public boolean deleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public EBasicClobNoVerChild deleted(boolean deleted) {
|
||||
this.deleted = deleted;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,6 @@ import javax.annotation.Nullable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
@Entity
|
||||
public class MDateTime {
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ public class TWithPreInsert implements TWithPreInsertCommon {
|
||||
*/
|
||||
transient int requestCascadeState;
|
||||
|
||||
@Override
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -36,18 +37,22 @@ public class TWithPreInsert implements TWithPreInsertCommon {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
@@ -60,6 +65,7 @@ public class TWithPreInsert implements TWithPreInsertCommon {
|
||||
return requestCascadeState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestCascadeState(int requestCascadeState) {
|
||||
this.requestCascadeState = requestCascadeState;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public class TWithPreInsertChild implements TWithPreInsertCommon {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -32,18 +33,22 @@ public class TWithPreInsertChild implements TWithPreInsertCommon {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
@@ -52,6 +57,7 @@ public class TWithPreInsertChild implements TWithPreInsertCommon {
|
||||
return requestCascadeState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestCascadeState(int requestCascadeState) {
|
||||
this.requestCascadeState = requestCascadeState;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class TestHistoryExclude extends BaseTestCase {
|
||||
linkFound.getDocs().size();
|
||||
}
|
||||
|
||||
@IgnorePlatform({Platform.ORACLE, Platform.DB2, Platform.COCKROACH})
|
||||
@IgnorePlatform({Platform.ORACLE, Platform.COCKROACH})
|
||||
@Test
|
||||
public void testAsOfThenLazy() {
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public class TestHistoryInclude extends BaseTestCase {
|
||||
assertThat(linkFound.getDocs().size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@IgnorePlatform({Platform.ORACLE, Platform.DB2, Platform.COCKROACH})
|
||||
@IgnorePlatform({Platform.ORACLE, Platform.COCKROACH})
|
||||
@Test
|
||||
public void testAsOfThenLazy() {
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestHistoryOneToMany extends BaseTestCase {
|
||||
|
||||
@IgnorePlatform({Platform.ORACLE, Platform.DB2, Platform.COCKROACH})
|
||||
@IgnorePlatform({Platform.ORACLE, Platform.COCKROACH})
|
||||
@Test
|
||||
public void test() throws InterruptedException {
|
||||
|
||||
|
||||
+11
-13
@@ -3,24 +3,22 @@ package org.tests.model.lazywithcache;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Transaction;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Test with bean cache and lazy loaded property.
|
||||
*
|
||||
* @author Noemi Szemenyei, FOCONIS AG
|
||||
*
|
||||
*/
|
||||
public class TestWithCacheAndLazyLoad extends BaseTestCase{
|
||||
class TestWithCacheAndLazyLoad extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetters() {
|
||||
void testGetters() {
|
||||
|
||||
ChildWithCache child = new ChildWithCache();
|
||||
child.setId(1L);
|
||||
@@ -52,19 +50,19 @@ public class TestWithCacheAndLazyLoad extends BaseTestCase{
|
||||
assertThat(temp.getAddress()).isEqualTo("Address");
|
||||
assertThat(temp.getName()).isEqualTo("Child With Cache");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBatch() throws Exception {
|
||||
|
||||
void testBatch() {
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
ChildWithCache child = new ChildWithCache();
|
||||
child.setId(1000L+i);
|
||||
child.setName("Child With Cache "+ i);
|
||||
child.setId(1000L + i);
|
||||
child.setName("Child With Cache " + i);
|
||||
child.setAddress("Address");
|
||||
DB.save(child);
|
||||
|
||||
ParentA parentA = new ParentA();
|
||||
parentA.setId(1000L+i);
|
||||
parentA.setId(1000L + i);
|
||||
parentA.setName("Parent A");
|
||||
parentA.setChild(child);
|
||||
DB.save(parentA);
|
||||
@@ -72,7 +70,7 @@ public class TestWithCacheAndLazyLoad extends BaseTestCase{
|
||||
// 0. load cache
|
||||
ParentA temp = DB.find(ParentA.class, 1000L);
|
||||
temp.getChild().getName();
|
||||
|
||||
|
||||
try (Transaction txn = DB.beginTransaction()) {
|
||||
// 1. FindList
|
||||
List<ParentA> list = DB.find(ParentA.class).where().ge("id", 1000L).orderBy("id").findList();
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.ebean.DB;
|
||||
import io.ebean.SqlRow;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.bean.EntityBeanIntercept;
|
||||
import io.ebean.test.LoggedSql;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -142,13 +143,16 @@ public class TestNoFk extends BaseTestCase {
|
||||
assertTrue(ownerEbi.isReference());
|
||||
assertTrue(ownerEbi.isPartial());
|
||||
assertTrue(ownerEbi.isLazyLoadFailure());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEagerLoadFile() {
|
||||
LoggedSql.start();
|
||||
List<EFileNoFk> files = DB.find(EFileNoFk.class).fetch("owner").findList();
|
||||
assertThat(files).hasSize(2);
|
||||
List<String> sql = LoggedSql.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("select t0.file_name, t0.owner_user_id, t0.owner_soft_del_user_id, t1.user_id, t1.user_name from efile_no_fk t0 left join euser_no_fk t1 on t1.user_id = t0.owner_user_id");
|
||||
|
||||
EFileNoFk file1 = files.get(0);
|
||||
EFileNoFk file2 = files.get(1);
|
||||
@@ -175,7 +179,6 @@ public class TestNoFk extends BaseTestCase {
|
||||
assertTrue(ownerEbi.isReference());
|
||||
assertTrue(ownerEbi.isPartial());
|
||||
assertTrue(ownerEbi.isLazyLoadFailure());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -259,8 +262,14 @@ public class TestNoFk extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testEagerLoadFileSoftDel() {
|
||||
LoggedSql.start();
|
||||
List<EFileNoFk> files = DB.find(EFileNoFk.class).fetch("ownerSoftDel").findList();
|
||||
assertThat(files).hasSize(2);
|
||||
List<String> sql = LoggedSql.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
if (isH2() || isPostgres()) {
|
||||
assertThat(sql.get(0)).contains("select t0.file_name, t0.owner_user_id, t0.owner_soft_del_user_id, t1.user_id, t1.user_name, t1.user_id is null from efile_no_fk t0 left join euser_no_fk_soft_del t1 on t1.user_id = t0.owner_soft_del_user_id");
|
||||
}
|
||||
|
||||
EFileNoFk file1 = files.get(0);
|
||||
EFileNoFk file2 = files.get(1);
|
||||
|
||||
@@ -14,7 +14,6 @@ class TestQueryMultiJoinFetchPath extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
|
||||
HCustomer c1 = new HCustomer("c1", "c1");
|
||||
DB.save(c1);
|
||||
|
||||
@@ -60,9 +59,9 @@ class TestQueryMultiJoinFetchPath extends BaseTestCase {
|
||||
|
||||
assertThat(accesses).hasSize(2);
|
||||
if (isH2()) {
|
||||
assertThat(query.getGeneratedSql()).isEqualTo("select t0.dtype, t0.id, t0.accessor_id, t0.principal_id, t2.dtype, t0.access_account_number, t0.accessor_id, t2.dtype, t0.access_account_number, t1.cid, t1.name, t2.dtype, t2.account_number from haccess t0 left join hcustomer t1 on t1.cid = t0.accessor_id left join haccount t2 on t2.account_number = t0.access_account_number and t2.dtype = 'B' left join hcustomer t3 on t3.cid = t0.principal_id where t1.status = ? and t3.status = ? and t0.id in (?,?,?,?,?)");
|
||||
assertThat(query.getGeneratedSql()).isEqualTo("select t0.dtype, t0.id, t0.accessor_id, t0.principal_id, t2.dtype, t0.access_account_number, t1.cid, t1.name, t2.dtype, t2.account_number from haccess t0 left join hcustomer t1 on t1.cid = t0.accessor_id left join haccount t2 on t2.account_number = t0.access_account_number and t2.dtype = 'B' left join hcustomer t3 on t3.cid = t0.principal_id where t1.status = ? and t3.status = ? and t0.id in (?,?,?,?,?)");
|
||||
} else {
|
||||
assertThat(query.getGeneratedSql()).contains("select t0.dtype, t0.id, t0.accessor_id, t0.principal_id, t2.dtype, t0.access_account_number, t0.accessor_id, t2.dtype, t0.access_account_number, t1.cid, t1.name, t2.dtype, t2.account_number from haccess t0 left join hcustomer t1 on t1.cid = t0.accessor_id left join haccount t2 on t2.account_number = t0.access_account_number and t2.dtype = 'B' left join hcustomer t3 on t3.cid = t0.principal_id where t1.status = ? and t3.status = ? and t0.id ");
|
||||
assertThat(query.getGeneratedSql()).contains("select t0.dtype, t0.id, t0.accessor_id, t0.principal_id, t2.dtype, t0.access_account_number, t1.cid, t1.name, t2.dtype, t2.account_number from haccess t0 left join hcustomer t1 on t1.cid = t0.accessor_id left join haccount t2 on t2.account_number = t0.access_account_number and t2.dtype = 'B' left join hcustomer t3 on t3.cid = t0.principal_id where t1.status = ? and t3.status = ? and t0.id ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.tests.query.finder;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.annotation.IgnorePlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.meta.*;
|
||||
import io.ebean.test.LoggedSql;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -163,6 +165,7 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@IgnorePlatform(Platform.DB2) // no query plans yet, for DB2
|
||||
public void test_finders_queryPlans() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class TestRawSqlNamedParams extends BaseTestCase {
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import io.ebean.util.IOUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user