Skip to content

Instantly share code, notes, and snippets.

@brunodutr
Created March 17, 2019 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunodutr/c4d23b43744c8f0a781ae6ca2fe3ee46 to your computer and use it in GitHub Desktop.
Save brunodutr/c4d23b43744c8f0a781ae6ca2fe3ee46 to your computer and use it in GitHub Desktop.
package example.bdutra.it;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.transaction.UserTransaction;
import example.bdutra.jpa.person.PersonEntity;
public class BaseIT {
@PersistenceContext(unitName = "ArquillianPU")
public EntityManager em;
@Inject
private UserTransaction utx;
public void clearDB() {
deleteEntity(PersonEntity.class);
}
private void deleteEntity(Class<?> entityClass) {
try {
utx.begin();
Query query = em.createQuery(String.format("delete from %s", entityClass.getSimpleName()));
query.executeUpdate();
utx.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment