use of org.apache.airavata.registry.core.experiment.catalog.model.TaskStatusPK in project airavata by apache.
the class TaskStatusResource method save.
public void save() throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
TaskStatus taskStatus;
if (taskId == null || statusId == null) {
throw new RegistryException("Does not have the task id or status id");
}
TaskStatusPK taskStatusPK = new TaskStatusPK();
taskStatusPK.setTaskId(taskId);
taskStatusPK.setStatusId(statusId);
TaskStatus existingStatus = em.find(TaskStatus.class, taskStatusPK);
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
if (existingStatus == null) {
taskStatus = new TaskStatus();
} else {
taskStatus = existingStatus;
}
taskStatus.setStatusId(statusId);
taskStatus.setTaskId(taskId);
taskStatus.setState(state);
taskStatus.setReason(reason);
taskStatus.setTimeOfStateChange(timeOfStateChange);
if (existingStatus == null) {
em.persist(taskStatus);
} else {
em.merge(taskStatus);
}
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RegistryException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
}
Aggregations