airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject svn commit: r1384324 - in /incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src: main/java/org/apache/airavata/persistance/registry/jpa/ main/java/org/apache/airavata/persistance/registry/jpa/model/ main/java/org/apache/airavata/persista...
Date Thu, 13 Sep 2012 13:43:49 GMT
Author: lahiru
Date: Thu Sep 13 13:43:47 2012
New Revision: 1384324

URL: http://svn.apache.org/viewvc?rev=1384324&view=rev
Log:
applying patch from chathuri for AIRAVATA-562

Added:
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Application_Descriptor_PK.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Configuration_PK.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Gateway_Worker_PK.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Host_Descriptor_PK.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Published_Workflow_PK.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Service_Descriptor_PK.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/User_Workflow_PK.java
Modified:
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Application_Descriptor.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Configuration.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Gateway_Worker.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Host_Descriptor.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Published_Workflow.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Service_Descriptor.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/User_Workflow.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationDescriptorResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ConfigurationResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ExperimentResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/HostDescriptorResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/PublishWorkflowResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ServiceDescriptorResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserWorkflowResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/data-derby.sql
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/data-mysql.sql
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java Thu Sep 13 13:43:47 2012
@@ -20,17 +20,11 @@
 */
 package org.apache.airavata.persistance.registry.jpa;
 
-import org.apache.airavata.persistance.registry.jpa.model.Configuration;
-import org.apache.airavata.persistance.registry.jpa.model.Gateway;
-import org.apache.airavata.persistance.registry.jpa.model.Gateway_Worker;
-import org.apache.airavata.persistance.registry.jpa.model.Users;
+import org.apache.airavata.persistance.registry.jpa.model.*;
 import org.apache.airavata.persistance.registry.jpa.resources.*;
 import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import javax.persistence.Query;
+import javax.persistence.*;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -41,7 +35,6 @@ import java.util.concurrent.locks.Reentr
 public class ResourceUtils {
     private static final String PERSISTENCE_UNIT_NAME = "airavata_data";
     protected static EntityManagerFactory factory;
-    // protected static EntityManager em;
 
     private static Lock lock = new ReentrantLock();
 
@@ -225,9 +218,7 @@ public class ResourceUtils {
     private static ConfigurationResource createConfigurationResourceObject(
             Object result) {
         Configuration configuration = (Configuration) result;
-        ConfigurationResource configurationResource = new ConfigurationResource(configuration.getConfig_ID());
-        configurationResource.setConfigKey(configuration.getConfig_key());
-        configurationResource.setConfigVal(configuration.getConfig_val());
+        ConfigurationResource configurationResource = new ConfigurationResource(configuration.getConfig_key(), configuration.getConfig_val());
         configurationResource.setExpireDate(configuration.getExpire_date());
         return configurationResource;
     }
@@ -237,31 +228,44 @@ public class ResourceUtils {
      * @param configValue
      */
     public static void removeConfiguration(String configkey, String configValue) {
-        EntityManager em = getEntityManager();
-        em.getTransaction().begin();
-//        QueryGenerator queryGenerator = new QueryGenerator(AbstractResource.CONFIGURATION);
-//        queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configkey);
-//        queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_VAL, configValue);
-//        Query q = queryGenerator.deleteQuery(em);
-//        q.executeUpdate();
-        em.getTransaction().commit();
-        em.close();
+        QueryGenerator queryGenerator = new QueryGenerator(AbstractResource.CONFIGURATION);
+        queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configkey);
+        queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_VAL, configValue);
+        if(isConfigurationExists(configkey, configValue)){
+            EntityManager em = getEntityManager();
+            em.getTransaction().begin();
+            Query q = queryGenerator.deleteQuery(em);
+            q.executeUpdate();
+            em.getTransaction().commit();
+            em.close();
+        }
     }
 
     /**
      * @param configkey
      */
     public static void removeConfiguration(String configkey) {
-        EntityManager em = getEntityManager();
-        em.getTransaction().begin();
-
-//        QueryGenerator queryGenerator = new QueryGenerator(AbstractResource.CONFIGURATION);
-//        queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configkey);
-//        Query q = queryGenerator.deleteQuery(em);
-//        q.executeUpdate();
-        em.getTransaction().commit();
-        em.close();
+        QueryGenerator queryGenerator = new QueryGenerator(AbstractResource.CONFIGURATION);
+        queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configkey);
+        if(isConfigurationExist(configkey)){
+            EntityManager em = getEntityManager();
+            em.getTransaction().begin();
+            Query q = queryGenerator.deleteQuery(em);
+            q.executeUpdate();
+            em.getTransaction().commit();
+            em.close();
+        }
+    }
 
+    public static boolean isConfigurationExists(String configKey, String configVal){
+        try{
+            EntityManager em = ResourceUtils.getEntityManager();
+            Configuration existing = em.find(Configuration.class, new Configuration_PK(configKey, configVal));
+            em.close();
+            return existing!= null;
+        } catch (Exception e){
+            throw new EntityNotFoundException();
+        }
     }
 
     public static Lock getLock() {

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Application_Descriptor.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Application_Descriptor.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Application_Descriptor.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Application_Descriptor.java Thu Sep 13 13:43:47 2012
@@ -101,56 +101,3 @@ public class Application_Descriptor {
         this.gateway_name = gateway_name;
     }
 }
