Package javax.persistence.spi

Examples of javax.persistence.spi.ProviderUtil


    @Override
    public boolean isLoaded(Object entity)
    {
      for (PersistenceProvider provider : _providerList) {
        try {
          ProviderUtil util = provider.getProviderUtil();
     
          if (util != null) {
            LoadState state = util.isLoaded(entity);
         
            if (state == LoadState.LOADED)
              return true;
            else if (state == LoadState.NOT_LOADED)
              return false;
View Full Code Here


        verifyIsLoadedEagerState(LoadState.NOT_LOADED);      
    }

   
    private void verifyIsLoadedEagerState(LoadState state) {
        ProviderUtil pu = getProviderUtil();
        EntityManager em = emf.createEntityManager();
        EagerEntity ee = createEagerEntity(true);
       
        // Vfy LoadState is unknown for the unmanaged entity
        assertEquals(LoadState.UNKNOWN, pu.isLoaded(ee));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithReference(ee,
            "id"));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithoutReference(ee,
            "id"));
       
        em.getTransaction().begin();
        em.persist(ee);
        em.getTransaction().commit();
        em.clear();
       
        if (state == LoadState.LOADED)
            ee = em.find(EagerEntity.class, ee.getId());
        else
            ee = em.getReference(EagerEntity.class, ee.getId());
       
        assertEquals(state, pu.isLoaded(ee));
        assertEquals(state, pu.isLoadedWithReference(ee,
            "id"));
        assertEquals(state, pu.isLoadedWithoutReference(ee,
            "id"));
        assertEquals(state, pu.isLoadedWithReference(ee,
            "name"));
        assertEquals(state, pu.isLoadedWithoutReference(ee,
            "name"));
        assertEquals(state, pu.isLoadedWithReference(ee,
            "eagerEmbed"));
        assertEquals(state, pu.isLoadedWithoutReference(ee,
            "eagerEmbed"));
        assertEquals(state, pu.isLoadedWithReference(ee,
            "eagerEmbedColl"));
        assertEquals(state, pu.isLoadedWithoutReference(ee,
            "eagerEmbedColl"));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithReference(ee,
            "transField"));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithoutReference(ee,
            "transField"));
       
        em.close();
    }
View Full Code Here

       
        em.close();
    }

    private void verifyIsLoadedLazyState(LoadState state) {
        ProviderUtil pu = getProviderUtil();
        EntityManager em = emf.createEntityManager();
        LazyEntity le = createLazyEntity();
       
        // Vfy LoadState is unknown for the unmanaged entity
        assertEquals(LoadState.UNKNOWN, pu.isLoaded(le));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithReference(le,
            "id"));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithoutReference(le,
            "id"));
       
        em.getTransaction().begin();
        em.persist(le);
        em.getTransaction().commit();
        em.clear();
       
        // Use find or getReference based upon expected state
        if (state == LoadState.LOADED)
            le = em.find(LazyEntity.class, le.getId());
        else
            le = em.getReference(LazyEntity.class, le.getId());
       
        assertEquals(state, pu.isLoaded(le));
        assertEquals(state, pu.isLoadedWithReference(le,
            "id"));
        assertEquals(state, pu.isLoadedWithoutReference(le,
            "id"));
        // Name is lazy fetch so it should not be loaded
        assertEquals(LoadState.NOT_LOADED, pu.isLoadedWithReference(le,
            "name"));
        assertEquals(LoadState.NOT_LOADED, pu.isLoadedWithoutReference(le,
            "name"));
        assertEquals(state, pu.isLoadedWithReference(le,
            "lazyEmbed"));
        assertEquals(state, pu.isLoadedWithoutReference(le,
            "lazyEmbed"));
        // lazyEmbedColl is lazy fetch so it should not be loaded
        assertEquals(LoadState.NOT_LOADED, pu.isLoadedWithReference(le,
            "lazyEmbedColl"));
        assertEquals(LoadState.NOT_LOADED, pu.isLoadedWithoutReference(le,
            "lazyEmbedColl"));       
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithReference(le,
            "transField"));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithoutReference(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() {
        ProviderUtil pu = getProviderUtil();
        EntityManager em = emf.createEntityManager();
        EagerEntity ee = createEagerEntity(true);
       
        em.getTransaction().begin();
        em.persist(ee);
View Full Code Here

       
    /*
     * Verifies that an entity not managed by a PU
     */
    public void testIsLoadedUnknown() {
        ProviderUtil pu = getProviderUtil();
       
        EagerEntity ee = new EagerEntity();
       
        assertEquals(LoadState.UNKNOWN, pu.isLoaded(ee));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithReference(ee,
            "id"));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithoutReference(ee,
            "id"));       
    }
