mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
findMap() with beanCache should use idPoperty if mapKey = null
This commit is contained in:
1 parent
5807874c9e
commit
60d0a3da39
2 files changed
+38
-1
No files matched your search
@@ -570,7 +570,12 @@ public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQuery
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ElPropertyValue mapProperty() {
|
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) {
|
if (property == null) {
|
||||||
throw new IllegalStateException("Unknown map key property " + query.getMapKey());
|
throw new IllegalStateException("Unknown map key property " + query.getMapKey());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,18 @@ package org.tests.basic;
|
|||||||
|
|
||||||
import io.ebean.BaseTestCase;
|
import io.ebean.BaseTestCase;
|
||||||
import io.ebean.DB;
|
import io.ebean.DB;
|
||||||
|
import io.ebean.test.LoggedSql;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.tests.model.basic.Country;
|
import org.tests.model.basic.Country;
|
||||||
|
import org.tests.model.basic.Customer;
|
||||||
import org.tests.model.basic.ResetBasicData;
|
import org.tests.model.basic.ResetBasicData;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
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;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class TestLoadBeanCache extends BaseTestCase {
|
public class TestLoadBeanCache extends BaseTestCase {
|
||||||
@@ -31,4 +37,30 @@ public class TestLoadBeanCache extends BaseTestCase {
|
|||||||
|
|
||||||
assertTrue(loadedNz == nz);
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user