-
-class Application_Descriptor_PK{
-    private String gateway_name;
-    private String application_descriptor_ID;
-    private String host_descriptor_ID;
-    private String service_descriptor_ID;
-
-    public Application_Descriptor_PK() {
-        ;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        return false;
-    }
-
-    @Override
-    public int hashCode() {
-        return 1;
-    }
-
-    public String getGateway_name() {
-        return gateway_name;
-    }
-
-    public String getApplication_descriptor_ID() {
-        return application_descriptor_ID;
-    }
-
-    public String getHost_descriptor_ID() {
-        return host_descriptor_ID;
-    }
-
-    public String getService_descriptor_ID() {
-        return service_descriptor_ID;
-    }
-
-    public void setGateway_name(String gateway_name) {
-        this.gateway_name = gateway_name;
-    }
-
-    public void setApplication_descriptor_ID(String application_descriptor_ID) {
-        this.application_descriptor_ID = application_descriptor_ID;
-    }
-
-    public void setHost_descriptor_ID(String host_descriptor_ID) {
-        this.host_descriptor_ID = host_descriptor_ID;
-    }
-
-    public void setService_descriptor_ID(String service_descriptor_ID) {
-        this.service_descriptor_ID = service_descriptor_ID;
-    }
-}

Added: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Application_Descriptor_PK.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Application_Descriptor_PK.java?rev=1384324&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Application_Descriptor_PK.java (added)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Application_Descriptor_PK.java Thu Sep 13 13:43:47 2012
@@ -0,0 +1,62 @@
+package org.apache.airavata.persistance.registry.jpa.model;
+
+
+public class Application_Descriptor_PK {
+    private String gateway_name;
+    private String application_descriptor_ID;
+    private String host_descriptor_ID;
+    private String service_descriptor_ID;
+
+    public Application_Descriptor_PK(String gateway_name, String application_descriptor_ID, String host_descriptor_ID, String service_descriptor_ID) {
+        this.gateway_name = gateway_name;
+        this.application_descriptor_ID = application_descriptor_ID;
+        this.host_descriptor_ID = host_descriptor_ID;
+        this.service_descriptor_ID = service_descriptor_ID;
+    }
+
+    public Application_Descriptor_PK() {
+        ;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return 1;
+    }
+
+    public String getGateway_name() {
+        return gateway_name;
+    }
+
+    public String getApplication_descriptor_ID() {
+        return application_descriptor_ID;
+    }
+
+    public String getHost_descriptor_ID() {
+        return host_descriptor_ID;
+    }
+
+    public String getService_descriptor_ID() {
+        return service_descriptor_ID;
+    }
+
+    public void setGateway_name(String gateway_name) {
+        this.gateway_name = gateway_name;
+    }
+
+    public void setApplication_descriptor_ID(String application_descriptor_ID) {
+        this.application_descriptor_ID = application_descriptor_ID;
+    }
+
+    public void setHost_descriptor_ID(String host_descriptor_ID) {
+        this.host_descriptor_ID = host_descriptor_ID;
+    }
+
+    public void setService_descriptor_ID(String service_descriptor_ID) {
+        this.service_descriptor_ID = service_descriptor_ID;
+    }
+}

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Configuration.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Configuration.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Configuration.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Configuration.java Thu Sep 13 13:43:47 2012
@@ -20,26 +20,19 @@
 */
 package org.apache.airavata.persistance.registry.jpa.model;
 
-import javax.persistence.Entity;
-import javax.persistence.Id;
+import javax.persistence.*;
+import java.io.Serializable;
 import java.sql.Date;
 
 @Entity
-public class Configuration {
+@IdClass(Configuration_PK.class)
+public class Configuration implements Serializable {
     @Id
-    private int config_ID;
     private String config_key;
+    @Id
     private String config_val;
     private Date expire_date;
 
-    public int getConfig_ID() {
-        return config_ID;
-    }
-
-    public void setConfig_ID(int config_ID) {
-        this.config_ID = config_ID;
-    }
-
     public String getConfig_key() {
         return config_key;
     }
@@ -64,3 +57,43 @@ public class Configuration {
         this.expire_date = expire_date;
     }
 }
+
+//class Configuration_PK{
+//    private String config_key;
+//    private String config_val;
+//
+//    public Configuration_PK(String config_key, String config_val) {
+//        this.config_key = config_key;
+//        this.config_val = config_val;
+//    }
+//
+//    public Configuration_PK() {
+//        ;
+//    }
+//
+//    @Override
+//    public boolean equals(Object o) {
+//        return false;
+//    }
+//
+//    @Override
+//    public int hashCode() {
+//        return 1;
+//    }
+//
+//    public String getConfig_key() {
+//        return config_key;
+//    }
+//
+//    public void setConfig_key(String config_key) {
+//        this.config_key = config_key;
+//    }
+//
+//    public void setConfig_val(String config_val) {
+//        this.config_val = config_val;
+//    }
+//
+//    public String getConfig_val() {
+//        return config_val;
+//    }
+//}

Added: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Configuration_PK.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Configuration_PK.java?rev=1384324&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Configuration_PK.java (added)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Configuration_PK.java Thu Sep 13 13:43:47 2012
@@ -0,0 +1,42 @@
+package org.apache.airavata.persistance.registry.jpa.model;
+
+
+public class Configuration_PK {
+    private String config_key;
+    private String config_val;
+
+    public Configuration_PK(String config_key, String config_val) {
+        this.config_key = config_key;
+        this.config_val = config_val;
+    }
+
+    public Configuration_PK() {
+        ;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return 1;
+    }
+
+    public String getConfig_key() {
+        return config_key;
+    }
+
+    public void setConfig_key(String config_key) {
+        this.config_key = config_key;
+    }
+
+    public void setConfig_val(String config_val) {
+        this.config_val = config_val;
+    }
+
+    public String getConfig_val() {
+        return config_val;
+    }
+}

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Gateway_Worker.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Gateway_Worker.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Gateway_Worker.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Gateway_Worker.java Thu Sep 13 13:43:47 2012
@@ -73,37 +73,3 @@ public class Gateway_Worker {
     }
 }
 
