use of org.apache.airavata.registry.core.experiment.catalog.model.Task in project airavata by apache.
the class TaskResource method save.
public void save() throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
Task task;
Task existingTask = em.find(Task.class, taskId);
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
if (existingTask == null) {
task = new Task();
} else {
task = existingTask;
}
task.setTaskId(taskId);
task.setTaskType(taskType);
task.setParentProcessId(parentProcessId);
task.setCreationTime(creationTime);
task.setLastUpdateTime(lastUpdateTime);
task.setTaskDetail(taskDetail);
task.setSetSubTaskModel(subTaskModel);
if (existingTask == null) {
em.persist(task);
} else {
em.merge(task);
}
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