#1566 - ENH: Support query.setBaseTable() ... to query against dynamic table (ala manual table partitioning)

This commit is contained in:
rob bygrave
2019-01-09 19:13:35 +13:00
parent 3207ae1f08
commit cd8c12a9a8
6 changed files with 97 additions and 7 deletions
@@ -0,0 +1,51 @@
package org.tests.query;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.annotation.ForPlatform;
import io.ebean.annotation.Platform;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class TestQueryBaseTable extends BaseTestCase {
@ForPlatform({Platform.H2, Platform.POSTGRES})
@Test
public void test() {
ResetBasicData.reset();
LoggedSqlCollector.start();
Customer one = Ebean.find(Customer.class)
.setBaseTable("O_CUSTOMER")
.where().startsWith("name", "Rob")
.findOne();
Customer two = Ebean.find(Customer.class)
.where().startsWith("name", "Rob")
.findOne();
Customer three = Ebean.find(Customer.class)
.setBaseTable("O_CUSTOMER")
.where().startsWith("name", "Fiona")
.findOne();
assertThat(one.getName()).isEqualTo(two.getName());
assertThat(three.getName()).isEqualTo("Fiona");
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(3);
assertThat(sql.get(0)).contains("from O_CUSTOMER");
assertThat(sql.get(1)).contains("from o_customer");
assertThat(sql.get(2)).contains("from O_CUSTOMER");
}
}