-class Gateway_Worker_PK {
-    private String gateway_name;
-    private String user_name;
-
-    public Gateway_Worker_PK() {
-        ;
-    }
-
-    @Override
-	public boolean equals(Object o) {
-		return false;
-	}
-
-	@Override
-	public int hashCode() {
-		return 1;
-	}
-
-    public String getUser_name() {
-        return user_name;
-    }
-
-    public void setUser_name(String user_name) {
-        this.user_name = user_name;
-    }
-
-    public String getGateway_name() {
-        return gateway_name;
-    }
-
-    public void setGateway_name(String gateway_name) {
-        this.gateway_name = gateway_name;
-    }
-}

Added: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Gateway_Worker_PK.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Gateway_Worker_PK.java?rev=1384324&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Gateway_Worker_PK.java (added)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Gateway_Worker_PK.java Thu Sep 13 13:43:47 2012
@@ -0,0 +1,41 @@
+package org.apache.airavata.persistance.registry.jpa.model;
+
+public class Gateway_Worker_PK {
+    private String gateway_name;
+    private String user_name;
+
+    public Gateway_Worker_PK(String gateway_name, String user_name) {
+        this.gateway_name = gateway_name;
+        this.user_name = user_name;
+    }
+
+    public Gateway_Worker_PK() {
+        ;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return 1;
+    }
+
+    public String getUser_name() {
+        return user_name;
+    }
+
+    public void setUser_name(String user_name) {
+        this.user_name = user_name;
+    }
+
+    public String getGateway_name() {
+        return gateway_name;
+    }
+
+    public void setGateway_name(String gateway_name) {
+        this.gateway_name = gateway_name;
+    }
+}

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Host_Descriptor.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Host_Descriptor.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Host_Descriptor.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Host_Descriptor.java Thu Sep 13 13:43:47 2012
@@ -80,38 +80,3 @@ public class Host_Descriptor {
     }
 }
 
-class Host_Descriptor_PK {
-    private String gateway_name;
-    private String host_descriptor_ID;
-
-    public Host_Descriptor_PK() {
-        ;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        return false;
-    }
-
-    @Override
-    public int hashCode() {
-        return 1;
-    }
-
-    public String getGateway_name() {
-        return gateway_name;
-    }
-
-    public String getHost_descriptor_ID() {
-        return host_descriptor_ID;
-    }
-
-    public void setGateway_name(String gateway_name) {
-        this.gateway_name = gateway_name;
-    }
-
-    public void setHost_descriptor_ID(String host_descriptor_ID) {
-        this.host_descriptor_ID = host_descriptor_ID;
-    }
-
-}

Added: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Host_Descriptor_PK.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Host_Descriptor_PK.java?rev=1384324&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Host_Descriptor_PK.java (added)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Host_Descriptor_PK.java Thu Sep 13 13:43:47 2012
@@ -0,0 +1,41 @@
+package org.apache.airavata.persistance.registry.jpa.model;
+
+public class Host_Descriptor_PK {
+    private String gateway_name;
+    private String host_descriptor_ID;
+
+    public Host_Descriptor_PK() {
+        ;
+    }
+
+    public Host_Descriptor_PK(String gateway_name, String host_descriptor_ID) {
+        this.gateway_name = gateway_name;
+        this.host_descriptor_ID = host_descriptor_ID;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return 1;
+    }
+
+    public String getGateway_name() {
+        return gateway_name;
+    }
+
+    public String getHost_descriptor_ID() {
+        return host_descriptor_ID;
+    }
+
+    public void setGateway_name(String gateway_name) {
+        this.gateway_name = gateway_name;
+    }
+
+    public void setHost_descriptor_ID(String host_descriptor_ID) {
+        this.host_descriptor_ID = host_descriptor_ID;
+    }
+}

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Published_Workflow.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Published_Workflow.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Published_Workflow.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Published_Workflow.java Thu Sep 13 13:43:47 2012
@@ -116,38 +116,4 @@ public class Published_Workflow {
     }
 }
 
