Package org.apache.openjpa.persistence.datacache.common.apps

Examples of org.apache.openjpa.persistence.datacache.common.apps.PObject


            ? emfWithDataCache : emfWithoutDataCache;
        emf.getConfiguration().setRefreshFromDataCache(refreshFromDataCache);
        OpenJPAEntityManagerSPI em = emf.createEntityManager();
       
        em.getTransaction().begin();
        PObject pc = new PObject();
        pc.setName(useDataCache ? MARKER_DATACACHE : MARKER_CACHE);
        em.persist(pc);
        em.getTransaction().commit();
       
        Object oid = pc.getId();
        StoreCache dataCache = emf.getStoreCache();
        assertEquals(useDataCache, dataCache.contains(PObject.class, oid));
       
        // Modify the record in the database in a separate transaction using
        // native SQL so that the in-memory instance is not altered
        em.getTransaction().begin();
        String sql = "UPDATE L2_PObject SET NAME='" + MARKER_DATABASE
        + "' WHERE id=" + oid;
        em.createNativeQuery(sql).executeUpdate();
        em.getTransaction().commit();
       
        assertEquals(useDataCache ? MARKER_DATACACHE : MARKER_CACHE,
                pc.getName());
       
        em.getTransaction().begin();
        if (makeDirtyBeforeRefresh) {
            pc.setName(MARKER_DIRTY_CACHE);
        }
        assertEquals(makeDirtyBeforeRefresh, em.isDirty(pc));

        if (lock != null) {
            ((EntityManagerImpl)em).getFetchPlan().setReadLockMode(lock);
        }
        em.refresh(pc);
       
        assertEquals(expected, pc.getName());
        em.getTransaction().commit();
    }
