Fix select distinct lob fields with db2

This commit is contained in:
Noemi Szemenyei committed 2022-01-21 14:30:06 +01:00
1 parent 1bdd54ac18
commit 14868f7d84
13 files changed
+112 -38

No files matched your search

@@ -3,6 +3,8 @@ package org.tests.json;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import io.ebean.Query;
import io.ebean.annotation.ForPlatform;
import io.ebean.annotation.Platform;
import io.ebean.test.LoggedSql;
import io.ebean.text.json.EJson;
import org.junit.jupiter.api.Test;
@@ -10,6 +12,7 @@ import org.tests.model.json.EBasicJsonMap;
import org.tests.model.json.EBasicJsonMapDetail;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -19,12 +22,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestJsonMapBasic extends BaseTestCase {
@Test
public void whereManyPredicate() {
if (!isPostgres()) {
// testing postgres specific select distinct on clause
return;
}
@ForPlatform(Platform.POSTGRES)
public void whereManyPredicatePg() {
EBasicJsonMap bean = new EBasicJsonMap();
bean.setName("own1");
@@ -33,28 +32,60 @@ public class TestJsonMapBasic extends BaseTestCase {
DB.save(bean);
Query<EBasicJsonMap> query1 = DB.find(EBasicJsonMap.class)
.fetch("details")
.where().startsWith("details.name", "detail")
.query();
Query<EBasicJsonMap> query1 = DB.find(EBasicJsonMap.class).fetch("details").where()
.startsWith("details.name", "detail").query();
query1.findList();
assertThat(query1.getGeneratedSql()).contains("select distinct on (t0.id, t1.id) ");
Query<EBasicJsonMap> query2 = DB.find(EBasicJsonMap.class)
.where().startsWith("details.name", "detail")
.query();
Query<EBasicJsonMap> query2 = DB.find(EBasicJsonMap.class).where().startsWith("details.name", "detail").query();
query2.findList();
assertThat(query2.getGeneratedSql()).contains("select distinct on (t0.id) ");
}
@Test
@ForPlatform(Platform.DB2)
public void whereManyPredicateDb2() {
EBasicJsonMap bean = new EBasicJsonMap();
Map<String, Object> m1 = new HashMap<>();
m1.put("foo", "bar");
bean.setContent(m1);
bean.setName("own1");
bean.getDetails().add(new EBasicJsonMapDetail("db2-detail1"));
bean.getDetails().add(new EBasicJsonMapDetail("db2-detail2"));
DB.save(bean);
try {
Query<EBasicJsonMap> query1 = DB.find(EBasicJsonMap.class).select("*").fetch("details").where()
.startsWith("details.name", "db2-detail").query();
List<EBasicJsonMap> lst = query1.findList();
assertThat(query1.getGeneratedSql()).contains("select distinct t0.id, t0.name, t0.version,")
.doesNotContain("content");
assertThat(lst).hasSize(1);
assertThat(lst.get(0).getContent()).containsEntry("foo", "bar");
Query<EBasicJsonMap> query2 = DB.find(EBasicJsonMap.class).where().startsWith("details.name", "db2-detail")
.query();
query2.findList();
assertThat(query2.getGeneratedSql()).contains("select distinct t0.id, t0.name, t0.version from");
} finally {
// temporär hier, sollte die ganze Testklasse aufräumen
DB.delete(bean);
}
}
@Test
public void testInsertUpdateDelete() throws IOException {
String s0 = "{\"docId\":18,\"contentId\":\"asd\",\"active\":true,\"contentType\":\"pg-hello\",\"content\":{\"name\":\"rob\",\"age\":45}}";
//String s1 = "{\"docId\":19,\"contentId\":\"asd\",\"active\":true,\"contentType\":\"pg-hello\",\"content\":{\"name\":\"rob\",\"age\":45}}";
// String s1 =
// "{\"docId\":19,\"contentId\":\"asd\",\"active\":true,\"contentType\":\"pg-hello\",\"content\":{\"name\":\"rob\",\"age\":45}}";
Map<String, Object> content = EJson.parseObject(s0);
@@ -117,10 +148,7 @@ public class TestJsonMapBasic extends BaseTestCase {
LoggedSql.start();
final int rows = DB.update(EBasicJsonMap.class)
.set("content", content1)
.where().eq("id", bean.getId())
.update();
final int rows = DB.update(EBasicJsonMap.class).set("content", content1).where().eq("id", bean.getId()).update();
final List<String> sql = LoggedSql.stop();