Search in sources :

Example 1 with HugeProject

use of org.eclipse.persistence.testing.models.jpa.advanced.HugeProject in project eclipselink by eclipse-ee4j.

the class AdvancedJPAJunitTest method testNonTriggerLazyForSProc.

// Test for lazy OneToOne relation not getting triggered
public void testNonTriggerLazyForSProc() {
    if (!supportsStoredProcedures()) {
        return;
    }
    Employee employee2;
    EntityManager em = createEntityManager();
    beginTransaction(em);
    try {
        Employee employee1 = new Employee();
        employee1.setFirstName("Me");
        employee1.setId(11);
        HugeProject hp = new HugeProject("big proj");
        employee1.setHugeProject(hp);
        em.persist(hp);
        em.persist(employee1);
        commitTransaction(em);
        em.clear();
        beginTransaction(em);
        Query q = em.createNamedQuery("SProcEmployee");
        q.setParameter("EMP_ID", employee1.getId());
        q.setFlushMode(FlushModeType.COMMIT);
        q.setHint(QueryHints.REFRESH, HintValues.TRUE);
        q.setHint(QueryHints.REFRESH_CASCADE, CascadePolicy.CascadeByMapping);
        employee2 = (Employee) q.getSingleResult();
        ProviderUtil util = (new PersistenceProvider()).getProviderUtil();
        // status can be LoadState.NOT_LOADED or LoadState.UNKNOWN
        assertFalse("ProviderUtil returned LOADED for isLoaded for hugeProject when it should not.", util.isLoadedWithReference(employee2, "hugeProject").equals(LoadState.LOADED));
    } catch (RuntimeException e) {
        // Re-throw exception to ensure stacktrace appears in test result.
        throw e;
    } finally {
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        closeEntityManager(em);
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) ProviderUtil(jakarta.persistence.spi.ProviderUtil) Employee(org.eclipse.persistence.testing.models.jpa.advanced.Employee) Query(jakarta.persistence.Query) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) DoesExistQuery(org.eclipse.persistence.queries.DoesExistQuery) TypedQuery(jakarta.persistence.TypedQuery) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) HugeProject(org.eclipse.persistence.testing.models.jpa.advanced.HugeProject) PersistenceProvider(org.eclipse.persistence.jpa.PersistenceProvider)

Example 2 with HugeProject

use of org.eclipse.persistence.testing.models.jpa.advanced.HugeProject 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 3 with HugeProject

use of org.eclipse.persistence.testing.models.jpa.advanced.HugeProject 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;
}
Also used : Project(org.eclipse.persistence.testing.models.jpa.advanced.Project) HugeProject(org.eclipse.persistence.testing.models.jpa.advanced.HugeProject) SmallProject(org.eclipse.persistence.testing.models.jpa.advanced.SmallProject) SuperLargeProject(org.eclipse.persistence.testing.models.jpa.advanced.SuperLargeProject) SpecialHugeProject(org.eclipse.persistence.testing.models.jpa.advanced.SpecialHugeProject) LargeProject(org.eclipse.persistence.testing.models.jpa.advanced.LargeProject) SmallProject(org.eclipse.persistence.testing.models.jpa.advanced.SmallProject) 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 4 with HugeProject

use of org.eclipse.persistence.testing.models.jpa.advanced.HugeProject in project eclipselink by eclipse-ee4j.

the class JUnitCriteriaSimpleTestSuiteBase method testEmptyLeftJoinInCriteriaQuery.

// Bug# 412582 - CriteriaBuilder.construct(...) fails with JoinType.LEFT and null.
/**
 * Verify criteria query with left outer join on empty table.
 */
public void testEmptyLeftJoinInCriteriaQuery() {
    EntityManager em = createEntityManager();
    // Make sure that no HugeProject instance exists.
    TypedQuery<Long> q1 = em.createQuery("SELECT COUNT(hp.id) FROM HugeProject hp", Long.class);
    Long count = q1.getSingleResult();
    assertEquals("There should be no HugeProject", 0, count.intValue());
    // Execute left outer join on empty table as criteria query.
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<EntityDTO> criteriaQuery = builder.createQuery(EntityDTO.class);
    Root<Employee> rootEmployee = wrapper.from(criteriaQuery, Employee.class);
    Join<Employee, HugeProject> joinHugeProject = wrapper.join(rootEmployee, Employee_hugeProject, JoinType.LEFT);
    criteriaQuery.select(builder.construct(EntityDTO.class, rootEmployee, joinHugeProject));
    TypedQuery<EntityDTO> query = em.createQuery(criteriaQuery);
    query.getResultList();
    closeEntityManager(em);
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) Employee(org.eclipse.persistence.testing.models.jpa.advanced.Employee) HugeProject(org.eclipse.persistence.testing.models.jpa.advanced.HugeProject)

Aggregations

HugeProject (org.eclipse.persistence.testing.models.jpa.advanced.HugeProject)4 EntityManager (jakarta.persistence.EntityManager)3 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)3 Employee (org.eclipse.persistence.testing.models.jpa.advanced.Employee)2 LargeProject (org.eclipse.persistence.testing.models.jpa.advanced.LargeProject)2 SmallProject (org.eclipse.persistence.testing.models.jpa.advanced.SmallProject)2 SpecialHugeProject (org.eclipse.persistence.testing.models.jpa.advanced.SpecialHugeProject)2 SuperLargeProject (org.eclipse.persistence.testing.models.jpa.advanced.SuperLargeProject)2 Query (jakarta.persistence.Query)1 TypedQuery (jakarta.persistence.TypedQuery)1 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)1 ProviderUtil (jakarta.persistence.spi.ProviderUtil)1 PersistenceProvider (org.eclipse.persistence.jpa.PersistenceProvider)1 DatabaseQuery (org.eclipse.persistence.queries.DatabaseQuery)1 DoesExistQuery (org.eclipse.persistence.queries.DoesExistQuery)1 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)1 Project (org.eclipse.persistence.testing.models.jpa.advanced.Project)1