fixing jpa issue
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/8f5997e9 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/8f5997e9 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/8f5997e9 Branch: refs/heads/master Commit: 8f5997e9e408e73c061f79d088a1611d5d34ebe9 Parents: 83d1dfd Author: Chathuri Wimalasena <[email protected]> Authored: Tue Sep 29 10:54:31 2015 -0400 Committer: Shameera Rathnayaka <[email protected]> Committed: Wed Sep 30 11:02:35 2015 -0400 ---------------------------------------------------------------------- .../experiment/catalog/ExpCatResourceUtils.java | 7 ++----- .../catalog/resources/ExperimentErrorResource.java | 17 ++++++++++++----- .../catalog/resources/ExperimentInputResource.java | 12 +++++++++--- .../resources/ExperimentOutputResource.java | 12 +++++++++--- .../catalog/resources/ExperimentResource.java | 14 ++++++++++---- .../resources/ExperimentStatusResource.java | 12 +++++++++--- .../experiment/catalog/resources/JobResource.java | 15 +++++++++++---- .../catalog/resources/JobStatusResource.java | 12 +++++++++--- .../catalog/resources/ProcessErrorResource.java | 13 +++++++++---- .../catalog/resources/ProcessInputResource.java | 13 +++++++++---- .../catalog/resources/ProcessOutputResource.java | 13 +++++++++---- .../catalog/resources/ProcessResource.java | 13 ++++++++++--- .../resources/ProcessResourceScheduleResource.java | 13 +++++++++---- .../catalog/resources/ProcessStatusResource.java | 13 +++++++++---- .../catalog/resources/TaskErrorResource.java | 14 +++++++++----- .../experiment/catalog/resources/TaskResource.java | 14 ++++++++++---- .../catalog/resources/TaskStatusResource.java | 13 +++++++++---- .../resources/UserConfigurationDataResource.java | 13 +++++++++---- 18 files changed, 163 insertions(+), 70 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/ExpCatResourceUtils.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/ExpCatResourceUtils.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/ExpCatResourceUtils.java index 36fd822..64ed997 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/ExpCatResourceUtils.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/ExpCatResourceUtils.java @@ -23,6 +23,7 @@ package org.apache.airavata.registry.core.experiment.catalog; import org.apache.airavata.registry.core.experiment.catalog.model.*; import org.apache.airavata.registry.core.experiment.catalog.resources.*; import org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator; +import org.apache.airavata.registry.cpi.ExperimentCatalogException; import org.apache.airavata.registry.cpi.RegistryException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,11 +42,7 @@ public class ExpCatResourceUtils { @PersistenceContext(unitName="experiment_data") private static EntityManager expCatEntityManager; - public static void reset(){ - expCatFactory=null; - } - - public static EntityManager getEntityManager(){ + public static EntityManager getEntityManager() throws ExperimentCatalogException{ if (expCatFactory == null) { String connectionProperties = "DriverClassName=" + Utils.getJDBCDriver() + "," + "Url=" + Utils.getJDBCURL() + "?autoReconnect=true," + http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentErrorResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentErrorResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentErrorResource.java index 7217599..86b2e34 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentErrorResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentErrorResource.java @@ -135,21 +135,28 @@ public class ExperimentErrorResource extends AbstractExpCatResource { ExperimentErrorPK experimentErrorPK = new ExperimentErrorPK(); experimentErrorPK.setExperimentId(experimentId); experimentErrorPK.setErrorId(errorId); - experimentError = em.find(ExperimentError.class, experimentErrorPK); + ExperimentError existingExpError = em.find(ExperimentError.class, experimentErrorPK); em.close(); - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - if(experimentError == null){ + if (existingExpError == null){ experimentError = new ExperimentError(); + }else { + experimentError = existingExpError; } + + em = ExpCatResourceUtils.getEntityManager(); + em.getTransaction().begin(); experimentError.setErrorId(errorId); experimentError.setExperimentId(experimentId); experimentError.setActualErrorMessage(actualErrorMessage); experimentError.setUserFriendlyMessage(userFriendlyMessage); experimentError.setRootCauseErrorIdList(rootCauseErrorIdList); experimentError.setTransientOrPersistent(transientOrPersistent); - em.persist(experimentError); + if (existingExpError == null){ + em.persist(experimentError); + }else { + em.merge(experimentError); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentInputResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentInputResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentInputResource.java index 2389b57..855735c 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentInputResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentInputResource.java @@ -179,13 +179,15 @@ public class ExperimentInputResource extends AbstractExpCatResource { ExperimentInputPK experimentInputPK = new ExperimentInputPK(); experimentInputPK.setExperimentId(experimentId); experimentInputPK.setInputName(inputName); - experimentInput = em.find(ExperimentInput.class, experimentInputPK); + ExperimentInput existingExpInput = em.find(ExperimentInput.class, experimentInputPK); em.close(); em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if(experimentInput == null){ + if(existingExpInput == null){ experimentInput = new ExperimentInput(); + }else { + experimentInput = existingExpInput; } experimentInput.setExperimentId(experimentId); experimentInput.setInputName(inputName); @@ -199,7 +201,11 @@ public class ExperimentInputResource extends AbstractExpCatResource { experimentInput.setIsRequired(isRequired); experimentInput.setRequiredToAddedToCmd(requiredToAddedToCmd); experimentInput.setDataStaged(dataStaged); - em.merge(experimentInput); + if (existingExpInput == null){ + em.persist(experimentInput); + }else { + em.merge(experimentInput); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentOutputResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentOutputResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentOutputResource.java index 57c28fd..2502306 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentOutputResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentOutputResource.java @@ -161,13 +161,15 @@ public class ExperimentOutputResource extends AbstractExpCatResource { ExperimentOutputPK experimentOutputPK = new ExperimentOutputPK(); experimentOutputPK.setExperimentId(experimentId); experimentOutputPK.setOutputName(outputName); - experimentOutput = em.find(ExperimentOutput.class, experimentOutputPK); + ExperimentOutput existingExpOutput = em.find(ExperimentOutput.class, experimentOutputPK); em.close(); em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if(experimentOutput == null){ + if(existingExpOutput == null){ experimentOutput = new ExperimentOutput(); + }else { + experimentOutput = existingExpOutput; } experimentOutput.setExperimentId(experimentId); experimentOutput.setOutputName(outputName); @@ -179,7 +181,11 @@ public class ExperimentOutputResource extends AbstractExpCatResource { experimentOutput.setDataMovement(dataMovement); experimentOutput.setLocation(location); experimentOutput.setSearchQuery(searchQuery); - em.merge(experimentOutput); + if (existingExpOutput == null){ + em.persist(experimentOutput); + }else { + em.merge(experimentOutput); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentResource.java index ad71f91..6098770 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentResource.java @@ -436,13 +436,15 @@ public class ExperimentResource extends AbstractExpCatResource { EntityManager em = null; try { em = ExpCatResourceUtils.getEntityManager(); - Experiment experiment = em.find(Experiment.class, experimentId); + Experiment existingExp = em.find(Experiment.class, experimentId); em.close(); - + Experiment experiment; em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if (experiment == null) { + if (existingExp == null) { experiment = new Experiment(); + }else { + experiment = existingExp; } experiment.setExperimentId(experimentId); experiment.setProjectId(projectId); @@ -456,7 +458,11 @@ public class ExperimentResource extends AbstractExpCatResource { experiment.setGatewayExecutionId(gatewayExecutionId); experiment.setEnableEmailNotification(enableEmailNotification); experiment.setEmailAddresses(emailAddresses); - em.merge(experiment); + if (existingExp == null){ + em.persist(experiment); + }else { + em.merge(experiment); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentStatusResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentStatusResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentStatusResource.java index c7242c2..3ea0b41 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentStatusResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentStatusResource.java @@ -117,20 +117,26 @@ public class ExperimentStatusResource extends AbstractExpCatResource { ExperimentStatusPK experimentStatusPK = new ExperimentStatusPK(); experimentStatusPK.setStatusId(statusId); experimentStatusPK.setExperimentId(experimentId); - experimentStatus = em.find(ExperimentStatus.class, experimentStatusPK); + ExperimentStatus existingStatus = em.find(ExperimentStatus.class, experimentStatusPK); em.close(); em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if(experimentStatus == null){ + if(existingStatus == null){ experimentStatus = new ExperimentStatus(); + }else { + experimentStatus = existingStatus; } experimentStatus.setStatusId(statusId); experimentStatus.setExperimentId(experimentId); experimentStatus.setState(state); experimentStatus.setReason(reason); experimentStatus.setTimeOfStateChange(timeOfStateChange); - em.merge(experimentStatus); + if (existingStatus == null){ + em.persist(experimentStatus); + }else { + em.merge(experimentStatus); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/JobResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/JobResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/JobResource.java index abee18f..941b267 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/JobResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/JobResource.java @@ -277,17 +277,20 @@ public class JobResource extends AbstractExpCatResource { JobPK jobPK = new JobPK(); jobPK.setJobId(jobId); jobPK.setProcessId(processId); - Job job = em.find(Job.class, jobPK); + Job existingJob = em.find(Job.class, jobPK); em.close(); + Job job; em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if(job == null){ + if(existingJob == null){ job = new Job(); + }else { + job = existingJob; } job.setJobId(jobId); job.setTaskId(taskId); - job.setProcessId(processId); + job.setProcessId(processId); if (jobDescription != null) { job.setJobDescription(jobDescription.toCharArray()); } @@ -302,7 +305,11 @@ public class JobResource extends AbstractExpCatResource { job.setJobName(jobName); job.setWorkingDir(workingDir); job.setExitCode(exitCode); - em.merge(job); + if (existingJob == null){ + em.persist(job); + }else { + em.merge(job); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/JobStatusResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/JobStatusResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/JobStatusResource.java index 3de163c..9ed1f31 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/JobStatusResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/JobStatusResource.java @@ -127,20 +127,26 @@ public class JobStatusResource extends AbstractExpCatResource { jobStatusPK.setJobId(jobId); jobStatusPK.setStatusId(statusId); jobStatusPK.setProcessId(processId); - jobStatus = em.find(JobStatus.class, jobStatusPK); + JobStatus existingJobStatus = em.find(JobStatus.class, jobStatusPK); em.close(); em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if(jobStatus == null){ + if(existingJobStatus == null){ jobStatus = new JobStatus(); + }else { + jobStatus = existingJobStatus; } jobStatus.setStatusId(statusId); jobStatus.setJobId(jobId); jobStatus.setProcessId(processId); jobStatus.setState(state); jobStatus.setReason(reason); - em.merge(jobStatus); + if (existingJobStatus == null){ + em.persist(jobStatus); + }else { + em.merge(jobStatus); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessErrorResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessErrorResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessErrorResource.java index 3faa9b5..9d13705 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessErrorResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessErrorResource.java @@ -131,18 +131,19 @@ public class ProcessErrorResource extends AbstractExpCatResource { throw new RegistryException("Does not have the process id or error id"); } em = ExpCatResourceUtils.getEntityManager(); - ProcessError processError; ProcessErrorPK processErrorPK = new ProcessErrorPK(); processErrorPK.setProcessId(processId); processErrorPK.setErrorId(errorId); - processError = em.find(ProcessError.class, processErrorPK); + ProcessError existingPrError = em.find(ProcessError.class, processErrorPK); em.close(); em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if(processError == null){ + if(existingPrError == null){ processError = new ProcessError(); + }else { + processError = existingPrError; } processError.setProcessId(processId); processError.setErrorId(errorId); @@ -150,7 +151,11 @@ public class ProcessErrorResource extends AbstractExpCatResource { processError.setUserFriendlyMessage(userFriendlyMessage); processError.setRootCauseErrorIdList(rootCauseErrorIdList); processError.setTransientOrPersistent(transientOrPersistent); - em.merge(processError); + if (existingPrError == null){ + em.persist(processError); + }else { + em.merge(processError); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessInputResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessInputResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessInputResource.java index 8f0531f..aff8ec8 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessInputResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessInputResource.java @@ -175,18 +175,19 @@ public class ProcessInputResource extends AbstractExpCatResource { throw new RegistryException("Does not have the process id"); } em = ExpCatResourceUtils.getEntityManager(); - ProcessInput processInput; ProcessInputPK processInputPk = new ProcessInputPK(); processInputPk.setProcessId(processId); processInputPk.setInputName(inputName); - processInput = em.find(ProcessInput.class, processInputPk); + ProcessInput existingProInput = em.find(ProcessInput.class, processInputPk); em.close(); em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if(processInput == null){ + if(existingProInput == null){ processInput = new ProcessInput(); + }else { + processInput = existingProInput; } processInput.setProcessId(processId); processInput.setInputName(inputName); @@ -200,7 +201,11 @@ public class ProcessInputResource extends AbstractExpCatResource { processInput.setIsRequired(isRequired); processInput.setRequiredToAddedToCmd(requiredToAddedToCmd); processInput.setDataStaged(dataStaged); - em.merge(processInput); + if (existingProInput == null){ + em.persist(processInput); + }else { + em.merge(processInput); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessOutputResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessOutputResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessOutputResource.java index 0b56cd1..de93b63 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessOutputResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessOutputResource.java @@ -158,18 +158,19 @@ public class ProcessOutputResource extends AbstractExpCatResource { + " OutputName:" + outputName); } em = ExpCatResourceUtils.getEntityManager(); - ProcessOutput processOutput; ProcessOutputPK processOutputPK = new ProcessOutputPK(); processOutputPK.setProcessId(processId); processOutputPK.setOutputName(outputName); - processOutput = em.find(ProcessOutput.class, processOutputPK); + ProcessOutput existingProcessOutput = em.find(ProcessOutput.class, processOutputPK); em.close(); em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if(processOutput == null){ + if(existingProcessOutput == null){ processOutput = new ProcessOutput(); + }else { + processOutput = existingProcessOutput; } processOutput.setProcessId(processId); processOutput.setOutputName(outputName); @@ -181,7 +182,11 @@ public class ProcessOutputResource extends AbstractExpCatResource { processOutput.setDataMovement(dataMovement); processOutput.setLocation(location); processOutput.setSearchQuery(searchQuery); - em.merge(processOutput); + if (existingProcessOutput == null){ + em.persist(processOutput); + }else { + em.merge(processOutput); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessResource.java index 2cab3e9..1c89cba 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessResource.java @@ -471,13 +471,16 @@ public class ProcessResource extends AbstractExpCatResource { EntityManager em = null; try { em = ExpCatResourceUtils.getEntityManager(); - Process process = em.find(Process.class, processId); + Process existingProcess = em.find(Process.class, processId); em.close(); + Process process; em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if (process == null) { + if (existingProcess == null) { process = new Process(); + }else { + process = existingProcess; } process.setProcessId(processId); process.setExperimentId(experimentId); @@ -491,7 +494,11 @@ public class ProcessResource extends AbstractExpCatResource { process.setGatewayExecutionId(gatewayExecutionId); process.setEnableEmailNotification(enableEmailNotification); process.setEmailAddresses(emailAddresses); - em.merge(process); + if (existingProcess == null){ + em.persist(process); + }else { + em.merge(process); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessResourceScheduleResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessResourceScheduleResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessResourceScheduleResource.java index 0e7c4f8..2513213 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessResourceScheduleResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessResourceScheduleResource.java @@ -138,15 +138,16 @@ public class ProcessResourceScheduleResource extends AbstractExpCatResource { throw new RegistryException("Does not have the process id"); } em = ExpCatResourceUtils.getEntityManager(); - ProcessResourceSchedule processResourceSchedule; - processResourceSchedule = em.find(ProcessResourceSchedule.class, processId); + ProcessResourceSchedule existingSchedule = em.find(ProcessResourceSchedule.class, processId); em.close(); em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if(processResourceSchedule == null){ + if(existingSchedule == null){ processResourceSchedule = new ProcessResourceSchedule(); + }else { + processResourceSchedule = existingSchedule; } processResourceSchedule.setProcessId(processId); processResourceSchedule.setResourceHostId(resourceHostId); @@ -156,7 +157,11 @@ public class ProcessResourceScheduleResource extends AbstractExpCatResource { processResourceSchedule.setQueueName(queueName); processResourceSchedule.setWallTimeLimit(wallTimeLimit); processResourceSchedule.setTotalPhysicalMemory(totalPhysicalMemory); - em.merge(processResourceSchedule); + if (existingSchedule == null){ + em.persist(processResourceSchedule); + }else { + em.merge(processResourceSchedule); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessStatusResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessStatusResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessStatusResource.java index 285a81e..2e5e10c 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessStatusResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProcessStatusResource.java @@ -113,24 +113,29 @@ public class ProcessStatusResource extends AbstractExpCatResource { throw new RegistryException("Does not have the process id or status id"); } em = ExpCatResourceUtils.getEntityManager(); - ProcessStatus processStatus; ProcessStatusPK processStatusPK = new ProcessStatusPK(); processStatusPK.setStatusId(statusId); processStatusPK.setProcessId(processId); - processStatus = em.find(ProcessStatus.class, processStatusPK); + ProcessStatus existingStatus = em.find(ProcessStatus.class, processStatusPK); em.close(); em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if(processStatus == null){ + if(existingStatus == null){ processStatus = new ProcessStatus(); + }else { + processStatus = existingStatus; } processStatus.setStatusId(statusId); processStatus.setProcessId(processId); processStatus.setState(state); processStatus.setReason(reason); - em.merge(processStatus); + if (existingStatus == null){ + em.persist(processStatus); + }else { + em.merge(processStatus); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/TaskErrorResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/TaskErrorResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/TaskErrorResource.java index 5d5730f..8fd71f5 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/TaskErrorResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/TaskErrorResource.java @@ -128,7 +128,6 @@ public class TaskErrorResource extends AbstractExpCatResource { EntityManager em = null; try { em = ExpCatResourceUtils.getEntityManager(); - TaskError taskError; if(taskId == null || errorId == null){ throw new RegistryException("Does not have the task id or error id"); @@ -136,22 +135,27 @@ public class TaskErrorResource extends AbstractExpCatResource { TaskErrorPK taskErrorPK = new TaskErrorPK(); taskErrorPK.setTaskId(taskId); taskErrorPK.setErrorId(errorId); - taskError = em.find(TaskError.class, taskErrorPK); + TaskError existingTaskError = em.find(TaskError.class, taskErrorPK); em.close(); em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if(taskError == null){ + if(existingTaskError == null){ taskError = new TaskError(); + }else { + taskError = existingTaskError; } - taskError.setTaskId(taskId); taskError.setErrorId(errorId); taskError.setActualErrorMessage(actualErrorMessage); taskError.setUserFriendlyMessage(userFriendlyMessage); taskError.setRootCauseErrorIdList(rootCauseErrorIdList); taskError.setTransientOrPersistent(transientOrPersistent); - em.merge(taskError); + if (existingTaskError == null){ + em.persist(taskError); + }else { + em.merge(taskError); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/TaskResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/TaskResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/TaskResource.java index 3904283..0226f30 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/TaskResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/TaskResource.java @@ -274,14 +274,16 @@ public class TaskResource extends AbstractExpCatResource { EntityManager em = null; try { em = ExpCatResourceUtils.getEntityManager(); - - Task task = em.find(Task.class, taskId); + Task task; + Task existingTask = em.find(Task.class, taskId); em.close(); em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if(task == null){ + if(existingTask == null){ task = new Task(); + }else { + task = existingTask; } task.setTaskId(taskId); task.setTaskType(taskType); @@ -290,7 +292,11 @@ public class TaskResource extends AbstractExpCatResource { task.setLastUpdateTime(lastUpdateTime); task.setTaskDetail(taskDetail); task.setSetSubTaskModel(subTaskModel); - em.merge(task); + if (existingTask == null){ + em.persist(task); + }else { + em.merge(task); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/TaskStatusResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/TaskStatusResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/TaskStatusResource.java index 7b3d085..dc59e83 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/TaskStatusResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/TaskStatusResource.java @@ -110,7 +110,6 @@ public class TaskStatusResource extends AbstractExpCatResource { 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"); @@ -118,20 +117,26 @@ public class TaskStatusResource extends AbstractExpCatResource { TaskStatusPK taskStatusPK = new TaskStatusPK(); taskStatusPK.setTaskId(taskId); taskStatusPK.setStatusId(statusId); - taskStatus = em.find(TaskStatus.class, taskStatusPK); + TaskStatus existingStatus = em.find(TaskStatus.class, taskStatusPK); em.close(); em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if(taskStatus == null){ + if(existingStatus == null){ taskStatus = new TaskStatus(); + }else { + taskStatus = existingStatus; } taskStatus.setStatusId(statusId); taskStatus.setTaskId(taskId); taskStatus.setState(state); taskStatus.setReason(reason); taskStatus.setTimeOfStateChange(timeOfStateChange); - em.merge(taskStatus); + if (existingStatus == null){ + em.persist(taskStatus); + }else { + em.merge(taskStatus); + } em.getTransaction().commit(); em.close(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/airavata/blob/8f5997e9/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/UserConfigurationDataResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/UserConfigurationDataResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/UserConfigurationDataResource.java index f7c2090..ef670f2 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/UserConfigurationDataResource.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/UserConfigurationDataResource.java @@ -189,18 +189,19 @@ public class UserConfigurationDataResource extends AbstractExpCatResource { EntityManager em = null; try { em = ExpCatResourceUtils.getEntityManager(); - UserConfigurationData userConfigurationData; if(experimentId == null){ throw new RegistryException("Does not have the experiment id"); } - userConfigurationData = em.find(UserConfigurationData.class, experimentId); + UserConfigurationData existingConf = em.find(UserConfigurationData.class, experimentId); em.close(); em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); - if(userConfigurationData == null){ + if(existingConf == null){ userConfigurationData = new UserConfigurationData(); + }else { + userConfigurationData = existingConf; } userConfigurationData.setExperimentId(experimentId); userConfigurationData.setAiravataAutoSchedule(airavataAutoSchedule); @@ -216,7 +217,11 @@ public class UserConfigurationDataResource extends AbstractExpCatResource { userConfigurationData.setQueueName(queueName); userConfigurationData.setWallTimeLimit(wallTimeLimit); userConfigurationData.setTotalPhysicalMemory(totalPhysicalMemory); - em.merge(userConfigurationData); + if (existingConf == null){ + em.persist(userConfigurationData); + }else { + em.merge(userConfigurationData); + } em.getTransaction().commit(); em.close(); } catch (Exception e) {
