Package javax.persistence

Examples of javax.persistence.PersistenceUtil


    /*
     * Verifies that an entity and attributes are considered loaded if they
     * are in the detached state.
     */
    public void testIsDetachLoaded() {
        PersistenceUtil putil = Persistence.getPersistenceUtil();
        EntityManager em = emf.createEntityManager();
        EagerEntity ee = createEagerEntity();
       
        em.getTransaction().begin();
        em.persist(ee);
        em.getTransaction().commit();
        em.clear();
       
        // should be true, as detached is treated as LoadState.UNKNOWN
        assertEquals(true, putil.isLoaded(ee));
       
        em.close();
    }
View Full Code Here


       
        em.close();
    }

    private void verifyIsLoadedEagerState(boolean loaded) {
        PersistenceUtil putil = Persistence.getPersistenceUtil();
        EntityManager em = emf.createEntityManager();
        EagerEntity ee = createEagerEntity();
       
        // Vfy state is true for the unmanaged entity via
        // PeristenceUtil
        assertEquals(true, putil.isLoaded(ee));
        assertEquals(true, putil.isLoaded(ee,
            "id"));
       
        em.getTransaction().begin();
        em.persist(ee);
        em.getTransaction().commit();
        em.clear();
       
        if (loaded)
            ee = em.find(EagerEntity.class, ee.getId());
        else
            ee = em.getReference(EagerEntity.class, ee.getId());
       
        assertEquals(loaded, putil.isLoaded(ee));
        assertEquals(loaded, putil.isLoaded(ee, "id"));
        assertEquals(loaded, putil.isLoaded(ee, "name"));
        assertEquals(loaded, putil.isLoaded(ee, "eagerEmbed"));
        assertEquals(true, putil.isLoaded(ee, "transField"));
       
        em.close();
    }
View Full Code Here

       
        em.close();
    }

    private void verifyIsLoadedLazyState(boolean loaded) {
        PersistenceUtil putil = Persistence.getPersistenceUtil();
        EntityManager em = emf.createEntityManager();
        LazyEntity le = createLazyEntity();
       
        // Vfy LoadState is true for the unmanaged entity via
        // PersistenceUtil
        assertEquals(true, putil.isLoaded(le));
        assertEquals(true, putil.isLoaded(le,"id"));
       
        em.getTransaction().begin();
        em.persist(le);
        em.getTransaction().commit();
        em.clear();
       
        // Use find or getReference based upon expected state
        if (loaded)
            le = em.find(LazyEntity.class, le.getId());
        else
            le = em.getReference(LazyEntity.class, le.getId());
       
        assertEquals(loaded, putil.isLoaded(le));
        assertEquals(loaded, putil.isLoaded(le, "id"));

        // Name is lazy fetch so it should not be loaded
        assertEquals(false, putil.isLoaded(le, "name"));
        assertEquals(loaded, putil.isLoaded(le, "lazyEmbed"));
        assertEquals(true, putil.isLoaded(le, "transField"));
       
        em.close();
    }
View Full Code Here

    /*
     * Verifies that an entity and attributes are considered loaded if they
     * are assigned by the application.
     */
    public void testIsApplicationLoaded() {
        PersistenceUtil putil = Persistence.getPersistenceUtil();
        EntityManager em = emf.createEntityManager();
        EagerEntity ee = createEagerEntity();
       
        em.getTransaction().begin();
        em.persist(ee);
View Full Code Here

    /*
     * Verifies that an entity and attributes are considered loaded if they
     * are in the detached state.
     */
    public void testIsDetachLoaded() {
        PersistenceUtil putil = Persistence.getPersistenceUtil();
        EntityManager em = emf.createEntityManager();
        EagerEntity ee = createEagerEntity();
       
        em.getTransaction().begin();
        em.persist(ee);
        em.getTransaction().commit();
        em.clear();
       
        // should be true, as detached is treated as LoadState.UNKNOWN
        assertEquals(true, putil.isLoaded(ee));
       
        em.close();
    }
View Full Code Here

       
        em.close();
    }

    private void verifyIsLoadedEagerState(boolean loaded) {
        PersistenceUtil putil = Persistence.getPersistenceUtil();
        EntityManager em = emf.createEntityManager();
        EagerEntity ee = createEagerEntity();
       
        // Vfy state is true for the unmanaged entity via
        // PeristenceUtil
        assertEquals(true, putil.isLoaded(ee));
        assertEquals(true, putil.isLoaded(ee,
            "id"));
       
        em.getTransaction().begin();
        em.persist(ee);
        em.getTransaction().commit();
        em.clear();
       
        if (loaded)
            ee = em.find(EagerEntity.class, ee.getId());
        else
            ee = em.getReference(EagerEntity.class, ee.getId());
       
        assertEquals(loaded, putil.isLoaded(ee));
        assertEquals(loaded, putil.isLoaded(ee, "id"));
        assertEquals(loaded, putil.isLoaded(ee, "name"));
        assertEquals(loaded, putil.isLoaded(ee, "eagerEmbed"));
        assertEquals(true, putil.isLoaded(ee, "transField"));
       
        em.close();
    }
View Full Code Here

       
        em.close();
    }

    private void verifyIsLoadedLazyState(boolean loaded) {
        PersistenceUtil putil = Persistence.getPersistenceUtil();
        EntityManager em = emf.createEntityManager();
        LazyEntity le = createLazyEntity();
       
        // Vfy LoadState is true for the unmanaged entity via
        // PersistenceUtil
        assertEquals(true, putil.isLoaded(le));
        assertEquals(true, putil.isLoaded(le,"id"));
       
        em.getTransaction().begin();
        em.persist(le);
        em.getTransaction().commit();
        em.clear();
       
        // Use find or getReference based upon expected state
        if (loaded)
            le = em.find(LazyEntity.class, le.getId());
        else
            le = em.getReference(LazyEntity.class, le.getId());
       
        assertEquals(loaded, putil.isLoaded(le));
        assertEquals(loaded, putil.isLoaded(le, "id"));

        // Name is lazy fetch so it should not be loaded
        assertEquals(false, putil.isLoaded(le, "name"));
        assertEquals(loaded, putil.isLoaded(le, "lazyEmbed"));
        assertEquals(true, putil.isLoaded(le, "transField"));
       
        em.close();
    }
View Full Code Here

TOP

Related Classes of javax.persistence.PersistenceUtil

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.