Package org.apache.openjpa.persistence

Examples of org.apache.openjpa.persistence.FetchPlan


  }
 
  // OPENJPA-2413: FetchPlan.clearFetchGroups() does not retain "default" in list of active Fetch Groups.
  public void testClearFetchPlan() {
      OpenJPAEntityManager em = emf.createEntityManager();
      FetchPlan fp = em.getFetchPlan();

      // Make sure "default" is present in the list of active FetchGroups
      Collection<String> fetchGroups = fp.getFetchGroups();
      assertNotNull(fetchGroups);
      assertTrue(fetchGroups.contains(FetchGroup.NAME_DEFAULT));

      // Clear all active FetchGroups, only "default" should remain.
      fp.clearFetchGroups();
      Collection<String> fetchGroupsAfterClear = fp.getFetchGroups();
      assertNotNull(fetchGroupsAfterClear);
      assertTrue(fetchGroupsAfterClear.contains(FetchGroup.NAME_DEFAULT));   

      // Should still be able to remove the "default" FetchGroup
      fp.removeFetchGroup(FetchGroup.NAME_DEFAULT);
      Collection<String> fetchGroupsAfterRemove = fp.getFetchGroups();
      assertNotNull(fetchGroupsAfterClear);
      assertTrue(fetchGroupsAfterClear.isEmpty());   
  }
View Full Code Here


    public void test() {
        OpenJPAEntityManagerSPI em = emf.createEntityManager();
        StoreManager store = ((EntityManagerImpl) em).getBroker().getStoreManager().getDelegate();

        FetchPlan fp = getFetchPlan(em);
        try {
            sql.clear();

            if (store instanceof JDBCStoreManager == false) {
                fail("StoreManager is not an instanceof JDBCStoreManager");
            }
            // Set this JDBCFetchPlan property so that we will select FKs for fields that are in the DFG, but not
            // included in the current load. If this property isn't set, the FK for eagerOneToOneOwner will not be
            // selected.
             ((JDBCFetchPlan)fp).setIgnoreDfgForFkSelect(true);
            // Remove all relationships
            fp.removeField(OptSelectEntity.class, "eagerOneToOne");
            fp.removeField(OptSelectEntity.class, "eagerOneToOneOwner");
            fp.removeField(OptSelectEntity.class, "lazyOneToOne");
            fp.removeField(OptSelectEntity.class, "lazyOneToOneOwner");

            OptSelectEntity ee1 = em.find(OptSelectEntity.class, e1.getId());

            // Make sure our sql has no joins
            assertEquals(1, sql.size());
View Full Code Here

        }
    }

    private FetchPlan getFetchPlan(OpenJPAEntityManagerSPI em) {
        MetaDataRepository mdr = em.getConfiguration().getMetaDataRepositoryInstance();
        FetchPlan fp = em.pushFetchPlan();
        fp.removeFetchGroups(fp.getFetchGroups());
        for (Class<?> cls : new Class<?>[] { OptSelectEntity.class }) {
            ClassMetaData cmd = mdr.getMetaData(cls, null, true);
            for (FieldMetaData fmd : cmd.getFields()) {
                fp.addField(cls, fmd.getName());
            }
        }
        return fp;
    }
View Full Code Here

            assertClausePresentInSQL(lockClause, em.createNamedQuery("findEmployeeById").setParameter("id", 0));
        }
       
        OpenJPAEntityManager oem = (OpenJPAEntityManager)em;
        OpenJPAQuery<?> q = oem.createNamedQuery("findEmployeeById").setParameter("id", 0);
        FetchPlan fp = q.getFetchPlan();
        fp.setReadLockMode(LockModeType.NONE);

        em.getTransaction().commit();
    }
