findMap() with beanCache should use idPoperty if mapKey = null

This commit is contained in:
Noemi Szemenyei
2021-11-19 11:50:45 +01:00
parent 74f49b388d
commit 3efb552bd9
2 changed files with 38 additions and 1 deletions
@@ -570,7 +570,12 @@ public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQuery
}
private ElPropertyValue mapProperty() {
ElPropertyValue property = beanDescriptor.elGetValue(query.getMapKey());
ElPropertyValue property;
if (query.getMapKey() == null) {
property = beanDescriptor.idProperty();
} else {
property = beanDescriptor.elGetValue(query.getMapKey());
}
if (property == null) {
throw new IllegalStateException("Unknown map key property " + query.getMapKey());
}
@@ -2,12 +2,18 @@ package org.tests.basic;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import io.ebean.test.LoggedSql;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Country;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestLoadBeanCache extends BaseTestCase {
@@ -31,4 +37,30 @@ public class TestLoadBeanCache extends BaseTestCase {
assertTrue(loadedNz == nz);
}
@Test
public void testLoadWithFindMap() {
ResetBasicData.reset();
List<Object> ids = DB.find(Customer.class).findIds();
assertEquals(ids.size(), 4);
DB.getDefault().pluginApi().cacheManager().clearAll();
// hit database
LoggedSql.start();
DB.find(Customer.class).where().idIn(ids).findMap();
List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(1);
// hit beanCache
LoggedSql.start();
DB.find(Customer.class).where().idIn(ids).findMap();
sql = LoggedSql.stop();
assertThat(sql).hasSize(0);
}
}