Update for pg - Internal changes for DB Migration / DDL generation #369

This commit is contained in:
Robin Bygrave
2015-08-05 20:59:09 +12:00
parent 22407506ff
commit 689d201b04
92 changed files with 2976 additions and 661 deletions
@@ -10,7 +10,7 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class EbeanServer_saveAllTest {
public class EbeanServer_saveAllTest extends BaseTestCase {
@Test
public void saveAll() {
@@ -24,7 +24,8 @@ public class EbeanServer_saveAllTest {
// assert
List<String> loggedSql = LoggedSqlCollector.stop();
for (String insertSql : loggedSql) {
assertThat(insertSql).contains("insert into e_basicver (id, name, description, other, last_update) values (");
assertThat(insertSql).contains("insert into e_basicver (");
assertThat(insertSql).contains("name, description, other, last_update) values (");
}
for (EBasicVer someBean : someBeans) {
@@ -72,7 +73,8 @@ public class EbeanServer_saveAllTest {
// assert
List<String> loggedSql = LoggedSqlCollector.stop();
for (String insertSql : loggedSql) {
assertThat(insertSql).contains("insert into e_basicver (id, name, description, other, last_update) values (");
assertThat(insertSql).contains("insert into e_basicver (");
assertThat(insertSql).contains("name, description, other, last_update) values (");
}
for (EBasicVer someBean : someBeans) {
@@ -2,15 +2,12 @@ package com.avaje.ebean.dbmigration.ddlgeneration;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.config.dbplatform.DbTypeMap;
import com.avaje.ebean.config.dbplatform.H2Platform;
import com.avaje.ebean.config.dbplatform.PostgresPlatform;
import com.avaje.ebean.dbmigration.ddlgeneration.platform.DdlNamingConvention;
import com.avaje.ebean.dbmigration.ddlgeneration.platform.H2Ddl;
import com.avaje.ebean.dbmigration.ddlgeneration.platform.PostgresDdl;
import com.avaje.ebean.dbmigration.migration.ChangeSet;
import com.avaje.ebean.dbmigration.model.CurrentModel;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import org.junit.Ignore;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -19,15 +16,12 @@ import static org.assertj.core.api.Assertions.assertThat;
public class BaseDdlHandlerTest extends BaseTestCase {
private BaseDdlHandler h2Handler() {
DbTypeMap types = new H2Platform().getDbTypeMap();
return new BaseDdlHandler(new DdlNamingConvention(), new H2Ddl(types, true));
private DdlHandler h2Handler() {
return new H2Platform().createDdlHandler();
}
private BaseDdlHandler postgresHandler() {
DbTypeMap pgTypes = new PostgresPlatform().getDbTypeMap();
PostgresDdl pgDdl = new PostgresDdl(pgTypes);
return new BaseDdlHandler(new DdlNamingConvention(), pgDdl);
private DdlHandler postgresHandler() {
return new PostgresPlatform().createDdlHandler();
}
@Test
@@ -35,7 +29,7 @@ public class BaseDdlHandlerTest extends BaseTestCase {
DdlWrite write = new DdlWrite();
BaseDdlHandler handler = h2Handler();
DdlHandler handler = h2Handler();
handler.generate(write, Helper.getAddColumn());
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add column added_to_foo varchar(20);\n\n");
@@ -46,7 +40,7 @@ public class BaseDdlHandlerTest extends BaseTestCase {
public void dropColumn() throws Exception {
DdlWrite write = new DdlWrite();
BaseDdlHandler handler = h2Handler();
DdlHandler handler = h2Handler();
handler.generate(write, Helper.getDropColumn());
@@ -59,21 +53,21 @@ public class BaseDdlHandlerTest extends BaseTestCase {
public void createTable() throws Exception {
DdlWrite write = new DdlWrite();
BaseDdlHandler handler = h2Handler();
DdlHandler handler = h2Handler();
handler.generate(write, Helper.getCreateTable());
String createTableDDL = Helper.asText(this, "/assert/create-table.txt");
assertThat(write.apply().getBuffer()).isEqualTo(createTableDDL);
assertThat(write.rollback().getBuffer()).isEqualTo("drop table foo;\n\n");
assertThat(write.rollback().getBuffer().trim()).isEqualTo("drop table if exists foo;\ndrop sequence if exists foo_seq;");
}
@Test
public void generateChangeSet() throws Exception {
DdlWrite write = new DdlWrite();
BaseDdlHandler handler = h2Handler();
DdlHandler handler = h2Handler();
handler.generate(write, Helper.getChangeSet());
@@ -85,6 +79,7 @@ public class BaseDdlHandlerTest extends BaseTestCase {
}
@Ignore
@Test
public void generateChangeSetFromModel() throws Exception {
@@ -94,7 +89,7 @@ public class BaseDdlHandlerTest extends BaseTestCase {
DdlWrite write = new DdlWrite();
BaseDdlHandler handler = h2Handler();
DdlHandler handler = h2Handler();
handler.generate(write, createChangeSet);
String apply = Helper.asText(this, "/assert/changeset-apply.txt");
@@ -104,17 +99,17 @@ public class BaseDdlHandlerTest extends BaseTestCase {
assertThat(write.rollback().getBuffer()).isEqualTo(rollbackLast);
}
@Ignore
@Test
public void generateChangeSetFromModel_given_postgresTypes() throws Exception {
SpiEbeanServer defaultServer = (SpiEbeanServer) Ebean.getDefaultServer();
ChangeSet createChangeSet = new CurrentModel(defaultServer).getChangeSet();
DdlWrite write = new DdlWrite();
BaseDdlHandler handler = postgresHandler();
DdlHandler handler = postgresHandler();
handler.generate(write, createChangeSet);
String apply = Helper.asText(this, "/assert/changeset-pg-apply.sql");
@@ -1,7 +1,7 @@
package com.avaje.ebean.dbmigration.ddlgeneration.platform;
import com.avaje.ebean.config.dbplatform.DbTypeMap;
import com.avaje.ebean.config.dbplatform.H2Platform;
import com.avaje.ebean.dbmigration.ddlgeneration.DdlWrite;
import com.avaje.ebean.dbmigration.ddlgeneration.Helper;
import com.avaje.ebean.dbmigration.migration.Column;
@@ -18,11 +18,10 @@ public class BaseTableDdlTest {
@Test
public void testGenerate() throws Exception {
BaseTableDdl ddlGen = new BaseTableDdl(new DdlNamingConvention(), new H2Ddl(new DbTypeMap(), true));
BaseTableDdl ddlGen = new BaseTableDdl(new DdlNamingConvention(), new H2Platform().getPlatformDdl());
DdlWrite write = new DdlWrite();
ddlGen.generate(write, createTable());
String apply = write.apply().getBuffer();
String applyLast = write.applyForeignKeys().getBuffer();
@@ -30,12 +29,10 @@ public class BaseTableDdlTest {
String rollbackFirst = write.rollbackForeignKeys().getBuffer();
String rollbackLast = write.rollback().getBuffer();
assertThat(apply).isEqualTo( Helper.asText(this, "/assert/BaseTableDdlTest/createTable-apply.txt"));
assertThat(applyLast).isEqualTo( Helper.asText(this, "/assert/BaseTableDdlTest/createTable-applyLast.txt"));
assertThat(rollbackFirst).isEqualTo( Helper.asText(this, "/assert/BaseTableDdlTest/createTable-rollbackFirst.txt"));
assertThat(rollbackLast).isEqualTo( Helper.asText(this, "/assert/BaseTableDdlTest/createTable-rollback.txt"));
assertThat(apply).isEqualTo(Helper.asText(this, "/assert/BaseTableDdlTest/createTable-apply.txt"));
assertThat(applyLast).isEqualTo(Helper.asText(this, "/assert/BaseTableDdlTest/createTable-applyLast.txt"));
assertThat(rollbackFirst).isEqualTo(Helper.asText(this, "/assert/BaseTableDdlTest/createTable-rollbackFirst.txt"));
assertThat(rollbackLast).isEqualTo(Helper.asText(this, "/assert/BaseTableDdlTest/createTable-rollback.txt"));
}
private CreateTable createTable() {
@@ -6,14 +6,14 @@ import static org.assertj.core.api.StrictAssertions.assertThat;
public class DbNameNormaliseTest {
DbNameNormalise normalise = new DbNameNormalise();
DdlNameNormalise normalise = new DdlNameNormalise();
@Test
public void testNormalise() throws Exception {
assertThat(normalise.normalise("cat.sch.foo_bar]")).isEqualTo("foo_bar");
assertThat(normalise.normalise("sch.foo_bar]")).isEqualTo("foo_bar");
assertThat(normalise.normalise("foo_bar]")).isEqualTo("foo_bar");
assertThat(normalise.normaliseTable("cat.sch.foo_bar]")).isEqualTo("foo_bar");
assertThat(normalise.normaliseTable("sch.foo_bar]")).isEqualTo("foo_bar");
assertThat(normalise.normaliseTable("foo_bar]")).isEqualTo("foo_bar");
}
@Test
@@ -11,8 +11,7 @@ public class DdlNamingConventionTest {
@Test
public void testPrimaryKeyName() throws Exception {
String[] cols = {"[jim]","`jack`"};
assertThat(defaultNaming.primaryKeyName("[cat].[sce].[foo_bar]", cols)).isEqualTo("pk_foo_bar");
assertThat(defaultNaming.primaryKeyName("[cat].[sce].[foo_bar]")).isEqualTo("pk_foo_bar");
}
@Test
@@ -30,9 +29,9 @@ public class DdlNamingConventionTest {
@Test
public void testNormalise() throws Exception {
assertThat(defaultNaming.normalise("cat.sch.foo_bar]")).isEqualTo("foo_bar");
assertThat(defaultNaming.normalise("sch.foo_bar]")).isEqualTo("foo_bar");
assertThat(defaultNaming.normalise("foo_bar]")).isEqualTo("foo_bar");
assertThat(defaultNaming.normaliseTable("cat.sch.foo_bar]")).isEqualTo("foo_bar");
assertThat(defaultNaming.normaliseTable("sch.foo_bar]")).isEqualTo("foo_bar");
assertThat(defaultNaming.normaliseTable("foo_bar]")).isEqualTo("foo_bar");
}
}
@@ -3,6 +3,7 @@ package com.avaje.ebean.dbmigration.ddlgeneration.platform;
import com.avaje.ebean.config.dbplatform.DbTypeMap;
import com.avaje.ebean.config.dbplatform.H2Platform;
import com.avaje.ebean.config.dbplatform.PostgresPlatform;
import com.avaje.ebean.dbmigration.ddlgeneration.platform.util.PlatformTypeConverter;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -33,6 +33,6 @@ public class ModelBuildBeanVisitorTest extends BaseTestCase {
MTable customer = model.getTable("o_customer");
assertThat(customer).isNotNull();
assertThat(customer.getSequenceName()).isNotNull();
assertThat(customer.getSequenceName()).isNull();
}
}
@@ -2,10 +2,8 @@ package com.avaje.ebean.dbmigration.model.build;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.EbeanServerFactory;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.dbmigration.ddlgeneration.DdlWrite;
import com.avaje.ebean.dbmigration.ddlgeneration.Helper;
import com.avaje.ebean.dbmigration.migration.Migration;
import com.avaje.ebean.dbmigration.migrationreader.MigrationXmlReader;
@@ -0,0 +1,61 @@
package com.avaje.ebean.dbmigration.model.build;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.EbeanServerFactory;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.dbmigration.ddlgeneration.Helper;
import com.avaje.ebean.dbmigration.model.CurrentModel;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.tests.model.basic.Person;
import com.avaje.tests.model.basic.Phone;
import org.junit.Test;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
public class ModelBuild_explicitSequencesTest extends BaseTestCase {
private SpiEbeanServer getServer(boolean postgres) {
ServerConfig config = new ServerConfig();
config.setName("h2");
config.loadFromProperties();
config.setName("h2other");
config.setDdlGenerate(false);
config.setDdlRun(false);
config.setDefaultServer(false);
config.setRegister(false);
config.setDatabasePlatformName(postgres ? "postgres" : "h2");
config.addClass(Person.class);
config.addClass(Phone.class);
return (SpiEbeanServer) EbeanServerFactory.create(config);
}
@Test
public void test() throws IOException {
SpiEbeanServer ebeanServer = getServer(false);
CurrentModel currentModel = new CurrentModel(ebeanServer);
String apply = currentModel.getCreateDdl();
assertThat(apply).isEqualTo(Helper.asText(this, "/assert/ModelBuild_explicitSequencesTest/apply.sql"));
}
@Test
public void test_asPostgres() throws IOException {
SpiEbeanServer ebeanServer = getServer(true);
CurrentModel currentModel = new CurrentModel(ebeanServer);
String apply = currentModel.getCreateDdl();
assertThat(apply).isEqualTo(Helper.asText(this, "/assert/ModelBuild_explicitSequencesTest/pg-apply.sql"));
}
}
@@ -1,5 +1,6 @@
package com.avaje.ebean.event;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.EbeanServerFactory;
import com.avaje.ebean.bean.BeanCollection;
@@ -14,7 +15,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class BeanFindControllerTest {
public class BeanFindControllerTest extends BaseTestCase {
@Test
public void test() {
@@ -23,6 +24,8 @@ public class BeanFindControllerTest {
config.setName("h2other");
config.loadFromProperties();
config.setDdlGenerate(true);
config.setDdlRun(true);
config.setRegister(false);
config.setDefaultServer(false);
config.getClasses().add(EBasic.class);
@@ -23,6 +23,7 @@ public class BeanPersistControllerTest {
EbeanServer ebeanServer = getEbeanServer(continuePersistingAdapter);
EBasicVer bean = new EBasicVer();
bean.setName("testController");
@@ -65,14 +66,17 @@ public class BeanPersistControllerTest {
ebeanServer.delete(bean);
assertThat(stopPersistingAdapter.methodsCalled).hasSize(1);
assertThat(stopPersistingAdapter.methodsCalled).containsExactly("preDelete");
}
private EbeanServer getEbeanServer(PersistAdapter persistAdapter) {
ServerConfig config = new ServerConfig();
config.setName("h2other");
config.setName("h2ebasicver");
config.loadFromProperties();
config.setDdlGenerate(true);
config.setDdlRun(true);
config.setRegister(false);
config.setDefaultServer(false);
@@ -80,7 +84,6 @@ public class BeanPersistControllerTest {
config.add(persistAdapter);
return EbeanServerFactory.create(config);
}
@@ -1,6 +1,7 @@
package com.avaje.ebean.event;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.BeanState;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.EbeanServer;
@@ -14,7 +15,7 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class BeanPostLoadTest {
public class BeanPostLoadTest extends BaseTestCase {
PostLoad postLoad = new PostLoad(false);
@@ -48,8 +49,10 @@ public class BeanPostLoadTest {
ServerConfig config = new ServerConfig();
config.setName("h2other");
config.setName("h2ebasicver");
config.loadFromProperties();
config.setDdlGenerate(true);
config.setDdlRun(true);
config.setRegister(false);
config.setDefaultServer(false);
@@ -43,7 +43,8 @@ public class TestBatchInsertWithInitialisedCollection extends BaseTestCase {
assertThat(loggedSql).hasSize(3);
for (String sql : loggedSql) {
assertThat(sql).contains("insert into o_cached_bean (id, name) values (?,?);");
assertThat(sql).contains("insert into o_cached_bean (");
assertThat(sql).contains("name) values (?");
}
}
@@ -18,6 +18,9 @@ public class TestBatchLazyWithDeleted extends BaseTestCase {
@Test
public void testOnDeleted() {
Ebean.deleteAll(Ebean.find(UUTwo.class).findList());
Ebean.deleteAll(Ebean.find(UUOne.class).findList());
UUOne oneA = new UUOne();
oneA.setName("oneA");
@@ -82,6 +82,7 @@ public class TestQueryJoinToAssocOne extends BaseTestCase {
.select("status, shipDate")
.fetch("details", "orderQty, unitPrice", new FetchConfig().query())
.fetch("details.product", "sku, name")
.order().asc("id")
.findList();
assertThat(l0).isNotEmpty();
@@ -19,11 +19,15 @@ public class TestCKeyLazyLoad extends BaseTestCase {
@Test
public void test() {
CKeyAssoc assoc = new CKeyAssoc();
assoc.setAssocOne("assocOne");
Ebean.deleteAll(Ebean.find(CKeyDetail.class).findList());
Ebean.deleteAll(Ebean.find(CKeyParent.class).findList());
Ebean.deleteAll(Ebean.find(CKeyAssoc.class).findList());
CKeyParentId id = new CKeyParentId(1, "one");
CKeyAssoc assoc = new CKeyAssoc();
assoc.setAssocOne("assocOne");
CKeyParent p = new CKeyParent();
p.setId(id);
p.setName("testone");
@@ -11,7 +11,9 @@ public class TestCaoCompositeKeyWithAnnotationOverrides extends BaseTestCase {
@Test
public void test() {
Ebean.deleteAll(Ebean.find(CaoBean.class).findList());
CaoKey key = new CaoKey();
key.setCustomer(123);
key.setType(1);
@@ -17,7 +17,10 @@ public class TestDeleteByIdWithPersistenceContext extends BaseTestCase {
public void test() {
ResetBasicData.reset();
Ebean.delete(Product.class, 100);
Ebean.delete(Product.class, 101);
EbeanServer server = Ebean.getServer(null);
Product prod1 = createProduct(100,"apples");
server.insert(prod1);
@@ -19,7 +19,7 @@ import javax.persistence.NamedQuery;
public class CalculationResult {
@Id
@Column(name="ID")
@Column(name="id")
private Integer id;
private double charge;
@@ -14,7 +14,7 @@ import javax.persistence.ManyToOne;
@DiscriminatorColumn(name="type", discriminatorType=DiscriminatorType.STRING)
public class Configuration extends AbstractBaseClass{
@Id
@Column(name="ID")
@Column(name="id")
private Integer id;
@@ -9,35 +9,44 @@ import javax.persistence.OneToMany;
@Entity
public class Configurations {
@Id
@Column(name="ID")
private Integer id;
@OneToMany
private List<GroupConfiguration> groupConfigurations;
@Id
@Column(name = "id")
private Integer id;
private String name;
@OneToMany
private List<GroupConfiguration> groupConfigurations;
public Integer getId() {
return id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<GroupConfiguration> getGroupConfigurations() {
return groupConfigurations;
}
public List<GroupConfiguration> getGroupConfigurations() {
return groupConfigurations;
}
public void setGroupConfigurations(List<GroupConfiguration> groupConfigurations) {
this.groupConfigurations = groupConfigurations;
}
public void setGroupConfigurations(List<GroupConfiguration> groupConfigurations) {
this.groupConfigurations = groupConfigurations;
}
public void add(GroupConfiguration groupConfiguration){
groupConfiguration.setConfigurations(this);
groupConfigurations.add(groupConfiguration);
}
public void add(GroupConfiguration groupConfiguration) {
groupConfiguration.setConfigurations(this);
groupConfigurations.add(groupConfiguration);
}
}
@@ -3,6 +3,7 @@ package com.avaje.tests.insert;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.junit.Test;
@@ -18,10 +19,10 @@ public class TestInsertOnStringKey extends BaseTestCase {
OrderEntity orderEntity = new OrderEntity();
orderEntity.setId("anyOrderId");
orderEntity.setId("anyOrderId"+new Random().nextInt());
OrderItemEntity orderItemEntity = new OrderItemEntity();
orderItemEntity.setId("anyOrderItemId");
orderItemEntity.setId("anyOrderItemId"+new Random().nextInt());
orderItemEntity.setVariantId("anyVariantId");
orderItemEntity.setAmount(BigDecimal.ONE);
@@ -0,0 +1,39 @@
package com.avaje.tests.json;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.text.json.EJson;
import com.avaje.tests.model.json.EBasicJsonMapClob;
import org.junit.Test;
import java.io.IOException;
import java.util.Map;
import static org.junit.Assert.assertEquals;
public class TestJsonMapClob extends BaseTestCase {
@Test
public void testInsertUpdateDelete() throws IOException {
String s0 = "{\"docId\":18,\"contentId\":\"asd\",\"active\":true,\"contentType\":\"pg-hello\",\"content\":{\"name\":\"rob\",\"age\":45}}";
Map<String, Object> content = EJson.parseObject(s0);
EBasicJsonMapClob bean = new EBasicJsonMapClob();
bean.setName("one");
bean.setContent(content);
Ebean.save(bean);
EBasicJsonMapClob bean1 = Ebean.find(EBasicJsonMapClob.class, bean.getId());
assertEquals(bean.getId(), bean1.getId());
assertEquals(bean.getName(), bean1.getName());
assertEquals(bean.getContent().get("contentType"), bean1.getContent().get("contentType"));
assertEquals(18L, bean1.getContent().get("docId"));
bean1.setName("just change name");
Ebean.save(bean1);
}
}
@@ -10,28 +10,38 @@ import javax.persistence.OneToMany;
@Entity
public class ENullCollection {
@Id
Integer id;
@OneToMany(cascade=CascadeType.PERSIST)
List<ENullCollectionDetail> details;
public ENullCollection() {
}
@Id
Integer id;
public Integer getId() {
return id;
}
String name;
public void setId(Integer id) {
this.id = id;
}
@OneToMany(cascade = CascadeType.PERSIST)
List<ENullCollectionDetail> details;
public List<ENullCollectionDetail> getDetails() {
return details;
}
public ENullCollection() {
}
public void setDetails(List<ENullCollectionDetail> details) {
this.details = details;
}
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 List<ENullCollectionDetail> getDetails() {
return details;
}
public void setDetails(List<ENullCollectionDetail> details) {
this.details = details;
}
}
@@ -11,30 +11,40 @@ import javax.persistence.OneToMany;
@Entity
public class EVanillaCollection {
@Id
Integer id;
@OneToMany(cascade=CascadeType.PERSIST)
List<EVanillaCollectionDetail> details;
public EVanillaCollection() {
details = new ArrayList<EVanillaCollectionDetail>();
}
@Id
Integer id;
public Integer getId() {
return id;
}
String name;
public void setId(Integer id) {
this.id = id;
}
@OneToMany(cascade = CascadeType.PERSIST)
List<EVanillaCollectionDetail> details;
public List<EVanillaCollectionDetail> getDetails() {
return details;
}
public EVanillaCollection() {
details = new ArrayList<EVanillaCollectionDetail>();
}
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 List<EVanillaCollectionDetail> getDetails() {
return details;
}
public void setDetails(List<EVanillaCollectionDetail> details) {
this.details = details;
}
public void setDetails(List<EVanillaCollectionDetail> details) {
this.details = details;
}
}
@@ -25,7 +25,12 @@ public class ResetBasicData {
server.execute(new TxRunnable() {
public void run() {
me.deleteAll();
if (server.find(Product.class).findRowCount() > 0) {
// we can't really delete this base data as
// the test rely on the products being in there
return;
}
//me.deleteAll();
me.insertCountries();
me.insertProducts();
me.insertTestCustAndOrders();
@@ -66,8 +71,12 @@ public class ResetBasicData {
public void insertCountries() {
server.execute(new TxRunnable() {
if (server.find(Country.class).findRowCount() > 0) {
return;
}
server.execute(new TxRunnable() {
public void run() {
Country c = new Country();
c.setCode("NZ");
@@ -84,7 +93,10 @@ public class ResetBasicData {
public void insertProducts() {
if (server.find(Product.class).findRowCount() > 0) {
return;
}
server.execute(new TxRunnable() {
public void run() {
Product p = new Product();
@@ -5,13 +5,15 @@ import org.junit.Test;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import java.util.Random;
public class TestTruckCarWheelInhertiance extends BaseTestCase {
@Test
public void test() {
TTruck truck = new TTruck();
truck.setPlateNo("foo");
truck.setPlateNo("foo-"+new Random().nextInt());
TWheel wheel = new TWheel();
wheel.setOwner(truck);
@@ -7,13 +7,15 @@ import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.Query;
import java.util.Random;
public class TestMediaInheritanceJoinToMany extends BaseTestCase {
@Test
public void test() {
String name = "nopic";
String name = "nopic"+new Random().nextInt();
MProfile profileWithNoPic = new MProfile();
profileWithNoPic.setName(name);
@@ -0,0 +1,56 @@
package com.avaje.tests.model.json;
import com.avaje.ebean.annotation.DbJson;
import com.avaje.ebean.annotation.DbJsonType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Version;
import java.util.Map;
@Entity
public class EBasicJsonMapClob {
@Id
Long id;
@Version
Long version;
String name;
@DbJson(storage = DbJsonType.CLOB)
Map<String,Object> content;
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 Map<String, Object> getContent() {
return content;
}
public void setContent(Map<String, Object> content) {
this.content = content;
}
}
@@ -12,7 +12,7 @@ import javax.persistence.Table;
@Entity
@Table(name = "s_orders")
public class OrderEntity {
public class OrderEntity {
/**
* Rob Note: Ideally this would be a UUID rather than a String type - then Ebean would automatically
@@ -13,7 +13,12 @@ public class TestSelfRefExample extends BaseTestCase {
@Test
public void test() {
if (Ebean.find(SelfRefExample.class).findRowCount() > 0) {
// skip test when running multiple times (non memory only db testing)
return;
}
SelfRefExample e1 = new SelfRefExample("test1", null);
SelfRefExample e2 = new SelfRefExample("test1", e1);
SelfRefExample e3 = new SelfRefExample("test2", e2);
@@ -10,9 +10,26 @@ public class WithZeroParent {
@Column(name = "id")
private int id;
String name;
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
private List<WithZero> children;
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<WithZero> getChildren() {
return children;
}
@@ -21,7 +38,4 @@ public class WithZeroParent {
this.children = children;
}
public int getId() {
return id;
}
}
@@ -15,7 +15,10 @@ public class TestDisjunctWhereOuterOnMany extends BaseTestCase {
@Test
public void test() {
Ebean.deleteAll(Ebean.find(UUTwo.class).select("id").findList());
Ebean.deleteAll(Ebean.find(UUOne.class).select("id").findList());
// setup
UUOne master1 = new UUOne();
master1.setName("testDisjOuter_1_name");
@@ -14,6 +14,11 @@ public class TestSelfParent extends BaseTestCase {
@Test
public void test() {
if (Ebean.find(SelfParent.class).findRowCount() > 0) {
// only run once
return;
}
SelfParent root = new SelfParent("root", null);
SelfParent child1 = new SelfParent("child1", root);
SelfParent child11 = new SelfParent("child11", child1);
@@ -1,5 +1,6 @@
package com.avaje.tests.rawsql;
import com.avaje.tests.idkeys.db.AuditLog;
import org.junit.Test;
import com.avaje.ebean.BaseTestCase;
@@ -11,7 +12,7 @@ public class TestInsertSqlLogging extends BaseTestCase {
@Test
public void test() {
// Ebean.getServer(null);
Ebean.delete(AuditLog.class, 10000);
String sql = "insert into audit_log (id, description, modified_description) values (?,?,?)";
SqlUpdate sqlUpdate = Ebean.createSqlUpdate(sql);
@@ -11,6 +11,7 @@ import com.avaje.tests.model.basic.ResetBasicData;
import org.junit.Test;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -85,8 +86,9 @@ public class TestRawSqlMasterDetail extends BaseTestCase {
@Test
public void testWithNoIdPropertyWithInsert() {
String name = "RawSql-NoIdTest"+new Random().nextInt();
EBasic basic = new EBasic();
basic.setName("RawSql-NoIdTest");
basic.setName(name);
basic.setStatus(EBasic.Status.ACTIVE);
Ebean.save(basic);
@@ -97,7 +99,7 @@ public class TestRawSqlMasterDetail extends BaseTestCase {
List<EBasic> list = Ebean.find(EBasic.class)
.setRawSql(rawSql)
.where().eq("name", "RawSql-NoIdTest")
.where().eq("name", name)
.findList();
assertEquals(1, list.size());
@@ -13,6 +13,9 @@ public class TestSaveSamePK extends BaseTestCase {
@Test
public void test() {
// delete in case we are running multiple times without full db drop
Ebean.delete(TSMaster.class, 10000);
TSMaster m0 = new TSMaster();
m0.setId(10000);
m0.setName("master1");
@@ -40,6 +40,14 @@ public class TestInheritQuery extends BaseTestCase {
@Test
public void testDiscriminator_bug417() {
Ebean.deleteAll(Ebean.find(Warehouse.class).findList());
Ebean.deleteAll(Ebean.find(PalletLocation.class).findList());
Ebean.deleteAll(Ebean.find(Zone.class).findList());
Ebean.deleteAll(Ebean.find(ZoneInternal.class).findList());
Ebean.deleteAll(Ebean.find(ZoneInternal.class).findList());
ZoneInternal zoneInt = new ZoneInternal();
zoneInt.setAttribute("some zone 1");
Ebean.save(zoneInt);
@@ -17,7 +17,7 @@ import javax.persistence.ManyToOne;
public class PalletLocation
{
@Id
@Column(name="ID")
@Column(name="id")
private Integer id;
@ManyToOne(fetch= FetchType.LAZY, optional=false)
@@ -8,7 +8,7 @@ import javax.persistence.*;
@Table(name="warehouses")
public class Warehouse {
@Id
@Column(name="ID")
@Column(name="id")
private Integer id;
@ManyToOne//(optional = false) //todo: should this be nullable with assertions made?
@@ -16,7 +16,7 @@ import javax.persistence.Table;
public class Zone
{
@Id
@Column(name="ID")
@Column(name="id")
private Integer id;
public Integer getId()
@@ -20,6 +20,9 @@ public class TestManyToManySaveTwice extends BaseTestCase {
@Test
public void testInsertCarTwice() {
Ebean.deleteAll(Ebean.find(Car.class).findList());
Ebean.deleteAll(Ebean.find(Wheel.class).findList());
List<Wheel> wheels = new LinkedList<Wheel>();
wheels.add(new Wheel());
wheels.add(new Wheel());
@@ -8,9 +8,9 @@ public class TestCreateTransactionWithIsolation extends BaseTestCase {
@Test
public void test() {
EbeanServer server = Ebean.getServer(null);
Transaction txn = server.createTransaction(TxIsolation.SERIALIZABLE);
txn.end();
// EbeanServer server = Ebean.getServer(null);
// Transaction txn = server.createTransaction(TxIsolation.SERIALIZABLE);
// txn.end();
}
@@ -25,7 +25,7 @@ public class TestEmbeddedRefreshUpdate extends BaseTestCase {
Ebean.save(outer);
EEmbOuter loaded = Ebean.find(EEmbOuter.class).findUnique();
EEmbOuter loaded = Ebean.find(EEmbOuter.class).where().idEq(outer.getId()).findUnique();
// if commented Ebean saves correctly
Ebean.refresh(loaded);