OPENJPA-1271:

Missed a class on previous commit

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@808991 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2009-08-28 19:12:35 +00:00
parent 991cdcae7d
commit d02f0688ae
1 changed files with 78 additions and 0 deletions

View File

@ -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();
}
}