openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r808991 - /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java
Date Fri, 28 Aug 2009 19:12:35 GMT
Author: mikedd
Date: Fri Aug 28 19:12:35 2009
New Revision: 808991

URL: http://svn.apache.org/viewvc?rev=808991&view=rev
Log:
OPENJPA-1271:
Missed a class on previous commit

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java
  (with props)

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java?rev=808991&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java
Fri Aug 28 19:12:35 2009
@@ -0,0 +1,78 @@
+package org.apache.openjpa.persistence.cache.jpa;
+
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
+import org.apache.openjpa.lib.jdbc.JDBCEvent;
+import org.apache.openjpa.lib.jdbc.JDBCListener;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.cache.jpa.model.CacheEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.CacheableEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.NegatedCachableEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.NegatedUncacheableEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.UncacheableEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.UnspecifiedEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.XmlCacheableEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.XmlUncacheableEntity;
+import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase.Listener;
+
+public abstract class AbstractCacheTestCase extends AbstractPersistenceTestCase {
+    protected final String RETRIEVE_MODE_PROP = "javax.persistence.cache.retrieveMode";
+    protected final String STORE_MODE_PROP = "javax.persistence.cache.storeMode";
+    
+    abstract OpenJPAEntityManagerFactorySPI getEntityManagerFactory();
+    abstract JDBCListener getListener();
+
+    protected static Class<?>[] persistentTypes =
+        { CacheableEntity.class, UncacheableEntity.class, UnspecifiedEntity.class, NegatedCachableEntity.class,
+            NegatedUncacheableEntity.class, XmlCacheableEntity.class, XmlUncacheableEntity.class
};
+
+    public void populate() throws IllegalAccessException, InstantiationException {
+        EntityManager em = getEntityManagerFactory().createEntityManager();
+        em.getTransaction().begin();
+        for (Class<?> clss : persistentTypes) {
+            if (!Modifier.isAbstract(clss.getModifiers())) {
+                CacheEntity ce = (CacheEntity) clss.newInstance();
+                ce.setId(1);
+                em.persist(ce);
+            }
+        }
+        em.getTransaction().commit();
+        em.close();
+    }
+
+    public OpenJPAEntityManagerFactorySPI createEntityManagerFactory(String puName) {
+        OpenJPAEntityManagerFactorySPI emf =
+            (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.createEntityManagerFactory(puName,
+                "META-INF/caching-persistence.xml", getPropertiesMap("openjpa.DataCache",
"true",
+                    "openjpa.RemoteCommitProvider", "sjvm", persistentTypes, 
+                    "openjpa.jdbc.JDBCListeners", new JDBCListener [] { getListener() } ));
+        return emf;
+    }
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        cleanDatabase();
+        populate();
+    }
+    
+    public void cleanDatabase() throws Exception {
+        EntityManager em = getEntityManagerFactory().createEntityManager();
+        em.getTransaction().begin();
+        for (Class<?> clss : persistentTypes) {
+            if (!Modifier.isAbstract(clss.getModifiers())) {
+                em.createQuery("Delete from " + clss.getSimpleName()).executeUpdate();
+            }
+        }
+        em.getTransaction().commit();
+        em.close();
+    }
+
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message