mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
No effective change - change Line endings to CR (from CRLF)
This commit is contained in:
@@ -1,55 +1,55 @@
|
||||
package com.avaje.tests.inheritance;
|
||||
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.TxRunnable;
|
||||
import com.avaje.tests.model.basic.AttributeHolder;
|
||||
import com.avaje.tests.model.basic.ListAttribute;
|
||||
import com.avaje.tests.model.basic.ListAttributeValue;
|
||||
|
||||
public class TestDuplcateKeyException extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* Test query.
|
||||
* <p>This test covers the BUG 276. Cascade was not propagating to the ListAttribute because
|
||||
* it was considered safe to skip as it didn't take into account any derived classes
|
||||
* into account with e.g. collections and Cascade options </p>
|
||||
*/
|
||||
@Test
|
||||
public void testQuery() {
|
||||
|
||||
// Setup the data first
|
||||
final ListAttributeValue value1 = new ListAttributeValue();
|
||||
|
||||
Ebean.save(value1);
|
||||
|
||||
final ListAttribute listAttribute = new ListAttribute();
|
||||
listAttribute.add(value1);
|
||||
Ebean.save(listAttribute);
|
||||
|
||||
|
||||
|
||||
final AttributeHolder holder = new AttributeHolder();
|
||||
holder.add(listAttribute);
|
||||
|
||||
try {
|
||||
Ebean.execute(new TxRunnable() {
|
||||
public void run() {
|
||||
//Ebean.currentTransaction().log("-- saving holder first time");
|
||||
// Alternatively turn off cascade Persist for this transaction
|
||||
//Ebean.currentTransaction().setPersistCascade(false);
|
||||
Ebean.save(holder);
|
||||
//Ebean.currentTransaction().log("-- saving holder second time");
|
||||
// we don't get this far before failing
|
||||
//Ebean.save(holder);
|
||||
}
|
||||
});
|
||||
} catch (Exception e){
|
||||
Assert.assertEquals(e.getMessage(), "test rollback");
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.avaje.tests.inheritance;
|
||||
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.TxRunnable;
|
||||
import com.avaje.tests.model.basic.AttributeHolder;
|
||||
import com.avaje.tests.model.basic.ListAttribute;
|
||||
import com.avaje.tests.model.basic.ListAttributeValue;
|
||||
|
||||
public class TestDuplcateKeyException extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* Test query.
|
||||
* <p>This test covers the BUG 276. Cascade was not propagating to the ListAttribute because
|
||||
* it was considered safe to skip as it didn't take into account any derived classes
|
||||
* into account with e.g. collections and Cascade options </p>
|
||||
*/
|
||||
@Test
|
||||
public void testQuery() {
|
||||
|
||||
// Setup the data first
|
||||
final ListAttributeValue value1 = new ListAttributeValue();
|
||||
|
||||
Ebean.save(value1);
|
||||
|
||||
final ListAttribute listAttribute = new ListAttribute();
|
||||
listAttribute.add(value1);
|
||||
Ebean.save(listAttribute);
|
||||
|
||||
|
||||
|
||||
final AttributeHolder holder = new AttributeHolder();
|
||||
holder.add(listAttribute);
|
||||
|
||||
try {
|
||||
Ebean.execute(new TxRunnable() {
|
||||
public void run() {
|
||||
//Ebean.currentTransaction().log("-- saving holder first time");
|
||||
// Alternatively turn off cascade Persist for this transaction
|
||||
//Ebean.currentTransaction().setPersistCascade(false);
|
||||
Ebean.save(holder);
|
||||
//Ebean.currentTransaction().log("-- saving holder second time");
|
||||
// we don't get this far before failing
|
||||
//Ebean.save(holder);
|
||||
}
|
||||
});
|
||||
} catch (Exception e){
|
||||
Assert.assertEquals(e.getMessage(), "test rollback");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,117 +1,117 @@
|
||||
package com.avaje.tests.inheritance;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.inheritance.model.CalculationResult;
|
||||
import com.avaje.tests.inheritance.model.Configurations;
|
||||
import com.avaje.tests.inheritance.model.GroupConfiguration;
|
||||
import com.avaje.tests.inheritance.model.ProductConfiguration;
|
||||
|
||||
public class TestInheritanceJoins extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testAssocOne() {
|
||||
|
||||
EbeanServer server = Ebean.getDefaultServer();
|
||||
|
||||
ProductConfiguration pc = new ProductConfiguration();
|
||||
pc.setName("PC1");
|
||||
server.save(pc);
|
||||
|
||||
GroupConfiguration gc = new GroupConfiguration();
|
||||
gc.setName("GC1");
|
||||
server.save(gc);
|
||||
|
||||
CalculationResult r = new CalculationResult();
|
||||
r.setCharge(100.0);
|
||||
r.setProductConfiguration(pc);
|
||||
r.setGroupConfiguration(gc);
|
||||
server.save(r);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assocOne_when_null() {
|
||||
|
||||
EbeanServer server = Ebean.getDefaultServer();
|
||||
|
||||
GroupConfiguration gc = new GroupConfiguration();
|
||||
gc.setName("GC1");
|
||||
server.save(gc);
|
||||
|
||||
CalculationResult r = new CalculationResult();
|
||||
r.setCharge(100.0);
|
||||
|
||||
// @ManyToOne with inheritance and null
|
||||
r.setProductConfiguration(null);
|
||||
r.setGroupConfiguration(gc);
|
||||
server.save(r);
|
||||
|
||||
CalculationResult result = server.find(CalculationResult.class, r.getId());
|
||||
|
||||
GroupConfiguration group = result.getGroupConfiguration();
|
||||
Assert.assertEquals(group.getId(), gc.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssocOneWithNullAssoc() {
|
||||
|
||||
/* Ensures the fetch join to a property with inheritance work as a left join */
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
final ProductConfiguration pc = new ProductConfiguration();
|
||||
pc.setName("PC1");
|
||||
server.save(pc);
|
||||
|
||||
CalculationResult r = new CalculationResult();
|
||||
final Double charge = 100.0;
|
||||
r.setCharge(charge);
|
||||
r.setProductConfiguration(pc);
|
||||
r.setGroupConfiguration(null);
|
||||
server.save(r);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssocMany() {
|
||||
Configurations configurations = new Configurations();
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
server.save(configurations);
|
||||
|
||||
|
||||
final GroupConfiguration gc = new GroupConfiguration("GC1");
|
||||
configurations.add(gc);
|
||||
|
||||
|
||||
server.save(gc);
|
||||
|
||||
|
||||
Configurations configurationsQueried = server.find(Configurations.class, configurations.getId());
|
||||
|
||||
List<GroupConfiguration> groups = configurationsQueried.getGroupConfigurations();
|
||||
|
||||
Assert.assertTrue(!groups.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssocManyWithNoneRelated() {
|
||||
Configurations configurations = new Configurations();
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
server.save(configurations);
|
||||
|
||||
Configurations configurationsQueried = server.find(Configurations.class).fetch("groupConfigurations").where().idEq(configurations.getId()).findUnique();
|
||||
|
||||
Assert.assertNotNull(configurationsQueried);
|
||||
}
|
||||
|
||||
package com.avaje.tests.inheritance;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.inheritance.model.CalculationResult;
|
||||
import com.avaje.tests.inheritance.model.Configurations;
|
||||
import com.avaje.tests.inheritance.model.GroupConfiguration;
|
||||
import com.avaje.tests.inheritance.model.ProductConfiguration;
|
||||
|
||||
public class TestInheritanceJoins extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testAssocOne() {
|
||||
|
||||
EbeanServer server = Ebean.getDefaultServer();
|
||||
|
||||
ProductConfiguration pc = new ProductConfiguration();
|
||||
pc.setName("PC1");
|
||||
server.save(pc);
|
||||
|
||||
GroupConfiguration gc = new GroupConfiguration();
|
||||
gc.setName("GC1");
|
||||
server.save(gc);
|
||||
|
||||
CalculationResult r = new CalculationResult();
|
||||
r.setCharge(100.0);
|
||||
r.setProductConfiguration(pc);
|
||||
r.setGroupConfiguration(gc);
|
||||
server.save(r);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assocOne_when_null() {
|
||||
|
||||
EbeanServer server = Ebean.getDefaultServer();
|
||||
|
||||
GroupConfiguration gc = new GroupConfiguration();
|
||||
gc.setName("GC1");
|
||||
server.save(gc);
|
||||
|
||||
CalculationResult r = new CalculationResult();
|
||||
r.setCharge(100.0);
|
||||
|
||||
// @ManyToOne with inheritance and null
|
||||
r.setProductConfiguration(null);
|
||||
r.setGroupConfiguration(gc);
|
||||
server.save(r);
|
||||
|
||||
CalculationResult result = server.find(CalculationResult.class, r.getId());
|
||||
|
||||
GroupConfiguration group = result.getGroupConfiguration();
|
||||
Assert.assertEquals(group.getId(), gc.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssocOneWithNullAssoc() {
|
||||
|
||||
/* Ensures the fetch join to a property with inheritance work as a left join */
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
final ProductConfiguration pc = new ProductConfiguration();
|
||||
pc.setName("PC1");
|
||||
server.save(pc);
|
||||
|
||||
CalculationResult r = new CalculationResult();
|
||||
final Double charge = 100.0;
|
||||
r.setCharge(charge);
|
||||
r.setProductConfiguration(pc);
|
||||
r.setGroupConfiguration(null);
|
||||
server.save(r);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssocMany() {
|
||||
Configurations configurations = new Configurations();
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
server.save(configurations);
|
||||
|
||||
|
||||
final GroupConfiguration gc = new GroupConfiguration("GC1");
|
||||
configurations.add(gc);
|
||||
|
||||
|
||||
server.save(gc);
|
||||
|
||||
|
||||
Configurations configurationsQueried = server.find(Configurations.class, configurations.getId());
|
||||
|
||||
List<GroupConfiguration> groups = configurationsQueried.getGroupConfigurations();
|
||||
|
||||
Assert.assertTrue(!groups.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssocManyWithNoneRelated() {
|
||||
Configurations configurations = new Configurations();
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
server.save(configurations);
|
||||
|
||||
Configurations configurationsQueried = server.find(Configurations.class).fetch("groupConfigurations").where().idEq(configurations.getId()).findUnique();
|
||||
|
||||
Assert.assertNotNull(configurationsQueried);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +1,48 @@
|
||||
package com.avaje.tests.inheritance;
|
||||
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.TIntChild;
|
||||
import com.avaje.tests.model.basic.TIntRoot;
|
||||
|
||||
public class TestIntInherit extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testMe() {
|
||||
|
||||
TIntRoot r = new TIntRoot();
|
||||
r.setName("root1");
|
||||
|
||||
TIntRoot r2 = new TIntRoot();
|
||||
r.setName("root2");
|
||||
|
||||
TIntChild c1 = new TIntChild();
|
||||
c1.setName("child1");
|
||||
c1.setChildProperty("cp1");
|
||||
|
||||
TIntChild c2 = new TIntChild();
|
||||
c2.setName("child2");
|
||||
c2.setChildProperty("cp2");
|
||||
|
||||
|
||||
Ebean.save(r);
|
||||
Ebean.save(r2);
|
||||
Ebean.save(c1);
|
||||
Ebean.save(c2);
|
||||
|
||||
TIntRoot result1 = Ebean.find(TIntRoot.class, r.getId());
|
||||
Assert.assertTrue(result1 instanceof TIntRoot);
|
||||
|
||||
TIntRoot ref3 = Ebean.getReference(TIntRoot.class, c1.getId());
|
||||
Assert.assertTrue(ref3 instanceof TIntChild);
|
||||
|
||||
TIntRoot result3 = Ebean.find(TIntRoot.class, c1.getId());
|
||||
Assert.assertTrue(result3 instanceof TIntChild);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.tests.inheritance;
|
||||
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.TIntChild;
|
||||
import com.avaje.tests.model.basic.TIntRoot;
|
||||
|
||||
public class TestIntInherit extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testMe() {
|
||||
|
||||
TIntRoot r = new TIntRoot();
|
||||
r.setName("root1");
|
||||
|
||||
TIntRoot r2 = new TIntRoot();
|
||||
r.setName("root2");
|
||||
|
||||
TIntChild c1 = new TIntChild();
|
||||
c1.setName("child1");
|
||||
c1.setChildProperty("cp1");
|
||||
|
||||
TIntChild c2 = new TIntChild();
|
||||
c2.setName("child2");
|
||||
c2.setChildProperty("cp2");
|
||||
|
||||
|
||||
Ebean.save(r);
|
||||
Ebean.save(r2);
|
||||
Ebean.save(c1);
|
||||
Ebean.save(c2);
|
||||
|
||||
TIntRoot result1 = Ebean.find(TIntRoot.class, r.getId());
|
||||
Assert.assertTrue(result1 instanceof TIntRoot);
|
||||
|
||||
TIntRoot ref3 = Ebean.getReference(TIntRoot.class, c1.getId());
|
||||
Assert.assertTrue(ref3 instanceof TIntChild);
|
||||
|
||||
TIntRoot result3 = Ebean.find(TIntRoot.class, c1.getId());
|
||||
Assert.assertTrue(result3 instanceof TIntChild);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
package com.avaje.tests.inheritance;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.AttributeHolder;
|
||||
import com.avaje.tests.model.basic.ListAttribute;
|
||||
import com.avaje.tests.model.basic.ListAttributeValue;
|
||||
|
||||
public class TestSkippable extends BaseTestCase {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TestSkippable.class);
|
||||
|
||||
/**
|
||||
* Test query.
|
||||
* <p>This test covers the BUG 276. Cascade was not propagating to the ListAttribute because
|
||||
* it was considered safe to skip as it didn't take into account any derived classes
|
||||
* into account with e.g. collections and Cascade options </p>
|
||||
*/
|
||||
@Test
|
||||
public void testQuery() {
|
||||
|
||||
// Setup the data first
|
||||
final ListAttributeValue value1 = new ListAttributeValue();
|
||||
final ListAttributeValue value2 = new ListAttributeValue();
|
||||
|
||||
Ebean.save(value1);
|
||||
Ebean.save(value2);
|
||||
|
||||
final ListAttribute listAttribute = new ListAttribute();
|
||||
listAttribute.add(value1);
|
||||
Ebean.save(listAttribute);
|
||||
logger.info(" -- seeded data");
|
||||
|
||||
final ListAttribute listAttributeDB = Ebean.find(ListAttribute.class, listAttribute.getId());
|
||||
Assert.assertNotNull(listAttributeDB);
|
||||
|
||||
final ListAttributeValue value1_DB = listAttributeDB.getValues().iterator().next();
|
||||
Assert.assertTrue(value1.getId().equals(value1_DB.getId()));
|
||||
logger.info(" -- asserted data in db");
|
||||
|
||||
|
||||
final AttributeHolder holder = new AttributeHolder();
|
||||
holder.add(listAttributeDB);
|
||||
|
||||
Ebean.save(holder);
|
||||
logger.info(" -- saved holder");
|
||||
|
||||
// Now change the M2M listAttribute.values and save the holder
|
||||
// The save should cascade as follows
|
||||
// holder.attributes..ListAttribute.values
|
||||
listAttributeDB.getValues().clear();
|
||||
listAttributeDB.add(value2);
|
||||
|
||||
// Save the holder - should cascade down to the listAtribute and save the values
|
||||
Ebean.save(holder);
|
||||
logger.info(" -- M2M detected delete of value1 and add of value2 ?");
|
||||
|
||||
|
||||
final ListAttribute listAttributeDB_2 = Ebean.find(ListAttribute.class, listAttributeDB.getId());
|
||||
Assert.assertNotNull(listAttributeDB_2);
|
||||
final ListAttributeValue value2_DB_2 = listAttributeDB_2.getValues().iterator().next();
|
||||
|
||||
|
||||
Assert.assertEquals(value2.getId(), value2_DB_2.getId());
|
||||
Assert.assertTrue("Cascade failed", value2.getId().equals(value2_DB_2.getId()));
|
||||
|
||||
}
|
||||
}
|
||||
package com.avaje.tests.inheritance;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.AttributeHolder;
|
||||
import com.avaje.tests.model.basic.ListAttribute;
|
||||
import com.avaje.tests.model.basic.ListAttributeValue;
|
||||
|
||||
public class TestSkippable extends BaseTestCase {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TestSkippable.class);
|
||||
|
||||
/**
|
||||
* Test query.
|
||||
* <p>This test covers the BUG 276. Cascade was not propagating to the ListAttribute because
|
||||
* it was considered safe to skip as it didn't take into account any derived classes
|
||||
* into account with e.g. collections and Cascade options </p>
|
||||
*/
|
||||
@Test
|
||||
public void testQuery() {
|
||||
|
||||
// Setup the data first
|
||||
final ListAttributeValue value1 = new ListAttributeValue();
|
||||
final ListAttributeValue value2 = new ListAttributeValue();
|
||||
|
||||
Ebean.save(value1);
|
||||
Ebean.save(value2);
|
||||
|
||||
final ListAttribute listAttribute = new ListAttribute();
|
||||
listAttribute.add(value1);
|
||||
Ebean.save(listAttribute);
|
||||
logger.info(" -- seeded data");
|
||||
|
||||
final ListAttribute listAttributeDB = Ebean.find(ListAttribute.class, listAttribute.getId());
|
||||
Assert.assertNotNull(listAttributeDB);
|
||||
|
||||
final ListAttributeValue value1_DB = listAttributeDB.getValues().iterator().next();
|
||||
Assert.assertTrue(value1.getId().equals(value1_DB.getId()));
|
||||
logger.info(" -- asserted data in db");
|
||||
|
||||
|
||||
final AttributeHolder holder = new AttributeHolder();
|
||||
holder.add(listAttributeDB);
|
||||
|
||||
Ebean.save(holder);
|
||||
logger.info(" -- saved holder");
|
||||
|
||||
// Now change the M2M listAttribute.values and save the holder
|
||||
// The save should cascade as follows
|
||||
// holder.attributes..ListAttribute.values
|
||||
listAttributeDB.getValues().clear();
|
||||
listAttributeDB.add(value2);
|
||||
|
||||
// Save the holder - should cascade down to the listAtribute and save the values
|
||||
Ebean.save(holder);
|
||||
logger.info(" -- M2M detected delete of value1 and add of value2 ?");
|
||||
|
||||
|
||||
final ListAttribute listAttributeDB_2 = Ebean.find(ListAttribute.class, listAttributeDB.getId());
|
||||
Assert.assertNotNull(listAttributeDB_2);
|
||||
final ListAttributeValue value2_DB_2 = listAttributeDB_2.getValues().iterator().next();
|
||||
|
||||
|
||||
Assert.assertEquals(value2.getId(), value2_DB_2.getId());
|
||||
Assert.assertTrue("Cascade failed", value2.getId().equals(value2_DB_2.getId()));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user