View Full Code Here

            "transField"));       
    }
   
    private ProviderUtil getProviderUtil() {
        PersistenceProvider pp = new PersistenceProviderImpl();
        ProviderUtil pu = pp.getProviderUtil();
        return pu;
    }
View Full Code Here

        verifyIsLoadedEagerState(LoadState.NOT_LOADED);      
    }

   
    private void verifyIsLoadedEagerState(LoadState state) {
        ProviderUtil pu = getProviderUtil();
        EntityManager em = emf.createEntityManager();
        EagerEntity ee = createEagerEntity(true);
       
        // Vfy LoadState is unknown for the unmanaged entity
        assertEquals(LoadState.UNKNOWN, pu.isLoaded(ee));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithReference(ee,
            "id"));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithoutReference(ee,
            "id"));
       
        em.getTransaction().begin();
        em.persist(ee);
        em.getTransaction().commit();
        em.clear();
       
        if (state == LoadState.LOADED)
            ee = em.find(EagerEntity.class, ee.getId());
        else
            ee = em.getReference(EagerEntity.class, ee.getId());
       
        assertEquals(state, pu.isLoaded(ee));
        assertEquals(state, pu.isLoadedWithReference(ee,
            "id"));
        assertEquals(state, pu.isLoadedWithoutReference(ee,
            "id"));
        assertEquals(state, pu.isLoadedWithReference(ee,
            "name"));
        assertEquals(state, pu.isLoadedWithoutReference(ee,
            "name"));
        assertEquals(state, pu.isLoadedWithReference(ee,
            "eagerEmbed"));
        assertEquals(state, pu.isLoadedWithoutReference(ee,
            "eagerEmbed"));
        assertEquals(state, pu.isLoadedWithReference(ee,
            "eagerEmbedColl"));
        assertEquals(state, pu.isLoadedWithoutReference(ee,
            "eagerEmbedColl"));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithReference(ee,
            "transField"));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithoutReference(ee,
            "transField"));
       
        em.close();
    }
View Full Code Here

       
        em.close();
    }

    private void verifyIsLoadedLazyState(LoadState state) {
        ProviderUtil pu = getProviderUtil();
        EntityManager em = emf.createEntityManager();
        LazyEntity le = createLazyEntity();
       
        // Vfy LoadState is unknown for the unmanaged entity
        assertEquals(LoadState.UNKNOWN, pu.isLoaded(le));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithReference(le,
            "id"));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithoutReference(le,
            "id"));
       
        em.getTransaction().begin();
        em.persist(le);
        em.getTransaction().commit();
        em.clear();
       
        // Use find or getReference based upon expected state
        if (state == LoadState.LOADED)
            le = em.find(LazyEntity.class, le.getId());
        else
            le = em.getReference(LazyEntity.class, le.getId());
       
        assertEquals(state, pu.isLoaded(le));
        assertEquals(state, pu.isLoadedWithReference(le,
            "id"));
        assertEquals(state, pu.isLoadedWithoutReference(le,
            "id"));
        // Name is lazy fetch so it should not be loaded
        assertEquals(LoadState.NOT_LOADED, pu.isLoadedWithReference(le,
            "name"));
        assertEquals(LoadState.NOT_LOADED, pu.isLoadedWithoutReference(le,
            "name"));
        assertEquals(state, pu.isLoadedWithReference(le,
            "lazyEmbed"));
        assertEquals(state, pu.isLoadedWithoutReference(le,
            "lazyEmbed"));
        // lazyEmbedColl is lazy fetch so it should not be loaded
        assertEquals(LoadState.NOT_LOADED, pu.isLoadedWithReference(le,
            "lazyEmbedColl"));
        assertEquals(LoadState.NOT_LOADED, pu.isLoadedWithoutReference(le,
            "lazyEmbedColl"));       
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithReference(le,
            "transField"));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithoutReference(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() {
        ProviderUtil pu = getProviderUtil();
        EntityManager em = emf.createEntityManager();
        EagerEntity ee = createEagerEntity(true);
       
        em.getTransaction().begin();
        em.persist(ee);
View Full Code Here

       
    /*
     * Verifies that an entity not managed by a PU
     */
    public void testIsLoadedUnknown() {
        ProviderUtil pu = getProviderUtil();
       
        EagerEntity ee = new EagerEntity();
       
        assertEquals(LoadState.UNKNOWN, pu.isLoaded(ee));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithReference(ee,
            "id"));
        assertEquals(LoadState.UNKNOWN, pu.isLoadedWithoutReference(ee,
            "id"));       
    }
View Full Code Here

TOP

Related Classes of javax.persistence.spi.ProviderUtil

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.