use of org.eclipse.persistence.testing.models.jpa.advanced.SpecialHugeProject in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testDeleteAllProjects.
public void testDeleteAllProjects() {
if ((JUnitTestCase.getServerSession()).getPlatform().isSymfoware()) {
getServerSession().logMessage("Test testDeleteAllProjects skipped for this platform, " + "Symfoware doesn't support UpdateAll/DeleteAll on multi-table objects (see rfe 298193).");
return;
}
String errorMsg = "";
SmallProject sp = null;
LargeProject lp = null;
HugeProject hp = null;
SpecialHugeProject slp = null;
EntityManager em = createEntityManager();
beginTransaction(em);
String[] classesToDelete = { "Project", "SmallProject", "LargeProject", "HugeProject", "SpecialHugeProject" };
try {
for (int i = 0; i < classesToDelete.length; i++) {
if (sp == null) {
sp = new SmallProject();
em.persist(sp);
}
if (lp == null) {
lp = new LargeProject();
em.persist(lp);
}
if (hp == null) {
hp = new HugeProject();
em.persist(hp);
}
if (slp == null) {
slp = new SpecialHugeProject();
em.persist(slp);
}
em.flush();
String classToDelete = classesToDelete[i];
em.createQuery("DELETE FROM " + classToDelete + " p").executeUpdate();
em.clear();
sp = em.find(SmallProject.class, sp.getId());
lp = em.find(LargeProject.class, lp.getId());
hp = em.find(HugeProject.class, hp.getId());
slp = em.find(SpecialHugeProject.class, slp.getId());
String unexpectedlyDeleted = "";
String unexpectedlyNotDeleted = "";
if (sp == null) {
if (classToDelete.equals("LargeProject") || classToDelete.equals("HugeProject") || classToDelete.equals("SpecialHugeProject")) {
unexpectedlyDeleted += "SmallProject; ";
}
} else {
if (classToDelete.equals("Project") || classToDelete.equals("SmallProject")) {
unexpectedlyNotDeleted += "SmallProject; ";
}
}
if (lp == null) {
if (classToDelete.equals("SmallProject") || classToDelete.equals("HugeProject") || classToDelete.equals("SpecialHugeProject")) {
unexpectedlyDeleted += "LargeProject; ";
}
} else {
if (classToDelete.equals("Project") || classToDelete.equals("LargeProject")) {
unexpectedlyNotDeleted += "LargeProject; ";
}
}
if (hp == null) {
if (classToDelete.equals("SmallProject") || classToDelete.equals("SpecialHugeProject")) {
unexpectedlyDeleted += "HugeProject; ";
}
} else {
if (classToDelete.equals("Project") || classToDelete.equals("LargeProject") || classToDelete.equals("HugeProject")) {
unexpectedlyNotDeleted += "HugeProject; ";
}
}
if (slp == null) {
if (classToDelete.equals("SmallProject")) {
unexpectedlyDeleted += "SpecialHugeProject; ";
}
} else {
if (classToDelete.equals("Project") || classToDelete.equals("LargeProject") || classToDelete.equals("HugeProject") || classToDelete.equals("SpecialHugeProject")) {
unexpectedlyNotDeleted += "SpecialHugeProject; ";
}
}
String localErrorMsg = "";
if (unexpectedlyDeleted.length() > 0) {
localErrorMsg += "\n\t\tUnexpectedlyDeleted: " + unexpectedlyDeleted;
}
if (unexpectedlyNotDeleted.length() > 0) {
localErrorMsg += "\n\t\tUnexpectedlyNotDeleted: " + unexpectedlyNotDeleted;
}
if (localErrorMsg.length() > 0) {
errorMsg += "\n\tDELETE FROM " + classToDelete + " p" + localErrorMsg;
}
}
} finally {
closeEntityManagerAndTransaction(em);
}
if (errorMsg.length() > 0) {
fail(errorMsg);
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.SpecialHugeProject in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method createProjectsWithName.
/*this creates project types both with and without a teamLeader if one is passed in, and
* returns the number of project types created (2x the number of project instances will have been created if a team lead is specified)
*/
protected int createProjectsWithName(String name, Employee teamLeader, EntityManager em) {
Project p = new Project();
p.setName(name);
em.persist(p);
SmallProject sp = new SmallProject();
sp.setName(name);
em.persist(sp);
LargeProject lp = new LargeProject();
lp.setName(name);
em.persist(lp);
HugeProject hp = new HugeProject();
hp.setName(name);
em.persist(hp);
SpecialHugeProject shp = new SpecialHugeProject();
shp.setName(name);
em.persist(shp);
if (teamLeader != null) {
Project pWTL = new Project();
pWTL.setName(name);
pWTL.setTeamLeader(teamLeader);
em.persist(pWTL);
SmallProject spWTL = new SmallProject();
spWTL.setName(name);
spWTL.setTeamLeader(teamLeader);
em.persist(spWTL);
LargeProject lpWTL = new LargeProject();
lpWTL.setName(name);
lpWTL.setTeamLeader(teamLeader);
em.persist(lpWTL);
HugeProject hpWTL = new HugeProject();
hpWTL.setName(name);
hpWTL.setTeamLeader(teamLeader);
em.persist(hpWTL);
SpecialHugeProject shpWTL = new SpecialHugeProject();
shpWTL.setName(name);
shpWTL.setTeamLeader(teamLeader);
em.persist(shpWTL);
}
// change this if this method creates a new project subclass type.
return 5;
}
Aggregations