-class Published_Workflow_PK {
-    private String gateway_name;
-    private String publish_workflow_name;
-
-    public Published_Workflow_PK() {
-        ;
-    }
-
-    @Override
-	public boolean equals(Object o) {
-		return false;
-	}
-
-	@Override
-	public int hashCode() {
-		return 1;
-	}
-
-    public String getPublish_workflow_name() {
-        return publish_workflow_name;
-    }
-
-    public void setPublish_workflow_name(String publish_workflow_name) {
-        this.publish_workflow_name = publish_workflow_name;
-    }
-
-    public String getGateway_name() {
-        return gateway_name;
-    }
-
-    public void setGateway_name(String gateway_name) {
-        this.gateway_name = gateway_name;
-    }
-}
 

Added: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Published_Workflow_PK.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Published_Workflow_PK.java?rev=1384324&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Published_Workflow_PK.java (added)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Published_Workflow_PK.java Thu Sep 13 13:43:47 2012
@@ -0,0 +1,41 @@
+package org.apache.airavata.persistance.registry.jpa.model;
+
+public class Published_Workflow_PK {
+    private String gateway_name;
+    private String publish_workflow_name;
+
+    public Published_Workflow_PK(String gateway_name, String publish_workflow_name) {
+        this.gateway_name = gateway_name;
+        this.publish_workflow_name = publish_workflow_name;
+    }
+
+    public Published_Workflow_PK() {
+        ;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return 1;
+    }
+
+    public String getPublish_workflow_name() {
+        return publish_workflow_name;
+    }
+
+    public void setPublish_workflow_name(String publish_workflow_name) {
+        this.publish_workflow_name = publish_workflow_name;
+    }
+
+    public String getGateway_name() {
+        return gateway_name;
+    }
+
+    public void setGateway_name(String gateway_name) {
+        this.gateway_name = gateway_name;
+    }
+}

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Service_Descriptor.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Service_Descriptor.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Service_Descriptor.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Service_Descriptor.java Thu Sep 13 13:43:47 2012
@@ -81,39 +81,5 @@ public class Service_Descriptor {
     }
 }
 
-class Service_Descriptor_PK{
-    private String gateway_name;
-    private String service_descriptor_ID;
-
-    public Service_Descriptor_PK() {
-        ;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        return false;
-    }
-
-    @Override
-    public int hashCode() {
-        return 1;
-    }
-
-    public String getGateway_name() {
-        return gateway_name;
-    }
-
-    public String getService_descriptor_ID() {
-        return service_descriptor_ID;
-    }
-
-    public void setGateway_name(String gateway_name) {
-        this.gateway_name = gateway_name;
-    }
-
-    public void setService_descriptor_ID(String service_descriptor_ID) {
-        this.service_descriptor_ID = service_descriptor_ID;
-    }
-}
 
 

Added: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Service_Descriptor_PK.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Service_Descriptor_PK.java?rev=1384324&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Service_Descriptor_PK.java (added)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/Service_Descriptor_PK.java Thu Sep 13 13:43:47 2012
@@ -0,0 +1,42 @@
+package org.apache.airavata.persistance.registry.jpa.model;
+
+
+public class Service_Descriptor_PK {
+    private String gateway_name;
+    private String service_descriptor_ID;
+
+    public Service_Descriptor_PK() {
+        ;
+    }
+
+    public Service_Descriptor_PK(String gateway_name, String service_descriptor_ID) {
+        this.gateway_name = gateway_name;
+        this.service_descriptor_ID = service_descriptor_ID;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return 1;
+    }
+
+    public String getGateway_name() {
+        return gateway_name;
+    }
+
+    public String getService_descriptor_ID() {
+        return service_descriptor_ID;
+    }
+
+    public void setGateway_name(String gateway_name) {
+        this.gateway_name = gateway_name;
+    }
+
+    public void setService_descriptor_ID(String service_descriptor_ID) {
+        this.service_descriptor_ID = service_descriptor_ID;
+    }
+}

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/User_Workflow.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/User_Workflow.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/User_Workflow.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/User_Workflow.java Thu Sep 13 13:43:47 2012
@@ -115,46 +115,3 @@ public class User_Workflow {
 
 }
 
-class User_Workflow_PK {
-    private String template_name;
-    private String gateway_name;
-    private String owner;
-
-    public User_Workflow_PK() {
-        ;
-    }
-
-    @Override
-	public boolean equals(Object o) {
-		return false;
-	}
-
-	@Override
-	public int hashCode() {
-		return 1;
-	}
-
-    public String getTemplate_name() {
-        return template_name;
-    }
-
-    public String getGateway_name() {
-        return gateway_name;
-    }
-
-    public String getOwner() {
-        return owner;
-    }
-
-    public void setOwner(String owner) {
-        this.owner = owner;
-    }
-
-    public void setTemplate_name(String template_name) {
-        this.template_name = template_name;
-    }
-
-    public void setGateway_name(String gateway_name) {
-        this.gateway_name = gateway_name;
-    }
-}

