mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Refactor tests, move some internal deploy tests to ebean-core
This commit is contained in:
@@ -1,14 +1,50 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import org.tests.model.basic.Animal;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
public class BaseTest {
|
||||
|
||||
protected SpiEbeanServer server = (SpiEbeanServer)DB.getDefault();
|
||||
protected SpiEbeanServer db = (SpiEbeanServer)DB.getDefault();
|
||||
|
||||
protected <T> BeanDescriptor<T> getBeanDescriptor(Class<T> cls) {
|
||||
return server.descriptor(cls);
|
||||
return db.descriptor(cls);
|
||||
}
|
||||
|
||||
protected SpiEbeanServer spiEbeanServer() {
|
||||
return db;
|
||||
}
|
||||
|
||||
protected Database server() {
|
||||
return db;
|
||||
}
|
||||
|
||||
protected void initTables() {
|
||||
try {
|
||||
db.find(Animal.class).findCount();
|
||||
} catch (PersistenceException e) {
|
||||
db.script().run("/h2-init.sql");
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isH2() {
|
||||
return isPlatform(Platform.H2);
|
||||
}
|
||||
protected boolean isPostgres() {
|
||||
return isPlatform(Platform.POSTGRES);
|
||||
}
|
||||
protected boolean isSqlServer() {
|
||||
return isPlatform(Platform.SQLSERVER);
|
||||
}
|
||||
protected boolean isMySql() {
|
||||
return isPlatform(Platform.MYSQL);
|
||||
}
|
||||
protected boolean isPlatform(Platform platform) {
|
||||
return db.platform().base().equals(platform);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-7
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.plugin.Property;
|
||||
@@ -8,6 +7,7 @@ import io.ebeaninternal.server.core.CacheOptions;
|
||||
import io.ebeaninternal.server.deploy.meta.DeployBeanDescriptor;
|
||||
import io.ebeaninternal.server.deploy.meta.DeployIdentityMode;
|
||||
import io.ebeanservice.docstore.api.DocStoreBeanAdapter;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.*;
|
||||
import org.tests.model.bridge.BSite;
|
||||
@@ -21,7 +21,7 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class BeanDescriptorTest extends BaseTestCase {
|
||||
public class BeanDescriptorTest extends BaseTest {
|
||||
|
||||
private BeanDescriptor<Customer> customerDesc = spiEbeanServer().descriptor(Customer.class);
|
||||
|
||||
@@ -30,35 +30,37 @@ public class BeanDescriptorTest extends BaseTestCase {
|
||||
|
||||
Customer bean = customerDesc.createReference(null, false, 42, null);
|
||||
assertThat(bean.getId()).isEqualTo(42);
|
||||
assertThat(server().beanState(bean).isReadOnly()).isFalse();
|
||||
Assertions.assertThat(server().beanState(bean).isReadOnly()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createReference_whenReadOnly() {
|
||||
|
||||
Customer bean = customerDesc.createReference(Boolean.TRUE, false, 42, null);
|
||||
assertThat(server().beanState(bean).isReadOnly()).isTrue();
|
||||
Assertions.assertThat(server().beanState(bean).isReadOnly()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createReference_whenNotReadOnly() {
|
||||
|
||||
Customer bean = customerDesc.createReference(Boolean.FALSE, false, 42, null);
|
||||
assertThat(server().beanState(bean).isReadOnly()).isFalse();
|
||||
Assertions.assertThat(server().beanState(bean).isReadOnly()).isFalse();
|
||||
|
||||
bean = customerDesc.createReference(42, null);
|
||||
assertThat(server().beanState(bean).isReadOnly()).isFalse();
|
||||
Assertions.assertThat(server().beanState(bean).isReadOnly()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createReference_when_disabledLazyLoad() {
|
||||
|
||||
Customer bean = customerDesc.createReference(Boolean.FALSE, true, 42, null);
|
||||
assertThat(server().beanState(bean).isDisableLazyLoad()).isTrue();
|
||||
Assertions.assertThat(server().beanState(bean).isDisableLazyLoad()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createReference_with_inheritance() {
|
||||
initTables();
|
||||
|
||||
Cat cat = new Cat();
|
||||
cat.setName("Puss");
|
||||
DB.save(cat);
|
||||
+1
-4
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -10,9 +9,7 @@ import org.tests.model.basic.EBasic;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
|
||||
public class BeanDescriptor_whenCreatedPropertyTest extends BaseTestCase {
|
||||
|
||||
public class BeanDescriptor_whenCreatedPropertyTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
+19
-21
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.bean.BeanCollection;
|
||||
import io.ebean.bean.EntityBean;
|
||||
@@ -8,7 +7,6 @@ import io.ebean.common.BeanList;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -17,7 +15,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
public class BeanPropertyAssocManyTest extends BaseTestCase {
|
||||
public class BeanPropertyAssocManyTest extends BaseTest {
|
||||
|
||||
private BeanDescriptor<Customer> customerDesc = spiEbeanServer().descriptor(Customer.class);
|
||||
|
||||
@@ -62,22 +60,22 @@ public class BeanPropertyAssocManyTest extends BaseTestCase {
|
||||
assertThat(customer.getContacts().get(0)).isSameAs(contact);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findIdsByParentId() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Long> ids = DB.find(Customer.class).orderBy("id").setMaxRows(2).findIds();
|
||||
|
||||
List<Object> customerIds = new ArrayList<>();
|
||||
customerIds.add(ids.get(0));
|
||||
customerIds.add(ids.get(1));
|
||||
|
||||
List<Object> contactIdsForOne = contacts().findIdsByParentId(ids.get(0), null, null, null, true);
|
||||
|
||||
List<Object> contactIdsForMultiple = contacts().findIdsByParentId(null, customerIds, null, null, true);
|
||||
|
||||
assertThat(contactIdsForOne).isNotEmpty();
|
||||
assertThat(contactIdsForMultiple).isNotEmpty();
|
||||
}
|
||||
// @Test
|
||||
// public void findIdsByParentId() {
|
||||
//
|
||||
// ResetBasicData.reset();
|
||||
//
|
||||
// List<Long> ids = DB.find(Customer.class).orderBy("id").setMaxRows(2).findIds();
|
||||
//
|
||||
// List<Object> customerIds = new ArrayList<>();
|
||||
// customerIds.add(ids.get(0));
|
||||
// customerIds.add(ids.get(1));
|
||||
//
|
||||
// List<Object> contactIdsForOne = contacts().findIdsByParentId(ids.get(0), null, null, null, true);
|
||||
//
|
||||
// List<Object> contactIdsForMultiple = contacts().findIdsByParentId(null, customerIds, null, null, true);
|
||||
//
|
||||
// assertThat(contactIdsForOne).isNotEmpty();
|
||||
// assertThat(contactIdsForMultiple).isNotEmpty();
|
||||
// }
|
||||
}
|
||||
+8
-19
@@ -1,16 +1,12 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.xtest.ForPlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Address;
|
||||
import org.tests.model.basic.BWithQIdent;
|
||||
import org.tests.model.basic.Customer;
|
||||
|
||||
|
||||
public class DeployPropertyParserTest extends BaseTestCase {
|
||||
public class DeployPropertyParserTest extends BaseTest {
|
||||
|
||||
private final BeanDescriptor<Customer> descriptor = getBeanDescriptor(Customer.class);
|
||||
|
||||
@@ -61,21 +57,14 @@ public class DeployPropertyParserTest extends BaseTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ForPlatform({Platform.H2, Platform.POSTGRES})
|
||||
public void withQuote_when_match_h2() {
|
||||
Assertions.assertThat(withQuoteParser().parse("name like ?")).isEqualTo("${}\"Name\" like ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ForPlatform(Platform.SQLSERVER)
|
||||
public void withQuote_when_match_sqlserver() {
|
||||
Assertions.assertThat(withQuoteParser().parse("name like ?")).isEqualTo("${}[Name] like ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ForPlatform(Platform.MYSQL)
|
||||
public void withQuote_when_match_mysql() {
|
||||
Assertions.assertThat(withQuoteParser().parse("name like ?")).isEqualTo("${}`Name` like ?");
|
||||
if (isH2() || isPostgres()) {
|
||||
Assertions.assertThat(withQuoteParser().parse("name like ?")).isEqualTo("${}\"Name\" like ?");
|
||||
} else if (isSqlServer()) {
|
||||
Assertions.assertThat(withQuoteParser().parse("name like ?")).isEqualTo("${}[Name] like ?");
|
||||
} else if (isMySql()) {
|
||||
Assertions.assertThat(withQuoteParser().parse("name like ?")).isEqualTo("${}`Name` like ?");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
+1
-2
@@ -1,12 +1,11 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class FormulaPropertyPathTest extends BaseTestCase {
|
||||
public class FormulaPropertyPathTest extends BaseTest {
|
||||
|
||||
private BeanDescriptor<Customer> customerDesc = getBeanDescriptor(Customer.class);
|
||||
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.bean.EntityBean;
|
||||
@@ -19,7 +18,7 @@ import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestBeanDescriptorHasIdProperty extends BaseTestCase {
|
||||
public class TestBeanDescriptorHasIdProperty extends BaseTest {
|
||||
|
||||
SpiEbeanServer spiServer;
|
||||
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.bean.BeanCollection;
|
||||
import io.ebean.bean.EntityBean;
|
||||
@@ -14,7 +13,7 @@ import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestCollectionLoadedStatus extends BaseTestCase {
|
||||
public class TestCollectionLoadedStatus {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
+3
-10
@@ -1,10 +1,7 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.api.json.SpiJsonWriter;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
@@ -19,18 +16,14 @@ import java.sql.Timestamp;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class TestDiffHelpInsertSimple extends BaseTestCase {
|
||||
public class TestDiffHelpInsertSimple extends BaseTest {
|
||||
|
||||
private final long firstTime = System.currentTimeMillis() - 10000;
|
||||
|
||||
private final Database server;
|
||||
|
||||
private final BeanDescriptor<Order> orderDesc;
|
||||
|
||||
public TestDiffHelpInsertSimple() {
|
||||
server = DB.getDefault();
|
||||
SpiEbeanServer spiServer = (SpiEbeanServer) server;
|
||||
orderDesc = spiServer.descriptor(Order.class);
|
||||
orderDesc = db.descriptor(Order.class);
|
||||
}
|
||||
|
||||
private Order createBaseOrder(Database server) {
|
||||
@@ -49,7 +42,7 @@ public class TestDiffHelpInsertSimple extends BaseTestCase {
|
||||
|
||||
Date date = Date.valueOf("2000-01-01");
|
||||
|
||||
Order order1 = createBaseOrder(server);
|
||||
Order order1 = createBaseOrder(db);
|
||||
order1.setOrderDate(date);
|
||||
|
||||
StringWriter buffer = new StringWriter();
|
||||
+2
-8
@@ -1,10 +1,6 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.api.json.SpiJsonWriter;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.embedded.EMain;
|
||||
@@ -15,14 +11,12 @@ import java.io.StringWriter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestDiffHelpInsertWithEmbedded extends BaseTestCase {
|
||||
public class TestDiffHelpInsertWithEmbedded extends BaseTest {
|
||||
|
||||
private final BeanDescriptor<EMain> emainDesc;
|
||||
|
||||
public TestDiffHelpInsertWithEmbedded() {
|
||||
Database server = DB.getDefault();
|
||||
SpiEbeanServer spiServer = (SpiEbeanServer) server;
|
||||
emainDesc = spiServer.descriptor(EMain.class);
|
||||
emainDesc = getBeanDescriptor(EMain.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
@DiscriminatorColumn(name = "species")
|
||||
public abstract class Animal {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
@Version
|
||||
Long version;
|
||||
|
||||
@Column(name = "species", insertable = false, updatable = false, nullable = false)
|
||||
String species;
|
||||
|
||||
@ManyToOne
|
||||
AnimalShelter shelter;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getSpecies() {
|
||||
return species;
|
||||
}
|
||||
|
||||
public void setSpecies(String species) {
|
||||
this.species = species;
|
||||
}
|
||||
|
||||
public AnimalShelter getShelter() {
|
||||
return shelter;
|
||||
}
|
||||
|
||||
public void setShelter(AnimalShelter shelter) {
|
||||
this.shelter = shelter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Version;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.persistence.CascadeType.PERSIST;
|
||||
|
||||
@Entity
|
||||
public class AnimalShelter {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
@Version
|
||||
Long version;
|
||||
|
||||
String name;
|
||||
|
||||
@OneToMany(cascade = PERSIST, mappedBy = "shelter", orphanRemoval = true)
|
||||
List<Animal> animals;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Animal> getAnimals() {
|
||||
return animals;
|
||||
}
|
||||
|
||||
public void setAnimals(List<Animal> animals) {
|
||||
this.animals = animals;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Entity
|
||||
public class BWithQIdent {
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
@Column(name = "`Name`", unique = true)
|
||||
@Size(max = 191) // key must not exceed 767 Bytes, so max key len for mysql with utf8mb4 = 191*4 = 764 bytes
|
||||
String name;
|
||||
|
||||
@Column(name = "`CODE`")
|
||||
String CODE;
|
||||
|
||||
@Version
|
||||
Timestamp lastUpdated;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getCODE() {
|
||||
return CODE;
|
||||
}
|
||||
|
||||
public void setCODE(String CODE) {
|
||||
this.CODE = CODE;
|
||||
}
|
||||
|
||||
public Timestamp getLastUpdated() {
|
||||
return lastUpdated;
|
||||
}
|
||||
|
||||
public void setLastUpdated(Timestamp lastUpdated) {
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import io.ebean.annotation.Formula;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
@DiscriminatorValue("CAT")
|
||||
public class Cat extends Animal {
|
||||
|
||||
String name;
|
||||
|
||||
@Formula(select = "${ta}.species")
|
||||
String catFormula;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getCatFormula() {
|
||||
return catFormula;
|
||||
}
|
||||
|
||||
public void setCatFormula(String catFormula) {
|
||||
this.catFormula = catFormula;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import java.sql.Date;
|
||||
|
||||
@Entity
|
||||
@DiscriminatorValue("DOG")
|
||||
public class Dog extends Animal {
|
||||
|
||||
String registrationNumber;
|
||||
|
||||
Date dateOfBirth;
|
||||
|
||||
public String getRegistrationNumber() {
|
||||
return registrationNumber;
|
||||
}
|
||||
|
||||
public void setRegistrationNumber(String registrationNumber) {
|
||||
this.registrationNumber = registrationNumber;
|
||||
}
|
||||
|
||||
public Date getDateOfBirth() {
|
||||
return dateOfBirth;
|
||||
}
|
||||
|
||||
public void setDateOfBirth(Date dateOfBirth) {
|
||||
this.dateOfBirth = dateOfBirth;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.tests.model.bridge;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
public class BSite {
|
||||
|
||||
@Id @GeneratedValue
|
||||
UUID id;
|
||||
|
||||
String name;
|
||||
|
||||
public BSite(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.tests.model.bridge;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
public class BUser {
|
||||
|
||||
@Id
|
||||
UUID id;
|
||||
|
||||
String name;
|
||||
|
||||
public BUser(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.tests.model.composite;
|
||||
|
||||
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
* @author rnentjes
|
||||
*/
|
||||
@Entity
|
||||
public class RCustomer {
|
||||
|
||||
@EmbeddedId
|
||||
private RCustomerKey key;
|
||||
|
||||
private String description;
|
||||
|
||||
public RCustomer() {
|
||||
}
|
||||
|
||||
public RCustomer(RCustomerKey key, String description) {
|
||||
this.key = key;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public RCustomerKey getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(RCustomerKey key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.tests.model.composite;
|
||||
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@Embeddable
|
||||
public class RCustomerKey {
|
||||
|
||||
@Size(max=127)
|
||||
private String company;
|
||||
|
||||
@Size(max=127)
|
||||
private String name;
|
||||
|
||||
public RCustomerKey() {
|
||||
}
|
||||
|
||||
public RCustomerKey(String company, String name) {
|
||||
this.company = company;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public void setCompany(String company) {
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final RCustomerKey other = (RCustomerKey) obj;
|
||||
if ((this.company == null) ? (other.company != null) : !this.company.equals(other.company)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 3;
|
||||
hash = 89 * hash + (this.company != null ? this.company.hashCode() : 0);
|
||||
hash = 89 * hash + (this.name != null ? this.name.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.tests.model.embedded;
|
||||
|
||||
import io.ebean.Model;
|
||||
import io.ebean.annotation.WhenCreated;
|
||||
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
public class UserInterestLive extends Model {
|
||||
|
||||
@EmbeddedId
|
||||
private final UserInterestLiveKey key;
|
||||
|
||||
@WhenCreated
|
||||
private Date createdAt;
|
||||
|
||||
public UserInterestLive(UserInterestLiveKey key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public UserInterestLiveKey getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.tests.model.embedded;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
import java.util.Objects;
|
||||
|
||||
@Embeddable
|
||||
public class UserInterestLiveKey {
|
||||
|
||||
private long userId;
|
||||
private long liveId;
|
||||
|
||||
public UserInterestLiveKey(long userId, long liveId) {
|
||||
this.userId = userId;
|
||||
this.liveId = liveId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
UserInterestLiveKey that = (UserInterestLiveKey) o;
|
||||
return userId == that.userId &&
|
||||
liveId == that.liveId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(userId, liveId);
|
||||
}
|
||||
}
|
||||
@@ -4,3 +4,10 @@ datasource.h2.username=sa
|
||||
datasource.h2.password=
|
||||
datasource.h2.url=jdbc:h2:mem:testCoreMem;DB_CLOSE_ON_EXIT=FALSE;NON_KEYWORDS=KEY,VALUE
|
||||
|
||||
datasource.h2other.username=sa
|
||||
datasource.h2other.password=
|
||||
datasource.h2other.url=jdbc:h2:mem:testCoreOther;DB_CLOSE_ON_EXIT=FALSE;NON_KEYWORDS=KEY,VALUE
|
||||
|
||||
ebean.h2.ddl.generate=true
|
||||
ebean.h2.ddl.run=true
|
||||
ebean.h2.ddl.initSql=h2-init.sql
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
create table animal (
|
||||
species varchar(255) not null,
|
||||
id bigint generated by default as identity not null,
|
||||
shelter_id bigint,
|
||||
version bigint not null,
|
||||
name varchar(255),
|
||||
registration_number varchar(255),
|
||||
date_of_birth date,
|
||||
dog_size varchar(255),
|
||||
constraint pk_animal primary key (id)
|
||||
);
|
||||
|
||||
create table animal_shelter (
|
||||
id bigint generated by default as identity not null,
|
||||
name varchar(255),
|
||||
version bigint not null,
|
||||
constraint pk_animal_shelter primary key (id)
|
||||
);
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
package io.ebean.xtest.core;
|
||||
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
package io.ebean.xtest.core;
|
||||
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.BeanState;
|
||||
Reference in New Issue
Block a user