use of org.eclipse.persistence.testing.models.jpa.advanced.SmallProject 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.SmallProject in project eclipselink by eclipse-ee4j.
the class CriteriaQueryCastTestSuite method testDowncastInSelect.
public void testDowncastInSelect() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
LargeProject proj = new LargeProject();
proj.setBudget(1000);
proj.setName("test1");
em.persist(proj);
SmallProject sp = new SmallProject();
sp.setName("sp1");
em.persist(sp);
em.flush();
clearCache();
em.clear();
// this would work in the past if TYPE was added to the where clause
// Query query = em.createQuery("Select treat(c as LargeProject).budget from Project c");
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<Project> cq = qb.createQuery(Project.class);
Root<Project> root = cq.from(Project.class);
Root<LargeProject> largeProjectRoot = qb.treat(root, LargeProject.class);
cq.select(largeProjectRoot.get("budget"));
List<Project> resultList = em.createQuery(cq).getResultList();
assertTrue("Incorrect results returned", resultList.size() == 1);
} finally {
if (this.isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.SmallProject in project eclipselink by eclipse-ee4j.
the class CriteriaQueryCastTestSuite method testDowncastManyToManyExpressionBuilder.
public void testDowncastManyToManyExpressionBuilder() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
LargeProject proj = new LargeProject();
proj.setBudget(1000);
proj.setName("test1");
em.persist(proj);
SmallProject sp = new SmallProject();
sp.setName("sp1");
em.persist(sp);
Employee emp = new Employee();
emp.setFirstName("Reggie");
emp.setLastName("Josephson");
emp.addProject(proj);
proj.addTeamMember(emp);
emp.addProject(sp);
sp.addTeamMember(emp);
em.persist(emp);
emp = new Employee();
emp.setFirstName("Ron");
emp.setLastName("Josephson");
emp.addProject(sp);
sp.addTeamMember(emp);
em.persist(emp);
em.flush();
clearCache();
em.clear();
// JpaQuery query = (JpaQuery)em.createQuery("Select p from Project p where treat (p as LargeProject).budget > 100");
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<Project> cq = qb.createQuery(Project.class);
Root<Project> root = cq.from(Project.class);
Root<LargeProject> largeProjectRoot = qb.treat(root, LargeProject.class);
cq.where(qb.gt(largeProjectRoot.get("budget"), 100));
List<Project> resultList = em.createQuery(cq).getResultList();
assertTrue("Incorrect results returned", resultList.size() == 1);
} finally {
if (this.isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.SmallProject in project eclipselink by eclipse-ee4j.
the class CriteriaQueryCastTestSuite method testDowncastManyToManyQueryKey.
public void testDowncastManyToManyQueryKey() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
LargeProject proj = new LargeProject();
proj.setBudget(1000);
proj.setName("test1");
em.persist(proj);
SmallProject sp = new SmallProject();
sp.setName("sp1");
em.persist(sp);
Employee emp = new Employee();
emp.setFirstName("Reggie");
emp.setLastName("Josephson");
emp.addProject(proj);
proj.addTeamMember(emp);
emp.addProject(sp);
sp.addTeamMember(emp);
em.persist(emp);
emp = new Employee();
emp.setFirstName("Ron");
emp.setLastName("Josephson");
emp.addProject(sp);
sp.addTeamMember(emp);
em.persist(emp);
em.flush();
clearCache();
em.clear();
// Query query = em.createQuery("Select e from Employee e join treat(e.projects as LargeProject) p where p.budget > 100");
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<Employee> cq = qb.createQuery(Employee.class);
Root<Employee> root = cq.from(Employee.class);
Join<Object, Object> projectsJoin = root.join("projects");
Join<Object, LargeProject> largeProjectJoin = qb.treat(projectsJoin, LargeProject.class);
cq.where(qb.gt(largeProjectJoin.get("budget"), 100));
List<Employee> resultList = em.createQuery(cq).getResultList();
assertTrue("Incorrect results returned", resultList.size() == 1);
} finally {
if (this.isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.SmallProject in project eclipselink by eclipse-ee4j.
the class JUnitJPQLComplexTestSuite method complexTypeInTest.
public void complexTypeInTest() {
EntityManager em = createEntityManager();
beginTransaction(em);
List expectedResult = getServerSession().readAllObjects(LargeProject.class);
expectedResult.addAll(getServerSession().readAllObjects(SmallProject.class));
clearCache();
String ejbqlString = "select p from Project p where TYPE(p) in(LargeProject, SmallProject)";
List result = em.createQuery(ejbqlString).getResultList();
Assert.assertTrue("complexTypeParameterTest failed", comparer.compareObjects(result, expectedResult));
rollbackTransaction(em);
closeEntityManager(em);
}
Aggregations