use of org.apache.openjpa.persistence.RollbackException in project oozie by apache.
the class XTestCase method cleanUpDBTablesInternal.
private void cleanUpDBTablesInternal() throws StoreException {
EntityManager entityManager = Services.get().get(JPAService.class).getEntityManager();
entityManager.setFlushMode(FlushModeType.COMMIT);
entityManager.getTransaction().begin();
final int wfjSize = getCountAndRemoveAll(entityManager, "GET_WORKFLOWS", WorkflowJobBean.class);
final int wfaSize = getCountAndRemoveAll(entityManager, "GET_ACTIONS", WorkflowActionBean.class);
final int cojSize = getCountAndRemoveAll(entityManager, "GET_COORD_JOBS", CoordinatorJobBean.class);
final int coaSize = getCountAndRemoveAll(entityManager, "GET_COORD_ACTIONS", CoordinatorActionBean.class);
final int bjSize = getCountAndRemoveAll(entityManager, "GET_BUNDLE_JOBS", BundleJobBean.class);
final int baSize = getCountAndRemoveAll(entityManager, "GET_BUNDLE_ACTIONS", BundleActionBean.class);
final int slaSize = getCountAndRemoveAll(entityManager, "GET_SLA_EVENTS", SLAEventBean.class);
final int slaRegSize = getCountAndRemoveAll(entityManager, "GET_SLA_REGISTRATIONS", SLARegistrationBean.class);
final int ssSize = getCountAndRemoveAll(entityManager, "GET_SLA_SUMMARY_ALL", SLASummaryBean.class);
try {
if (entityManager.getTransaction().isActive()) {
entityManager.getTransaction().commit();
}
if (entityManager.isOpen()) {
entityManager.close();
}
} catch (final RollbackException e) {
log.warn("Cannot commit current transaction. [e.message={0}]", e.getMessage());
}
log.info(wfjSize + " entries in WF_JOBS removed from DB!");
log.info(wfaSize + " entries in WF_ACTIONS removed from DB!");
log.info(cojSize + " entries in COORD_JOBS removed from DB!");
log.info(coaSize + " entries in COORD_ACTIONS removed from DB!");
log.info(bjSize + " entries in BUNDLE_JOBS removed from DB!");
log.info(baSize + " entries in BUNDLE_ACTIONS removed from DB!");
log.info(slaSize + " entries in SLA_EVENTS removed from DB!");
log.info(slaRegSize + " entries in SLA_REGISTRATION removed from DB!");
log.info(ssSize + " entries in SLA_SUMMARY removed from DB!");
}
use of org.apache.openjpa.persistence.RollbackException in project oozie by apache.
the class XTestCase method getCountAndRemoveAll.
private <E> int getCountAndRemoveAll(final EntityManager entityManager, final String queryName, final Class<E> entityClass) {
try {
final TypedQuery<E> getAllQuery = entityManager.createNamedQuery(queryName, entityClass);
final List<E> allEntities = getAllQuery.getResultList();
final int entitiesCount = allEntities.size();
for (final E w : allEntities) {
entityManager.remove(w);
}
return entitiesCount;
} catch (final RollbackException e) {
log.warn("Cannot get count or remove all entities. [queryName={0};entityClass.name={1}]", queryName, entityClass.getName());
return 0;
} catch (final PersistenceException | ArgumentException e) {
log.warn("Cannot get count or remove all entities. [queryName={0};entityClass.name={1}]", queryName, entityClass.getName());
return 0;
}
}
Aggregations