You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by is...@apache.org on 2022/12/29 21:55:09 UTC

[airavata] branch develop updated: Queries

This is an automated email from the ASF dual-hosted git repository.

isjarana pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata.git


The following commit(s) were added to refs/heads/develop by this push:
     new 97decf3d3b Queries
     new 48d4b21f31 Merge pull request #367 from isururanawaka/metaschedular
97decf3d3b is described below

commit 97decf3d3b18fc2acd7e5fb27a79a37704318a10
Author: Isuru Ranawaka <ir...@gmail.com>
AuthorDate: Thu Dec 29 16:53:46 2022 -0500

    Queries
---
 .../airavata/registry/core/repositories/AbstractRepository.java   | 8 ++++----
 .../registry/core/repositories/expcatalog/JobRepository.java      | 5 +----
 .../org/apache/airavata/registry/core/utils/QueryConstants.java   | 2 +-
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/repositories/AbstractRepository.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/repositories/AbstractRepository.java
index fd88e6b296..3d0590766c 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/repositories/AbstractRepository.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/repositories/AbstractRepository.java
@@ -155,7 +155,7 @@ public abstract class AbstractRepository<T, E, Id> {
     }
 
 
-    public void execute(String query, Map<String, Object> queryParams) {
+    public void execute(String query, String... params) {
         EntityManager entityManager = null;
         try {
             entityManager = getEntityManager();
@@ -164,9 +164,9 @@ public abstract class AbstractRepository<T, E, Id> {
             throw new RuntimeException("Failed to get EntityManager", e);
         }
         try {
-           Query nativeQuery =  entityManager.createNamedQuery(query);
-           for(Map.Entry<String, Object> keyVal :queryParams.entrySet()) {
-               nativeQuery.setParameter(keyVal.getKey(),keyVal.getValue());
+           Query nativeQuery =  entityManager.createNativeQuery(query);
+           for(int i=1;i<params.length;i++){
+               nativeQuery.setParameter(i,params[i]);
            }
            nativeQuery.executeUpdate();
         } catch(Exception e) {
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/JobRepository.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/JobRepository.java
index 2f39bd93da..a817b8518e 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/JobRepository.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/JobRepository.java
@@ -157,10 +157,7 @@ public class JobRepository extends ExpCatAbstractRepository<JobModel, JobEntity,
     }
 
     public void removeJob(JobModel jobModel) throws RegistryException {
-        Map map = new HashMap();
-        map.put(DBConstants.Job.JOB_ID,jobModel.getJobId());
-        map.put(DBConstants.Job.TASK_ID,jobModel.getTaskId());
-        execute(QueryConstants.DELETE_JOB,map);
+        execute(QueryConstants.DELETE_JOB_NATIVE_QUERY,jobModel.getJobId(),jobModel.getTaskId());
     }
 
 }
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java
index d4f07193c3..c9ae6d4777 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java
@@ -194,5 +194,5 @@ public interface QueryConstants {
     String GET_ALL_PROCESSES = "SELECT P FROM " + ProcessEntity.class.getSimpleName() +" P ";
 
 
-    String DELETE_JOB = " DELETE FROM "+JobEntity.class.getSimpleName()+ " WHERE JOB_ID = :"+DBConstants.Job.JOB_ID+" AND TASK_ID = :"+DBConstants.Job.TASK_ID;
+    String DELETE_JOB_NATIVE_QUERY = "DELETE FROM "+JobEntity.class.getSimpleName()+ " WHERE JOB_ID = ?1 AND TASK_ID = ?2";
 }