Created
March 17, 2019 22:34
-
-
Save brunodutr/c4d23b43744c8f0a781ae6ca2fe3ee46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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