mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#115 - Mapping - Add support for @ElementCollection enhancement
Initial support - simple List.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebeaninternal.server.query.SqlTreeProperty;
|
||||
import io.ebeaninternal.server.query.STreeProperty;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
|
||||
@@ -76,7 +76,7 @@ public class FormulaPropertyPathTest extends BaseTestCase {
|
||||
assertThat(propertyPath.alias()).isNull();
|
||||
}
|
||||
|
||||
SqlTreeProperty treeProperty = propertyPath.build();
|
||||
STreeProperty treeProperty = propertyPath.build();
|
||||
|
||||
assertThat(treeProperty).isNotNull();
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package org.tests.basic;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.annotation.Where;
|
||||
import io.ebean.util.AnnotationUtil;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
import org.tests.model.basic.ValidationGroupSomething;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.ValidationGroupSomething;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.validation.constraints.NotNull;
|
||||
@@ -125,23 +125,23 @@ public class TestAnnotationBase extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void testFindMaxSize() throws NoSuchFieldException, SecurityException {
|
||||
public void testFindMaxSize() throws SecurityException {
|
||||
BeanDescriptor<TestAnnotationBaseEntity> descriptor = spiEbeanServer().getBeanDescriptor(TestAnnotationBaseEntity.class);
|
||||
BeanProperty bp = descriptor.findBeanProperty("constraintAnnotation");
|
||||
BeanProperty bp = descriptor.findProperty("constraintAnnotation");
|
||||
assertEquals(40, bp.getDbLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotNullWithGroup() throws NoSuchFieldException, SecurityException {
|
||||
public void testNotNullWithGroup() throws SecurityException {
|
||||
BeanDescriptor<TestAnnotationBaseEntity> descriptor = spiEbeanServer().getBeanDescriptor(TestAnnotationBaseEntity.class);
|
||||
|
||||
BeanProperty bp = descriptor.findBeanProperty("null1");
|
||||
BeanProperty bp = descriptor.findProperty("null1");
|
||||
assertFalse(bp.isNullable());
|
||||
|
||||
bp = descriptor.findBeanProperty("null2");
|
||||
bp = descriptor.findProperty("null2");
|
||||
assertTrue(bp.isNullable());
|
||||
|
||||
bp = descriptor.findBeanProperty("null3");
|
||||
bp = descriptor.findProperty("null3");
|
||||
assertTrue(bp.isNullable());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package org.tests.model.elementcollection;
|
||||
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.Version;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class EcPerson {
|
||||
|
||||
@Id
|
||||
long id;
|
||||
|
||||
String name;
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "ec_person_phone", joinColumns = @JoinColumn(name = "owner_id", referencedColumnName = "id"))
|
||||
@Column(name = "phone")
|
||||
List<String> phoneNumbers = new ArrayList<>();
|
||||
|
||||
@Version
|
||||
long version;
|
||||
|
||||
public EcPerson(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "person id:" + id + " name:" + name + " phs:" + phoneNumbers;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<String> getPhoneNumbers() {
|
||||
return phoneNumbers;
|
||||
}
|
||||
|
||||
public void setPhoneNumbers(List<String> phoneNumbers) {
|
||||
this.phoneNumbers = phoneNumbers;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(long version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.tests.model.elementcollection;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestElementCollectionBasic extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
EcPerson person = new EcPerson("Fiona021");
|
||||
person.getPhoneNumbers().add("021 1234");
|
||||
person.getPhoneNumbers().add("021 4321");
|
||||
Ebean.save(person);
|
||||
|
||||
|
||||
EcPerson person1 = new EcPerson("Fiona09");
|
||||
person1.getPhoneNumbers().add("09 1234");
|
||||
person1.getPhoneNumbers().add("09 4321");
|
||||
Ebean.save(person1);
|
||||
|
||||
List<EcPerson> found =
|
||||
Ebean.find(EcPerson.class).where()
|
||||
.startsWith("name", "Fiona0")
|
||||
.order().asc("id")
|
||||
.findList();
|
||||
|
||||
List<String> phoneNumbers0 = found.get(0).getPhoneNumbers();
|
||||
List<String> phoneNumbers1 = found.get(1).getPhoneNumbers();
|
||||
phoneNumbers0.size();
|
||||
|
||||
assertThat(phoneNumbers0).containsExactly("021 1234", "021 4321");
|
||||
assertThat(phoneNumbers1).containsExactly("09 1234", "09 4321");
|
||||
|
||||
|
||||
List<EcPerson> found2 =
|
||||
Ebean.find(EcPerson.class)
|
||||
.fetch("phoneNumbers")
|
||||
.where()
|
||||
.startsWith("name", "Fiona0")
|
||||
.order().asc("id")
|
||||
.findList();
|
||||
|
||||
System.out.println(found2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user