mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Merge remote-tracking branch 'upstream/master' into subquery-with-fetch-path
This commit is contained in:
@@ -90,14 +90,14 @@ public abstract class BaseTestCase {
|
||||
}
|
||||
|
||||
protected List<MetaTimedMetric> visitTimedMetrics() {
|
||||
return collectMetrics().getTimedMetrics();
|
||||
return collectMetrics().timedMetrics();
|
||||
}
|
||||
|
||||
protected List<MetaTimedMetric> sqlMetrics() {
|
||||
List<MetaTimedMetric> timedMetrics = visitTimedMetrics();
|
||||
|
||||
return timedMetrics.stream()
|
||||
.filter((it) -> it.getName().startsWith("sql.") || it.getName().startsWith("orm."))
|
||||
.filter((it) -> it.name().startsWith("sql.") || it.name().startsWith("orm."))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
@@ -191,13 +191,13 @@ public class DtoQuery2Test extends BaseTestCase {
|
||||
BasicMetricVisitor basic = new BasicMetricVisitor(false, true, true, true);
|
||||
server().getMetaInfoManager().visitMetrics(basic);
|
||||
|
||||
List<MetaQueryMetric> stats = basic.getQueryMetrics();
|
||||
List<MetaQueryMetric> stats = basic.queryMetrics();
|
||||
assertThat(stats).hasSize(1);
|
||||
|
||||
MetaQueryMetric queryMetric = stats.get(0);
|
||||
assertThat(queryMetric.getLabel()).isEqualTo("basic");
|
||||
assertThat(queryMetric.getCount()).isEqualTo(3);
|
||||
assertThat(queryMetric.getName()).isEqualTo("dto.DCust_basic");
|
||||
assertThat(queryMetric.label()).isEqualTo("basic");
|
||||
assertThat(queryMetric.count()).isEqualTo(3);
|
||||
assertThat(queryMetric.name()).isEqualTo("dto.DCust_basic");
|
||||
|
||||
|
||||
server().findDto(DCust.class, "select c4.id, c4.name from o_customer c4 where lower(c4.name) = :name")
|
||||
@@ -207,7 +207,7 @@ public class DtoQuery2Test extends BaseTestCase {
|
||||
|
||||
BasicMetricVisitor metric2 = server().getMetaInfoManager().visitBasic();
|
||||
|
||||
stats = metric2.getQueryMetrics();
|
||||
stats = metric2.queryMetrics();
|
||||
assertThat(stats).hasSize(2);
|
||||
|
||||
log.info("stats " + stats);
|
||||
|
||||
@@ -27,12 +27,12 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
@AfterClass
|
||||
public static void reportStats() {
|
||||
ServerMetrics metrics = DB.getDefault().getMetaInfoManager().collectMetrics();
|
||||
for (MetaQueryMetric metric : metrics.getQueryMetrics()) {
|
||||
for (MetaQueryMetric metric : metrics.queryMetrics()) {
|
||||
System.out.println(metric);
|
||||
}
|
||||
|
||||
System.out.println("-- transaction metrics --");
|
||||
for (MetaTimedMetric metric : metrics.getTimedMetrics()) {
|
||||
for (MetaTimedMetric metric : metrics.timedMetrics()) {
|
||||
System.out.println(metric);
|
||||
}
|
||||
}
|
||||
@@ -59,15 +59,15 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
ServerMetrics metrics = collectMetrics();
|
||||
|
||||
List<MetaQueryMetric> stats = metrics.getQueryMetrics();
|
||||
List<MetaQueryMetric> stats = metrics.queryMetrics();
|
||||
for (MetaQueryMetric stat : stats) {
|
||||
long meanMicros = stat.getMean();
|
||||
long meanMicros = stat.mean();
|
||||
assertThat(meanMicros).isLessThan(900_000);
|
||||
assertThat(stat.getLocation()).isSameAs(loc0.location());
|
||||
assertThat(stat.location()).isSameAs(loc0.location());
|
||||
}
|
||||
|
||||
assertThat(stats).hasSize(1);
|
||||
assertThat(stats.get(0).getCount()).isEqualTo(4);
|
||||
assertThat(stats.get(0).count()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@ForPlatform(Platform.H2)
|
||||
|
||||
@@ -42,14 +42,14 @@ public class DtoQueryTest extends BaseTestCase {
|
||||
|
||||
ServerMetrics metrics = collectMetrics();
|
||||
|
||||
List<MetaQueryMetric> stats = metrics.getQueryMetrics();
|
||||
List<MetaQueryMetric> stats = metrics.queryMetrics();
|
||||
for (MetaQueryMetric stat : stats) {
|
||||
long meanMicros = stat.getMean();
|
||||
long meanMicros = stat.mean();
|
||||
assertThat(meanMicros).isLessThan(900_000);
|
||||
}
|
||||
|
||||
assertThat(stats).hasSize(1);
|
||||
assertThat(stats.get(0).getCount()).isEqualTo(1);
|
||||
assertThat(stats.get(0).count()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -283,13 +283,13 @@ public class DtoQueryTest extends BaseTestCase {
|
||||
BasicMetricVisitor basic = new BasicMetricVisitor(false, true, true, true);
|
||||
server().getMetaInfoManager().visitMetrics(basic);
|
||||
|
||||
List<MetaQueryMetric> stats = basic.getQueryMetrics();
|
||||
List<MetaQueryMetric> stats = basic.queryMetrics();
|
||||
assertThat(stats).hasSize(1);
|
||||
|
||||
MetaQueryMetric queryMetric = stats.get(0);
|
||||
assertThat(queryMetric.getLabel()).isEqualTo("basic");
|
||||
assertThat(queryMetric.getCount()).isEqualTo(3);
|
||||
assertThat(queryMetric.getName()).isEqualTo("dto.DCust_basic");
|
||||
assertThat(queryMetric.label()).isEqualTo("basic");
|
||||
assertThat(queryMetric.count()).isEqualTo(3);
|
||||
assertThat(queryMetric.name()).isEqualTo("dto.DCust_basic");
|
||||
|
||||
|
||||
server().findDto(DCust.class, "select c4.id, c4.name from o_customer c4 where lower(c4.name) = :name")
|
||||
@@ -299,7 +299,7 @@ public class DtoQueryTest extends BaseTestCase {
|
||||
|
||||
ServerMetrics metric2 = server().getMetaInfoManager().collectMetrics();
|
||||
|
||||
stats = metric2.getQueryMetrics();
|
||||
stats = metric2.queryMetrics();
|
||||
assertThat(stats).hasSize(2);
|
||||
|
||||
log.info("stats " + stats);
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class EbeanServer_refresh {
|
||||
|
||||
@@ -39,8 +39,11 @@ public class EbeanServer_refresh {
|
||||
|
||||
assertEquals(rows, 1);
|
||||
|
||||
basic.setName("modify");
|
||||
assertTrue(DB.getBeanState(basic).isDirty());
|
||||
server.refresh(basic);
|
||||
assertEquals(basic.getStatus(), EBasic.Status.ACTIVE);
|
||||
assertFalse(DB.getBeanState(basic).isDirty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -39,10 +39,10 @@ public class UpdateQueryTest extends BaseTestCase {
|
||||
assertSql(query).contains("update o_customer set status=?, updtime=? where status = ? and id > ?");
|
||||
|
||||
ServerMetrics metrics = collectMetrics();
|
||||
List<MetaQueryMetric> ormQueryMetrics = metrics.getQueryMetrics();
|
||||
List<MetaQueryMetric> ormQueryMetrics = metrics.queryMetrics();
|
||||
assertThat(ormQueryMetrics).hasSize(1);
|
||||
assertThat(ormQueryMetrics.get(0).getType()).isEqualTo(Customer.class);
|
||||
assertThat(ormQueryMetrics.get(0).getLabel()).isEqualTo("updateActive");
|
||||
assertThat(ormQueryMetrics.get(0).type()).isEqualTo(Customer.class);
|
||||
assertThat(ormQueryMetrics.get(0).label()).isEqualTo("updateActive");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,10 +69,10 @@ public class UpdateQueryTest extends BaseTestCase {
|
||||
assertSql(sql.get(0)).contains("update o_customer set status = status");
|
||||
|
||||
ServerMetrics metrics = collectMetrics();
|
||||
List<MetaQueryMetric> ormQueryMetrics = metrics.getQueryMetrics();
|
||||
List<MetaQueryMetric> ormQueryMetrics = metrics.queryMetrics();
|
||||
assertThat(ormQueryMetrics).hasSize(1);
|
||||
assertThat(ormQueryMetrics.get(0).getType()).isEqualTo(Customer.class);
|
||||
assertThat(ormQueryMetrics.get(0).getLabel()).isEqualTo("updateAll");
|
||||
assertThat(ormQueryMetrics.get(0).type()).isEqualTo(Customer.class);
|
||||
assertThat(ormQueryMetrics.get(0).label()).isEqualTo("updateAll");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -4,7 +4,6 @@ import io.ebean.bean.BeanCollection;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -13,9 +12,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BeanListTest {
|
||||
|
||||
private Object object1 = new Object();
|
||||
private Object object2 = new Object();
|
||||
private Object object3 = new Object();
|
||||
private final Object object1 = new Object();
|
||||
private final Object object2 = new Object();
|
||||
private final Object object3 = new Object();
|
||||
|
||||
private List<Object> all() {
|
||||
List<Object> all = new ArrayList<>();
|
||||
@@ -33,7 +32,7 @@ public class BeanListTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_setModifyListening_null() throws Exception {
|
||||
public void test_setModifyListening_null() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>();
|
||||
list.setModifyListening(null);
|
||||
@@ -45,7 +44,7 @@ public class BeanListTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_setModifyListening_none() throws Exception {
|
||||
public void test_setModifyListening_none() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>();
|
||||
list.setModifyListening(BeanCollection.ModifyListenMode.NONE);
|
||||
@@ -57,28 +56,28 @@ public class BeanListTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd() throws Exception {
|
||||
public void testAdd() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>();
|
||||
list.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
list.add(object1);
|
||||
|
||||
assertThat(list.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(list.getModifyAdditions()).containsOnly(object1);
|
||||
assertThat(list.getModifyRemovals()).isEmpty();
|
||||
|
||||
list.add(object1);
|
||||
assertThat(list.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(list.getModifyAdditions()).containsOnly(object1);
|
||||
|
||||
list.add(object2);
|
||||
assertThat(list.getModifyAdditions()).containsExactly(object1, object2);
|
||||
assertThat(list.getModifyAdditions()).containsOnly(object1, object2);
|
||||
|
||||
list.remove(object1);
|
||||
assertThat(list.getModifyAdditions()).containsExactly(object2);
|
||||
assertThat(list.getModifyAdditions()).containsOnly(object2);
|
||||
assertThat(list.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAll_given_emptyStart() throws Exception {
|
||||
public void testAddAll_given_emptyStart() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>();
|
||||
list.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -86,12 +85,12 @@ public class BeanListTest {
|
||||
// act
|
||||
list.addAll(all());
|
||||
|
||||
assertThat(list.getModifyAdditions()).containsExactly(object1, object2, object3);
|
||||
assertThat(list.getModifyAdditions()).containsOnly(object1, object2, object3);
|
||||
assertThat(list.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_removals_DeleteThenAddBack_expect_noChange() throws Exception {
|
||||
public void test_removals_DeleteThenAddBack_expect_noChange() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>(some());
|
||||
list.setModifyListening(BeanCollection.ModifyListenMode.REMOVALS);
|
||||
@@ -106,33 +105,33 @@ public class BeanListTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_sort_whenAll_expect_noChange() throws Exception {
|
||||
public void test_sort_whenAll_expect_noChange() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>(all());
|
||||
list.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
|
||||
// act
|
||||
Collections.sort(list, Comparator.comparingInt(Object::hashCode));
|
||||
list.sort(Comparator.comparingInt(Object::hashCode));
|
||||
|
||||
assertThat(list.getModifyRemovals()).isEmpty();
|
||||
assertThat(list.getModifyAdditions()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_sort_whenRemovals_expect_noChange() throws Exception {
|
||||
public void test_sort_whenRemovals_expect_noChange() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>(all());
|
||||
list.setModifyListening(BeanCollection.ModifyListenMode.REMOVALS);
|
||||
|
||||
// act
|
||||
Collections.sort(list, Comparator.comparingInt(Object::hashCode));
|
||||
list.sort(Comparator.comparingInt(Object::hashCode));
|
||||
|
||||
assertThat(list.getModifyRemovals()).isEmpty();
|
||||
assertThat(list.getModifyAdditions()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd_given_someAlreadyIn() throws Exception {
|
||||
public void testAdd_given_someAlreadyIn() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>(some());
|
||||
list.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -143,12 +142,12 @@ public class BeanListTest {
|
||||
assertThat(list.contains(object2)).isTrue();
|
||||
list.add(object2); // object2 added as List allows duplicates
|
||||
|
||||
assertThat(list.getModifyAdditions()).containsExactly(object1, object2);
|
||||
assertThat(list.getModifyAdditions()).containsOnly(object1, object2);
|
||||
assertThat(list.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddSome_given_someAlreadyIn() throws Exception {
|
||||
public void testAddSome_given_someAlreadyIn() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>(some());
|
||||
list.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -156,43 +155,43 @@ public class BeanListTest {
|
||||
// act
|
||||
list.addAll(all());
|
||||
|
||||
assertThat(list.getModifyAdditions()).containsExactly(object1, object2, object3);
|
||||
assertThat(list.getModifyAdditions()).containsOnly(object1, object2, object3);
|
||||
assertThat(list.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove_given_beansInAdditions() throws Exception {
|
||||
public void testRemove_given_beansInAdditions() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>();
|
||||
list.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
list.addAll(all());
|
||||
assertThat(list.getModifyAdditions()).containsExactly(object1, object2, object3);
|
||||
assertThat(list.getModifyAdditions()).containsOnly(object1, object2, object3);
|
||||
|
||||
// act
|
||||
list.remove(object2);
|
||||
list.remove(object3);
|
||||
|
||||
assertThat(list.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(list.getModifyAdditions()).containsOnly(object1);
|
||||
assertThat(list.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAll_given_beansInAdditions() throws Exception {
|
||||
public void testRemoveAll_given_beansInAdditions() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>();
|
||||
list.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
list.addAll(all());
|
||||
assertThat(list.getModifyAdditions()).containsExactly(object1, object2, object3);
|
||||
assertThat(list.getModifyAdditions()).containsOnly(object1, object2, object3);
|
||||
|
||||
// act
|
||||
list.removeAll(some());
|
||||
|
||||
assertThat(list.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(list.getModifyAdditions()).containsOnly(object1);
|
||||
assertThat(list.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove_given_beansNotInAdditions() throws Exception {
|
||||
public void testRemove_given_beansNotInAdditions() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>(all());
|
||||
list.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -203,11 +202,11 @@ public class BeanListTest {
|
||||
|
||||
// assert
|
||||
assertThat(list.getModifyAdditions()).isEmpty();
|
||||
assertThat(list.getModifyRemovals()).containsExactly(object2, object3);
|
||||
assertThat(list.getModifyRemovals()).containsOnly(object2, object3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAll_given_beansNotInAdditions() throws Exception {
|
||||
public void testRemoveAll_given_beansNotInAdditions() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>(all());
|
||||
list.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -217,11 +216,11 @@ public class BeanListTest {
|
||||
|
||||
// assert
|
||||
assertThat(list.getModifyAdditions()).isEmpty();
|
||||
assertThat(list.getModifyRemovals()).containsExactly(object2, object3);
|
||||
assertThat(list.getModifyRemovals()).containsOnly(object2, object3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClear() throws Exception {
|
||||
public void testClear() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>(all());
|
||||
list.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -230,12 +229,12 @@ public class BeanListTest {
|
||||
list.clear();
|
||||
|
||||
//assert
|
||||
assertThat(list.getModifyRemovals()).containsExactly(object1, object2, object3);
|
||||
assertThat(list.getModifyRemovals()).containsOnly(object1, object2, object3);
|
||||
assertThat(list.getModifyAdditions()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClear_given_someBeansInAdditions() throws Exception {
|
||||
public void testClear_given_someBeansInAdditions() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>();
|
||||
list.add(object1);
|
||||
@@ -247,27 +246,27 @@ public class BeanListTest {
|
||||
list.clear();
|
||||
|
||||
//assert
|
||||
assertThat(list.getModifyRemovals()).containsExactly(object1);
|
||||
assertThat(list.getModifyRemovals()).containsOnly(object1);
|
||||
assertThat(list.getModifyAdditions()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetainAll_given_beansInAdditions() throws Exception {
|
||||
public void testRetainAll_given_beansInAdditions() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>();
|
||||
list.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
list.addAll(all());
|
||||
assertThat(list.getModifyAdditions()).containsExactly(object1, object2, object3);
|
||||
assertThat(list.getModifyAdditions()).containsOnly(object1, object2, object3);
|
||||
|
||||
// act
|
||||
list.retainAll(some());
|
||||
|
||||
assertThat(list.getModifyAdditions()).containsExactly(object2, object3);
|
||||
assertThat(list.getModifyAdditions()).containsOnly(object2, object3);
|
||||
assertThat(list.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetainAll_given_someBeansInAdditions() throws Exception {
|
||||
public void testRetainAll_given_someBeansInAdditions() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>();
|
||||
list.add(object1);
|
||||
@@ -278,12 +277,12 @@ public class BeanListTest {
|
||||
// act
|
||||
list.retainAll(some());
|
||||
|
||||
assertThat(list.getModifyAdditions()).containsExactly(object3);
|
||||
assertThat(list.getModifyRemovals()).containsExactly(object1);
|
||||
assertThat(list.getModifyAdditions()).containsOnly(object3);
|
||||
assertThat(list.getModifyRemovals()).containsOnly(object1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetainAll_given_noBeansInAdditions() throws Exception {
|
||||
public void testRetainAll_given_noBeansInAdditions() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>(all());
|
||||
list.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -291,7 +290,7 @@ public class BeanListTest {
|
||||
// act
|
||||
list.retainAll(some());
|
||||
|
||||
assertThat(list.getModifyRemovals()).containsExactly(object1);
|
||||
assertThat(list.getModifyRemovals()).containsOnly(object1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -34,30 +34,30 @@ public class BeanMapTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd() throws Exception {
|
||||
public void testAdd() {
|
||||
|
||||
BeanMap<String, Object> map = new BeanMap<>();
|
||||
map.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
map.put("1", object1);
|
||||
map.put("4", null);
|
||||
|
||||
assertThat(map.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(map.getModifyAdditions()).containsOnly(object1);
|
||||
assertThat(map.getModifyRemovals()).isEmpty();
|
||||
|
||||
map.put("1", object1);
|
||||
map.put("4", null);
|
||||
assertThat(map.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(map.getModifyAdditions()).containsOnly(object1);
|
||||
|
||||
map.put("2", object2);
|
||||
assertThat(map.getModifyAdditions()).containsExactly(object1, object2);
|
||||
assertThat(map.getModifyAdditions()).containsOnly(object1, object2);
|
||||
|
||||
map.remove("1");
|
||||
assertThat(map.getModifyAdditions()).containsExactly(object2);
|
||||
assertThat(map.getModifyAdditions()).containsOnly(object2);
|
||||
assertThat(map.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAll_given_emptyStart() throws Exception {
|
||||
public void testAddAll_given_emptyStart() {
|
||||
|
||||
BeanMap<String, Object> set = new BeanMap<>();
|
||||
set.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -65,28 +65,28 @@ public class BeanMapTest {
|
||||
// act
|
||||
set.putAll(all());
|
||||
|
||||
assertThat(set.getModifyAdditions()).containsExactly(object1, object2, object3);
|
||||
assertThat(set.getModifyAdditions()).containsOnly(object1, object2, object3);
|
||||
assertThat(set.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd_given_someAlreadyIn() throws Exception {
|
||||
public void testAdd_given_someAlreadyIn() {
|
||||
|
||||
BeanMap<String, Object> map = new BeanMap<>(some());
|
||||
map.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
|
||||
// act
|
||||
assertThat(map.values().contains(object1)).isFalse();
|
||||
assertThat(map.containsValue(object1)).isFalse();
|
||||
map.put("1", object1);
|
||||
assertThat(map.values().contains(object2)).isTrue();
|
||||
assertThat(map.containsValue(object2)).isTrue();
|
||||
map.put("2", object2);
|
||||
|
||||
assertThat(map.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(map.getModifyAdditions()).containsOnly(object1);
|
||||
assertThat(map.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddSome_given_someAlreadyIn() throws Exception {
|
||||
public void testAddSome_given_someAlreadyIn() {
|
||||
|
||||
BeanMap<String, Object> map = new BeanMap<>(some());
|
||||
map.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -94,44 +94,44 @@ public class BeanMapTest {
|
||||
// act
|
||||
map.putAll(all());
|
||||
|
||||
assertThat(map.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(map.getModifyAdditions()).containsOnly(object1);
|
||||
assertThat(map.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove_given_beansInAdditions() throws Exception {
|
||||
public void testRemove_given_beansInAdditions() {
|
||||
|
||||
BeanMap<String, Object> map = new BeanMap<>();
|
||||
map.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
map.putAll(all());
|
||||
assertThat(map.getModifyAdditions()).containsExactly(object1, object2, object3);
|
||||
assertThat(map.getModifyAdditions()).containsOnly(object1, object2, object3);
|
||||
|
||||
// act
|
||||
map.remove("2");
|
||||
map.remove("3");
|
||||
|
||||
assertThat(map.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(map.getModifyAdditions()).containsOnly(object1);
|
||||
assertThat(map.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAll_given_beansInAdditions() throws Exception {
|
||||
public void testRemoveAll_given_beansInAdditions() {
|
||||
|
||||
BeanMap<String, Object> map = new BeanMap<>();
|
||||
map.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
map.putAll(all());
|
||||
assertThat(map.getModifyAdditions()).containsExactly(object1, object2, object3);
|
||||
assertThat(map.getModifyAdditions()).containsOnly(object1, object2, object3);
|
||||
|
||||
// act
|
||||
map.remove("2");
|
||||
map.remove("3");
|
||||
|
||||
assertThat(map.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(map.getModifyAdditions()).containsOnly(object1);
|
||||
assertThat(map.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove_given_beansNotInAdditions() throws Exception {
|
||||
public void testRemove_given_beansNotInAdditions() {
|
||||
|
||||
BeanMap<String, Object> map = new BeanMap<>(all());
|
||||
map.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -142,11 +142,11 @@ public class BeanMapTest {
|
||||
|
||||
// assert
|
||||
assertThat(map.getModifyAdditions()).isEmpty();
|
||||
assertThat(map.getModifyRemovals()).containsExactly(object2, object3);
|
||||
assertThat(map.getModifyRemovals()).containsOnly(object2, object3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAll_given_beansNotInAdditions() throws Exception {
|
||||
public void testRemoveAll_given_beansNotInAdditions() {
|
||||
|
||||
BeanMap<String, Object> map = new BeanMap<>(all());
|
||||
map.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -157,11 +157,11 @@ public class BeanMapTest {
|
||||
|
||||
// assert
|
||||
assertThat(map.getModifyAdditions()).isEmpty();
|
||||
assertThat(map.getModifyRemovals()).containsExactly(object2, object3);
|
||||
assertThat(map.getModifyRemovals()).containsOnly(object2, object3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClear() throws Exception {
|
||||
public void testClear() {
|
||||
|
||||
BeanMap<String, Object> map = new BeanMap<>(all());
|
||||
map.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -170,12 +170,12 @@ public class BeanMapTest {
|
||||
map.clear();
|
||||
|
||||
//assert
|
||||
assertThat(map.getModifyRemovals()).containsExactly(object1, object2, object3);
|
||||
assertThat(map.getModifyRemovals()).containsOnly(object1, object2, object3);
|
||||
assertThat(map.getModifyAdditions()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClear_given_someBeansInAdditions() throws Exception {
|
||||
public void testClear_given_someBeansInAdditions() {
|
||||
|
||||
BeanMap<String, EBasic> map = newModifyListeningMap();
|
||||
map.put("2", object2);
|
||||
@@ -185,7 +185,7 @@ public class BeanMapTest {
|
||||
map.clear();
|
||||
|
||||
//assert
|
||||
assertThat(map.getModifyRemovals()).containsExactly(object1);
|
||||
assertThat(map.getModifyRemovals()).containsOnly(object1);
|
||||
assertThat(map.getModifyAdditions()).isEmpty();
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ public class BeanMapTest {
|
||||
assertThat(map).doesNotContainKeys("1");
|
||||
assertThat(map.get("1")).isNull();
|
||||
|
||||
assertThat(map.getModifyRemovals()).containsExactly(object1);
|
||||
assertThat(map.getModifyRemovals()).containsOnly(object1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -245,7 +245,7 @@ public class BeanMapTest {
|
||||
assertThat(map).isEmpty();
|
||||
assertThat(keySet).isEmpty();
|
||||
|
||||
assertThat(map.getModifyRemovals()).containsExactly(object1, object2);
|
||||
assertThat(map.getModifyRemovals()).containsOnly(object1, object2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -258,20 +258,14 @@ public class BeanMapTest {
|
||||
map.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
|
||||
final Set<String> keySet = map.keySet();
|
||||
final Iterator<String> iterator = keySet.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final String key = iterator.next();
|
||||
if (key.equals("2")) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
keySet.removeIf(key -> key.equals("2"));
|
||||
|
||||
assertThat(map).hasSize(2);
|
||||
assertThat(keySet).hasSize(2);
|
||||
assertThat(keySet).containsExactly("1", "3");
|
||||
assertThat(map).containsKeys("1", "3");
|
||||
|
||||
assertThat(map.getModifyRemovals()).containsExactly(object2);
|
||||
assertThat(map.getModifyRemovals()).containsOnly(object2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -294,7 +288,7 @@ public class BeanMapTest {
|
||||
assertThat(keySet).containsExactly("1", "4");
|
||||
assertThat(map).containsKeys("1", "4");
|
||||
|
||||
assertThat(map.getModifyRemovals()).containsExactly(object2, object3, object5);
|
||||
assertThat(map.getModifyRemovals()).containsOnly(object2, object3, object5);
|
||||
}
|
||||
|
||||
|
||||
@@ -318,7 +312,7 @@ public class BeanMapTest {
|
||||
assertThat(keySet).containsExactly("2", "3", "5");
|
||||
assertThat(map).containsKeys("2", "3", "5");
|
||||
|
||||
assertThat(map.getModifyRemovals()).containsExactly(object1, object4);
|
||||
assertThat(map.getModifyRemovals()).containsOnly(object1, object4);
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
@@ -348,7 +342,7 @@ public class BeanMapTest {
|
||||
|
||||
assertThat(entries).isEmpty();
|
||||
assertThat(map).isEmpty();
|
||||
assertThat(map.getModifyRemovals()).containsExactly(object1);
|
||||
assertThat(map.getModifyRemovals()).containsOnly(object1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -365,7 +359,7 @@ public class BeanMapTest {
|
||||
assertThat(existed22).isFalse();
|
||||
|
||||
assertThat(map).hasSize(4);
|
||||
assertThat(map.getModifyRemovals()).containsExactly(object1);
|
||||
assertThat(map.getModifyRemovals()).containsOnly(object1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -395,7 +389,7 @@ public class BeanMapTest {
|
||||
}
|
||||
assertThat(map).hasSize(3);
|
||||
assertThat(entries).hasSize(3);
|
||||
assertThat(map.getModifyRemovals()).containsExactly(object2, object5);
|
||||
assertThat(map.getModifyRemovals()).containsOnly(object2, object5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -406,7 +400,7 @@ public class BeanMapTest {
|
||||
entries.removeAll(asList(new AbstractMap.SimpleEntry<>("1", object1), new AbstractMap.SimpleEntry<>("3", object4), new AbstractMap.SimpleEntry<>("4", object4)));
|
||||
assertThat(map).hasSize(3);
|
||||
assertThat(entries).hasSize(3);
|
||||
assertThat(map.getModifyRemovals()).containsExactly(object1, object4);
|
||||
assertThat(map.getModifyRemovals()).containsOnly(object1, object4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -417,7 +411,7 @@ public class BeanMapTest {
|
||||
entries.retainAll(asList(new AbstractMap.SimpleEntry<>("1", object1), new AbstractMap.SimpleEntry<>("3", object4), new AbstractMap.SimpleEntry<>("4", object4)));
|
||||
assertThat(map).hasSize(2);
|
||||
assertThat(entries).hasSize(2);
|
||||
assertThat(map.getModifyRemovals()).containsExactly(object2, object3, object5);
|
||||
assertThat(map.getModifyRemovals()).containsOnly(object2, object3, object5);
|
||||
}
|
||||
|
||||
private BeanMap<String, EBasic> newModifyListeningMap() {
|
||||
|
||||
@@ -31,28 +31,28 @@ public class BeanSetTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd() throws Exception {
|
||||
public void testAdd() {
|
||||
|
||||
BeanSet<Object> set = new BeanSet<>();
|
||||
set.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
set.add(object1);
|
||||
|
||||
assertThat(set.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(set.getModifyAdditions()).containsOnly(object1);
|
||||
assertThat(set.getModifyRemovals()).isEmpty();
|
||||
|
||||
set.add(object1);
|
||||
assertThat(set.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(set.getModifyAdditions()).containsOnly(object1);
|
||||
|
||||
set.add(object2);
|
||||
assertThat(set.getModifyAdditions()).containsExactly(object1, object2);
|
||||
assertThat(set.getModifyAdditions()).containsOnly(object1, object2);
|
||||
|
||||
set.remove(object1);
|
||||
assertThat(set.getModifyAdditions()).containsExactly(object2);
|
||||
assertThat(set.getModifyAdditions()).containsOnly(object2);
|
||||
assertThat(set.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAll_given_emptyStart() throws Exception {
|
||||
public void testAddAll_given_emptyStart() {
|
||||
|
||||
BeanSet<Object> set = new BeanSet<>();
|
||||
set.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -60,12 +60,12 @@ public class BeanSetTest {
|
||||
// act
|
||||
set.addAll(all());
|
||||
|
||||
assertThat(set.getModifyAdditions()).containsExactly(object1, object2, object3);
|
||||
assertThat(set.getModifyAdditions()).containsOnly(object1, object2, object3);
|
||||
assertThat(set.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd_given_someAlreadyIn() throws Exception {
|
||||
public void testAdd_given_someAlreadyIn() {
|
||||
|
||||
BeanSet<Object> set = new BeanSet<>(some());
|
||||
set.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -76,12 +76,12 @@ public class BeanSetTest {
|
||||
assertThat(set.contains(object2)).isTrue();
|
||||
set.add(object2);
|
||||
|
||||
assertThat(set.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(set.getModifyAdditions()).containsOnly(object1);
|
||||
assertThat(set.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddSome_given_someAlreadyIn() throws Exception {
|
||||
public void testAddSome_given_someAlreadyIn() {
|
||||
|
||||
BeanSet<Object> set = new BeanSet<>(some());
|
||||
set.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -89,43 +89,43 @@ public class BeanSetTest {
|
||||
// act
|
||||
set.addAll(all());
|
||||
|
||||
assertThat(set.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(set.getModifyAdditions()).containsOnly(object1);
|
||||
assertThat(set.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove_given_beansInAdditions() throws Exception {
|
||||
public void testRemove_given_beansInAdditions() {
|
||||
|
||||
BeanSet<Object> set = new BeanSet<>();
|
||||
set.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
set.addAll(all());
|
||||
assertThat(set.getModifyAdditions()).containsExactly(object1, object2, object3);
|
||||
assertThat(set.getModifyAdditions()).containsOnly(object1, object2, object3);
|
||||
|
||||
// act
|
||||
set.remove(object2);
|
||||
set.remove(object3);
|
||||
|
||||
assertThat(set.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(set.getModifyAdditions()).containsOnly(object1);
|
||||
assertThat(set.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAll_given_beansInAdditions() throws Exception {
|
||||
public void testRemoveAll_given_beansInAdditions() {
|
||||
|
||||
BeanSet<Object> set = new BeanSet<>();
|
||||
set.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
set.addAll(all());
|
||||
assertThat(set.getModifyAdditions()).containsExactly(object1, object2, object3);
|
||||
assertThat(set.getModifyAdditions()).containsOnly(object1, object2, object3);
|
||||
|
||||
// act
|
||||
set.removeAll(some());
|
||||
|
||||
assertThat(set.getModifyAdditions()).containsExactly(object1);
|
||||
assertThat(set.getModifyAdditions()).containsOnly(object1);
|
||||
assertThat(set.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove_given_beansNotInAdditions() throws Exception {
|
||||
public void testRemove_given_beansNotInAdditions() {
|
||||
|
||||
BeanSet<Object> set = new BeanSet<>(all());
|
||||
set.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -136,11 +136,11 @@ public class BeanSetTest {
|
||||
|
||||
// assert
|
||||
assertThat(set.getModifyAdditions()).isEmpty();
|
||||
assertThat(set.getModifyRemovals()).containsExactly(object2, object3);
|
||||
assertThat(set.getModifyRemovals()).containsOnly(object2, object3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAll_given_beansNotInAdditions() throws Exception {
|
||||
public void testRemoveAll_given_beansNotInAdditions() {
|
||||
|
||||
BeanSet<Object> set = new BeanSet<>(all());
|
||||
set.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -150,11 +150,11 @@ public class BeanSetTest {
|
||||
|
||||
// assert
|
||||
assertThat(set.getModifyAdditions()).isEmpty();
|
||||
assertThat(set.getModifyRemovals()).containsExactly(object2, object3);
|
||||
assertThat(set.getModifyRemovals()).containsOnly(object2, object3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClear() throws Exception {
|
||||
public void testClear() {
|
||||
|
||||
BeanSet<Object> set = new BeanSet<>(all());
|
||||
set.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -163,12 +163,12 @@ public class BeanSetTest {
|
||||
set.clear();
|
||||
|
||||
//assert
|
||||
assertThat(set.getModifyRemovals()).containsExactly(object1, object2, object3);
|
||||
assertThat(set.getModifyRemovals()).containsOnly(object1, object2, object3);
|
||||
assertThat(set.getModifyAdditions()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClear_given_someBeansInAdditions() throws Exception {
|
||||
public void testClear_given_someBeansInAdditions() {
|
||||
|
||||
BeanSet<Object> set = new BeanSet<>();
|
||||
set.add(object1);
|
||||
@@ -180,27 +180,27 @@ public class BeanSetTest {
|
||||
set.clear();
|
||||
|
||||
//assert
|
||||
assertThat(set.getModifyRemovals()).containsExactly(object1);
|
||||
assertThat(set.getModifyRemovals()).containsOnly(object1);
|
||||
assertThat(set.getModifyAdditions()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetainAll_given_beansInAdditions() throws Exception {
|
||||
public void testRetainAll_given_beansInAdditions() {
|
||||
|
||||
BeanSet<Object> set = new BeanSet<>();
|
||||
set.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
set.addAll(all());
|
||||
assertThat(set.getModifyAdditions()).containsExactly(object1, object2, object3);
|
||||
assertThat(set.getModifyAdditions()).containsOnly(object1, object2, object3);
|
||||
|
||||
// act
|
||||
set.retainAll(some());
|
||||
|
||||
assertThat(set.getModifyAdditions()).containsExactly(object2, object3);
|
||||
assertThat(set.getModifyAdditions()).containsOnly(object2, object3);
|
||||
assertThat(set.getModifyRemovals()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetainAll_given_someBeansInAdditions() throws Exception {
|
||||
public void testRetainAll_given_someBeansInAdditions() {
|
||||
|
||||
BeanSet<Object> set = new BeanSet<>();
|
||||
set.add(object1);
|
||||
@@ -211,12 +211,12 @@ public class BeanSetTest {
|
||||
// act
|
||||
set.retainAll(some());
|
||||
|
||||
assertThat(set.getModifyAdditions()).containsExactly(object3);
|
||||
assertThat(set.getModifyRemovals()).containsExactly(object1);
|
||||
assertThat(set.getModifyAdditions()).containsOnly(object3);
|
||||
assertThat(set.getModifyRemovals()).containsOnly(object1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetainAll_given_noBeansInAdditions() throws Exception {
|
||||
public void testRetainAll_given_noBeansInAdditions() {
|
||||
|
||||
BeanSet<Object> set = new BeanSet<>(all());
|
||||
set.setModifyListening(BeanCollection.ModifyListenMode.ALL);
|
||||
@@ -224,7 +224,7 @@ public class BeanSetTest {
|
||||
// act
|
||||
set.retainAll(some());
|
||||
|
||||
assertThat(set.getModifyRemovals()).containsExactly(object1);
|
||||
assertThat(set.getModifyRemovals()).containsOnly(object1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
package io.ebean.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.ebean.annotation.MutationDetection;
|
||||
import io.ebean.annotation.PersistBatch;
|
||||
import io.ebean.config.dbplatform.IdType;
|
||||
import io.ebean.datasource.DataSourceConfig;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class DatabaseConfigTest {
|
||||
|
||||
@Test
|
||||
public void testLoadFromEbeanProperties() {
|
||||
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.loadFromProperties();
|
||||
|
||||
assertEquals(PersistBatch.NONE, config.getPersistBatch());
|
||||
assertNotNull(config.getProperties());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void evalPropertiesInput() {
|
||||
|
||||
String home = System.getenv("HOME");
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty("ddl.initSql", "${HOME}/initSql");
|
||||
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.loadFromProperties(props);
|
||||
|
||||
String ddlInitSql = config.getDdlInitSql();
|
||||
assertThat(ddlInitSql).isEqualTo(home+"/initSql");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadWithProperties() {
|
||||
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.setPersistBatch(PersistBatch.NONE);
|
||||
config.setPersistBatchOnCascade(PersistBatch.NONE);
|
||||
config.setAutoReadOnlyDataSource(false);
|
||||
config.setReadOnlyDataSource(null);
|
||||
config.setReadOnlyDataSourceConfig(new DataSourceConfig());
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty("persistBatch", "ALL");
|
||||
props.setProperty("persistBatchOnCascade", "ALL");
|
||||
props.setProperty("dbuuid", "binary");
|
||||
props.setProperty("jdbcFetchSizeFindEach", "42");
|
||||
props.setProperty("jdbcFetchSizeFindList", "43");
|
||||
props.setProperty("backgroundExecutorShutdownSecs", "98");
|
||||
props.setProperty("backgroundExecutorSchedulePoolSize", "4");
|
||||
props.setProperty("dbOffline", "true");
|
||||
props.setProperty("jsonDateTime", "MILLIS");
|
||||
props.setProperty("jsonDate", "MILLIS");
|
||||
props.setProperty("jsonMutationDetection", "NONE");
|
||||
props.setProperty("autoReadOnlyDataSource", "true");
|
||||
props.setProperty("disableL2Cache", "true");
|
||||
props.setProperty("notifyL2CacheInForeground", "true");
|
||||
props.setProperty("idType", "SEQUENCE");
|
||||
props.setProperty("mappingLocations", "classpath:/foo;bar");
|
||||
props.setProperty("namingConvention", "io.ebean.config.MatchingNamingConvention");
|
||||
props.setProperty("idGeneratorAutomatic", "true");
|
||||
props.setProperty("enabledL2Regions", "r0,users,orgs");
|
||||
props.setProperty("caseSensitiveCollation", "false");
|
||||
props.setProperty("loadModuleInfo", "true");
|
||||
props.setProperty("forUpdateNoKey", "true");
|
||||
props.setProperty("defaultServer", "false");
|
||||
props.setProperty("skipDataSourceCheck", "true");
|
||||
|
||||
props.setProperty("queryPlan.enable", "true");
|
||||
props.setProperty("queryPlan.thresholdMicros", "10000");
|
||||
props.setProperty("queryPlan.capture", "true");
|
||||
props.setProperty("queryPlan.capturePeriodSecs", "42");
|
||||
props.setProperty("queryPlan.captureMaxTimeMillis", "560");
|
||||
props.setProperty("queryPlan.captureMaxCount", "7");
|
||||
|
||||
config.loadFromProperties(props);
|
||||
|
||||
assertFalse(config.isDefaultServer());
|
||||
assertTrue(config.isDisableL2Cache());
|
||||
assertTrue(config.isNotifyL2CacheInForeground());
|
||||
assertTrue(config.isDbOffline());
|
||||
assertTrue(config.isAutoReadOnlyDataSource());
|
||||
assertTrue(config.isAutoLoadModuleInfo());
|
||||
assertTrue(config.skipDataSourceCheck());
|
||||
|
||||
assertTrue(config.isIdGeneratorAutomatic());
|
||||
assertFalse(config.getPlatformConfig().isCaseSensitiveCollation());
|
||||
assertTrue(config.getPlatformConfig().isForUpdateNoKey());
|
||||
|
||||
assertThat(config.getNamingConvention()).isInstanceOf(MatchingNamingConvention.class);
|
||||
|
||||
assertEquals(MutationDetection.NONE, config.getJsonMutationDetection());
|
||||
config.setJsonMutationDetection(MutationDetection.SOURCE);
|
||||
assertEquals(MutationDetection.SOURCE, config.getJsonMutationDetection());
|
||||
assertEquals(IdType.SEQUENCE, config.getIdType());
|
||||
assertEquals(PersistBatch.ALL, config.getPersistBatch());
|
||||
assertEquals(PersistBatch.ALL, config.getPersistBatchOnCascade());
|
||||
assertEquals(PlatformConfig.DbUuid.BINARY, config.getPlatformConfig().getDbUuid());
|
||||
assertEquals(JsonConfig.DateTime.MILLIS, config.getJsonDateTime());
|
||||
assertEquals(JsonConfig.Date.MILLIS, config.getJsonDate());
|
||||
|
||||
assertEquals("r0,users,orgs", config.getEnabledL2Regions());
|
||||
|
||||
assertEquals(42, config.getJdbcFetchSizeFindEach());
|
||||
assertEquals(43, config.getJdbcFetchSizeFindList());
|
||||
assertEquals(4, config.getBackgroundExecutorSchedulePoolSize());
|
||||
assertEquals(98, config.getBackgroundExecutorShutdownSecs());
|
||||
|
||||
assertTrue(config.isQueryPlanEnable());
|
||||
assertEquals(10000, config.getQueryPlanThresholdMicros());
|
||||
assertTrue(config.isQueryPlanCapture());
|
||||
assertEquals(42, config.getQueryPlanCapturePeriodSecs());
|
||||
assertEquals(560, config.getQueryPlanCaptureMaxTimeMillis());
|
||||
assertEquals(7, config.getQueryPlanCaptureMaxCount());
|
||||
|
||||
assertThat(config.getMappingLocations()).containsExactly("classpath:/foo","bar");
|
||||
|
||||
config.setPersistBatch(PersistBatch.NONE);
|
||||
config.setPersistBatchOnCascade(PersistBatch.NONE);
|
||||
|
||||
Properties props1 = new Properties();
|
||||
props1.setProperty("ebean.persistBatch", "ALL");
|
||||
props1.setProperty("ebean.persistBatchOnCascade", "ALL");
|
||||
|
||||
config.setNotifyL2CacheInForeground(true);
|
||||
config.setDisableL2Cache(true);
|
||||
props1.setProperty("ebean.disableL2Cache", "false");
|
||||
props1.setProperty("ebean.notifyL2CacheInForeground", "false");
|
||||
|
||||
config.loadFromProperties(props1);
|
||||
assertFalse(config.isDisableL2Cache());
|
||||
assertFalse(config.isNotifyL2CacheInForeground());
|
||||
|
||||
assertEquals(PersistBatch.ALL, config.getPersistBatch());
|
||||
assertEquals(PersistBatch.ALL, config.getPersistBatchOnCascade());
|
||||
|
||||
config.setEnabledL2Regions("r0,orgs");
|
||||
assertEquals("r0,orgs", config.getEnabledL2Regions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_defaults() {
|
||||
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
assertTrue(config.isIdGeneratorAutomatic());
|
||||
assertTrue(config.isDefaultServer());
|
||||
assertFalse(config.isAutoPersistUpdates());
|
||||
assertFalse(config.skipDataSourceCheck());
|
||||
|
||||
config.setIdGeneratorAutomatic(false);
|
||||
assertFalse(config.isIdGeneratorAutomatic());
|
||||
assertEquals(JsonConfig.DateTime.ISO8601, config.getJsonDateTime());
|
||||
assertEquals(JsonConfig.Date.ISO8601, config.getJsonDate());
|
||||
assertEquals(MutationDetection.HASH, config.getJsonMutationDetection());
|
||||
assertTrue(config.getPlatformConfig().isCaseSensitiveCollation());
|
||||
assertTrue(config.isAutoLoadModuleInfo());
|
||||
|
||||
assertFalse(config.isQueryPlanEnable());
|
||||
assertEquals(Long.MAX_VALUE, config.getQueryPlanThresholdMicros());
|
||||
assertFalse(config.isQueryPlanCapture());
|
||||
assertEquals(600, config.getQueryPlanCapturePeriodSecs());
|
||||
assertEquals(10000L, config.getQueryPlanCaptureMaxTimeMillis());
|
||||
assertEquals(10, config.getQueryPlanCaptureMaxCount());
|
||||
|
||||
config.setLoadModuleInfo(false);
|
||||
assertFalse(config.isAutoLoadModuleInfo());
|
||||
config.setAutoPersistUpdates(true);
|
||||
assertTrue(config.isAutoPersistUpdates());
|
||||
config.setSkipDataSourceCheck(true);
|
||||
assertTrue(config.skipDataSourceCheck());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_putServiceObject() {
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.putServiceObject(objectMapper);
|
||||
|
||||
ObjectMapper mapper0 = config.getServiceObject(ObjectMapper.class);
|
||||
ObjectMapper mapper1 = (ObjectMapper)config.getServiceObject("objectMapper");
|
||||
|
||||
assertThat(objectMapper).isSameAs(mapper0);
|
||||
assertThat(objectMapper).isSameAs(mapper1);
|
||||
}
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
package io.ebean.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.ebean.annotation.PersistBatch;
|
||||
import io.ebean.config.dbplatform.IdType;
|
||||
import io.ebean.datasource.DataSourceConfig;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ServerConfigTest {
|
||||
|
||||
@Test
|
||||
public void testLoadFromEbeanProperties() {
|
||||
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
serverConfig.loadFromProperties();
|
||||
|
||||
assertEquals(PersistBatch.NONE, serverConfig.getPersistBatch());
|
||||
assertNotNull(serverConfig.getProperties());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void evalPropertiesInput() {
|
||||
|
||||
String home = System.getenv("HOME");
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty("ddl.initSql", "${HOME}/initSql");
|
||||
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
serverConfig.loadFromProperties(props);
|
||||
|
||||
String ddlInitSql = serverConfig.getDdlInitSql();
|
||||
assertThat(ddlInitSql).isEqualTo(home+"/initSql");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadWithProperties() {
|
||||
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
serverConfig.setPersistBatch(PersistBatch.NONE);
|
||||
serverConfig.setPersistBatchOnCascade(PersistBatch.NONE);
|
||||
serverConfig.setAutoReadOnlyDataSource(false);
|
||||
serverConfig.setReadOnlyDataSource(null);
|
||||
serverConfig.setReadOnlyDataSourceConfig(new DataSourceConfig());
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty("persistBatch", "ALL");
|
||||
props.setProperty("persistBatchOnCascade", "ALL");
|
||||
props.setProperty("dbuuid", "binary");
|
||||
props.setProperty("jdbcFetchSizeFindEach", "42");
|
||||
props.setProperty("jdbcFetchSizeFindList", "43");
|
||||
props.setProperty("backgroundExecutorShutdownSecs", "98");
|
||||
props.setProperty("backgroundExecutorSchedulePoolSize", "4");
|
||||
props.setProperty("dbOffline", "true");
|
||||
props.setProperty("jsonDateTime", "MILLIS");
|
||||
props.setProperty("jsonDate", "MILLIS");
|
||||
props.setProperty("jsonDirtyByDefault", "false");
|
||||
props.setProperty("autoReadOnlyDataSource", "true");
|
||||
props.setProperty("disableL2Cache", "true");
|
||||
props.setProperty("notifyL2CacheInForeground", "true");
|
||||
props.setProperty("idType", "SEQUENCE");
|
||||
props.setProperty("mappingLocations", "classpath:/foo;bar");
|
||||
props.setProperty("namingConvention", "io.ebean.config.MatchingNamingConvention");
|
||||
props.setProperty("idGeneratorAutomatic", "true");
|
||||
props.setProperty("enabledL2Regions", "r0,users,orgs");
|
||||
props.setProperty("caseSensitiveCollation", "false");
|
||||
props.setProperty("loadModuleInfo", "true");
|
||||
props.setProperty("forUpdateNoKey", "true");
|
||||
props.setProperty("defaultServer", "false");
|
||||
|
||||
props.setProperty("queryPlan.enable", "true");
|
||||
props.setProperty("queryPlan.thresholdMicros", "10000");
|
||||
props.setProperty("queryPlan.capture", "true");
|
||||
props.setProperty("queryPlan.capturePeriodSecs", "42");
|
||||
props.setProperty("queryPlan.captureMaxTimeMillis", "560");
|
||||
props.setProperty("queryPlan.captureMaxCount", "7");
|
||||
|
||||
serverConfig.loadFromProperties(props);
|
||||
|
||||
assertFalse(serverConfig.isDefaultServer());
|
||||
assertTrue(serverConfig.isDisableL2Cache());
|
||||
assertTrue(serverConfig.isNotifyL2CacheInForeground());
|
||||
assertTrue(serverConfig.isDbOffline());
|
||||
assertTrue(serverConfig.isAutoReadOnlyDataSource());
|
||||
assertTrue(serverConfig.isAutoLoadModuleInfo());
|
||||
|
||||
assertTrue(serverConfig.isIdGeneratorAutomatic());
|
||||
assertFalse(serverConfig.getPlatformConfig().isCaseSensitiveCollation());
|
||||
assertTrue(serverConfig.getPlatformConfig().isForUpdateNoKey());
|
||||
|
||||
assertThat(serverConfig.getNamingConvention()).isInstanceOf(MatchingNamingConvention.class);
|
||||
|
||||
assertEquals(IdType.SEQUENCE, serverConfig.getIdType());
|
||||
assertEquals(PersistBatch.ALL, serverConfig.getPersistBatch());
|
||||
assertEquals(PersistBatch.ALL, serverConfig.getPersistBatchOnCascade());
|
||||
assertEquals(PlatformConfig.DbUuid.BINARY, serverConfig.getPlatformConfig().getDbUuid());
|
||||
assertEquals(JsonConfig.DateTime.MILLIS, serverConfig.getJsonDateTime());
|
||||
assertEquals(JsonConfig.Date.MILLIS, serverConfig.getJsonDate());
|
||||
assertFalse(serverConfig.isJsonDirtyByDefault());
|
||||
serverConfig.setJsonDirtyByDefault(true);
|
||||
assertTrue(serverConfig.isJsonDirtyByDefault());
|
||||
|
||||
assertEquals("r0,users,orgs", serverConfig.getEnabledL2Regions());
|
||||
|
||||
assertEquals(42, serverConfig.getJdbcFetchSizeFindEach());
|
||||
assertEquals(43, serverConfig.getJdbcFetchSizeFindList());
|
||||
assertEquals(4, serverConfig.getBackgroundExecutorSchedulePoolSize());
|
||||
assertEquals(98, serverConfig.getBackgroundExecutorShutdownSecs());
|
||||
|
||||
assertTrue(serverConfig.isQueryPlanEnable());
|
||||
assertEquals(10000, serverConfig.getQueryPlanThresholdMicros());
|
||||
assertTrue(serverConfig.isQueryPlanCapture());
|
||||
assertEquals(42, serverConfig.getQueryPlanCapturePeriodSecs());
|
||||
assertEquals(560, serverConfig.getQueryPlanCaptureMaxTimeMillis());
|
||||
assertEquals(7, serverConfig.getQueryPlanCaptureMaxCount());
|
||||
|
||||
assertThat(serverConfig.getMappingLocations()).containsExactly("classpath:/foo","bar");
|
||||
|
||||
serverConfig.setPersistBatch(PersistBatch.NONE);
|
||||
serverConfig.setPersistBatchOnCascade(PersistBatch.NONE);
|
||||
|
||||
Properties props1 = new Properties();
|
||||
props1.setProperty("ebean.persistBatch", "ALL");
|
||||
props1.setProperty("ebean.persistBatchOnCascade", "ALL");
|
||||
|
||||
serverConfig.setNotifyL2CacheInForeground(true);
|
||||
serverConfig.setDisableL2Cache(true);
|
||||
props1.setProperty("ebean.disableL2Cache", "false");
|
||||
props1.setProperty("ebean.notifyL2CacheInForeground", "false");
|
||||
|
||||
serverConfig.loadFromProperties(props1);
|
||||
assertFalse(serverConfig.isDisableL2Cache());
|
||||
assertFalse(serverConfig.isNotifyL2CacheInForeground());
|
||||
|
||||
assertEquals(PersistBatch.ALL, serverConfig.getPersistBatch());
|
||||
assertEquals(PersistBatch.ALL, serverConfig.getPersistBatchOnCascade());
|
||||
|
||||
serverConfig.setEnabledL2Regions("r0,orgs");
|
||||
assertEquals("r0,orgs", serverConfig.getEnabledL2Regions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_defaults() {
|
||||
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
assertTrue(serverConfig.isIdGeneratorAutomatic());
|
||||
assertTrue(serverConfig.isDefaultServer());
|
||||
assertFalse(serverConfig.isAutoPersistUpdates());
|
||||
|
||||
serverConfig.setIdGeneratorAutomatic(false);
|
||||
assertFalse(serverConfig.isIdGeneratorAutomatic());
|
||||
assertEquals(JsonConfig.DateTime.ISO8601, serverConfig.getJsonDateTime());
|
||||
assertEquals(JsonConfig.Date.ISO8601, serverConfig.getJsonDate());
|
||||
assertTrue(serverConfig.isJsonDirtyByDefault());
|
||||
assertTrue(serverConfig.getPlatformConfig().isCaseSensitiveCollation());
|
||||
assertTrue(serverConfig.isAutoLoadModuleInfo());
|
||||
|
||||
assertFalse(serverConfig.isQueryPlanEnable());
|
||||
assertEquals(Long.MAX_VALUE, serverConfig.getQueryPlanThresholdMicros());
|
||||
assertFalse(serverConfig.isQueryPlanCapture());
|
||||
assertEquals(600, serverConfig.getQueryPlanCapturePeriodSecs());
|
||||
assertEquals(10000L, serverConfig.getQueryPlanCaptureMaxTimeMillis());
|
||||
assertEquals(10, serverConfig.getQueryPlanCaptureMaxCount());
|
||||
|
||||
serverConfig.setLoadModuleInfo(false);
|
||||
assertFalse(serverConfig.isAutoLoadModuleInfo());
|
||||
serverConfig.setAutoPersistUpdates(true);
|
||||
assertTrue(serverConfig.isAutoPersistUpdates());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_putServiceObject() {
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
ServerConfig config = new ServerConfig();
|
||||
config.putServiceObject(objectMapper);
|
||||
|
||||
ObjectMapper mapper0 = config.getServiceObject(ObjectMapper.class);
|
||||
ObjectMapper mapper1 = (ObjectMapper)config.getServiceObject("objectMapper");
|
||||
|
||||
assertThat(objectMapper).isSameAs(mapper0);
|
||||
assertThat(objectMapper).isSameAs(mapper1);
|
||||
}
|
||||
}
|
||||
@@ -650,7 +650,7 @@ public class TDSpiEbeanServer implements SpiEbeanServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean exists(Query<?> ormQuery, Transaction transaction) {
|
||||
public <T> boolean exists(Query<T> ormQuery, Transaction transaction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,11 @@ public class BeanIudMetricsTest {
|
||||
BasicMetricVisitor basic = new BasicMetricVisitor();
|
||||
iudMetrics.visit(basic);
|
||||
|
||||
List<MetaTimedMetric> timed = basic.getTimedMetrics();
|
||||
List<MetaTimedMetric> timed = basic.timedMetrics();
|
||||
assertThat(timed).hasSize(1);
|
||||
|
||||
assertThat(timed.get(0).getCount()).isEqualTo(4);
|
||||
assertThat(timed.get(0).getName()).isEqualTo("iud.one.insertBatch");
|
||||
assertThat(timed.get(0).count()).isEqualTo(4);
|
||||
assertThat(timed.get(0).name()).isEqualTo("iud.one.insertBatch");
|
||||
|
||||
iudMetrics.addBatch(PersistRequest.Type.UPDATE, startNanos, 1);
|
||||
iudMetrics.addBatch(PersistRequest.Type.DELETE_SOFT, startNanos, 2);
|
||||
@@ -37,15 +37,15 @@ public class BeanIudMetricsTest {
|
||||
|
||||
basic = new BasicMetricVisitor();
|
||||
iudMetrics.visit(basic);
|
||||
timed = basic.getTimedMetrics();
|
||||
timed = basic.timedMetrics();
|
||||
assertThat(timed).hasSize(3);
|
||||
|
||||
assertThat(timed.get(0).getCount()).isEqualTo(16);
|
||||
assertThat(timed.get(0).getName()).isEqualTo("iud.one.insertBatch");
|
||||
assertThat(timed.get(1).getCount()).isEqualTo(3);
|
||||
assertThat(timed.get(1).getName()).isEqualTo("iud.one.updateBatch");
|
||||
assertThat(timed.get(2).getCount()).isEqualTo(12);
|
||||
assertThat(timed.get(2).getName()).isEqualTo("iud.one.deleteBatch");
|
||||
assertThat(timed.get(0).count()).isEqualTo(16);
|
||||
assertThat(timed.get(0).name()).isEqualTo("iud.one.insertBatch");
|
||||
assertThat(timed.get(1).count()).isEqualTo(3);
|
||||
assertThat(timed.get(1).name()).isEqualTo("iud.one.updateBatch");
|
||||
assertThat(timed.get(2).count()).isEqualTo(12);
|
||||
assertThat(timed.get(2).name()).isEqualTo("iud.one.deleteBatch");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,15 +63,15 @@ public class BeanIudMetricsTest {
|
||||
BasicMetricVisitor basic = new BasicMetricVisitor();
|
||||
iudMetrics.visit(basic);
|
||||
|
||||
List<MetaTimedMetric> timed = basic.getTimedMetrics();
|
||||
List<MetaTimedMetric> timed = basic.timedMetrics();
|
||||
assertThat(timed).hasSize(3);
|
||||
|
||||
assertThat(timed.get(0).getCount()).isEqualTo(1);
|
||||
assertThat(timed.get(0).getName()).isEqualTo("iud.one.insert");
|
||||
assertThat(timed.get(1).getCount()).isEqualTo(2);
|
||||
assertThat(timed.get(1).getName()).isEqualTo("iud.one.update");
|
||||
assertThat(timed.get(2).getCount()).isEqualTo(2);
|
||||
assertThat(timed.get(2).getName()).isEqualTo("iud.one.delete");
|
||||
assertThat(timed.get(0).count()).isEqualTo(1);
|
||||
assertThat(timed.get(0).name()).isEqualTo("iud.one.insert");
|
||||
assertThat(timed.get(1).count()).isEqualTo(2);
|
||||
assertThat(timed.get(1).name()).isEqualTo("iud.one.update");
|
||||
assertThat(timed.get(2).count()).isEqualTo(2);
|
||||
assertThat(timed.get(2).name()).isEqualTo("iud.one.delete");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ public class TestNotEnhancedMappedSuper extends BaseTestCase {
|
||||
|
||||
NotEnhancedMappedSuper mappedSuper = new NotEnhancedMappedSuper();
|
||||
boolean enhanced = (mappedSuper instanceof EntityBean);
|
||||
Assert.assertFalse(enhanced);
|
||||
Assert.assertTrue(enhanced);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.ebeaninternal.server.expression;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
|
||||
public class RawExpressionTest extends BaseExpressionTest {
|
||||
|
||||
@@ -61,11 +62,16 @@ public class RawExpressionTest extends BaseExpressionTest {
|
||||
}
|
||||
|
||||
public void assert_queryBindHash_isDifferent(RawExpression exp0, RawExpression exp1) {
|
||||
assertThat(exp0.queryBindHash()).isNotEqualTo(exp1.queryBindHash());
|
||||
assertThat(bindKey(exp0)).isNotEqualTo(bindKey(exp1));
|
||||
}
|
||||
|
||||
public void assert_queryBindHash_isSame(RawExpression exp0, RawExpression exp1) {
|
||||
assertThat(exp0.queryBindHash()).isEqualTo(exp1.queryBindHash());
|
||||
assertThat(bindKey(exp0)).isEqualTo(bindKey(exp1));
|
||||
}
|
||||
|
||||
private BindValuesKey bindKey(RawExpression query) {
|
||||
BindValuesKey bindValuesKey = new BindValuesKey();
|
||||
query.queryBindKey(bindValuesKey);
|
||||
return bindValuesKey;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -14,7 +14,11 @@ public class BasicProfileLocationTest {
|
||||
|
||||
assertThat(loc.obtain()).isTrue();
|
||||
assertThat(loc.fullLocation()).endsWith(":12)");
|
||||
assertThat(loc.location()).isEqualTo("NativeMethodAccessorImpl.invoke0(Native Method:12)");
|
||||
if (System.getProperty("java.version").startsWith("1.8")) {
|
||||
assertThat(loc.location()).isEqualTo("sun.reflect.NativeMethodAccessorImpl.invoke0");
|
||||
} else {
|
||||
assertThat(loc.location()).isEqualTo("java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0");
|
||||
}
|
||||
assertThat(loc.label()).isEqualTo("NativeMethodAccessorImpl.invoke0");
|
||||
}
|
||||
|
||||
@@ -24,7 +28,7 @@ public class BasicProfileLocationTest {
|
||||
BasicProfileLocation loc = new BasicProfileLocation("com.foo.Bar.all");
|
||||
assertThat(loc.obtain()).isFalse();
|
||||
assertThat(loc.fullLocation()).isEqualTo("com.foo.Bar.all");
|
||||
assertThat(loc.location()).isEqualTo("Bar.all");
|
||||
assertThat(loc.location()).isEqualTo("com.foo.Bar.all");
|
||||
assertThat(loc.label()).isEqualTo("Bar.all");
|
||||
}
|
||||
|
||||
@@ -34,7 +38,7 @@ public class BasicProfileLocationTest {
|
||||
BasicProfileLocation loc = new BasicProfileLocation("foo.Bar.all");
|
||||
assertThat(loc.obtain()).isFalse();
|
||||
assertThat(loc.fullLocation()).isEqualTo("foo.Bar.all");
|
||||
assertThat(loc.location()).isEqualTo("Bar.all");
|
||||
assertThat(loc.location()).isEqualTo("foo.Bar.all");
|
||||
assertThat(loc.label()).isEqualTo("Bar.all");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,17 +21,17 @@ public class DTimedMetricMapTest {
|
||||
BasicMetricVisitor visitor = new BasicMetricVisitor();
|
||||
metricMap.visit(visitor);
|
||||
|
||||
MetaTimedMetric timedMetric = visitor.getTimedMetrics().get(0);
|
||||
assertThat(timedMetric.getCount()).isEqualTo(1);
|
||||
assertThat(timedMetric.getTotal()).isGreaterThan(10);
|
||||
MetaTimedMetric timedMetric = visitor.timedMetrics().get(0);
|
||||
assertThat(timedMetric.count()).isEqualTo(1);
|
||||
assertThat(timedMetric.total()).isGreaterThan(10);
|
||||
|
||||
metricMap.addSinceNanos("some", nanos);
|
||||
|
||||
visitor = new BasicMetricVisitor();
|
||||
metricMap.visit(visitor);
|
||||
|
||||
timedMetric = visitor.getTimedMetrics().get(0);
|
||||
assertThat(timedMetric.getCount()).isEqualTo(1);
|
||||
assertThat(timedMetric.getTotal()).isGreaterThan(10);
|
||||
timedMetric = visitor.timedMetrics().get(0);
|
||||
assertThat(timedMetric.count()).isEqualTo(1);
|
||||
assertThat(timedMetric.total()).isGreaterThan(10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,16 +17,16 @@ public class DTimedMetricTest {
|
||||
metric.addSinceNanos(start);
|
||||
|
||||
DTimeMetricStats stats = metric.collect(true);
|
||||
assertThat(stats.getCount()).isEqualTo(1);
|
||||
assertThat(stats.getTotal()).isGreaterThan(10);
|
||||
assertThat(stats.getMax()).isEqualTo(stats.getTotal());
|
||||
assertThat(stats.count()).isEqualTo(1);
|
||||
assertThat(stats.total()).isGreaterThan(10);
|
||||
assertThat(stats.max()).isEqualTo(stats.total());
|
||||
|
||||
metric.addSinceNanos(start);
|
||||
|
||||
stats = metric.collect(true);
|
||||
assertThat(stats.getCount()).isEqualTo(1);
|
||||
assertThat(stats.getTotal()).isGreaterThan(10);
|
||||
assertThat(stats.getMax()).isEqualTo(stats.getTotal());
|
||||
assertThat(stats.count()).isEqualTo(1);
|
||||
assertThat(stats.total()).isGreaterThan(10);
|
||||
assertThat(stats.max()).isEqualTo(stats.total());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -40,16 +40,16 @@ public class DTimedMetricTest {
|
||||
metric.addBatchSince(start, 5);
|
||||
|
||||
DTimeMetricStats stats = metric.collect(true);
|
||||
assertThat(stats.getCount()).isEqualTo(5);
|
||||
assertThat(stats.getTotal()).isGreaterThan(10000);
|
||||
assertThat(stats.getMax()).isEqualTo(stats.getTotal() / 5);
|
||||
assertThat(stats.getMax()).isGreaterThan(10000 / 5);
|
||||
assertThat(stats.count()).isEqualTo(5);
|
||||
assertThat(stats.total()).isGreaterThan(10000);
|
||||
assertThat(stats.max()).isEqualTo(stats.total() / 5);
|
||||
assertThat(stats.max()).isGreaterThan(10000 / 5);
|
||||
|
||||
metric.addBatchSince(start, 2);
|
||||
|
||||
stats = metric.collect(true);
|
||||
assertThat(stats.getCount()).isEqualTo(2);
|
||||
assertThat(stats.getTotal()).isGreaterThan(10000);
|
||||
assertThat(stats.getMax()).isEqualTo(stats.getTotal() / 2);
|
||||
assertThat(stats.count()).isEqualTo(2);
|
||||
assertThat(stats.total()).isGreaterThan(10000);
|
||||
assertThat(stats.max()).isEqualTo(stats.total() / 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class SortMetricTest {
|
||||
list.add(create("a"));
|
||||
list.sort(sortMetric);
|
||||
|
||||
String names = list.stream().map(DTimeMetricStats::getName).collect(Collectors.joining());
|
||||
String names = list.stream().map(DTimeMetricStats::name).collect(Collectors.joining());
|
||||
|
||||
assertEquals("nullabcd", names);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,13 @@ public class UtilLocationTest {
|
||||
|
||||
@Test
|
||||
public void label() {
|
||||
|
||||
assertThat(UtilLocation.label("foo")).isEqualTo("foo");
|
||||
assertThat(UtilLocation.label("ProfileLocationTest$Other.<init>(ProfileLocationTest.java:47)")).isEqualTo("ProfileLocationTest$Other.init");
|
||||
assertThat(UtilLocation.label("ProfileLocationTest$Other.<init>")).isEqualTo("ProfileLocationTest$Other.init");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loc() {
|
||||
assertThat(UtilLocation.loc("org.foo.MyFoo.doIt(MyFoo.java:12)")).isEqualTo("org.foo.MyFoo.doIt");
|
||||
assertThat(UtilLocation.label("org.foo.MyFoo.doIt")).isEqualTo("MyFoo.doIt");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package io.ebeaninternal.server.querydefn;
|
||||
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BindValuesKeyTest {
|
||||
|
||||
@Test
|
||||
public void update_with_null() {
|
||||
|
||||
BindValuesKey hash = new BindValuesKey();
|
||||
hash.add(1).add(null).add("hello");
|
||||
|
||||
BindValuesKey hash2 = new BindValuesKey();
|
||||
hash2.add(1).add(null).add("hello");
|
||||
|
||||
assertThat(hash).isEqualTo(hash2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notEqual() {
|
||||
|
||||
BindValuesKey hash = new BindValuesKey();
|
||||
hash.add(1).add(null).add("hello");
|
||||
|
||||
BindValuesKey hash2 = new BindValuesKey();
|
||||
hash2.add(1).add("hello");
|
||||
|
||||
BindValuesKey hash3 = new BindValuesKey();
|
||||
hash2.add(1).add(null);
|
||||
|
||||
assertThat(hash).isNotEqualTo(hash2);
|
||||
assertThat(hash).isNotEqualTo(hash3);
|
||||
assertThat(hash2).isNotEqualTo(hash3);
|
||||
}
|
||||
}
|
||||
+10
-3
@@ -4,6 +4,7 @@ package io.ebeaninternal.server.querydefn;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.CacheMode;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.SpiQuery;
|
||||
import io.ebeaninternal.server.core.OrmQueryRequest;
|
||||
import org.junit.Test;
|
||||
@@ -62,7 +63,7 @@ public class DefaultOrmQueryTest extends BaseTestCase {
|
||||
|
||||
prepare(q1, q2);
|
||||
assertThat(q1.createQueryPlanKey()).isNotEqualTo(q2.createQueryPlanKey());
|
||||
assertThat(q1.queryBindHash()).isNotEqualTo(q2.queryBindHash());
|
||||
assertThat(bindKey(q1)).isNotEqualTo(bindKey(q2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +74,7 @@ public class DefaultOrmQueryTest extends BaseTestCase {
|
||||
|
||||
prepare(q1, q2);
|
||||
assertThat(q1.createQueryPlanKey()).isEqualTo(q2.createQueryPlanKey());
|
||||
assertThat(q1.queryBindHash()).isNotEqualTo(q2.queryBindHash());
|
||||
assertThat(bindKey(q1)).isNotEqualTo(bindKey(q2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +85,7 @@ public class DefaultOrmQueryTest extends BaseTestCase {
|
||||
|
||||
prepare(q1, q2);
|
||||
assertThat(q1.createQueryPlanKey()).isEqualTo(q2.createQueryPlanKey());
|
||||
assertThat(q1.queryBindHash()).isEqualTo(q2.queryBindHash());
|
||||
assertThat(bindKey(q1)).isEqualTo(bindKey(q2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,4 +111,10 @@ public class DefaultOrmQueryTest extends BaseTestCase {
|
||||
OrmQueryRequest<T> r2 = createQueryRequest(SpiQuery.Type.LIST, q2, null);
|
||||
q2.prepare(r2);
|
||||
}
|
||||
|
||||
private BindValuesKey bindKey(DefaultOrmQuery<Order> query) {
|
||||
BindValuesKey key = new BindValuesKey();
|
||||
query.queryBindKey(key);
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,17 +9,25 @@ import io.ebean.RawSqlBuilder;
|
||||
import io.ebean.SqlRow;
|
||||
import io.ebean.annotation.ForPlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.datasource.DataSourceConfig;
|
||||
import io.ebeaninternal.server.core.DefaultServer;
|
||||
import io.ebeaninternal.server.rawsql.SpiRawSql.Sql;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.EBasicClob;
|
||||
import org.tests.model.basic.PersistentFileContent;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
import org.tests.model.rawsql.ERawSqlAggBean;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -283,4 +291,58 @@ public class TestRawSqlBuilder extends BaseTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCLobClosedConnection() throws Exception {
|
||||
final EBasicClob eBasicClob = new EBasicClob();
|
||||
eBasicClob.setName("eBasicClob");
|
||||
final String description = "This is the CLob description";
|
||||
eBasicClob.setDescription(description);
|
||||
DB.save(eBasicClob);
|
||||
|
||||
final String sql = "select description from ebasic_clob where id = ?";
|
||||
|
||||
List<SqlRow> rows = new ArrayList<>();
|
||||
final DataSourceConfig config = ((DefaultServer) DB.getDefault()).getServerConfig().getDataSourceConfig();
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(config.getUrl(), config.getUsername(), config.getPassword());
|
||||
PreparedStatement stmt = connection.prepareStatement(sql)) {
|
||||
stmt.setLong(1, eBasicClob.getId());
|
||||
|
||||
try (ResultSet resultSet = stmt.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
rows.add(RawSqlBuilder.sqlRow(resultSet, "true", false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertThat(rows).hasSize(1);
|
||||
assertThat(rows.get(0).getString("description")).isEqualTo(description);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBLobClosedConnection() throws Exception {
|
||||
final PersistentFileContent pfc = new PersistentFileContent();
|
||||
final byte[] bytes = "This is the blob as String".getBytes(StandardCharsets.UTF_8);
|
||||
pfc.setContent(bytes);
|
||||
DB.save(pfc);
|
||||
|
||||
List<SqlRow> rows = new ArrayList<>();
|
||||
final DataSourceConfig config = ((DefaultServer) DB.getDefault()).getServerConfig().getDataSourceConfig();
|
||||
|
||||
final String sql = "select content from persistent_file_content where id = ?";
|
||||
try (Connection connection = DriverManager.getConnection(config.getUrl(), config.getUsername(), config.getPassword());
|
||||
PreparedStatement stmt = connection.prepareStatement(sql)) {
|
||||
stmt.setLong(1, pfc.getId());
|
||||
|
||||
try (ResultSet resultSet = stmt.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
rows.add(RawSqlBuilder.sqlRow(resultSet, "true", false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertThat(rows).hasSize(1);
|
||||
assertThat(rows.get(0).get("content")).isEqualTo(bytes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+44
-6
@@ -5,6 +5,8 @@ import org.junit.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -14,12 +16,12 @@ import static org.junit.Assert.assertTrue;
|
||||
public class ScalarTypeOffsetDateTimeTest {
|
||||
|
||||
|
||||
ScalarTypeOffsetDateTime type = new ScalarTypeOffsetDateTime(JsonConfig.DateTime.MILLIS);
|
||||
ScalarTypeOffsetDateTime type = new ScalarTypeOffsetDateTime(JsonConfig.DateTime.MILLIS, ZoneOffset.systemDefault());
|
||||
|
||||
OffsetDateTime warmUp = OffsetDateTime.now();
|
||||
|
||||
@Test
|
||||
public void testConvertToMillis() throws Exception {
|
||||
public void testConvertToMillis() {
|
||||
|
||||
warmUp.hashCode();
|
||||
|
||||
@@ -30,7 +32,43 @@ public class ScalarTypeOffsetDateTimeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFromTimestamp() throws Exception {
|
||||
public void convertFromInstant_with_UTC_expect_matchingZoneOffset() {
|
||||
final TimeZone timeZoneToUse = TimeZone.getTimeZone("UTC");
|
||||
final ZoneOffset expectedZoneOffset = ZoneOffset.UTC;
|
||||
|
||||
convertFromInstantWithConfiguredTimeZone(timeZoneToUse, expectedZoneOffset);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertFromInstant_with_EST_expect_matchingZoneOffset() {
|
||||
final TimeZone timeZoneToUse = TimeZone.getTimeZone("EST");
|
||||
final ZoneOffset expectedOffset = OffsetDateTime.now(timeZoneToUse.toZoneId()).getOffset();
|
||||
|
||||
convertFromInstantWithConfiguredTimeZone(timeZoneToUse, expectedOffset);
|
||||
}
|
||||
|
||||
private void convertFromInstantWithConfiguredTimeZone(TimeZone timeZoneToUse, ZoneOffset expectedZoneOffset) {
|
||||
TimeZone previous = TimeZone.getDefault();
|
||||
try {
|
||||
OffsetDateTime dateTime = OffsetDateTime.parse("2021-01-01T00:00:00+11:00");
|
||||
|
||||
// test ScalarTypeOffsetDateTime with the configured timeZone to use
|
||||
ScalarTypeOffsetDateTime type = new ScalarTypeOffsetDateTime(JsonConfig.DateTime.MILLIS, timeZoneToUse.toZoneId());
|
||||
|
||||
// effectively we desire to ignore the system timezone and use the configured one
|
||||
TimeZone.setDefault(timeZoneToUse);
|
||||
|
||||
final OffsetDateTime offsetDateTime = type.convertFromInstant(dateTime.toInstant());
|
||||
|
||||
assertEquals(expectedZoneOffset, offsetDateTime.getOffset());
|
||||
|
||||
} finally {
|
||||
TimeZone.setDefault(previous);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFromTimestamp() {
|
||||
|
||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
@@ -69,11 +107,11 @@ public class ScalarTypeOffsetDateTimeTest {
|
||||
JsonTester<OffsetDateTime> jsonTester = new JsonTester<>(type);
|
||||
jsonTester.test(now);
|
||||
|
||||
ScalarTypeOffsetDateTime typeNanos = new ScalarTypeOffsetDateTime(JsonConfig.DateTime.NANOS);
|
||||
ScalarTypeOffsetDateTime typeNanos = new ScalarTypeOffsetDateTime(JsonConfig.DateTime.NANOS, ZoneOffset.systemDefault());
|
||||
jsonTester = new JsonTester<>(typeNanos);
|
||||
jsonTester.test(now);
|
||||
|
||||
ScalarTypeOffsetDateTime typeIso = new ScalarTypeOffsetDateTime(JsonConfig.DateTime.ISO8601);
|
||||
ScalarTypeOffsetDateTime typeIso = new ScalarTypeOffsetDateTime(JsonConfig.DateTime.ISO8601, ZoneOffset.systemDefault());
|
||||
jsonTester = new JsonTester<>(typeIso);
|
||||
jsonTester.test(now);
|
||||
}
|
||||
@@ -81,7 +119,7 @@ public class ScalarTypeOffsetDateTimeTest {
|
||||
@Test
|
||||
public void isoJsonFormatParse() {
|
||||
|
||||
ScalarTypeOffsetDateTime typeIso = new ScalarTypeOffsetDateTime(JsonConfig.DateTime.ISO8601);
|
||||
ScalarTypeOffsetDateTime typeIso = new ScalarTypeOffsetDateTime(JsonConfig.DateTime.ISO8601, ZoneOffset.systemDefault());
|
||||
|
||||
OffsetDateTime now = OffsetDateTime.now();
|
||||
String asJson = typeIso.toJsonISO8601(now);
|
||||
|
||||
+45
-6
@@ -4,7 +4,11 @@ import io.ebean.config.JsonConfig;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
@@ -12,12 +16,12 @@ import static org.junit.Assert.*;
|
||||
public class ScalarTypeZonedDateTimeTest {
|
||||
|
||||
|
||||
ScalarTypeZonedDateTime type = new ScalarTypeZonedDateTime(JsonConfig.DateTime.MILLIS);
|
||||
ScalarTypeZonedDateTime type = new ScalarTypeZonedDateTime(JsonConfig.DateTime.MILLIS, ZoneId.systemDefault());
|
||||
|
||||
ZonedDateTime warmUp = ZonedDateTime.now();
|
||||
|
||||
@Test
|
||||
public void testConvertToMillis() throws Exception {
|
||||
public void testConvertToMillis() {
|
||||
|
||||
warmUp.hashCode();
|
||||
|
||||
@@ -29,7 +33,7 @@ public class ScalarTypeZonedDateTimeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFromTimestamp() throws Exception {
|
||||
public void testConvertFromTimestamp() {
|
||||
|
||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
@@ -39,6 +43,41 @@ public class ScalarTypeZonedDateTimeTest {
|
||||
assertEquals(now, timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertFromInstant_with_UTC_expect_matchingZoneOffset() {
|
||||
final TimeZone timeZoneToUse = TimeZone.getTimeZone("UTC");
|
||||
final ZoneOffset expectedZoneOffset = ZoneOffset.UTC;
|
||||
|
||||
convertFromInstantWithConfiguredTimeZone(timeZoneToUse, expectedZoneOffset);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertFromInstant_with_EST_expect_matchingZoneOffset() {
|
||||
final TimeZone timeZoneToUse = TimeZone.getTimeZone("EST");
|
||||
final ZoneOffset expectedOffset = OffsetDateTime.now(timeZoneToUse.toZoneId()).getOffset();
|
||||
|
||||
convertFromInstantWithConfiguredTimeZone(timeZoneToUse, expectedOffset);
|
||||
}
|
||||
|
||||
private void convertFromInstantWithConfiguredTimeZone(TimeZone timeZoneToUse, ZoneOffset expectedZoneOffset) {
|
||||
TimeZone previous = TimeZone.getDefault();
|
||||
try {
|
||||
OffsetDateTime dateTime = OffsetDateTime.parse("2021-01-01T00:00:00+11:00");
|
||||
|
||||
// test ScalarTypeOffsetDateTime with the configured timeZone to use
|
||||
ScalarTypeZonedDateTime type = new ScalarTypeZonedDateTime(JsonConfig.DateTime.MILLIS, timeZoneToUse.toZoneId());
|
||||
|
||||
// effectively we desire to ignore the system timezone and use the configured one
|
||||
TimeZone.setDefault(timeZoneToUse);
|
||||
|
||||
final ZonedDateTime zonedDateTime = type.convertFromInstant(dateTime.toInstant());
|
||||
|
||||
assertEquals(expectedZoneOffset, zonedDateTime.getOffset());
|
||||
|
||||
} finally {
|
||||
TimeZone.setDefault(previous);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToJdbcType() throws Exception {
|
||||
@@ -68,11 +107,11 @@ public class ScalarTypeZonedDateTimeTest {
|
||||
JsonTester<ZonedDateTime> jsonTester = new JsonTester<>(type);
|
||||
jsonTester.test(now);
|
||||
|
||||
ScalarTypeZonedDateTime typeNanos = new ScalarTypeZonedDateTime(JsonConfig.DateTime.NANOS);
|
||||
ScalarTypeZonedDateTime typeNanos = new ScalarTypeZonedDateTime(JsonConfig.DateTime.NANOS, ZoneId.systemDefault());
|
||||
jsonTester = new JsonTester<>(typeNanos);
|
||||
jsonTester.test(now);
|
||||
|
||||
ScalarTypeZonedDateTime typeIso = new ScalarTypeZonedDateTime(JsonConfig.DateTime.ISO8601);
|
||||
ScalarTypeZonedDateTime typeIso = new ScalarTypeZonedDateTime(JsonConfig.DateTime.ISO8601, ZoneId.systemDefault());
|
||||
jsonTester = new JsonTester<>(typeIso);
|
||||
jsonTester.test(now);
|
||||
}
|
||||
@@ -80,7 +119,7 @@ public class ScalarTypeZonedDateTimeTest {
|
||||
@Test
|
||||
public void toJsonISO8601() {
|
||||
|
||||
ScalarTypeZonedDateTime typeIso = new ScalarTypeZonedDateTime(JsonConfig.DateTime.ISO8601);
|
||||
ScalarTypeZonedDateTime typeIso = new ScalarTypeZonedDateTime(JsonConfig.DateTime.ISO8601, ZoneId.systemDefault());
|
||||
|
||||
ZonedDateTime now = ZonedDateTime.now();
|
||||
String asJson = typeIso.toJsonISO8601(now);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package io.ebeaninternal.server.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ChecksumTest {
|
||||
|
||||
@Test
|
||||
public void checksum() {
|
||||
final long val = Checksum.checksum("Hello world");
|
||||
assertThat(val).isEqualTo(2346098258L);
|
||||
assertThat(Checksum.checksum("Hello world")).isEqualTo(val);
|
||||
assertThat(Checksum.checksum("hello world")).isNotEqualTo(val);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checksum_shortString() {
|
||||
final long val0 = Checksum.checksum("2012-01-11");
|
||||
final long val1 = Checksum.checksum("2012-10-02");
|
||||
assertThat(val0).isNotEqualTo(val1);
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,51 @@ package io.ebeaninternal.server.util;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
public class Md5Test {
|
||||
|
||||
@Test
|
||||
public void hash() throws Exception {
|
||||
|
||||
String content = "some random content we wish to hash";
|
||||
String hash1 = Md5.hash(content);
|
||||
String hash2 = Md5.hash(content);
|
||||
assertEquals(hash1, hash2);
|
||||
assertEquals(hash1, "62c20bf679ff56cb746452ab5c88e3ed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashDifferent() throws Exception {
|
||||
String hash1 = Md5.hash("one");
|
||||
String hash2 = Md5.hash("two");
|
||||
String hash3 = Md5.hash("onetwo");
|
||||
|
||||
assertNotEquals(hash1, hash2);
|
||||
assertNotEquals(hash2, hash3);
|
||||
assertEquals(hash1, "f97c5d29941bfb1b2fdab0874906ab82");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashMulti() {
|
||||
String hash1 = Md5.hash("one", "two");
|
||||
String hash2 = Md5.hash("onetwo");
|
||||
|
||||
assertEquals(hash1, hash2);
|
||||
assertEquals(hash1, "5b9164ad6f496d9dee12ec7634ce253f");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashMulti_when_null() {
|
||||
String hash1 = Md5.hash("one", null);
|
||||
String hash2 = Md5.hash("one");
|
||||
|
||||
assertEquals(hash1, hash2);
|
||||
assertEquals(hash1, "f97c5d29941bfb1b2fdab0874906ab82");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_null() {
|
||||
String hash1 = Md5.hash(null, null);
|
||||
assertEquals(hash1, "d41d8cd98f00b204e9800998ecf8427e");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,15 +80,15 @@ public class TestBatchInsertFlush extends BaseTestCase {
|
||||
}
|
||||
|
||||
ServerMetrics metrics = collectMetrics();
|
||||
List<MetaTimedMetric> txnStats = metrics.getTimedMetrics();
|
||||
List<MetaTimedMetric> txnStats = metrics.timedMetrics();
|
||||
for (MetaTimedMetric txnMetric : txnStats) {
|
||||
System.out.println(txnMetric);
|
||||
}
|
||||
assertThat(txnStats).hasSize(4);
|
||||
assertThat(txnStats.get(0).getName()).isEqualTo("txn.main");
|
||||
assertThat(txnStats.get(1).getName()).isEqualTo("txn.named.TestBatchInsertFlush.no_cascade");
|
||||
assertThat(txnStats.get(2).getName()).isEqualTo("iud.TSDetail.insertBatch");
|
||||
assertThat(txnStats.get(3).getName()).isEqualTo("iud.TSMaster.insertBatch");
|
||||
assertThat(txnStats.get(0).name()).isEqualTo("txn.main");
|
||||
assertThat(txnStats.get(1).name()).isEqualTo("txn.named.TestBatchInsertFlush.no_cascade");
|
||||
assertThat(txnStats.get(2).name()).isEqualTo("iud.TSDetail.insertBatch");
|
||||
assertThat(txnStats.get(3).name()).isEqualTo("iud.TSMaster.insertBatch");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+58
-28
@@ -3,7 +3,7 @@ package org.tests.cache;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.CacheMode;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.ExpressionList;
|
||||
import io.ebean.bean.BeanCollection;
|
||||
import io.ebean.cache.ServerCache;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
@@ -14,6 +14,7 @@ import org.tests.model.basic.ResetBasicData;
|
||||
import org.tests.model.cache.EColAB;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -26,8 +27,7 @@ public class TestQueryCache extends BaseTestCase {
|
||||
new EColAB("02", "10").save();
|
||||
|
||||
List<EColAB> list1 =
|
||||
Ebean.getServer(null)
|
||||
.find(EColAB.class)
|
||||
DB.find(EColAB.class)
|
||||
.setUseQueryCache(true)
|
||||
.where()
|
||||
.eq("columnA", "01")
|
||||
@@ -35,8 +35,7 @@ public class TestQueryCache extends BaseTestCase {
|
||||
.findList();
|
||||
|
||||
List<EColAB> list2 =
|
||||
Ebean.getServer(null)
|
||||
.find(EColAB.class)
|
||||
DB.find(EColAB.class)
|
||||
.setUseQueryCache(true)
|
||||
.where()
|
||||
.eq("columnA", "02")
|
||||
@@ -57,7 +56,7 @@ public class TestQueryCache extends BaseTestCase {
|
||||
new EColAB("03", "SingleAttribute").save();
|
||||
new EColAB("03", "SingleAttribute").save();
|
||||
|
||||
List<String> colA_first = Ebean.getServer(null)
|
||||
List<String> colA_first = DB
|
||||
.find(EColAB.class)
|
||||
.setUseQueryCache(true)
|
||||
.setDistinct(true)
|
||||
@@ -66,7 +65,7 @@ public class TestQueryCache extends BaseTestCase {
|
||||
.eq("columnB", "SingleAttribute")
|
||||
.findSingleAttributeList();
|
||||
|
||||
List<String> colA_Second = Ebean.getServer(null)
|
||||
List<String> colA_Second = DB
|
||||
.find(EColAB.class)
|
||||
.setUseQueryCache(true)
|
||||
.setDistinct(true)
|
||||
@@ -77,7 +76,7 @@ public class TestQueryCache extends BaseTestCase {
|
||||
|
||||
assertThat(colA_Second).isSameAs(colA_first);
|
||||
|
||||
List<String> colA_NotDistinct = Ebean.getServer(null)
|
||||
List<String> colA_NotDistinct = DB
|
||||
.find(EColAB.class)
|
||||
.setUseQueryCache(true)
|
||||
.select("columnA")
|
||||
@@ -89,7 +88,7 @@ public class TestQueryCache extends BaseTestCase {
|
||||
|
||||
// ensure that findCount & findSingleAttribute use different
|
||||
// slots in cache. If not a "Cannot cast List to int" should happen.
|
||||
int count = Ebean.getServer(null)
|
||||
int count = DB
|
||||
.find(EColAB.class)
|
||||
.setUseQueryCache(true)
|
||||
.select("columnA")
|
||||
@@ -107,13 +106,13 @@ public class TestQueryCache extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
int count0 = Ebean.find(EColAB.class)
|
||||
int count0 = DB.find(EColAB.class)
|
||||
.setUseQueryCache(CacheMode.ON)
|
||||
.where()
|
||||
.eq("columnB", "count")
|
||||
.findCount();
|
||||
|
||||
int count1 = Ebean.find(EColAB.class)
|
||||
int count1 = DB.find(EColAB.class)
|
||||
.setUseQueryCache(CacheMode.ON)
|
||||
.where()
|
||||
.eq("columnB", "count")
|
||||
@@ -126,7 +125,7 @@ public class TestQueryCache extends BaseTestCase {
|
||||
|
||||
// and now, ensure that we hit the database
|
||||
LoggedSqlCollector.start();
|
||||
int count2 = Ebean.find(EColAB.class)
|
||||
int count2 = DB.find(EColAB.class)
|
||||
.setUseQueryCache(CacheMode.OFF)
|
||||
.where()
|
||||
.eq("columnB", "count")
|
||||
@@ -142,13 +141,13 @@ public class TestQueryCache extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
int count0 = Ebean.find(EColAB.class)
|
||||
int count0 = DB.find(EColAB.class)
|
||||
.setUseQueryCache(CacheMode.ON)
|
||||
.where()
|
||||
.eq("columnB", "abc")
|
||||
.findCount();
|
||||
|
||||
int count1 = Ebean.find(EColAB.class)
|
||||
int count1 = DB.find(EColAB.class)
|
||||
.setUseQueryCache(CacheMode.ON)
|
||||
.where()
|
||||
.eq("columnB", "def")
|
||||
@@ -167,13 +166,13 @@ public class TestQueryCache extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
int count0 = Ebean.find(EColAB.class)
|
||||
int count0 = DB.find(EColAB.class)
|
||||
.setUseQueryCache(CacheMode.ON)
|
||||
.where()
|
||||
.eq("columnB", "uvw")
|
||||
.findCount();
|
||||
|
||||
int count1 = Ebean.find(EColAB.class)
|
||||
int count1 = DB.find(EColAB.class)
|
||||
.setUseQueryCache(CacheMode.PUT)
|
||||
.where()
|
||||
.eq("columnB", "uvw")
|
||||
@@ -193,13 +192,13 @@ public class TestQueryCache extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
int count0 = Ebean.find(EColAB.class)
|
||||
int count0 = DB.find(EColAB.class)
|
||||
.setUseQueryCache(CacheMode.PUT)
|
||||
.where()
|
||||
.eq("columnB", "xyz")
|
||||
.findCount();
|
||||
|
||||
int count1 = Ebean.find(EColAB.class)
|
||||
int count1 = DB.find(EColAB.class)
|
||||
.setUseQueryCache(CacheMode.ON)
|
||||
.where()
|
||||
.eq("columnB", "xyz")
|
||||
@@ -214,26 +213,26 @@ public class TestQueryCache extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void test() {
|
||||
public void testReadOnlyFind() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
ServerCache customerCache = Ebean.getServerCacheManager().getQueryCache(Customer.class);
|
||||
ServerCache customerCache = DB.getServerCacheManager().getQueryCache(Customer.class);
|
||||
customerCache.clear();
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class).setUseQueryCache(true).setReadOnly(true).where()
|
||||
List<Customer> list = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(true).where()
|
||||
.ilike("name", "Rob").findList();
|
||||
|
||||
BeanCollection<Customer> bc = (BeanCollection<Customer>) list;
|
||||
Assert.assertTrue(bc.isReadOnly());
|
||||
Assert.assertFalse(bc.isEmpty());
|
||||
Assert.assertTrue(!list.isEmpty());
|
||||
Assert.assertTrue(Ebean.getBeanState(list.get(0)).isReadOnly());
|
||||
Assert.assertTrue(DB.getBeanState(list.get(0)).isReadOnly());
|
||||
|
||||
List<Customer> list2 = Ebean.find(Customer.class).setUseQueryCache(true).setReadOnly(true).where()
|
||||
List<Customer> list2 = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(true).where()
|
||||
.ilike("name", "Rob").findList();
|
||||
|
||||
List<Customer> list2B = Ebean.find(Customer.class).setUseQueryCache(true)
|
||||
List<Customer> list2B = DB.find(Customer.class).setUseQueryCache(true)
|
||||
// .setReadOnly(true)
|
||||
.where().ilike("name", "Rob").findList();
|
||||
|
||||
@@ -245,7 +244,7 @@ public class TestQueryCache extends BaseTestCase {
|
||||
|
||||
|
||||
|
||||
List<Customer> list3 = Ebean.find(Customer.class).setUseQueryCache(true).setReadOnly(false).where()
|
||||
List<Customer> list3 = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(false).where()
|
||||
.ilike("name", "Rob").findList();
|
||||
|
||||
Assert.assertNotSame(list, list3);
|
||||
@@ -269,13 +268,13 @@ public class TestQueryCache extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<Integer> colA_first = Ebean.find(EColAB.class)
|
||||
List<Integer> colA_first = DB.find(EColAB.class)
|
||||
.setUseQueryCache(CacheMode.ON)
|
||||
.where()
|
||||
.eq("columnB", "someId")
|
||||
.findIds();
|
||||
|
||||
List<Integer> colA_second = Ebean.find(EColAB.class)
|
||||
List<Integer> colA_second = DB.find(EColAB.class)
|
||||
.setUseQueryCache(CacheMode.ON)
|
||||
.where()
|
||||
.eq("columnB", "someId")
|
||||
@@ -289,7 +288,7 @@ public class TestQueryCache extends BaseTestCase {
|
||||
|
||||
// and now, ensure that we hit the database
|
||||
LoggedSqlCollector.start();
|
||||
colA_second = Ebean.find(EColAB.class)
|
||||
colA_second = DB.find(EColAB.class)
|
||||
.setUseQueryCache(CacheMode.PUT)
|
||||
.where()
|
||||
.eq("columnB", "someId")
|
||||
@@ -299,4 +298,35 @@ public class TestQueryCache extends BaseTestCase {
|
||||
assertThat(sql).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findCountDifferentQueriesBit() {
|
||||
DB.getDefault().getPluginApi().getServerCacheManager().clearAll();
|
||||
differentFindCount(q->q.bitwiseAny("id",1), q->q.bitwiseAny("id",0));
|
||||
differentFindCount(q->q.bitwiseAll("id",1), q->q.bitwiseAll("id",0));
|
||||
// differentFindCount(q->q.bitwiseNot("id",1), q->q.bitwiseNot("id",0)); NOT 1 == AND 1 = 0
|
||||
differentFindCount(q->q.bitwiseAnd("id",1, 0), q->q.bitwiseAnd("id",1, 1));
|
||||
|
||||
differentFindCount(q->q.bitwiseAnd("id",2, 0), q->q.bitwiseAnd("id",4, 0));
|
||||
differentFindCount(q->q.bitwiseAnd("id",2, 1), q->q.bitwiseAnd("id",4, 1));
|
||||
// Will produce hash collision
|
||||
differentFindCount(q->q.bitwiseAnd("id",10, 0), q->q.bitwiseAnd("id",0, 928210));
|
||||
|
||||
}
|
||||
|
||||
void differentFindCount(Consumer<ExpressionList<EColAB>> q0, Consumer<ExpressionList<EColAB>> q1) {
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
ExpressionList<EColAB> el0 = DB.find(EColAB.class).setUseQueryCache(CacheMode.ON).where();
|
||||
q0.accept(el0);
|
||||
el0.findCount();
|
||||
|
||||
ExpressionList<EColAB> el1 = DB.find(EColAB.class).setUseQueryCache(CacheMode.ON).where();
|
||||
q1.accept(el1);
|
||||
el1.findCount();
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(sql).hasSize(2); // different queries
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,13 @@ import io.ebean.event.changelog.ChangeLogRegister;
|
||||
import io.ebean.event.changelog.ChangeSet;
|
||||
import io.ebean.event.changelog.ChangeType;
|
||||
import io.ebean.event.changelog.TxnState;
|
||||
import io.ebeantest.LoggedSql;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.EBasicChangeLog;
|
||||
import org.tests.model.json.PlainBean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -130,7 +133,31 @@ public class TestChangeLog extends BaseTestCase {
|
||||
assertThat(change.getEvent()).isEqualTo(ChangeType.DELETE);
|
||||
assertThat(change.getData()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithJsonMutationDetection() {
|
||||
|
||||
EBasicChangeLog bean = new EBasicChangeLog();
|
||||
bean.setName(null);
|
||||
bean.setShortDescription("hello");
|
||||
PlainBean jsonBean = new PlainBean();
|
||||
bean.setPlainBean(jsonBean);
|
||||
jsonBean.setName("A");
|
||||
server.save(bean);
|
||||
|
||||
BeanChange change = firstChange();
|
||||
assertThat(change.getEvent()).isEqualTo(ChangeType.INSERT);
|
||||
|
||||
jsonBean.setName("B");
|
||||
LoggedSql.start();
|
||||
server.save(bean);
|
||||
assertThat(LoggedSql.stop()).isNotEmpty();
|
||||
|
||||
change = firstChange();
|
||||
assertThat(change.getEvent()).isEqualTo(ChangeType.UPDATE);
|
||||
assertThat(change.getData()).contains("\"plainBean\":{\"name\":\"B\"");
|
||||
assertThat(change.getOldData()).contains("\"plainBean\":{\"name\":\"A\"");
|
||||
}
|
||||
private Database createServer() {
|
||||
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
|
||||
@@ -1,21 +1,48 @@
|
||||
package org.tests.json;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.BeanState;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.ValuePair;
|
||||
import io.ebean.event.BeanPersistAdapter;
|
||||
import io.ebean.event.BeanPersistRequest;
|
||||
import io.ebeantest.LoggedSql;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.json.EBasicJsonJackson3;
|
||||
import org.tests.model.json.EBasicJsonList;
|
||||
import org.tests.model.json.EBasicJsonMulti;
|
||||
import org.tests.model.json.PlainBean;
|
||||
import org.tests.model.json.PlainBeanDirtyAware;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestDbJson_Jackson3 extends BaseTestCase {
|
||||
|
||||
public static class EBasicJsonListPersistController extends BeanPersistAdapter {
|
||||
|
||||
private static Map<String, ValuePair> updatedValues;
|
||||
|
||||
@Override
|
||||
public boolean isRegisterFor(Class<?> cls) {
|
||||
return EBasicJsonList.class.isAssignableFrom(cls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preInsert(BeanPersistRequest<?> request) {
|
||||
updatedValues = request.getUpdatedValues();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preUpdate(BeanPersistRequest<?> request) {
|
||||
updatedValues = request.getUpdatedValues();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void updateIncludesJsonColumn_when_explicit_isMarkedDirty() {
|
||||
|
||||
@@ -24,6 +51,7 @@ public class TestDbJson_Jackson3 extends BaseTestCase {
|
||||
EBasicJsonJackson3 bean = new EBasicJsonJackson3();
|
||||
bean.setName("b1");
|
||||
bean.setPlainValue(contentBean);
|
||||
bean.setPlainValue2(contentBean);
|
||||
|
||||
bean.save();
|
||||
|
||||
@@ -32,20 +60,15 @@ public class TestDbJson_Jackson3 extends BaseTestCase {
|
||||
|
||||
LoggedSql.start();
|
||||
found.save();
|
||||
|
||||
List<String> sql = LoggedSql.collect();
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("update ebasic_json_jackson3 set name=?, version=? where id=? and version=?");
|
||||
expectedSql(0, "update ebasic_json_jackson3 set name=?, version=? where id=? and version=?");
|
||||
|
||||
found.setName("b1-mod2");
|
||||
found.getPlainValue().setName("b");
|
||||
found.getPlainValue().setMarkedDirty(true);
|
||||
// found.getPlainValue().setMarkedDirty(true); // Irrelevant for SOURCE or HASH based mutation detection
|
||||
|
||||
found.save();
|
||||
|
||||
sql = LoggedSql.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("update ebasic_json_jackson3 set name=?, plain_value=?, version=? where id=? and version=?");
|
||||
expectedSql(0, "update ebasic_json_jackson3 set name=?, plain_value=?, version=? where id=? and version=?");
|
||||
LoggedSql.stop();
|
||||
|
||||
final EBasicJsonJackson3 found2 = DB.find(EBasicJsonJackson3.class, bean.getId());
|
||||
|
||||
@@ -69,11 +92,153 @@ public class TestDbJson_Jackson3 extends BaseTestCase {
|
||||
found.setName("p1-mod");
|
||||
found.setBeanList(null);
|
||||
|
||||
BeanState state = DB.getBeanState(found);
|
||||
assertThat(state.getChangedProps()).containsExactlyInAnyOrder("name", "beanList");
|
||||
|
||||
ValuePair pair = state.getDirtyValues().get("name");
|
||||
assertThat(pair.getNewValue()).isEqualTo("p1-mod");
|
||||
assertThat(pair.getOldValue()).isEqualTo("p1");
|
||||
|
||||
pair = state.getDirtyValues().get("beanList");
|
||||
assertThat(pair.getNewValue()).isEqualTo(null);
|
||||
assertThat((List<PlainBean>)pair.getOldValue()).hasSize(1)
|
||||
.extracting(PlainBean::getName).containsExactly("a");
|
||||
|
||||
|
||||
LoggedSql.start();
|
||||
DB.save(found);
|
||||
|
||||
final List<String> sql = LoggedSql.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("update ebasic_json_list set name=?, bean_list=?, plain_bean=?, version=? where id=?");
|
||||
// plain_bean=?, no longer included with MD5 dirty detection
|
||||
expectedSql(0, "update ebasic_json_list set name=?, bean_list=?, version=? where id=?");
|
||||
|
||||
assertThat(EBasicJsonListPersistController.updatedValues.entrySet())
|
||||
.extracting(Map.Entry::toString)
|
||||
.containsExactlyInAnyOrder("beanList=null,[name:a]","name=p1-mod,p1","version=2,1");
|
||||
|
||||
assertThat(DB.getBeanState(found).isDirty()).isFalse();
|
||||
|
||||
found.getPlainBean().setName("b");
|
||||
assertThat(DB.getBeanState(found).isDirty()).isTrue();
|
||||
|
||||
state = DB.getBeanState(found);
|
||||
assertThat(state.getChangedProps()).containsExactlyInAnyOrder("plainBean");
|
||||
pair = state.getDirtyValues().get("plainBean");
|
||||
assertThat(pair.getNewValue()).hasToString("name:b");
|
||||
assertThat(pair.getOldValue()).hasToString("name:a");
|
||||
|
||||
|
||||
LoggedSql.start();
|
||||
DB.save(found);
|
||||
|
||||
// plain_bean=?, no longer included with MD5 dirty detection
|
||||
expectedSql(0, "update ebasic_json_list set plain_bean=?, version=? where id=?");
|
||||
|
||||
assertThat(EBasicJsonListPersistController.updatedValues.entrySet())
|
||||
.extracting(Map.Entry::toString)
|
||||
.containsExactlyInAnyOrder("plainBean=name:b,name:a", "version=3,2");
|
||||
|
||||
LoggedSql.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateIncludesJsonColumn_when_list_loadedAndNotDirtyAware() {
|
||||
|
||||
PlainBean contentBean = new PlainBean("a", 42);
|
||||
EBasicJsonList bean = new EBasicJsonList();
|
||||
bean.setName("p1");
|
||||
bean.setPlainBean(contentBean);
|
||||
bean.setBeanList(Arrays.asList(contentBean));
|
||||
|
||||
DB.save(bean);
|
||||
final EBasicJsonList found = DB.find(EBasicJsonList.class, bean.getId());
|
||||
found.getBeanList().get(0).setName("p1-mod");
|
||||
|
||||
BeanState state = DB.getBeanState(found);
|
||||
assertThat(state.getChangedProps()).containsExactlyInAnyOrder("beanList");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update_with_differentDbJsonSettings() {
|
||||
PlainBeanDirtyAware contentBean1 = new PlainBeanDirtyAware("x", 42);
|
||||
PlainBeanDirtyAware contentBean2 = new PlainBeanDirtyAware("y", 43);
|
||||
PlainBeanDirtyAware contentBean3 = new PlainBeanDirtyAware("z", 44);
|
||||
|
||||
EBasicJsonJackson3 bean = new EBasicJsonJackson3();
|
||||
bean.setName("b1");
|
||||
bean.setPlainValue(contentBean1);
|
||||
bean.setPlainValue2(contentBean2);
|
||||
bean.setPlainValue3(contentBean3);
|
||||
|
||||
BeanState state = DB.getBeanState(bean);
|
||||
// a new bean is not considered as dirty (thus have no changed props)
|
||||
assertThat(state.isDirty()).isFalse();
|
||||
assertThat(state.isNewOrDirty()).isTrue();
|
||||
assertThat(state.getChangedProps()).isEmpty();
|
||||
|
||||
bean.save();
|
||||
|
||||
bean = DB.find(EBasicJsonJackson3.class, bean.getId());
|
||||
state = DB.getBeanState(bean);
|
||||
// a fresh loaded bean is also not considered as dirty
|
||||
assertThat(state.isDirty()).isFalse();
|
||||
assertThat(state.isNewOrDirty()).isFalse();
|
||||
assertThat(state.getChangedProps()).isEmpty();
|
||||
|
||||
bean.getPlainValue().setName("a"); // has SOURCE
|
||||
|
||||
assertThat(state.isDirty()).isTrue();
|
||||
assertThat(state.getChangedProps()).containsExactly("plainValue");
|
||||
|
||||
bean.getPlainValue2().setName("b");
|
||||
assertThat(state.getChangedProps()).containsExactlyInAnyOrder("plainValue", "plainValue2");
|
||||
|
||||
bean.getPlainValue3().setName("c"); // has mutationDetection = NONE
|
||||
|
||||
Map<String, ValuePair> dirtyValues = state.getDirtyValues();
|
||||
assertThat(dirtyValues).hasSize(2).containsKeys("plainValue", "plainValue2");
|
||||
|
||||
assertThat(dirtyValues.get("plainValue")).hasToString("name:a,name:x"); // SOURCE -> origValue present
|
||||
assertThat(dirtyValues.get("plainValue2")).hasToString("name:b,null"); // without SOURCE no origValue present
|
||||
|
||||
LoggedSql.start();
|
||||
bean.save();
|
||||
expectedSql(0, "update ebasic_json_jackson3 set plain_value=?, plain_value2=?, version=? where id=?");
|
||||
|
||||
bean = DB.find(EBasicJsonJackson3.class, bean.getId());
|
||||
LoggedSql.collect(); // ignore the select
|
||||
assertThat(bean.getPlainValue().getName()).isEqualTo("a");
|
||||
assertThat(bean.getPlainValue2().getName()).isEqualTo("b");
|
||||
assertThat(bean.getPlainValue3().getName()).isEqualTo("z"); // value is not updated
|
||||
|
||||
bean.getPlainValue3().setName("c");
|
||||
bean.getPlainValue3().setMarkedDirty(true); // This is ignored because it is MutationDetection.NONE
|
||||
bean.save();
|
||||
// no update as plainValue3 has MutationDetection.NONE (ModifyAwareType = NONE isn't an expected combination to me)
|
||||
assertThat(LoggedSql.collect()).isEmpty();
|
||||
|
||||
bean.getPlainValue2().setName("b2"); // effectively HASH mode mutation detection
|
||||
bean.save();
|
||||
expectedSql(0, "update ebasic_json_jackson3 set plain_value2=?, version=? where id=? and version=?");
|
||||
|
||||
LoggedSql.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void push_pop_test() {
|
||||
|
||||
EBasicJsonMulti bean = new EBasicJsonMulti();
|
||||
bean.setPlainValue2(new PlainBeanDirtyAware("x", 42));
|
||||
bean.save();
|
||||
|
||||
bean = DB.find(EBasicJsonMulti.class, bean.getId());
|
||||
bean.setPlainValue1(null); // already null
|
||||
bean.setPlainValue2(null);
|
||||
bean.setPlainValue3(null); // already null
|
||||
BeanState state = DB.getBeanState(bean);
|
||||
assertThat(state.getDirtyValues()).hasSize(1).containsKey("plainValue2");
|
||||
}
|
||||
|
||||
private void expectedSql(int i, String s) {
|
||||
assertThat(LoggedSql.collect().get(i)).contains(s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,10 +76,11 @@ public class TestDbJson_List extends BaseTestCase {
|
||||
update_when_dirty();
|
||||
update_when_dirty_flags();
|
||||
update_when_dirty_SetListMap();
|
||||
|
||||
DB.delete(found);
|
||||
}
|
||||
|
||||
//@Test//(dependsOnMethods = "insert")
|
||||
public void json_parse_format() {
|
||||
private void json_parse_format() {
|
||||
|
||||
String asJson = DB.json().toJson(found);
|
||||
assertThat(asJson).contains("\"tags\":[\"one\",\"two\"]");
|
||||
@@ -104,8 +105,7 @@ public class TestDbJson_List extends BaseTestCase {
|
||||
assertThat(fromJson.getBeanMap()).hasSize(2);
|
||||
}
|
||||
|
||||
//@Test//(dependsOnMethods = "insert")
|
||||
public void update_when_notDirty() {
|
||||
private void update_when_notDirty() {
|
||||
|
||||
found.setName("mod");
|
||||
LoggedSqlCollector.start();
|
||||
@@ -113,10 +113,11 @@ public class TestDbJson_List extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
// we don't update the phone numbers (as they are not dirty)
|
||||
assertSql(sql.get(0)).contains("update ebasic_json_list set name=?, plain_bean=?, version=? where");
|
||||
// plain_bean=?, no longer included with MD5 dirty detection
|
||||
assertSql(sql.get(0)).contains("update ebasic_json_list set name=?, version=? where");
|
||||
}
|
||||
|
||||
public void update_when_dirty() {
|
||||
private void update_when_dirty() {
|
||||
|
||||
//found.setName("modAgain");
|
||||
found.getTags().add("three");
|
||||
@@ -126,10 +127,11 @@ public class TestDbJson_List extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
// we don't update the phone numbers (as they are not dirty)
|
||||
assertSql(sql.get(0)).contains("update ebasic_json_list set plain_bean=?, tags=?, version=? where id=? and version=?");
|
||||
// plain_bean=? not included using MD5 dirty detection
|
||||
assertSql(sql.get(0)).contains("update ebasic_json_list set tags=?, version=? where id=? and version=?");
|
||||
}
|
||||
|
||||
public void update_when_dirty_flags() {
|
||||
private void update_when_dirty_flags() {
|
||||
|
||||
//found.setName("modAgain");
|
||||
found.getFlags().remove(42L);
|
||||
@@ -139,10 +141,11 @@ public class TestDbJson_List extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
// we don't update the phone numbers (as they are not dirty)
|
||||
assertSql(sql.get(0)).contains("update ebasic_json_list set plain_bean=?, flags=?, version=? where id=? and version=?;");
|
||||
// plain_bean=? not included with MD5 dirty detection
|
||||
assertSql(sql.get(0)).contains("update ebasic_json_list set flags=?, version=? where id=? and version=?;");
|
||||
}
|
||||
|
||||
public void update_when_dirty_SetListMap() {
|
||||
private void update_when_dirty_SetListMap() {
|
||||
|
||||
//found.setName("modAgain");
|
||||
found.getBeanSet().clear();
|
||||
@@ -154,7 +157,8 @@ public class TestDbJson_List extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
// we don't update the phone numbers (as they are not dirty)
|
||||
assertSql(sql.get(0)).contains("update ebasic_json_list set beans=?, bean_list=?, bean_map=?, plain_bean=?, version=? where id=? and version=?");
|
||||
// plain_bean=? not included with MD5 dirty detection
|
||||
assertSql(sql.get(0)).contains("update ebasic_json_list set beans=?, bean_list=?, bean_map=?, version=? where id=? and version=?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -221,4 +225,19 @@ public class TestDbJson_List extends BaseTestCase {
|
||||
|
||||
DB.delete(bean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullToEmpty() {
|
||||
EBasicJsonList bean = new EBasicJsonList();
|
||||
bean.setFlags(null);
|
||||
bean.setTags(null);
|
||||
bean.setBeanMap(null);
|
||||
DB.save(bean);
|
||||
|
||||
bean = DB.find(EBasicJsonList.class).setId(bean.getId()).findOne();
|
||||
|
||||
assertThat(bean.getFlags()).isEmpty();
|
||||
assertThat(bean.getTags()).isEmpty();
|
||||
assertThat(bean.getBeanMap()).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package org.tests.m2m;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.DB;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.MRole;
|
||||
import org.tests.model.basic.MUser;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestM2MModifyTest extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
@@ -19,8 +20,8 @@ public class TestM2MModifyTest extends BaseTestCase {
|
||||
MRole r1 = new MRole("r1");
|
||||
|
||||
// Save r1 and r2
|
||||
Ebean.save(r0);
|
||||
Ebean.save(r1);
|
||||
DB.save(r0);
|
||||
DB.save(r1);
|
||||
|
||||
// Create a new user
|
||||
MUser u0 = new MUser("usr0");
|
||||
@@ -28,32 +29,27 @@ public class TestM2MModifyTest extends BaseTestCase {
|
||||
u0.addRole(r1);
|
||||
|
||||
// Save the user
|
||||
Ebean.save(u0);
|
||||
DB.save(u0);
|
||||
|
||||
List<MRole> roles = u0.getRoles();
|
||||
|
||||
Assert.assertTrue(roles.size() == 2);
|
||||
assertThat(roles).hasSize(2);
|
||||
|
||||
u0 = Ebean.find(MUser.class, u0.getUserid());
|
||||
u0 = DB.find(MUser.class, u0.getUserid());
|
||||
|
||||
roles = u0.getRoles();
|
||||
int nrRoles = roles.size();
|
||||
|
||||
Assert.assertTrue(nrRoles == 2);
|
||||
assertThat(roles).hasSize(2);
|
||||
|
||||
roles.clear();
|
||||
roles.add(r0);
|
||||
roles.add(r1);
|
||||
roles.remove(r1);
|
||||
|
||||
Ebean.save(u0);
|
||||
DB.save(u0);
|
||||
|
||||
u0 = Ebean.find(MUser.class, u0.getUserid());
|
||||
u0 = DB.find(MUser.class, u0.getUserid());
|
||||
|
||||
roles = u0.getRoles();
|
||||
|
||||
nrRoles = roles.size();
|
||||
|
||||
Assert.assertTrue(nrRoles == 1);
|
||||
assertThat(roles).hasSize(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class TestM2mDeleteObject extends BaseTestCase {
|
||||
|
||||
List<MetaTimedMetric> sqlMetrics = sqlMetrics();
|
||||
assertThat(sqlMetrics).hasSize(1);
|
||||
assertThat(sqlMetrics.get(0).getName()).isEqualTo("orm.update.deleteAllPermissions");
|
||||
assertThat(sqlMetrics.get(0).name()).isEqualTo("orm.update.deleteAllPermissions");
|
||||
|
||||
Tenant t = new Tenant("tenant");
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.tests.model.basic;
|
||||
|
||||
import io.ebean.annotation.Cache;
|
||||
import io.ebean.annotation.ChangeLog;
|
||||
import io.ebean.annotation.DbJson;
|
||||
import io.ebean.annotation.ReadAudit;
|
||||
import io.ebean.annotation.WhenCreated;
|
||||
import io.ebean.annotation.WhenModified;
|
||||
@@ -12,11 +13,16 @@ import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import org.tests.model.json.PlainBean;
|
||||
|
||||
import static io.ebean.annotation.MutationDetection.SOURCE;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Cache(enableQueryCache = true)
|
||||
@ReadAudit
|
||||
@ChangeLog(updatesThatInclude = {"name", "shortDescription"})
|
||||
@ChangeLog(updatesThatInclude = {"name", "shortDescription", "plainBean"})
|
||||
@Entity
|
||||
public class EBasicChangeLog {
|
||||
|
||||
@@ -46,6 +52,9 @@ public class EBasicChangeLog {
|
||||
|
||||
@Version
|
||||
Long version;
|
||||
|
||||
@DbJson(length = 500, mutationDetection = SOURCE) // such that we can rebuild old values
|
||||
PlainBean plainBean;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
@@ -118,4 +127,12 @@ public class EBasicChangeLog {
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public PlainBean getPlainBean() {
|
||||
return plainBean;
|
||||
}
|
||||
|
||||
public void setPlainBean(PlainBean plainBean) {
|
||||
this.plainBean = plainBean;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ public class CustomerFinder extends Finder<Integer, Customer> {
|
||||
}
|
||||
|
||||
public List<Customer> byNameStatus(String nameStartsWith, Customer.Status status) {
|
||||
|
||||
return query("where status = :status and name istartsWith :name order by name")
|
||||
.setParameter("status", status)
|
||||
.setParameter("name", nameStartsWith)
|
||||
@@ -45,7 +44,6 @@ public class CustomerFinder extends Finder<Integer, Customer> {
|
||||
}
|
||||
|
||||
public List<String> namesStartingWith(String name) {
|
||||
|
||||
return nativeSql("select name from o_customer where name like ? order by name")
|
||||
.setParameter(name + "%")
|
||||
.findSingleAttributeList();
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package org.tests.model.embedded;
|
||||
|
||||
import io.ebean.annotation.DbJson;
|
||||
import org.tests.model.json.PlainBean;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import java.util.Map;
|
||||
|
||||
@Embeddable
|
||||
public class EAddress {
|
||||
@@ -18,6 +22,12 @@ public class EAddress {
|
||||
@Enumerated(EnumType.STRING)
|
||||
EAddressStatus status;
|
||||
|
||||
@DbJson
|
||||
PlainBean jbean;
|
||||
|
||||
@DbJson
|
||||
Map<String, Object> jraw;
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
@@ -42,6 +52,22 @@ public class EAddress {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public PlainBean getJbean() {
|
||||
return jbean;
|
||||
}
|
||||
|
||||
public void setJbean(PlainBean jbean) {
|
||||
this.jbean = jbean;
|
||||
}
|
||||
|
||||
public Map<String, Object> getJraw() {
|
||||
return jraw;
|
||||
}
|
||||
|
||||
public void setJraw(Map<String, Object> jraw) {
|
||||
this.jraw = jraw;
|
||||
}
|
||||
|
||||
public EAddressStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ public class EPerson {
|
||||
@Embedded
|
||||
@AttributeOverrides({
|
||||
@AttributeOverride(name = "city", column = @Column(name = "addr_city")),
|
||||
@AttributeOverride(name = "status", column = @Column(name = "addr_status"))
|
||||
@AttributeOverride(name = "status", column = @Column(name = "addr_status")),
|
||||
@AttributeOverride(name = "jbean", column = @Column(name = "addr_jbean"))
|
||||
})
|
||||
EAddress address;
|
||||
|
||||
|
||||
@@ -2,11 +2,15 @@ package org.tests.model.json;
|
||||
|
||||
import io.ebean.Model;
|
||||
import io.ebean.annotation.DbJson;
|
||||
import io.ebean.annotation.MutationDetection;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
|
||||
import static io.ebean.annotation.MutationDetection.NONE;
|
||||
import static io.ebean.annotation.MutationDetection.SOURCE;
|
||||
|
||||
@Entity
|
||||
public class EBasicJsonJackson3 extends Model {
|
||||
|
||||
@@ -15,9 +19,15 @@ public class EBasicJsonJackson3 extends Model {
|
||||
|
||||
String name;
|
||||
|
||||
@DbJson(length = 500)
|
||||
@DbJson(length = 500, mutationDetection = SOURCE)
|
||||
PlainBeanDirtyAware plainValue;
|
||||
|
||||
@DbJson(length = 500)
|
||||
PlainBeanDirtyAware plainValue2;
|
||||
|
||||
@DbJson(length = 500, mutationDetection = NONE)
|
||||
PlainBeanDirtyAware plainValue3;
|
||||
|
||||
@Version
|
||||
long version;
|
||||
|
||||
@@ -45,6 +55,22 @@ public class EBasicJsonJackson3 extends Model {
|
||||
this.plainValue = plainValue;
|
||||
}
|
||||
|
||||
public PlainBeanDirtyAware getPlainValue2() {
|
||||
return plainValue2;
|
||||
}
|
||||
|
||||
public void setPlainValue2(PlainBeanDirtyAware plainValue2) {
|
||||
this.plainValue2 = plainValue2;
|
||||
}
|
||||
|
||||
public PlainBeanDirtyAware getPlainValue3() {
|
||||
return plainValue3;
|
||||
}
|
||||
|
||||
public void setPlainValue3(PlainBeanDirtyAware plainValue3) {
|
||||
this.plainValue3 = plainValue3;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@@ -7,12 +7,10 @@ import io.ebean.annotation.DbJsonType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static io.ebean.annotation.MutationDetection.HASH;
|
||||
import static io.ebean.annotation.MutationDetection.SOURCE;
|
||||
|
||||
@Entity
|
||||
public class EBasicJsonList {
|
||||
@@ -22,16 +20,17 @@ public class EBasicJsonList {
|
||||
|
||||
String name;
|
||||
|
||||
// @JsonDeserialize(as=LinkedHashSet.class)
|
||||
@DbJson(length = 700, name = "beans")
|
||||
Set<PlainBean> beanSet;
|
||||
|
||||
@DbJsonB
|
||||
@DbJsonB(mutationDetection = HASH)
|
||||
List<PlainBean> beanList;
|
||||
|
||||
@DbJson(length = 700)
|
||||
Map<String, PlainBean> beanMap = new LinkedHashMap<>();
|
||||
|
||||
@DbJson(length = 500)
|
||||
@DbJson(length = 500, mutationDetection = SOURCE) // such that we can rebuild old values
|
||||
PlainBean plainBean;
|
||||
|
||||
@DbJson(length = 50)
|
||||
|
||||
@@ -20,7 +20,7 @@ public class EBasicJsonMapVarchar {
|
||||
String name;
|
||||
|
||||
@DbJson(storage = DbJsonType.VARCHAR)//, length = 2200)
|
||||
Map<String, Object> content;
|
||||
Map<String, Object> content;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package org.tests.model.json;
|
||||
|
||||
import io.ebean.Model;
|
||||
import io.ebean.annotation.DbJson;
|
||||
import io.ebean.annotation.MutationDetection;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
|
||||
import static io.ebean.annotation.MutationDetection.NONE;
|
||||
import static io.ebean.annotation.MutationDetection.SOURCE;
|
||||
|
||||
@Entity
|
||||
public class EBasicJsonMulti extends Model {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
String name;
|
||||
|
||||
@DbJson(length = 500, mutationDetection = SOURCE)
|
||||
PlainBeanDirtyAware plainValue1;
|
||||
|
||||
@DbJson(length = 500, mutationDetection = SOURCE)
|
||||
PlainBeanDirtyAware plainValue2;
|
||||
|
||||
@DbJson(length = 500, mutationDetection = SOURCE)
|
||||
PlainBeanDirtyAware plainValue3;
|
||||
|
||||
@Version
|
||||
long version;
|
||||
|
||||
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 PlainBeanDirtyAware getPlainValue1() {
|
||||
return plainValue1;
|
||||
}
|
||||
|
||||
public void setPlainValue1(PlainBeanDirtyAware plainValue1) {
|
||||
this.plainValue1 = plainValue1;
|
||||
}
|
||||
|
||||
public PlainBeanDirtyAware getPlainValue2() {
|
||||
return plainValue2;
|
||||
}
|
||||
|
||||
public void setPlainValue2(PlainBeanDirtyAware plainValue2) {
|
||||
this.plainValue2 = plainValue2;
|
||||
}
|
||||
|
||||
public PlainBeanDirtyAware getPlainValue3() {
|
||||
return plainValue3;
|
||||
}
|
||||
|
||||
public void setPlainValue3(PlainBeanDirtyAware plainValue3) {
|
||||
this.plainValue3 = plainValue3;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(long version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package org.tests.model.json;
|
||||
|
||||
import io.ebean.annotation.DbJson;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
|
||||
import static io.ebean.annotation.MutationDetection.NONE;
|
||||
|
||||
@Entity
|
||||
public class EBasicPlain {
|
||||
|
||||
@Id
|
||||
long id;
|
||||
|
||||
String attr;
|
||||
|
||||
@DbJson(length = 500)
|
||||
PlainBean plainBean;
|
||||
|
||||
@DbJson(length = 500, mutationDetection = NONE) // only update when property set
|
||||
PlainBean plainBean2;
|
||||
|
||||
@Version
|
||||
long version;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAttr() {
|
||||
return attr;
|
||||
}
|
||||
|
||||
public void setAttr(String attr) {
|
||||
this.attr = attr;
|
||||
}
|
||||
|
||||
public PlainBean getPlainBean() {
|
||||
return plainBean;
|
||||
}
|
||||
|
||||
public void setPlainBean(PlainBean plainBean) {
|
||||
this.plainBean = plainBean;
|
||||
}
|
||||
|
||||
public PlainBean getPlainBean2() {
|
||||
return plainBean2;
|
||||
}
|
||||
|
||||
public void setPlainBean2(PlainBean plainBean2) {
|
||||
this.plainBean2 = plainBean2;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(long version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package org.tests.model.json;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebeantest.LoggedSql;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestJacksonPlainBean {
|
||||
|
||||
@Test
|
||||
public void insertNullStayNull() {
|
||||
|
||||
// insert with jackson beans as null
|
||||
EBasicPlain bean = new EBasicPlain();
|
||||
bean.setAttr("n0");
|
||||
DB.save(bean);
|
||||
|
||||
LoggedSql.start();
|
||||
bean.setAttr("n1");
|
||||
DB.save(bean);
|
||||
expectedSql(0, "update ebasic_plain set attr=?, version=? where id=? and version=?");
|
||||
|
||||
bean.setPlainBean(new PlainBean("x", 1));
|
||||
DB.save(bean);
|
||||
expectedSql(0, "update ebasic_plain set plain_bean=?, version=? where id=? and version=?");
|
||||
|
||||
final EBasicPlain found = DB.find(EBasicPlain.class, bean.getId());
|
||||
found.setAttr("n2");
|
||||
DB.save(found);
|
||||
expectedSql(1, "update ebasic_plain set attr=?, version=? where id=? and version=?");
|
||||
|
||||
LoggedSql.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insertUpdate() {
|
||||
|
||||
DB.getDefault();
|
||||
LoggedSql.start();
|
||||
|
||||
PlainBean content = new PlainBean("foo", 42);
|
||||
EBasicPlain bean = new EBasicPlain();
|
||||
bean.setAttr("attr0");
|
||||
bean.setPlainBean(content);
|
||||
bean.setPlainBean2(new PlainBean("bar", 27));
|
||||
|
||||
DB.save(bean);
|
||||
expectedSql(0, "insert into ebasic_plain (attr, plain_bean, plain_bean2, version) values (?,?,?,?)");
|
||||
|
||||
// inserted plainBean has not been mutated
|
||||
bean.setAttr("attr1");
|
||||
DB.save(bean);
|
||||
expectedSql(0, "update ebasic_plain set attr=?, version=? where id=? and version=?");
|
||||
|
||||
// inserted plainBean has now been mutated
|
||||
content.setName("notFoo");
|
||||
bean.setAttr("attr2");
|
||||
DB.save(bean);
|
||||
expectedSql(0, "update ebasic_plain set attr=?, plain_bean=?, version=? where id=? and version=?");
|
||||
|
||||
|
||||
final EBasicPlain found = DB.find(EBasicPlain.class, bean.getId());
|
||||
|
||||
// update mutating PlainBean only
|
||||
final PlainBean plainBean = found.getPlainBean();
|
||||
plainBean.setName("mod1");
|
||||
DB.save(found);
|
||||
expectedSql(1, "update ebasic_plain set plain_bean=?, version=? where id=? and version=?");
|
||||
|
||||
// dirtyDetection = false, so not included in update
|
||||
found.getPlainBean2().setName("Modification Ignored");
|
||||
// dirtyDetection = true, mutation detected
|
||||
plainBean.setName("mod2");
|
||||
DB.save(found);
|
||||
expectedSql(0, "update ebasic_plain set plain_bean=?, version=? where id=? and version=?");
|
||||
|
||||
// update bean, not mutating PlainBean
|
||||
found.setAttr("attr3");
|
||||
DB.save(found);
|
||||
expectedSql(0, "update ebasic_plain set attr=?, version=? where id=? and version=?");
|
||||
|
||||
// dirtyDetection = false, set a new plainBean2 instance, included in update
|
||||
found.setPlainBean2(new PlainBean("bar", 27));
|
||||
DB.save(found);
|
||||
expectedSql(0, "update ebasic_plain set plain_bean2=?, version=? where id=? and version=?");
|
||||
|
||||
LoggedSql.stop();
|
||||
}
|
||||
|
||||
private void expectedSql(int i, String s) {
|
||||
assertThat(LoggedSql.collect().get(i)).contains(s);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.tests.model.orphanremoval;
|
||||
|
||||
import io.ebean.Model;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class OmBeanListChild extends Model {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
private final String name;
|
||||
|
||||
@ManyToOne
|
||||
private OmBeanListParent parent;
|
||||
|
||||
@Version
|
||||
private long version;
|
||||
|
||||
public OmBeanListChild(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.tests.model.orphanremoval;
|
||||
|
||||
import io.ebean.Model;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Version;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.persistence.CascadeType.ALL;
|
||||
|
||||
@Entity
|
||||
public class OmBeanListParent extends Model {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
@Version
|
||||
private long version;
|
||||
|
||||
@OneToMany(cascade = ALL, mappedBy = "parent", orphanRemoval = true)
|
||||
private List<OmBeanListChild> children;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public List<OmBeanListChild> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<OmBeanListChild> children) {
|
||||
// So a BeanList is used and overwriting children will replace the table entries
|
||||
this.children.clear();
|
||||
this.children.addAll(children);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package org.tests.model.orphanremoval;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class TestOrphanRemovalOverwrite {
|
||||
|
||||
@Test
|
||||
public void testOverwritingMapping() {
|
||||
OmBeanListParent parent = new OmBeanListParent();
|
||||
parent.save();
|
||||
|
||||
// Refreshing/querying sets the modifyListening flag on the association's BeanList
|
||||
parent.refresh();
|
||||
|
||||
List<OmBeanListChild> childList = singletonList(new OmBeanListChild("child1"));
|
||||
// Adding the children to the BeanList causes _ebean_getIdentity to be invoked before the children have been persisted and
|
||||
// have Ids.
|
||||
parent.setChildren(childList);
|
||||
|
||||
// Give the children Ids
|
||||
parent.save();
|
||||
|
||||
// Refreshing here generates new objects for the associated children that are referred to by the parent.
|
||||
parent.refresh();
|
||||
|
||||
assertNotNull("The children should now have Ids as they are persisted to the db.", childList.get(0).getId());
|
||||
assertEquals("The children should have the same Id as the ones on the parent.",
|
||||
childList.get(0).getId(), parent.getChildren().get(0).getId());
|
||||
assertEquals("The children should therefore equal the children on the parent.", childList, parent.getChildren());
|
||||
}
|
||||
}
|
||||
@@ -7,20 +7,26 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ProfileLocationTest {
|
||||
|
||||
private static ProfileLocation loc = ProfileLocation.create(12, "foo");
|
||||
|
||||
private static ProfileLocation loc2 = ProfileLocation.create();
|
||||
private static final ProfileLocation loc = ProfileLocation.create(12, "foo");
|
||||
private static final ProfileLocation locB = ProfileLocation.create();
|
||||
private static final ProfileLocation loc2 = ProfileLocation.create();
|
||||
|
||||
private boolean doIt() {
|
||||
locB.obtain(); // simulate a location moving by line number only
|
||||
return loc.obtain();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_obtain() {
|
||||
assertThat(doIt()).isTrue();
|
||||
assertThat(loc.fullLocation()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt(ProfileLocationTest.java:15)");
|
||||
assertThat(loc.location()).isEqualTo("ProfileLocationTest.doIt(ProfileLocationTest.java:15)");
|
||||
assertThat(loc.fullLocation()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt(ProfileLocationTest.java:16)");
|
||||
assertThat(loc.location()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt");
|
||||
assertThat(loc.label()).isEqualTo("ProfileLocationTest.doIt");
|
||||
|
||||
// same hash even when the line number has changed
|
||||
assertThat(locB.fullLocation()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt(ProfileLocationTest.java:15)");
|
||||
assertThat(locB.location()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt");
|
||||
assertThat(locB.label()).isEqualTo("ProfileLocationTest.doIt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -35,7 +41,7 @@ public class ProfileLocationTest {
|
||||
other.hashCode();
|
||||
|
||||
assertThat(loc2.label()).isEqualTo("ProfileLocationTest$Other.init");
|
||||
assertThat(loc2.location()).isEqualTo("ProfileLocationTest$Other.<init>(ProfileLocationTest.java:44)");
|
||||
assertThat(loc2.location()).isEqualTo("org.tests.profile.ProfileLocationTest$Other.<init>");
|
||||
}
|
||||
|
||||
static class Other {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.tests.query;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Query;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.CKeyParent;
|
||||
@@ -16,11 +16,11 @@ public class TestQueryAlias extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<CKeyParent> sq = Ebean.createQuery(CKeyParent.class)
|
||||
Query<CKeyParent> sq = DB.createQuery(CKeyParent.class)
|
||||
.select("id.oneKey").alias("st0")
|
||||
.setAutoTune(false).where().query();
|
||||
|
||||
Query<CKeyParent> pq = Ebean.find(CKeyParent.class).alias("myt0").where().in("id.oneKey", sq).query();
|
||||
Query<CKeyParent> pq = DB.find(CKeyParent.class).alias("myt0").where().in("id.oneKey", sq).query();
|
||||
|
||||
pq.findList();
|
||||
|
||||
@@ -36,17 +36,36 @@ public class TestQueryAlias extends BaseTestCase {
|
||||
assertThat(sql).contains("ckey_parent myt0");
|
||||
assertThat(sql).contains("(myt0.one_key) in (select st0.one_key from ckey_parent st0)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExistsWithConcat() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<CKeyParent> sq = DB.createQuery(CKeyParent.class)
|
||||
.select("concat(id.oneKey,id.twoKey)").alias("st0")
|
||||
.setAutoTune(false).where().query();
|
||||
|
||||
Query<CKeyParent> pq = DB.find(CKeyParent.class).alias("myt0").where().in("concat(id.oneKey,id.twoKey)", sq).query();
|
||||
|
||||
pq.findList();
|
||||
|
||||
String sql = pq.getGeneratedSql();
|
||||
|
||||
assertThat(sql).contains("ckey_parent myt0");
|
||||
assertThat(sql).contains("(concat(myt0.one_key,myt0.two_key)) in (select concat(st0.one_key,st0.two_key) from ckey_parent st0)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotExists() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<CKeyParent> sq = Ebean.createQuery(CKeyParent.class)
|
||||
Query<CKeyParent> sq = DB.createQuery(CKeyParent.class)
|
||||
.select("id.oneKey").alias("st0")
|
||||
.setAutoTune(false).where().query();
|
||||
|
||||
Query<CKeyParent> pq = Ebean.find(CKeyParent.class).alias("myt0").where().notIn("id.oneKey", sq).query();
|
||||
Query<CKeyParent> pq = DB.find(CKeyParent.class).alias("myt0").where().notIn("id.oneKey", sq).query();
|
||||
|
||||
pq.findList();
|
||||
|
||||
|
||||
@@ -30,18 +30,18 @@ import io.ebean.annotation.Platform;
|
||||
* Tests, if all kind of queries are cancelable. There are two ways how to
|
||||
* cancel a query: <br/>
|
||||
* <b>At begin:</b>
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* query = DB.find(...)
|
||||
* query.cancel();
|
||||
* query.findList();
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* The query was caneled before executing. In this case we do hit the DB driver
|
||||
* <br/>
|
||||
* <br/>
|
||||
* <b>During run:</b>
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* // Thread 1: Thread 2
|
||||
* query = DB.find(...)
|
||||
@@ -50,26 +50,26 @@ import io.ebean.annotation.Platform;
|
||||
* ...finding query.cancel();
|
||||
* ...JDBC-Exception
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* The test tries to simulate a slow query by installing the
|
||||
* {@link SlowDownEBasic} 'SELECT' trigger. The trigger can be configured to
|
||||
* wait 3 * <code>timing</code> ms and a second thread will cancel the query in
|
||||
* <code>timing</code> ms.
|
||||
*
|
||||
*
|
||||
* in this case, we expect a JDBC exception from the driver. <br/>
|
||||
* <br/>
|
||||
* NOTE:<br/>
|
||||
* H2 checks the cancel flag in org.h2.command.Prepared::setCurrentRowNumber
|
||||
* only every 128th row. So we need at least 128 models and we cannot check
|
||||
* queries like findCount or findOne, because they only return one row.
|
||||
*
|
||||
*
|
||||
* @author Roland Praml, FOCONIS AG
|
||||
*
|
||||
*/
|
||||
public class SqlQueryCancelTest extends BaseTestCase {
|
||||
|
||||
private int timing = 10;
|
||||
|
||||
private final int timing = 20;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupTestData() throws SQLException {
|
||||
for (int i = 0; i < 128; i++) {
|
||||
@@ -98,10 +98,10 @@ public class SqlQueryCancelTest extends BaseTestCase {
|
||||
doCancelSqlDuringRun(q -> q.findEachWhile(e -> true));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void cancelOrmQueryAtBegin() throws SQLException {
|
||||
doCancelOrmAtBegin(Query::findCount);
|
||||
doCancelOrmAtBegin(Query::findCount);
|
||||
doCancelOrmAtBegin(Query::findFutureCount);
|
||||
// We cannot test 'findCount' due H2 restrictions
|
||||
doCancelOrmAtBegin(Query::findFutureIds);
|
||||
@@ -206,7 +206,7 @@ public class SqlQueryCancelTest extends BaseTestCase {
|
||||
.isInstanceOf(PersistenceException.class)
|
||||
.hasMessageContaining("Query was cancelled");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void cancelSqlDtoQueryAtBegin() throws SQLException {
|
||||
|
||||
@@ -290,7 +290,7 @@ public class SqlQueryCancelTest extends BaseTestCase {
|
||||
private void doCancelOrmFutureDuringRun(Function<Query<EBasic>, Future<?>> test) throws SQLException, InterruptedException, ExecutionException {
|
||||
Query<EBasic> warmup = DB.find(EBasic.class);
|
||||
test.apply(warmup).get();
|
||||
|
||||
|
||||
Query<EBasic> query = DB.find(EBasic.class);
|
||||
executeDelayed(query::cancel);
|
||||
assertThatThrownBy(() -> {
|
||||
@@ -311,18 +311,18 @@ public class SqlQueryCancelTest extends BaseTestCase {
|
||||
.isInstanceOf(PersistenceException.class)
|
||||
.hasMessageContaining("Query was cancelled");
|
||||
}
|
||||
|
||||
|
||||
private void doCancelOrmDtoDuringRun(Consumer<DtoQuery<EBasicDto>> test) throws SQLException {
|
||||
DtoQuery<EBasicDto> warmup = DB.find(EBasic.class).select("id,status").asDto(EBasicDto.class);
|
||||
test.accept(warmup);
|
||||
|
||||
|
||||
DtoQuery<EBasicDto> query = DB.find(EBasic.class).select("id,status").asDto(EBasicDto.class);
|
||||
executeDelayed(query::cancel);
|
||||
assertThatThrownBy(() -> test.accept(query))
|
||||
.isInstanceOf(PersistenceException.class)
|
||||
.hasCauseInstanceOf(org.h2.jdbc.JdbcSQLTimeoutException.class);
|
||||
}
|
||||
|
||||
|
||||
private void doCancelSqlDtoAtBegin(Consumer<DtoQuery<EBasicDto>> test) throws SQLException {
|
||||
DtoQuery<EBasicDto> query = DB.findDto(EBasicDto.class, "select id, status from e_basic");
|
||||
query.cancel();
|
||||
@@ -334,14 +334,14 @@ public class SqlQueryCancelTest extends BaseTestCase {
|
||||
private void doCancelSqlDtoDuringRun(Consumer<DtoQuery<EBasicDto>> test) throws SQLException {
|
||||
DtoQuery<EBasicDto> warmup = DB.findDto(EBasicDto.class, "select id, status from e_basic");
|
||||
test.accept(warmup);
|
||||
|
||||
|
||||
DtoQuery<EBasicDto> query = DB.findDto(EBasicDto.class, "select id, status from e_basic");
|
||||
executeDelayed(query::cancel);
|
||||
assertThatThrownBy(() -> test.accept(query))
|
||||
.isInstanceOf(PersistenceException.class)
|
||||
.hasCauseInstanceOf(org.h2.jdbc.JdbcSQLTimeoutException.class);
|
||||
}
|
||||
|
||||
|
||||
private void executeDelayed(Runnable r) throws SQLException {
|
||||
// We modify the DB here. Otherwise we may hit an internal H2 cache, if the
|
||||
// same query is performed. Queries from the cache cannot be canceled.
|
||||
|
||||
@@ -176,7 +176,7 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
// change default collect query plan threshold to 200 micros
|
||||
QueryPlanInit init0 = new QueryPlanInit();
|
||||
init0.setAll(true);
|
||||
init0.setThresholdMicros(2);
|
||||
init0.thresholdMicros(2);
|
||||
final List<MetaQueryPlan> plans = server().getMetaInfoManager().queryPlanInit(init0);
|
||||
assertThat(plans.size()).isGreaterThan(1);
|
||||
|
||||
@@ -186,7 +186,7 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
// change query plan threshold to 100 micros
|
||||
QueryPlanInit init = new QueryPlanInit();
|
||||
init.setAll(true);
|
||||
init.setThresholdMicros(1);
|
||||
init.thresholdMicros(1);
|
||||
final List<MetaQueryPlan> appliedToPlans = server().getMetaInfoManager().queryPlanInit(init);
|
||||
assertThat(appliedToPlans.size()).isGreaterThan(4);
|
||||
|
||||
@@ -195,30 +195,30 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
|
||||
ServerMetrics metrics = DB.getDefault().getMetaInfoManager().collectMetrics();
|
||||
|
||||
List<MetaQueryMetric> planStats = metrics.getQueryMetrics();
|
||||
List<MetaQueryMetric> planStats = metrics.queryMetrics();
|
||||
assertThat(planStats.size()).isGreaterThan(4);
|
||||
|
||||
for (MetaQueryMetric planStat : planStats) {
|
||||
System.out.println(planStat);
|
||||
}
|
||||
|
||||
for (MetaTimedMetric txnTimed : metrics.getTimedMetrics()) {
|
||||
for (MetaTimedMetric txnTimed : metrics.timedMetrics()) {
|
||||
System.out.println(txnTimed);
|
||||
}
|
||||
|
||||
// obtains db query plans ...
|
||||
QueryPlanRequest request = new QueryPlanRequest();
|
||||
// collect max 1000 plans (use something more like 10)
|
||||
request.setMaxCount(1_000);
|
||||
request.maxCount(1_000);
|
||||
// don't collect any more plans if used 10 secs
|
||||
request.setMaxTimeMillis(10_000);
|
||||
request.maxTimeMillis(10_000);
|
||||
List<MetaQueryPlan> plans0 = server().getMetaInfoManager().queryPlanCollectNow(request);
|
||||
assertThat(plans0).isNotEmpty();
|
||||
|
||||
for (MetaQueryPlan plan : plans) {
|
||||
logger.info("queryplan label:{}, queryTimeMicros:{} loc:{} sql:{} bind:{} plan:{}",
|
||||
plan.getLabel(), plan.getQueryTimeMicros(), plan.getProfileLocation(),
|
||||
plan.getSql(), plan.getBind(), plan.getPlan());
|
||||
logger.info("queryPlan label:{}, queryTimeMicros:{} loc:{} sql:{} bind:{} plan:{}",
|
||||
plan.label(), plan.queryTimeMicros(), plan.profileLocation(),
|
||||
plan.sql(), plan.bind(), plan.plan());
|
||||
System.out.println(plan);
|
||||
}
|
||||
|
||||
@@ -242,9 +242,9 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
|
||||
assertThat(metricsJson).contains("\"name\":\"txn.main\"");
|
||||
assertThat(metricsJson).contains("\"name\":\"orm.Customer.findList\"");
|
||||
assertThat(metricsJson).contains("\"loc\":\"CustomerFinder.byNameStatus(CustomerFinder.java:44)\"");
|
||||
assertThat(metricsJson).contains("\"loc\":\"org.tests.model.basic.finder.CustomerFinder.byNameStatus\"");
|
||||
if (isH2() || isPostgres()) {
|
||||
assertThat(metricsJson).contains("\"hash\":\"cc20eb930403cfd418db2d0475c6e26a\"");
|
||||
assertThat(metricsJson).contains("\"hash\":\"de3affa5b4bff07e19c1c012590dcde6\"");
|
||||
assertThat(metricsJson).contains("\"sql\":\"select t0.id, t0.status,");
|
||||
}
|
||||
}
|
||||
@@ -267,7 +267,7 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
assertThat(metricsJson).contains("\"name\":\"txn.main\"");
|
||||
assertThat(metricsJson).contains("\"name\":\"orm.Customer.findList\"");
|
||||
assertThat(metricsJson).doesNotContain("\"loc\":");
|
||||
assertThat(metricsJson).doesNotContain("\"hash\":");
|
||||
assertThat(metricsJson).doesNotContain("\"sqlHash\":");
|
||||
assertThat(metricsJson).doesNotContain("\"sql\":");
|
||||
}
|
||||
|
||||
|
||||
@@ -407,7 +407,7 @@ public class SqlQueryTests extends BaseTestCase {
|
||||
|
||||
List<MetaTimedMetric> sqlMetrics = sqlMetrics();
|
||||
assertThat(sqlMetrics).hasSize(1);
|
||||
assertThat(sqlMetrics.get(0).getName()).isEqualTo("sql.query.findEach-Max10Rows");
|
||||
assertThat(sqlMetrics.get(0).name()).isEqualTo("sql.query.findEach-Max10Rows");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package org.tests.rawsql.nativesql;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Query;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.embedded.EAddress;
|
||||
import org.tests.model.embedded.EPerson;
|
||||
import org.tests.model.json.PlainBean;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -17,25 +20,31 @@ public class TestNativeWithEmbedded extends BaseTestCase {
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Map<String, Object> rawMap = new LinkedHashMap<>();
|
||||
rawMap.put("a","1");
|
||||
EPerson person = new EPerson();
|
||||
person.setName("Frank");
|
||||
EAddress address = new EAddress();
|
||||
address.setStreet("1 foo st");
|
||||
address.setCity("barv");
|
||||
address.setJbean(new PlainBean("hi", 3));
|
||||
address.setJraw(rawMap);
|
||||
person.setAddress(address);
|
||||
|
||||
Ebean.save(person);
|
||||
DB.save(person);
|
||||
|
||||
String sql = "select id, name, street, suburb, addr_city, addr_status from eperson where id = ?";
|
||||
String sql = "select id, name, street, suburb, addr_city, addr_status, addr_jbean, jraw from eperson where id = ?";
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
Query<EPerson> query = Ebean.findNative(EPerson.class, sql);
|
||||
Query<EPerson> query = DB.findNative(EPerson.class, sql);
|
||||
query.setParameter(person.getId());
|
||||
EPerson one = query.findOne();
|
||||
|
||||
assertThat(one.getName()).isEqualTo("Frank");
|
||||
assertThat(one.getAddress().getStreet()).isEqualTo("1 foo st");
|
||||
assertThat(one.getAddress().getJbean().getName()).isEqualTo("hi");
|
||||
assertThat(one.getAddress().getJraw().get("a")).isEqualTo("1");
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
assertThat(loggedSql).hasSize(1);
|
||||
|
||||
@@ -58,6 +58,52 @@ public class TestSoftDeleteBasic extends BaseTestCase {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findSingleAttribute() {
|
||||
|
||||
EBasicSoftDelete bean = new EBasicSoftDelete();
|
||||
bean.setName("findSingleAttribute");
|
||||
DB.save(bean);
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
final String name0 = DB.find(EBasicSoftDelete.class)
|
||||
.select("name")
|
||||
.where().eq("name", "findSingleAttribute")
|
||||
.findSingleAttribute();
|
||||
|
||||
List<String> sql0 = LoggedSqlCollector.current();
|
||||
assertThat(sql0.get(0)).contains("where t0.name = ? and t0.deleted =");
|
||||
assertThat(name0).isEqualTo("findSingleAttribute");
|
||||
|
||||
// now soft delete the bean
|
||||
DB.delete(bean);
|
||||
List<String> sqlUpdate = LoggedSqlCollector.current();
|
||||
assertThat(sqlUpdate.get(0)).contains("update ebasic_sdchild set");
|
||||
|
||||
// use setIncludeSoftDeletes
|
||||
final String name1 = DB.find(EBasicSoftDelete.class)
|
||||
.select("name")
|
||||
.where().eq("name", "findSingleAttribute")
|
||||
.setIncludeSoftDeletes()
|
||||
.findSingleAttribute();
|
||||
|
||||
List<String> sql1 = LoggedSqlCollector.current();
|
||||
assertThat(sql1.get(0)).doesNotContain(" and t0.deleted =");
|
||||
assertThat(name1).isEqualTo("findSingleAttribute");
|
||||
|
||||
|
||||
// not using setIncludeSoftDeletes, so don't find it
|
||||
final String name2 = DB.find(EBasicSoftDelete.class)
|
||||
.select("name")
|
||||
.where().eq("name", "findSingleAttribute")
|
||||
.findSingleAttribute();
|
||||
|
||||
List<String> sql2 = LoggedSqlCollector.stop();
|
||||
assertThat(sql2.get(0)).contains(" and t0.deleted =");
|
||||
assertThat(name2).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindIdsWhenIncludeSoftDeletedChlld() {
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class TestNestedMandatory extends BaseTestCase {
|
||||
}
|
||||
|
||||
assertThat(txnMetrics).hasSize(2);
|
||||
assertThat(txnMetrics.get(1).getName()).isEqualTo("txn.named.outer");
|
||||
assertThat(txnMetrics.get(1).name()).isEqualTo("txn.named.outer");
|
||||
}
|
||||
|
||||
class Outer {
|
||||
|
||||
@@ -20,9 +20,9 @@ public class TestTransactionalReadOnly extends BaseTestCase {
|
||||
resetAllMetrics();
|
||||
executeTransactionalUsingReadOnlyDataSource();
|
||||
|
||||
final List<MetaTimedMetric> timedMetrics = collectMetrics().getTimedMetrics();
|
||||
final List<MetaTimedMetric> timedMetrics = collectMetrics().timedMetrics();
|
||||
final Optional<MetaTimedMetric> txnReadOnly = metric(timedMetrics, "txn.readonly");
|
||||
assertThat(txnReadOnly.get().getCount()).isEqualTo(1);
|
||||
assertThat(txnReadOnly.get().count()).isEqualTo(1);
|
||||
assertThat(metric(timedMetrics, "txn")).isEmpty();
|
||||
}
|
||||
|
||||
@@ -32,15 +32,15 @@ public class TestTransactionalReadOnly extends BaseTestCase {
|
||||
resetAllMetrics();
|
||||
executeTransactionalUsingMainDataSource();
|
||||
|
||||
final List<MetaTimedMetric> timedMetrics = collectMetrics().getTimedMetrics();
|
||||
final List<MetaTimedMetric> timedMetrics = collectMetrics().timedMetrics();
|
||||
final Optional<MetaTimedMetric> txnMain = metric(timedMetrics, "txn.main");
|
||||
assertThat(txnMain.get().getCount()).isEqualTo(1);
|
||||
assertThat(txnMain.get().count()).isEqualTo(1);
|
||||
assertThat(metric(timedMetrics, "txn.readonly")).isEmpty();
|
||||
}
|
||||
|
||||
private Optional<MetaTimedMetric> metric(List<MetaTimedMetric> timedMetrics, String name) {
|
||||
return timedMetrics.stream()
|
||||
.filter(metaTimedMetric -> metaTimedMetric.getName().equals(name))
|
||||
.filter(metaTimedMetric -> metaTimedMetric.name().equals(name))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
|
||||
@@ -126,8 +126,8 @@ public class TestSqlUpdateInTxn extends BaseTestCase {
|
||||
|
||||
List<MetaTimedMetric> sqlMetrics = sqlMetrics();
|
||||
assertThat(sqlMetrics).hasSize(1);
|
||||
assertThat(sqlMetrics.get(0).getName()).isEqualTo("sql.update.auditLargeUpdate");
|
||||
assertThat(sqlMetrics.get(0).getCount()).isEqualTo(1);
|
||||
assertThat(sqlMetrics.get(0).name()).isEqualTo("sql.update.auditLargeUpdate");
|
||||
assertThat(sqlMetrics.get(0).count()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user