Search in sources :

Example 16 with SmallProject

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);
    }
}
Also used : SmallProject(org.eclipse.persistence.testing.models.jpa.advanced.SmallProject) EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) HugeProject(org.eclipse.persistence.testing.models.jpa.advanced.HugeProject) SpecialHugeProject(org.eclipse.persistence.testing.models.jpa.advanced.SpecialHugeProject) SpecialHugeProject(org.eclipse.persistence.testing.models.jpa.advanced.SpecialHugeProject) SuperLargeProject(org.eclipse.persistence.testing.models.jpa.advanced.SuperLargeProject) LargeProject(org.eclipse.persistence.testing.models.jpa.advanced.LargeProject)

Example 17 with SmallProject

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);
    }
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) SmallProject(org.eclipse.persistence.testing.models.jpa.advanced.SmallProject) Project(org.eclipse.persistence.testing.models.jpa.advanced.Project) SmallProject(org.eclipse.persistence.testing.models.jpa.advanced.SmallProject) LargeProject(org.eclipse.persistence.testing.models.jpa.advanced.LargeProject) EntityManager(jakarta.persistence.EntityManager) LargeProject(org.eclipse.persistence.testing.models.jpa.advanced.LargeProject)

Example 18 with SmallProject

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);
    }
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) SmallProject(org.eclipse.persistence.testing.models.jpa.advanced.SmallProject) Project(org.eclipse.persistence.testing.models.jpa.advanced.Project) SmallProject(org.eclipse.persistence.testing.models.jpa.advanced.SmallProject) LargeProject(org.eclipse.persistence.testing.models.jpa.advanced.LargeProject) EntityManager(jakarta.persistence.EntityManager) Employee(org.eclipse.persistence.testing.models.jpa.advanced.Employee) LargeProject(org.eclipse.persistence.testing.models.jpa.advanced.LargeProject)

Example 19 with SmallProject

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);
    }
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) SmallProject(org.eclipse.persistence.testing.models.jpa.advanced.SmallProject) EntityManager(jakarta.persistence.EntityManager) Employee(org.eclipse.persistence.testing.models.jpa.advanced.Employee) LargeProject(org.eclipse.persistence.testing.models.jpa.advanced.LargeProject)

Example 20 with SmallProject

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);
}
Also used : SmallProject(org.eclipse.persistence.testing.models.jpa.advanced.SmallProject) EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

SmallProject (org.eclipse.persistence.testing.models.jpa.advanced.SmallProject)30 EntityManager (jakarta.persistence.EntityManager)27 LargeProject (org.eclipse.persistence.testing.models.jpa.advanced.LargeProject)21 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)19 Employee (org.eclipse.persistence.testing.models.jpa.advanced.Employee)17 List (java.util.List)13 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)11 Project (org.eclipse.persistence.testing.models.jpa.advanced.Project)11 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)9 SuperLargeProject (org.eclipse.persistence.testing.models.jpa.advanced.SuperLargeProject)9 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)8 HugeProject (org.eclipse.persistence.testing.models.jpa.advanced.HugeProject)8 SpecialHugeProject (org.eclipse.persistence.testing.models.jpa.advanced.SpecialHugeProject)8 JpaQuery (org.eclipse.persistence.jpa.JpaQuery)7 Query (jakarta.persistence.Query)6 ArrayList (java.util.ArrayList)6 ReportQuery (org.eclipse.persistence.queries.ReportQuery)6 Vector (java.util.Vector)5 Expression (org.eclipse.persistence.expressions.Expression)5 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)5