Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge remote branch 'origin/integration/master' into integration/master
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Jun 12, 2013
2 parents 81a8a9f + 4edb0a3 commit 5132c08
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
51 changes: 23 additions & 28 deletions zanata-war/src/test/java/org/zanata/ZanataJpaTest.java
@@ -1,24 +1,19 @@
package org.zanata;

import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.persister.collection.AbstractCollectionPersister;
import org.hibernate.persister.entity.EntityPersister;
import org.jboss.seam.log.Log;
import org.jboss.seam.log.Logging;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.testng.annotations.*;
import org.zanata.testng.TestMethodListener;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.Map;

@Listeners(TestMethodListener.class)
@Test(groups = { "jpa-tests" })
public abstract class ZanataJpaTest
Expand Down Expand Up @@ -46,7 +41,7 @@ public void shutdownEM()
log.debug("Shutting down EM");
clearHibernateSecondLevelCache();
em.getTransaction().rollback();
em = null;
em.close();
}

protected EntityManager getEm()
Expand Down Expand Up @@ -83,10 +78,10 @@ public void shutDownEMF()
emf.close();
emf = null;
}

/**
* Commits the changes on the current session and starts a new one.
* This method is useful whenever multi-session tests are needed.
* Commits the changes on the current session and starts a new one. This
* method is useful whenever multi-session tests are needed.
*
* @return The newly started session
*/
Expand All @@ -98,10 +93,10 @@ protected Session newSession()
}

/**
* This method is used to test multiple Entity Managers (or hibernate sessions)
* working together simultaneously. Use {@link org.zanata.ZanataJpaTest#getEm()}
* for all other tests.
*
* This method is used to test multiple Entity Managers (or hibernate
* sessions) working together simultaneously. Use
* {@link org.zanata.ZanataJpaTest#getEm()} for all other tests.
*
* @return A new instance of an entity manager.
*/
protected EntityManager newEntityManagerInstance()
Expand All @@ -114,27 +109,27 @@ protected EntityManager newEntityManagerInstance()
*/
protected void clearHibernateSecondLevelCache()
{
SessionFactory sessionFactory = ((Session)em.getDelegate()).getSessionFactory();
SessionFactory sessionFactory = ((Session) em.getDelegate()).getSessionFactory();

// Clear the Entity cache
Map classMetadata = sessionFactory.getAllClassMetadata();
for( Object obj : classMetadata.values() )
for (Object obj : classMetadata.values())
{
EntityPersister p = (EntityPersister)obj;
if( p.hasCache() )
EntityPersister p = (EntityPersister) obj;
if (p.hasCache())
{
sessionFactory.evictEntity( p.getEntityName() );
sessionFactory.evictEntity(p.getEntityName());
}
}

// Clear the Collection cache
Map collMetadata = sessionFactory.getAllCollectionMetadata();
for( Object obj : collMetadata.values() )
for (Object obj : collMetadata.values())
{
AbstractCollectionPersister p = (AbstractCollectionPersister)obj;
if( p.hasCache() )
AbstractCollectionPersister p = (AbstractCollectionPersister) obj;
if (p.hasCache())
{
sessionFactory.evictCollection( p.getRole() );
sessionFactory.evictCollection(p.getRole());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion zanata-war/src/test/resources/META-INF/persistence.xml
Expand Up @@ -17,7 +17,7 @@
See also zanata-model/src/test/resources/META-INF/persistence.xml.
-->

<mapping-file>META-INF/orm.xml</mapping-file>
<!-- <mapping-file>META-INF/orm.xml</mapping-file> -->

<class>org.zanata.model.HAccountActivationKey</class>
<class>org.zanata.model.HAccount</class>
Expand Down

0 comments on commit 5132c08

Please sign in to comment.