Search in sources :

Example 1 with Task

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();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) Task(org.apache.airavata.registry.core.experiment.catalog.model.Task) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Aggregations

EntityManager (javax.persistence.EntityManager)1 Task (org.apache.airavata.registry.core.experiment.catalog.model.Task)1 RegistryException (org.apache.airavata.registry.cpi.RegistryException)1