Added: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/User_Workflow_PK.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/User_Workflow_PK.java?rev=1384324&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/User_Workflow_PK.java (added)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model/User_Workflow_PK.java Thu Sep 13 13:43:47 2012
@@ -0,0 +1,51 @@
+package org.apache.airavata.persistance.registry.jpa.model;
+
+
+public class User_Workflow_PK {
+    private String template_name;
+    private String gateway_name;
+    private String owner;
+
+    public User_Workflow_PK(String template_name, String gateway_name) {
+        this.template_name = template_name;
+        this.gateway_name = gateway_name;
+    }
+
+    public User_Workflow_PK() {
+        ;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return 1;
+    }
+
+    public String getTemplate_name() {
+        return template_name;
+    }
+
+    public String getGateway_name() {
+        return gateway_name;
+    }
+
+    public String getOwner() {
+        return owner;
+    }
+
+    public void setOwner(String owner) {
+        this.owner = owner;
+    }
+
+    public void setTemplate_name(String template_name) {
+        this.template_name = template_name;
+    }
+
+    public void setGateway_name(String gateway_name) {
+        this.gateway_name = gateway_name;
+    }
+}

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java Thu Sep 13 13:43:47 2012
@@ -31,10 +31,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 public abstract class AbstractResource implements Resource {
-    private static final String PERSISTENCE_UNIT_NAME = "airavata_data";
-    protected EntityManagerFactory factory;
-    // protected EntityManager em;
-
     //table names
     public static final String GATEWAY = "Gateway";
     public static final String CONFIGURATION = "Configuration";
@@ -56,7 +52,7 @@ public abstract class AbstractResource i
 
     //Configuration Table
     public final class ConfigurationConstants {
-        public static final String CONFIG_ID = "config_ID";
+//        public static final String CONFIG_ID = "config_ID";
         public static final String CONFIG_KEY = "config_key";
         public static final String CONFIG_VAL = "config_val";
         public static final String EXPIRE_DATE = "expire_date";
@@ -141,32 +137,7 @@ public abstract class AbstractResource i
     }
 
     protected AbstractResource() {
-//        Map<String, String> properties = new HashMap<String, String>();
-//        properties.put("openjpa.ConnectionURL", Utils.getJDBCURL());
-//        properties.put("openjpa.ConnectionDriverName", Utils.getJDBCDriver());
-//        properties.put("openjpa.ConnectionUserName",Utils.getJDBCUser());
-//        properties.put("openjpa.ConnectionPassword",Utils.getJDBCPassword());
-//        properties.put("openjpa.DynamicEnhancementAgent","true");
-//        properties.put("openjpa.RuntimeUnenhancedClasses","supported");
-//        properties.put("openjpa.Log","SQL=ERROR");
-//        properties.put("openjpa.ConnectionFactoryProperties","PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=60000");
-//
-//        factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
-        // em = ResourceUtils.getEntityManager();
-    }
-
-//    protected void begin() {
-////        if(em == null)
-//            em = ResourceUtils.getEntityManager();
-////        }
-//        em.getTransaction().begin();
-//    }
-
-//    protected void end() {
-//        em.getTransaction().commit();
-//        //em.close();
-//
-//    }
+    }
 
     public boolean isExists(ResourceType type, Object name) {
         try {

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationDescriptorResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationDescriptorResource.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationDescriptorResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationDescriptorResource.java Thu Sep 13 13:43:47 2012
@@ -233,6 +233,11 @@ public class ApplicationDescriptorResour
      */
     public void save() {
         EntityManager em = ResourceUtils.getEntityManager();
+        Application_Descriptor existingAppDesc = em.find(Application_Descriptor.class, new Application_Descriptor_PK(gatewayName,
+                name, hostDescName, serviceDescName));
+        em.close();
+
+        em = ResourceUtils.getEntityManager();
         em.getTransaction().begin();
         Application_Descriptor applicationDescriptor = new Application_Descriptor();
         applicationDescriptor.setApplication_descriptor_ID(getName());
@@ -245,10 +250,14 @@ public class ApplicationDescriptorResour
         applicationDescriptor.setApplication_descriptor_xml(content);
         applicationDescriptor.setService_descriptor_ID(serviceDescName);
         applicationDescriptor.setHost_descriptor_ID(hostDescName);
-        em.merge(applicationDescriptor);
+        if (existingAppDesc != null) {
+            applicationDescriptor = em.merge(existingAppDesc);
+        } else {
+            em.merge(applicationDescriptor);
+        }
+
         em.getTransaction().commit();
         em.close();
-
     }
 
     /**

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ConfigurationResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ConfigurationResource.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ConfigurationResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ConfigurationResource.java Thu Sep 13 13:43:47 2012
@@ -32,10 +32,10 @@ import org.apache.airavata.persistance.r
 import org.apache.airavata.persistance.registry.jpa.ResourceType;
 import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
 import org.apache.airavata.persistance.registry.jpa.model.Configuration;
+import org.apache.airavata.persistance.registry.jpa.model.Configuration_PK;
 import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
 public class ConfigurationResource extends AbstractResource {
-    private int configID = -1;
     private String configKey;
     private String configVal;
     private Date expireDate;
@@ -48,10 +48,12 @@ public class ConfigurationResource exten
 
     /**
      *
-     * @param configID configuration ID
+     * @param configKey
+     * @param configVal
      */
-    public ConfigurationResource(int configID) {
-        this.configID = configID;
+    public ConfigurationResource(String configKey, String configVal) {
+        this.configKey = configKey;
+        this.configVal = configVal;
     }
 
     /**
@@ -137,19 +139,32 @@ public class ConfigurationResource exten
      *  save configuration to database
      */
     public synchronized void save() {
-        return;
-//        EntityManager em = ResourceUtils.getEntityManager();
-//        em.getTransaction().begin();
-//        Configuration configuration = new Configuration();
-//        configuration.setConfig_key(configKey);
-//        configuration.setConfig_val(configVal);
-//        configuration.setExpire_date(expireDate);
-//        if (configID != -1) {
-//            configuration.setConfig_ID(configID);
-//        }
-//        em.merge(configuration);
-//        em.getTransaction().commit();
-//        em.close();
+        Lock lock = ResourceUtils.getLock();
+        lock.lock();
+        try {
+            EntityManager em = ResourceUtils.getEntityManager();
+            //whether existing
+            Configuration existing = em.find(Configuration.class, new Configuration_PK(configKey, configVal));
+            em.close();
+
+            em = ResourceUtils.getEntityManager();
+            em.getTransaction().begin();
+            Configuration configuration = new Configuration();
+            configuration.setConfig_key(configKey);
+            configuration.setConfig_val(configVal);
+            configuration.setExpire_date(expireDate);
+            if(existing != null){
+               configuration = em.merge(existing);
+            }  else {
+                em.persist(configuration);
+            }
+
+            em.getTransaction().commit();
+            em.close();
+        }
+        finally {
+            lock.unlock();
+        }
     }
 
     /**

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ExperimentResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ExperimentResource.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ExperimentResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ExperimentResource.java Thu Sep 13 13:43:47 2012
@@ -142,6 +142,10 @@ public class ExperimentResource extends 
      */
     public void save() {
         EntityManager em = ResourceUtils.getEntityManager();
+        Experiment existingExp = em.find(Experiment.class, expID);
+        em.close();
+
+        em = ResourceUtils.getEntityManager();
         em.getTransaction().begin();
         Experiment experiment = new Experiment();
         Project project = new Project();
@@ -155,7 +159,12 @@ public class ExperimentResource extends 
         experiment.setUser(user);
         experiment.setGateway(gateway);
         experiment.setSubmitted_date(submittedDate);
-        em.merge(experiment);
+        if(existingExp != null){
+            experiment = em.merge(existingExp);
+        } else{
+           em.merge(experiment);
+        }
+
         em.getTransaction().commit();
         em.close();
     }

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java Thu Sep 13 13:43:47 2012
@@ -385,13 +385,22 @@ public class GatewayResource extends Abs
      */
     public void save() {
         EntityManager em = ResourceUtils.getEntityManager();
+        Gateway existingGateway = em.find(Gateway.class, gatewayName);
+        em.close();
+
+        em = ResourceUtils.getEntityManager();
         em.getTransaction().begin();
         Gateway gateway = new Gateway();
         gateway.setGateway_name(gatewayName);
         gateway.setOwner(owner);
-        em.merge(gateway);
+        if (existingGateway != null) {
+            gateway = em.merge(existingGateway);
+        } else {
+            em.persist(gateway);
+        }
         em.getTransaction().commit();
         em.close();
+
     }
 
     /**
@@ -405,7 +414,6 @@ public class GatewayResource extends Abs
         em.getTransaction().begin();
         Query q;
         Number count;
-        QueryGenerator generator;
         switch (type){
             case USER:
                 q = em.createQuery("SELECT COUNT(p.user_name) FROM Gateway_Worker p WHERE p.gateway_name =:gate_name and p.user_name =:userName");

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/HostDescriptorResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/HostDescriptorResource.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/HostDescriptorResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/HostDescriptorResource.java Thu Sep 13 13:43:47 2012
@@ -23,10 +23,7 @@ package org.apache.airavata.persistance.
 import org.apache.airavata.persistance.registry.jpa.Resource;
 import org.apache.airavata.persistance.registry.jpa.ResourceType;
 import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
-import org.apache.airavata.persistance.registry.jpa.model.Application_Descriptor;
-import org.apache.airavata.persistance.registry.jpa.model.Gateway;
-import org.apache.airavata.persistance.registry.jpa.model.Host_Descriptor;
-import org.apache.airavata.persistance.registry.jpa.model.Users;
+import org.apache.airavata.persistance.registry.jpa.model.*;
 import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
 import javax.persistence.EntityManager;
@@ -193,6 +190,10 @@ public class HostDescriptorResource exte
      */
     public void save() {
         EntityManager em = ResourceUtils.getEntityManager();
+        Host_Descriptor existingHost_desc = em.find(Host_Descriptor.class, new Host_Descriptor_PK(gatewayName, hostDescName));
+        em.close();
+
+        em = ResourceUtils.getEntityManager();
         em.getTransaction().begin();
         Host_Descriptor hostDescriptor = new Host_Descriptor();
         Gateway gateway = new Gateway();
@@ -203,7 +204,12 @@ public class HostDescriptorResource exte
         hostDescriptor.setGateway(gateway);
         hostDescriptor.setHost_descriptor_xml(content);
         hostDescriptor.setUser(user);
-        em.merge(hostDescriptor);
+        if(existingHost_desc != null){
+            hostDescriptor = em.merge(existingHost_desc);
+        } else {
+            em.merge(hostDescriptor);
+        }
+
         em.getTransaction().commit();
         em.close();
 

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/PublishWorkflowResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/PublishWorkflowResource.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/PublishWorkflowResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/PublishWorkflowResource.java Thu Sep 13 13:43:47 2012
@@ -25,6 +25,7 @@ import org.apache.airavata.persistance.r
 import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
 import org.apache.airavata.persistance.registry.jpa.model.Gateway;
 import org.apache.airavata.persistance.registry.jpa.model.Published_Workflow;
+import org.apache.airavata.persistance.registry.jpa.model.Published_Workflow_PK;
 import org.apache.airavata.persistance.registry.jpa.model.Users;
 import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
@@ -213,6 +214,10 @@ public class PublishWorkflowResource ext
      */
     public void save() {
         EntityManager em = ResourceUtils.getEntityManager();
+        Published_Workflow existingWF = em.find(Published_Workflow.class, new Published_Workflow_PK(gateway.getGatewayName(), name));
+        em.close();
+
+        em = ResourceUtils.getEntityManager();
         em.getTransaction().begin();
         Published_Workflow publishedWorkflow = new Published_Workflow();
         publishedWorkflow.setPublish_workflow_name(getName());
@@ -225,7 +230,12 @@ public class PublishWorkflowResource ext
         Users user = new Users();
         user.setUser_name(createdUser);
         publishedWorkflow.setUser(user);
-        em.merge(gateway);
+        if(existingWF != null){
+            publishedWorkflow = em.merge(existingWF);
+        }else {
+            em.merge(gateway);
+        }
+
         em.getTransaction().commit();
         em.close();
     }

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ServiceDescriptorResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ServiceDescriptorResource.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ServiceDescriptorResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ServiceDescriptorResource.java Thu Sep 13 13:43:47 2012
@@ -23,10 +23,7 @@ package org.apache.airavata.persistance.
 import org.apache.airavata.persistance.registry.jpa.Resource;
 import org.apache.airavata.persistance.registry.jpa.ResourceType;
 import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
-import org.apache.airavata.persistance.registry.jpa.model.Application_Descriptor;
-import org.apache.airavata.persistance.registry.jpa.model.Gateway;
-import org.apache.airavata.persistance.registry.jpa.model.Service_Descriptor;
-import org.apache.airavata.persistance.registry.jpa.model.Users;
+import org.apache.airavata.persistance.registry.jpa.model.*;
 import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
 import javax.persistence.EntityManager;
@@ -136,6 +133,10 @@ public class ServiceDescriptorResource e
 
     public void save() {
         EntityManager em = ResourceUtils.getEntityManager();
+        Service_Descriptor existingServiceDesc = em.find(Service_Descriptor.class, new Service_Descriptor_PK(gatewayName, serviceDescName));
+        em.close();
+
+        em = ResourceUtils.getEntityManager();
         em.getTransaction().begin();
         Service_Descriptor serviceDescriptor = new Service_Descriptor();
         serviceDescriptor.setService_descriptor_ID(getServiceDescName());
@@ -146,7 +147,11 @@ public class ServiceDescriptorResource e
         Users user = new Users();
         user.setUser_name(userName);
         serviceDescriptor.setUser(user);
-        em.merge(serviceDescriptor);
+        if(existingServiceDesc != null) {
+            serviceDescriptor = em.merge(existingServiceDesc);
+        }else {
+            em.merge(serviceDescriptor);
+        }
         em.getTransaction().commit();
         em.close();
 

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserResource.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserResource.java Thu Sep 13 13:43:47 2012
@@ -115,11 +115,19 @@ public class UserResource extends Abstra
      */
     public void save() {
         EntityManager em = ResourceUtils.getEntityManager();
+        Users existingUser = em.find(Users.class, userName);
+        em.close();
+
+        em = ResourceUtils.getEntityManager();
         em.getTransaction().begin();
         Users user = new Users();
         user.setUser_name(userName);
         user.setPassword(password);
-        em.merge(user);
+        if(existingUser != null){
+            user = em.merge(existingUser);
+        }else {
+            em.persist(user);
+        }
         em.getTransaction().commit();
         em.close();
     }

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserWorkflowResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserWorkflowResource.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserWorkflowResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserWorkflowResource.java Thu Sep 13 13:43:47 2012
@@ -25,6 +25,7 @@ import org.apache.airavata.persistance.r
 import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
 import org.apache.airavata.persistance.registry.jpa.model.Gateway;
 import org.apache.airavata.persistance.registry.jpa.model.User_Workflow;
+import org.apache.airavata.persistance.registry.jpa.model.User_Workflow_PK;
 import org.apache.airavata.persistance.registry.jpa.model.Users;
 import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
@@ -124,6 +125,10 @@ public class UserWorkflowResource extend
 
     public void save() {
         EntityManager em = ResourceUtils.getEntityManager();
+        User_Workflow existingWF = em.find(User_Workflow.class, new User_Workflow_PK(gateway.getGatewayName(), name));
+        em.close();
+
+        em = ResourceUtils.getEntityManager();
         em.getTransaction().begin();
         User_Workflow userWorkflow = new User_Workflow();
         userWorkflow.setTemplate_name(name);
@@ -136,7 +141,11 @@ public class UserWorkflowResource extend
         user.setUser_name(worker.getUser());
         userWorkflow.setUser(user);
         userWorkflow.setPath(path);
-        em.merge(userWorkflow);
+        if(existingWF != null){
+            userWorkflow = em.merge(existingWF);
+        } else {
+            em.merge(userWorkflow);
+        }
         em.getTransaction().commit();
         em.close();
     }

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java Thu Sep 13 13:43:47 2012
@@ -37,7 +37,7 @@ public class Utils {
         try {
             properties.load(resource.openStream());
         } catch (IOException e) {
-            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            e.printStackTrace();
         }
         return properties;
     }

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java Thu Sep 13 13:43:47 2012
@@ -224,6 +224,10 @@ public class WorkerResource extends Abst
      */
 	public void save() {
         EntityManager em = ResourceUtils.getEntityManager();
+        Gateway_Worker existingWorker = em.find(Gateway_Worker.class, new Gateway_Worker_PK(gateway.getGatewayName(), user));
+        em.close();
+
+        em = ResourceUtils.getEntityManager();
         em.getTransaction().begin();
         Gateway_Worker gatewayWorker = new Gateway_Worker();
         Users users = new Users();
@@ -233,7 +237,11 @@ public class WorkerResource extends Abst
         gatewaymodel.setGateway_name(gateway.getGatewayName());
         gatewaymodel.setOwner(gateway.getOwner());
         gatewayWorker.setGateway(gatewaymodel);
-        em.merge(gatewayWorker);
+        if(existingWorker != null){
+            gatewayWorker = em.merge(existingWorker);
+        }else {
+            em.merge(gatewayWorker);
+        }
         em.getTransaction().commit();
         em.close();
 	}

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/data-derby.sql
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/data-derby.sql?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/data-derby.sql (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/data-derby.sql Thu Sep 13 13:43:47 2012
@@ -28,12 +28,10 @@ create table Gateway
 
 create table Configuration
 (
-        config_ID int NOT NULL primary key
-        GENERATED ALWAYS AS IDENTITY
-        (START WITH 1, INCREMENT BY 1),
         config_key varchar(255),
         config_val varchar(255),
-        expire_date TIMESTAMP DEFAULT '0000-00-00 00:00:00'
+        expire_date TIMESTAMP DEFAULT '0000-00-00 00:00:00',
+        PRIMARY KEY(config_key, config_val)
 );
 
 create table Users

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/data-mysql.sql
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/data-mysql.sql?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/data-mysql.sql (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/data-mysql.sql Thu Sep 13 13:43:47 2012
@@ -27,11 +27,10 @@ create table Gateway
 
 create table Configuration
 (
-        config_ID int(11) NOT NULL AUTO_INCREMENT,
         config_key varchar(255),
         config_val varchar(255),
         expire_date TIMESTAMP DEFAULT '0000-00-00 00:00:00',
-        PRIMARY KEY(config_ID)
+        PRIMARY KEY(config_key, config_val)
 );
 
 create table Users

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java?rev=1384324&r1=1384323&r2=1384324&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java Thu Sep 13 13:43:47 2012
@@ -32,6 +32,29 @@ public class GatewayResourceTest extends
     }
 
     public void testSave() throws Exception {
+//        Calendar cal = Calendar.getInstance();
+//        cal.set( cal.YEAR, 1970 );
+//        cal.set( cal.MONTH, cal.JANUARY );
+//        cal.set( cal.DATE, 1 );
+//
+//        cal.set( cal.HOUR_OF_DAY, 0 );
+//        cal.set( cal.MINUTE, 0 );
+//        cal.set( cal.SECOND, 0 );
+//        cal.set( cal.MILLISECOND, 0 );
+//
+//        java.sql.Date jsqlD =
+//                new java.sql.Date( cal.getTime().getTime() );
+//
+//        ConfigurationResource config = ResourceUtils.createConfiguration("aa");
+//        config.setConfigVal("http://129.79.49.142:8080/axis2/services/WorkflowInterpretor/aaaa");
+//        config.setExpireDate(jsqlD);
+//        config.save();
+
+//        ConfigurationResource configurationResource = new ConfigurationResource();
+//        configurationResource.setConfigKey("cc");
+//        configurationResource.setConfigVal("http://129.79.49.142:8080/axis2/services/WorkflowInterpretor/aaaa");
+//        configurationResource.setExpireDate(jsqlD);
+//        configurationResource.save();
 //        List<HostDescriptorResource>  list = gatewayResource.getHostDescriptorResources();
 //        for(HostDescriptorResource resource : list) {
 //            System.out.println("Host Descriptor name :" +  resource.getHostDescName());



Mime
View raw message