View Full Code Here


            ? emfWithDataCache : emfWithoutDataCache;
           
        OpenJPAEntityManagerSPI em = emf.createEntityManager();
       
        em.getTransaction().begin();
        PObject pc = new PObject();
        pc.setName(useDataCache ? MARKER_DATACACHE : MARKER_CACHE);
        em.persist(pc);
        em.getTransaction().commit();
       
        Object oid = pc.getId();
        StoreCache dataCache = emf.getStoreCache();
        assertEquals(useDataCache, dataCache.contains(PObject.class, oid));
       
        // delete the record in the database in a separate transaction using
        // native SQL so that the in-memory instance is not altered
        em.getTransaction().begin();
        String sql = "DELETE FROM L2_PObject WHERE id="+oid;
        em.createNativeQuery(sql).executeUpdate();
        em.getTransaction().commit();
       
        // the object cache does not know that the record was deleted
        assertTrue(em.contains(pc));
        // nor does the data cache
        assertEquals(useDataCache, dataCache.contains(PObject.class, oid));
       
        /**
         * refresh behavior no more depends on current lock. Refresh
         * will always attempt to fetch the instance from database
         * raising EntityNotFoundException.
         *  
         */
        em.getTransaction().begin();
        em.getFetchPlan().setReadLockMode(lock);
        if (dirty)
            pc.setName("Dirty Name");
        try {
            em.refresh(pc);
            if (expectedExceptionType != null) {
                fail("expected " + expectedExceptionType.getSimpleName() +
                        " for PObject:" + oid);
View Full Code Here

    OpenJPAConfiguration conf = emf.getConfiguration();
   
    // ensure that PObject is in metadata repository
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    PObject pc = new PObject();
    em.persist(pc);
   
    int oldValue = conf.getDataCacheTimeout();
   
    ClassMetaData meta = conf.getMetaDataRepositoryInstance()
View Full Code Here

    OpenJPAConfiguration conf = emf.getConfiguration();
   
    // ensure that PObject is in metadata repository
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    PObject pc = new PObject();
    em.persist(pc);
   
    int oldValue = conf.getDataCacheTimeout();
   
    ClassMetaData meta = conf.getMetaDataRepositoryInstance()
View Full Code Here

    OpenJPAConfiguration conf = emf.getConfiguration();
   
    // ensure that PObject is in metadata repository
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    PObject pc = new PObject();
    em.persist(pc);
   
    int oldValue = conf.getDataCacheTimeout();
   
    ClassMetaData meta = conf.getMetaDataRepositoryInstance()
View Full Code Here

      ? emfWithDataCache : emfWithoutDataCache;
    emf.getConfiguration().setRefreshFromDataCache(refreshFromDataCache);
    OpenJPAEntityManagerSPI em = emf.createEntityManager();
       
    em.getTransaction().begin();
    PObject pc = new PObject();
    pc.setName(useDataCache ? MARKER_DATACACHE : MARKER_CACHE);
    em.persist(pc);
    em.getTransaction().commit();
   
    Object oid = pc.getId();
    StoreCache dataCache = emf.getStoreCache();
    assertEquals(useDataCache, dataCache.contains(PObject.class, oid));
   
    // Modify the record in the database in a separate transaction using
    // native SQL so that the in-memory instance is not altered
    em.getTransaction().begin();
    String sql = "UPDATE POBJECT SET NAME='"+ MARKER_DATABASE +"' WHERE id="+oid;
    em.createNativeQuery(sql).executeUpdate();
    em.getTransaction().commit();
   
    assertEquals(useDataCache ? MARKER_DATACACHE : MARKER_CACHE, pc.getName());
   
    em.getTransaction().begin();
    if (makeDirtyBeforeRefresh) {
      pc.setName(MARKER_DIRTY_CACHE);
    }
    assertEquals(makeDirtyBeforeRefresh, em.isDirty(pc));

    if (lock != null) {
      ((EntityManagerImpl)em).getFetchPlan().setReadLockMode(lock);
    }
    em.refresh(pc);
   
    assertEquals(expected, pc.getName());
    em.getTransaction().commit();
  }
View Full Code Here

      ? emfWithDataCache : emfWithoutDataCache;
     
    OpenJPAEntityManagerSPI em = emf.createEntityManager();
       
    em.getTransaction().begin();
    PObject pc = new PObject();
    pc.setName(useDataCache ? MARKER_DATACACHE : MARKER_CACHE);
    em.persist(pc);
    em.getTransaction().commit();
   
    Object oid = pc.getId();
    StoreCache dataCache = emf.getStoreCache();
    assertEquals(useDataCache, dataCache.contains(PObject.class, oid));
   
    // delete the record in the database in a separate transaction using
    // native SQL so that the in-memory instance is not altered
    em.getTransaction().begin();
    String sql = "DELETE FROM POBJECT WHERE id="+oid;
    em.createNativeQuery(sql).executeUpdate();
    em.getTransaction().commit();
   
    // the object cache does not know that the record was deleted
    assertTrue(em.contains(pc));
    // nor does the data cache
    assertEquals(useDataCache, dataCache.contains(PObject.class, oid));
   
    /**
     * refresh behavior no more depends on current lock. Refresh
     * will always attempt to fetch the instance from database
     * raising EntityNotFoundException.
     *  
     */
    em.getTransaction().begin();
    em.getFetchPlan().setReadLockMode(lock);
    if (dirty)
      pc.setName("Dirty Name");
    try {
      em.refresh(pc);
      if (expectedExceptionType != null) {
        fail("expected " + expectedExceptionType.getSimpleName() +
            " for PObject:" + oid);
View Full Code Here

    OpenJPAConfiguration conf = emf.getConfiguration();
   
    // ensure that PObject is in metadata repository
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    PObject pc = new PObject();
    em.persist(pc);
   
    int oldValue = conf.getDataCacheTimeout();
   
    ClassMetaData meta = conf.getMetaDataRepositoryInstance()
View Full Code Here

            ? emfWithDataCache : emfWithoutDataCache;
        emf.getConfiguration().setRefreshFromDataCache(refreshFromDataCache);
        OpenJPAEntityManagerSPI em = emf.createEntityManager();
       
        em.getTransaction().begin();
        PObject pc = new PObject();
        pc.setName(useDataCache ? MARKER_DATACACHE : MARKER_CACHE);
        em.persist(pc);
        em.getTransaction().commit();
       
        Object oid = pc.getId();
        StoreCache dataCache = emf.getStoreCache();
        assertEquals(useDataCache, dataCache.contains(PObject.class, oid));
       
        // Modify the record in the database in a separate transaction using
        // native SQL so that the in-memory instance is not altered
        em.getTransaction().begin();
        String sql = "UPDATE L2_PObject SET NAME='" + MARKER_DATABASE
        + "' WHERE id=" + oid;
        em.createNativeQuery(sql).executeUpdate();
        em.getTransaction().commit();
       
        assertEquals(useDataCache ? MARKER_DATACACHE : MARKER_CACHE,
                pc.getName());
       
        em.getTransaction().begin();
        if (makeDirtyBeforeRefresh) {
            pc.setName(MARKER_DIRTY_CACHE);
        }
        assertEquals(makeDirtyBeforeRefresh, em.isDirty(pc));

        if (lock != null) {
            ((EntityManagerImpl)em).getFetchPlan().setReadLockMode(lock);
        }
        em.refresh(pc);
       
        assertEquals(expected, pc.getName());
        em.getTransaction().commit();
    }
View Full Code Here

            ? emfWithDataCache : emfWithoutDataCache;
           
        OpenJPAEntityManagerSPI em = emf.createEntityManager();
       
        em.getTransaction().begin();
        PObject pc = new PObject();
        pc.setName(useDataCache ? MARKER_DATACACHE : MARKER_CACHE);
        em.persist(pc);
        em.getTransaction().commit();
       
        Object oid = pc.getId();
        StoreCache dataCache = emf.getStoreCache();
        assertEquals(useDataCache, dataCache.contains(PObject.class, oid));
       
        // delete the record in the database in a separate transaction using
        // native SQL so that the in-memory instance is not altered
        em.getTransaction().begin();
        String sql = "DELETE FROM L2_PObject WHERE id="+oid;
        em.createNativeQuery(sql).executeUpdate();
        em.getTransaction().commit();
       
        // the object cache does not know that the record was deleted
        assertTrue(em.contains(pc));
        // nor does the data cache
        assertEquals(useDataCache, dataCache.contains(PObject.class, oid));
       
        /**
         * refresh behavior no more depends on current lock. Refresh
         * will always attempt to fetch the instance from database
         * raising EntityNotFoundException.
         *  
         */
        em.getTransaction().begin();
        em.getFetchPlan().setReadLockMode(lock);
        if (dirty)
            pc.setName("Dirty Name");
        try {
            em.refresh(pc);
            if (expectedExceptionType != null) {
                fail("expected " + expectedExceptionType.getSimpleName() +
                        " for PObject:" + oid);
View Full Code Here

TOP

Related Classes of org.apache.openjpa.persistence.datacache.common.apps.PObject

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.