mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Refactor FetchConfig
This commit is contained in:
@@ -2,7 +2,7 @@ package io.ebeaninternal.server.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -11,49 +11,49 @@ public class DSelectColumnsParserTest {
|
||||
@Test
|
||||
public void parse() {
|
||||
|
||||
List<String> cols = DSelectColumnsParser.parse("a,MD5(id::text) as b,c");
|
||||
Set<String> cols = DSelectColumnsParser.parse("a,MD5(id::text) as b,c");
|
||||
assertThat(cols).containsExactly("a", "MD5(id::text) as b", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whitespace_is_trimmed() {
|
||||
|
||||
List<String> cols = DSelectColumnsParser.parse("a , MD5(id::text) as b , c ");
|
||||
Set<String> cols = DSelectColumnsParser.parse("a , MD5(id::text) as b , c ");
|
||||
assertThat(cols).containsExactly("a", "MD5(id::text) as b", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedFunctions() {
|
||||
|
||||
List<String> cols = DSelectColumnsParser.parse("a , concat(id,'sd',inner(foo)) as b , c ");
|
||||
Set<String> cols = DSelectColumnsParser.parse("a , concat(id,'sd',inner(foo)) as b , c ");
|
||||
assertThat(cols).containsExactly("a", "concat(id,'sd',inner(foo)) as b", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basic() {
|
||||
|
||||
List<String> cols = DSelectColumnsParser.parse("name , status , billingAddress ");
|
||||
Set<String> cols = DSelectColumnsParser.parse("name , status , billingAddress ");
|
||||
assertThat(cols).containsExactly("name", "status", "billingAddress");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basic_noWhitespace() {
|
||||
|
||||
List<String> cols = DSelectColumnsParser.parse("a,b,c");
|
||||
Set<String> cols = DSelectColumnsParser.parse("a,b,c");
|
||||
assertThat(cols).containsExactly("a", "b", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formula_noWhitespace() {
|
||||
|
||||
List<String> cols = DSelectColumnsParser.parse("a,concat(x,y),c");
|
||||
Set<String> cols = DSelectColumnsParser.parse("a,concat(x,y),c");
|
||||
assertThat(cols).containsExactly("a", "concat(x,y)", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void with_logicalCast_andAsAlias() {
|
||||
|
||||
List<String> cols = DSelectColumnsParser.parse("name , concat(status,'-end')::String as fullName , billingAddress ");
|
||||
Set<String> cols = DSelectColumnsParser.parse("name , concat(status,'-end')::String as fullName , billingAddress ");
|
||||
assertThat(cols).containsExactly("name", "concat(status,'-end')::String as fullName", "billingAddress");
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public class TestQueryJoin extends BaseTestCase {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class).select("status")
|
||||
// .join("details","+query(10)")
|
||||
.fetch("customer", "+lazy(10) name, status").fetch("customer.contacts").order().asc("id");
|
||||
.fetch("customer", "+lazy(10), name, status").fetch("customer.contacts").order().asc("id");
|
||||
// .join("customer.billingAddress");
|
||||
|
||||
List<Order> list = query.findList();
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.tests.model.interfaces;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class SelfManyMany {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
private final String name;
|
||||
|
||||
@ManyToMany
|
||||
// requires explicit @JoinTable
|
||||
@JoinTable(name = "self_many_bridge",
|
||||
joinColumns = @JoinColumn(name = "self_1_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "self_2_id"))
|
||||
private List<SelfManyMany> related;
|
||||
|
||||
public SelfManyMany(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<SelfManyMany> getRelated() {
|
||||
return related;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.tests.model.interfaces;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestSelfMany extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void self_manyToMany() {
|
||||
|
||||
SelfManyMany m = new SelfManyMany("1");
|
||||
DB.save(m);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user