mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1214 - ENH: Add inPairs() expression - support L2 cache hits for complex natural key with findList() and in pairs expression
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.EbeanServer;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.event.BeanQueryRequest;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.Order;
|
||||
|
||||
import static org.assertj.core.api.StrictAssertions.assertThat;
|
||||
@@ -29,4 +34,56 @@ public abstract class BaseExpressionTest extends BaseTestCase {
|
||||
protected void different(SpiExpression one, SpiExpression two){
|
||||
assertThat(hash(one)).isNotEqualTo(hash(two));
|
||||
}
|
||||
|
||||
/**
|
||||
* Request with Multi-Value support.
|
||||
*/
|
||||
protected InExpressionTest.TDQueryRequest<Customer> multi() {
|
||||
return MULTI_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request with NO Multi-Value support.
|
||||
*/
|
||||
protected InExpressionTest.TDQueryRequest<Customer> noMulti() {
|
||||
return NO_MULTI_VALUE;
|
||||
}
|
||||
|
||||
|
||||
private static final TDQueryRequest<Customer> MULTI_VALUE= new TDQueryRequest<>(true);
|
||||
private static final TDQueryRequest<Customer> NO_MULTI_VALUE = new TDQueryRequest<>(false);
|
||||
|
||||
static class TDQueryRequest<T> implements BeanQueryRequest<T> {
|
||||
|
||||
final boolean supported;
|
||||
|
||||
TDQueryRequest(boolean supported) {
|
||||
this.supported = supported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EbeanServer getEbeanServer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transaction getTransaction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> getQuery() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMultiValueIdSupported() {
|
||||
return supported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMultiValueSupported(Class<?> valueType) {
|
||||
return supported;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebean.EbeanServer;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.event.BeanQueryRequest;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -15,20 +10,6 @@ import static org.assertj.core.api.StrictAssertions.assertThat;
|
||||
|
||||
public class InExpressionTest extends BaseExpressionTest {
|
||||
|
||||
/**
|
||||
* Request with Multi-Value support.
|
||||
*/
|
||||
private TDQueryRequest<Customer> multi() {
|
||||
return MULTI_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request with NO Multi-Value support.
|
||||
*/
|
||||
private TDQueryRequest<Customer> noMulti() {
|
||||
return NO_MULTI_VALUE;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryPlanHash_given_diffPropertyName_should_differentPlanHash() throws Exception {
|
||||
|
||||
@@ -182,41 +163,5 @@ public class InExpressionTest extends BaseExpressionTest {
|
||||
}
|
||||
|
||||
|
||||
private static final TDQueryRequest<Customer> MULTI_VALUE= new TDQueryRequest<>(true);
|
||||
private static final TDQueryRequest<Customer> NO_MULTI_VALUE = new TDQueryRequest<>(false);
|
||||
|
||||
static class TDQueryRequest<T> implements BeanQueryRequest<T> {
|
||||
|
||||
final boolean supported;
|
||||
|
||||
TDQueryRequest(boolean supported) {
|
||||
this.supported = supported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EbeanServer getEbeanServer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transaction getTransaction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> getQuery() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMultiValueIdSupported() {
|
||||
return supported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMultiValueSupported(Class<?> valueType) {
|
||||
return supported;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebean.Pairs;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class InPairsExpressionTest extends BaseExpressionTest {
|
||||
|
||||
private Pairs pairs() {
|
||||
return pairs("sku", "code");
|
||||
}
|
||||
|
||||
private Pairs pairs(String property0, String property1) {
|
||||
Pairs pairs = new Pairs(property0, property1)
|
||||
.add("2", 1000)
|
||||
.add("2", 1001)
|
||||
.add("3", 1000);
|
||||
|
||||
return pairs;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void same_samePlan_sameBind() throws Exception {
|
||||
|
||||
InPairsExpression e0 = new InPairsExpression(pairs(), false);
|
||||
InPairsExpression e1 = new InPairsExpression(pairs(), false);
|
||||
|
||||
same(e0, e1);
|
||||
|
||||
assertTrue(e0.isSameByBind(e1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void same_samePlan_diffBind() throws Exception {
|
||||
|
||||
InPairsExpression e0 = new InPairsExpression(pairs(), false);
|
||||
InPairsExpression e1 = new InPairsExpression(pairs().add("4", 1000), false);
|
||||
e0.prepareExpression(multi());
|
||||
e1.prepareExpression(multi());
|
||||
|
||||
// when multi() ... same as bind count not important
|
||||
same(e0, e1);
|
||||
assertFalse(e0.isSameByBind(e1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void same_noMulti_diffPlan() throws Exception {
|
||||
|
||||
InPairsExpression e0 = new InPairsExpression(pairs(), false);
|
||||
InPairsExpression e1 = new InPairsExpression(pairs().add("4", 1000), false);
|
||||
e0.prepareExpression(noMulti());
|
||||
e1.prepareExpression(noMulti());
|
||||
|
||||
// when noMulti() ... bind count different so different plan
|
||||
different(e0, e1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diffProperty0_diff() throws Exception {
|
||||
|
||||
InPairsExpression e0 = new InPairsExpression(pairs(), false);
|
||||
InPairsExpression e1 = new InPairsExpression(pairs("k", "code"), false);
|
||||
different(e0, e1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diffProperty1_diff() throws Exception {
|
||||
|
||||
InPairsExpression e0 = new InPairsExpression(pairs(), false);
|
||||
InPairsExpression e1 = new InPairsExpression(pairs("sku", "c"), false);
|
||||
different(e0, e1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diffSeparator_diff() throws Exception {
|
||||
|
||||
InPairsExpression e0 = new InPairsExpression(pairs(), false);
|
||||
InPairsExpression e1 = new InPairsExpression(pairs().setConcatSeparator(":"), false);
|
||||
different(e0, e1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diffSuffix_diff() throws Exception {
|
||||
|
||||
InPairsExpression e0 = new InPairsExpression(pairs(), false);
|
||||
InPairsExpression e1 = new InPairsExpression(pairs().setConcatSuffix(":"), false);
|
||||
different(e0, e1);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user