View Full Code Here

    public void testForUpdateClauseAbsentInQueryWithFetchPlanNoneLockMode() {
        OpenJPAEntityManagerSPI em = emf.createEntityManager();
        em.getTransaction().begin();       
        lockClause = getForUpdateClause();
        OpenJPAQuery<?> q = em.createNamedQuery("findEmployeeById").setParameter("id", 0);
        FetchPlan fp = q.getFetchPlan();
        fp.setReadLockMode(LockModeType.NONE);
        assertClauseAbsentInSQL(lockClause, q);
       
        q = em.createNamedQuery("findEmployeeByIdWithNoLock").setParameter("id", 0);
        fp = q.getFetchPlan();
        fp.setReadLockMode(LockModeType.NONE);
        assertClauseAbsentInSQL(lockClause, q);
       
        em.getTransaction().commit();
    }
View Full Code Here

        assertClauseAbsentInSQL(lockClause, em.createNamedQuery("findEmployeeById").setParameter("id", 0));
        assertClauseAbsentInSQL(lockClause, em.createNamedQuery("findEmployeeById").setParameter("id", 0));
       
        OpenJPAEntityManager oem = (OpenJPAEntityManager)em;
        OpenJPAQuery<?> q = oem.createNamedQuery("findEmployeeById").setParameter("id", 0);
        FetchPlan fp = q.getFetchPlan();
        fp.setReadLockMode(LockModeType.NONE);

        em.getTransaction().commit();
        em.close();
    }
View Full Code Here

    public void testForUpdateClauseAbsentInQueryWithFetchPlanNoneLockMode() {
        OpenJPAEntityManagerSPI em = emf.createEntityManager();
        em.getTransaction().begin();
        lockClause = getForUpdateClause();       
        OpenJPAQuery<?> q = em.createNamedQuery("findEmployeeById").setParameter("id", 0);
        FetchPlan fp = q.getFetchPlan();
        fp.setReadLockMode(LockModeType.NONE);
        assertClauseAbsentInSQL(lockClause, q);
       
        q = em.createNamedQuery("findEmployeeByIdWithNoLock").setParameter("id", 0);
        fp = q.getFetchPlan();
        fp.setReadLockMode(LockModeType.NONE);
        assertClauseAbsentInSQL(lockClause, q);
       
        em.getTransaction().commit();
        em.close();
    }
View Full Code Here

    /**
     * Verify the "default" fetch plan that models JPA's expected eager/lazy fetch load behaviors.
     */
    public void testDefaultFetchPlan001() {
        OpenJPAEntityManager em = emf.createEntityManager();
        FetchPlan fp = em.getFetchPlan();
        assertNotNull(fp);
        assertNotNull(fp.getFetchGroups());
        assertEquals(1, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
       
        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
                .getBroker()
                .getFetchConfiguration();
        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
View Full Code Here

     * Verify that adding a FetchGroup to the fetch plan makes a normally JPA determined lazy loaded
     * field to behave as an eagerly loaded field.
     */
    public void testDefaultFetchPlan002() {
        OpenJPAEntityManager em = emf.createEntityManager();
        FetchPlan fp = em.getFetchPlan();
        assertNotNull(fp);
       
        fp.addFetchGroup("DescFetchGroup");
        assertNotNull(fp.getFetchGroups());
        assertEquals(2, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
       
        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
                .getBroker()
                .getFetchConfiguration();
        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
View Full Code Here

     * Verify that adding a field to the fetch plan makes a normally JPA determined lazy loaded
     * field to behave as an eagerly loaded field.
     */
    public void testDefaultFetchPlan003() {
        OpenJPAEntityManager em = emf.createEntityManager();
        FetchPlan fp = em.getFetchPlan();
        assertNotNull(fp);
       
        fp.addField(empDescriptionFieldStr);
        assertNotNull(fp.getFetchGroups());
        assertEquals(1, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertTrue(fp.getFields().contains(empDescriptionFieldStr));
       
        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
                .getBroker()
                .getFetchConfiguration();
        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
View Full Code Here

TOP

Related Classes of org.apache.openjpa.persistence.FetchPlan

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.