Package javax.persistence

Examples of javax.persistence.PersistenceUnitUtil


    // of ids)
    if (entityManager != null && args.get(0).getType().isAnnotationPresent(Entity.class)) {
      Path<?> lhs = (Path<?>) args.get(0);
      Constant<?> rhs = (Constant<?>) args.get(1);
      Metamodel metamodel = entityManager.getMetamodel();
      PersistenceUnitUtil util = entityManager.getEntityManagerFactory().getPersistenceUnitUtil();
      EntityType<?> entityType = metamodel.entity(args.get(0).getType());
      if (entityType.hasSingleIdAttribute()) {
        SingularAttribute<?, ?> id = getIdProperty(entityType);
        // turn lhs into id path
        lhs = new PathImpl(id.getJavaType(), lhs, id.getName());
        // turn rhs into id collection
        Set ids = new HashSet();
        for (Object entity : (Collection<?>) rhs.getConstant()) {
          ids.add(util.getIdentifier(entity));
        }
        rhs = new ConstantImpl(ids);
        args = Arrays.asList(lhs, rhs);
      }
    }
View Full Code Here


       
        assertNotNull(emf2);
        assertNotSame(emf, emf1);
        assertNotSame(emf1, emf2);

        PersistenceUnitUtil puu = emf.getPersistenceUnitUtil();
        PersistenceUnitUtil puu1 = emf1.getPersistenceUnitUtil();
        PersistenceUnitUtil puu2 = emf2.getPersistenceUnitUtil();

        assertNotSame(puu, puu1);
        assertNotSame(puu, puu2);
        assertNotSame(puu1, puu2);
View Full Code Here

            "id"));
    }

   
    private void verifyIsLoadedEagerState(boolean loaded) {
        PersistenceUnitUtil puu = emf.getPersistenceUnitUtil();
        assertSame(emf, puu);
        EntityManager em = emf.createEntityManager();
        EagerEntity ee = createEagerEntity();
       
        // Vfy LoadState is false for the unmanaged entity
        assertEquals(false, puu.isLoaded(ee));
        assertEquals(false, puu.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, puu.isLoaded(ee));
        assertEquals(loaded, puu.isLoaded(ee, "id"));
        assertEquals(loaded, puu.isLoaded(ee, "name"));
        assertEquals(loaded, puu.isLoaded(ee, "eagerEmbed"));
        assertEquals(false, puu.isLoaded(ee, "transField"));
       
        em.close();
    }
View Full Code Here

       
        em.close();
    }

    private void verifyIsLoadedLazyState(boolean loaded) {
        PersistenceUnitUtil puu = emf.getPersistenceUnitUtil();
        assertSame(emf, puu);
        EntityManager em = emf.createEntityManager();
        LazyEntity le = createLazyEntity();
       
        // Vfy LoadState is false for the unmanaged entity
        assertEquals(false, puu.isLoaded(le));
        assertEquals(false, puu.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, puu.isLoaded(le));
        assertEquals(loaded, puu.isLoaded(le, "id"));

        // Name is lazy fetch so it should not be loaded
        assertEquals(false, puu.isLoaded(le, "name"));
        assertEquals(loaded, puu.isLoaded(le, "lazyEmbed"));
        assertEquals(false, puu.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() {
        PersistenceUnitUtil puu = emf.getPersistenceUnitUtil();
        assertSame(emf, puu);
        EntityManager em = emf.createEntityManager();
        EagerEntity ee = createEagerEntity();
       
        em.getTransaction().begin();
View Full Code Here

       
        em.close();
    }

    public void testPCMapEager() {       
        PersistenceUnitUtil puu = emf.getPersistenceUnitUtil();
        EntityManager em = emf.createEntityManager();
       
        MapValEntity mve = new MapValEntity();
        mve.setIntVal(10);
        MapKeyEmbed mke = new MapKeyEmbed();
        mke.setFirstName("Jane");
        mke.setLastName("Doe");
       
        MapEntity me = new MapEntity();

        assertEquals(false, puu.isLoaded(me));
        assertEquals(false, puu.isLoaded(me,
            "mapValEntity"));
        assertEquals(false, puu.isLoaded(me,
            "mapEntities"));

        assertEquals(false, puu.isLoaded(mve));

        // Create a circular ref
        me.setMapValEntity(mve);
        mve.setMapEntity(me);

        HashMap<MapKeyEmbed, MapValEntity> hm =
            new HashMap<MapKeyEmbed, MapValEntity>();
       
        hm.put(mke, mve);
        me.setMapEntities(hm);

        em.getTransaction().begin();
        em.persist(me);
        em.getTransaction().commit();
       
        assertEquals(true, puu.isLoaded(me));
        assertEquals(true, puu.isLoaded(me,
            "mapValEntity"));
        assertEquals(true, puu.isLoaded(me,
            "mapEntities"));

        assertEquals(true, puu.isLoaded(mve));
       
        em.close();
    }
View Full Code Here

        em.persist(a);
        em.getTransaction().begin();
        em.getTransaction().commit();
        em.clear();
       
        PersistenceUnitUtil puu = emf.getPersistenceUnitUtil();
        OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
        // do not fetch emb
        kem.getFetchPlan().resetFetchGroups().removeFetchGroup("default")
            .addField(EntityA_Embed.class, "name")
            .addField(EntityA_Embed.class, "age");
        a = em.find(EntityA_Embed.class, ID);
        assertNotNull(a);
        Embed embed = a.getEmbed();
        assertNull(embed);
        assertFalse(puu.isLoaded(a, "embed"));
    }
View Full Code Here

       
        assertNotNull(emf2);
        assertNotSame(emf, emf1);
        assertNotSame(emf1, emf2);

        PersistenceUnitUtil puu = emf.getPersistenceUnitUtil();
        PersistenceUnitUtil puu1 = emf1.getPersistenceUnitUtil();
        PersistenceUnitUtil puu2 = emf2.getPersistenceUnitUtil();

        assertNotSame(puu, puu1);
        assertNotSame(puu, puu2);
        assertNotSame(puu1, puu2);
View Full Code Here

            "id"));
    }

   
    private void verifyIsLoadedEagerState(boolean loaded) {
        PersistenceUnitUtil puu = emf.getPersistenceUnitUtil();
        assertSame(emf, puu);
        EntityManager em = emf.createEntityManager();
        EagerEntity ee = createEagerEntity();
       
        // Vfy LoadState is false for the unmanaged entity
        assertEquals(false, puu.isLoaded(ee));
        assertEquals(false, puu.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, puu.isLoaded(ee));
        assertEquals(loaded, puu.isLoaded(ee, "id"));
        assertEquals(loaded, puu.isLoaded(ee, "name"));
        assertEquals(loaded, puu.isLoaded(ee, "eagerEmbed"));
        assertEquals(false, puu.isLoaded(ee, "transField"));
       
        em.close();
    }
View Full Code Here

       
        em.close();
    }

    private void verifyIsLoadedLazyState(boolean loaded) {
        PersistenceUnitUtil puu = emf.getPersistenceUnitUtil();
        assertSame(emf, puu);
        EntityManager em = emf.createEntityManager();
        LazyEntity le = createLazyEntity();
       
        // Vfy LoadState is false for the unmanaged entity
        assertEquals(false, puu.isLoaded(le));
        assertEquals(false, puu.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, puu.isLoaded(le));
        assertEquals(loaded, puu.isLoaded(le, "id"));

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

TOP

Related Classes of javax.persistence.PersistenceUnitUtil

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.