airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject svn commit: r1384144 - in /incubator/airavata/trunk/modules: distribution/src/main/resources/conf/ registry/airavata-jpa-registry/ registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ registry/airavata-jpa-registry...
Date Wed, 12 Sep 2012 21:52:49 GMT
Author: lahiru
Date: Wed Sep 12 21:52:49 2012
New Revision: 1384144

URL: http://svn.apache.org/viewvc?rev=1384144&view=rev
Log:
fixing configurations not saving issue

Added:
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/test/resources/
Modified:
    incubator/airavata/trunk/modules/distribution/src/main/resources/conf/repository.properties
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/pom.xml
    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/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/ProjectResource.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/WorkerResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java
    incubator/airavata/trunk/modules/xbaya-gui/src/main/resources/repository.properties

Modified: incubator/airavata/trunk/modules/distribution/src/main/resources/conf/repository.properties
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/distribution/src/main/resources/conf/repository.properties?rev=1384144&r1=1384143&r2=1384144&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/distribution/src/main/resources/conf/repository.properties (original)
+++ incubator/airavata/trunk/modules/distribution/src/main/resources/conf/repository.properties Wed Sep 12 21:52:49 2012
@@ -83,5 +83,9 @@ gateway.id=default
 registry.jdbc.driver=com.mysql.jdbc.Driver
 registry.jdbc.user=airavata
 registry.jdbc.password=airavata
-registry.jdbc.url=jdbc:mysql://140.182.193.104:3306/persistent_data_lahiru?user=airavata&password=airavata
+registry.jdbc.url=jdbc:mysql://localhost:3306/persistent_data
+
+#for derby database
+#registry.jdbc.driver=org.apache.derby.jdbc.EmbeddedDriver
+#registry.jdbc.url=jdbc:derby:persistent_data
 

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/pom.xml
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/pom.xml?rev=1384144&r1=1384143&r2=1384144&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/pom.xml (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/pom.xml Wed Sep 12 21:52:49 2012
@@ -64,6 +64,11 @@
             <artifactId>airavata-registry-api</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <!--dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>5.1.6</version>
+        </dependency-->
 
     </dependencies>
 

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=1384144&r1=1384143&r2=1384144&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 Wed Sep 12 21:52:49 2012
@@ -35,11 +35,15 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
 
 public class ResourceUtils {
     private static final String PERSISTENCE_UNIT_NAME = "airavata_data";
     protected static EntityManagerFactory factory;
-    protected static EntityManager em;
+    // protected static EntityManager em;
+
+    private static Lock lock = new ReentrantLock();
 
     public static EntityManager getEntityManager(){
         Map<String, String> properties = new HashMap<String, String>();
@@ -49,12 +53,15 @@ public class ResourceUtils {
         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.Log","SQL=TRACE");
+        properties.put("openjpa.LockManager", "none");
         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 = factory.createEntityManager();
-        return em;
+        if (factory == null) {
+            factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
+        }
+
+        return factory.createEntityManager();
     }
 
     /**
@@ -76,14 +83,15 @@ public class ResourceUtils {
      * @return
      */
     public static boolean isGatewayExist(String gatewayName) {
-        em = getEntityManager();
+
+        EntityManager em = getEntityManager();
         em.getTransaction().begin();
         QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY);
         generator.setParameter(AbstractResource.GatewayConstants.GATEWAY_NAME, gatewayName);
         Query q = generator.selectQuery(em);
         Gateway gateway = (Gateway) q.getSingleResult();
         em.getTransaction().commit();
-//        em.close();
+        em.close();
         return gateway != null;
     }
 
@@ -93,14 +101,14 @@ public class ResourceUtils {
      */
     public static boolean removeGateway(String gatewayName) {
         try {
-            em = getEntityManager();
+            EntityManager em = getEntityManager();
             em.getTransaction().begin();
             QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY);
             generator.setParameter(AbstractResource.GatewayConstants.GATEWAY_NAME, gatewayName);
             Query q = generator.deleteQuery(em);
             q.executeUpdate();
             em.getTransaction().commit();
-//            em.close();
+            em.close();
             return true;
         } catch (Exception e) {
             e.printStackTrace();
@@ -116,7 +124,7 @@ public class ResourceUtils {
      */
     public static void addGatewayWorker(GatewayResource gatewayResource, UserResource userResource) {
         try {
-            em = getEntityManager();
+            EntityManager em = getEntityManager();
             em.getTransaction().begin();
             Gateway gateway = new Gateway();
             gateway.setGateway_name(gatewayResource.getGatewayName());
@@ -127,7 +135,7 @@ public class ResourceUtils {
             gatewayWorker.setUser(user);
             em.persist(gatewayWorker);
             em.getTransaction().commit();
-//            em.close();
+            em.close();
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -141,7 +149,7 @@ public class ResourceUtils {
      */
     public static boolean removeGatewayWorker(GatewayResource gatewayResource, UserResource userResource) {
         try {
-            em = getEntityManager();
+            EntityManager em = getEntityManager();
             em.getTransaction().begin();
             QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY_WORKER);
             generator.setParameter(AbstractResource.GatewayWorkerConstants.GATEWAY_NAME,
@@ -150,7 +158,7 @@ public class ResourceUtils {
             Query q = generator.deleteQuery(em);
             q.executeUpdate();
             em.getTransaction().commit();
-//            em.close();
+            em.close();
             return true;
         } catch (Exception e) {
             e.printStackTrace();
@@ -165,7 +173,7 @@ public class ResourceUtils {
      */
     public static List<ConfigurationResource> getConfigurations(String configKey) {
         List<ConfigurationResource> list = new ArrayList<ConfigurationResource>();
-        em = getEntityManager();
+        EntityManager em = getEntityManager();
         em.getTransaction().begin();
         QueryGenerator generator = new QueryGenerator(AbstractResource.CONFIGURATION);
         generator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configKey);
@@ -178,7 +186,7 @@ public class ResourceUtils {
             }
         }
         em.getTransaction().commit();
-//        em.close();
+        em.close();
         return list;
     }
 
@@ -229,32 +237,34 @@ public class ResourceUtils {
      * @param configValue
      */
     public static void removeConfiguration(String configkey, String configValue) {
-        em = getEntityManager();
+        EntityManager em = getEntityManager();
         em.getTransaction().begin();
-//        Query q = em.createQuery("Delete FROM Configuration p WHERE p.config_key = :configKey and p.config_val = :configVal");
-//        q.setParameter("configKey", configkey);
-//        q.setParameter("configVal", configValue);
-        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();
+//        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();
-
+        em.close();
     }
 
     /**
      * @param configkey
      */
     public static void removeConfiguration(String configkey) {
-        em = getEntityManager();
+        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();
+
+//        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();
+        em.close();
+
+    }
+
+    public static Lock getLock() {
+        return lock;
     }
 }

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=1384144&r1=1384143&r2=1384144&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 Wed Sep 12 21:52:49 2012
@@ -25,9 +25,15 @@ import org.apache.airavata.persistance.r
 import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
 
 import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import java.util.HashMap;
+import java.util.Map;
 
 public abstract class AbstractResource implements Resource {
-    protected EntityManager em;
+    private static final String PERSISTENCE_UNIT_NAME = "airavata_data";
+    protected EntityManagerFactory factory;
+    // protected EntityManager em;
 
     //table names
     public static final String GATEWAY = "Gateway";
@@ -135,21 +141,32 @@ public abstract class AbstractResource i
     }
 
     protected AbstractResource() {
-        em = ResourceUtils.getEntityManager();
-    }
-
-    protected void begin() {
-        if(em == null){
-            em = ResourceUtils.getEntityManager();
-        }
-        em.getTransaction().begin();
-    }
-
-    protected void end() {
-        em.getTransaction().commit();
-//        em.close();
-
-    }
+//        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=1384144&r1=1384143&r2=1384144&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 Wed Sep 12 21:52:49 2012
@@ -22,9 +22,11 @@ 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.*;
 import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
+import javax.persistence.EntityManager;
 import javax.persistence.Query;
 import java.util.ArrayList;
 import java.util.List;
@@ -165,7 +167,8 @@ public class ApplicationDescriptorResour
      * @param keys primary keys of the Application_descriptor table
      */
     public void removeMe(Object[] keys) {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         QueryGenerator queryGenerator = new QueryGenerator(APPLICATION_DESCRIPTOR);
         queryGenerator.setParameter(ApplicationDescriptorConstants.GATEWAY_NAME, keys[0]);
         queryGenerator.setParameter(ApplicationDescriptorConstants.APPLICATION_DESC_ID, keys[1]);
@@ -173,7 +176,8 @@ public class ApplicationDescriptorResour
         queryGenerator.setParameter(ApplicationDescriptorConstants.SERVICE_DESC_ID, keys[3]);
         Query q = queryGenerator.deleteQuery(em);
         q.executeUpdate();
-        end();
+        em.getTransaction().commit();
+        em.close();
     }
 
     /**
@@ -196,7 +200,8 @@ public class ApplicationDescriptorResour
      */
     public List<Resource> populate(Object[] keys) {
         List<Resource> list = new ArrayList<Resource>();
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         QueryGenerator queryGenerator = new QueryGenerator(APPLICATION_DESCRIPTOR);
         queryGenerator.setParameter(ApplicationDescriptorConstants.GATEWAY_NAME, keys[0]);
         queryGenerator.setParameter(ApplicationDescriptorConstants.APPLICATION_DESC_ID, keys[1]);
@@ -207,7 +212,8 @@ public class ApplicationDescriptorResour
         ApplicationDescriptorResource applicationDescriptorResource =
                 (ApplicationDescriptorResource) Utils.getResource(
                         ResourceType.APPLICATION_DESCRIPTOR, applicationDescriptor);
-        end();
+        em.getTransaction().commit();
+        em.close();
         list.add(applicationDescriptorResource);
         return list;
     }
@@ -226,7 +232,8 @@ public class ApplicationDescriptorResour
      *  save application descriptor to database
      */
     public void save() {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         Application_Descriptor applicationDescriptor = new Application_Descriptor();
         applicationDescriptor.setApplication_descriptor_ID(getName());
         Gateway gateway = new Gateway();
@@ -239,7 +246,8 @@ public class ApplicationDescriptorResour
         applicationDescriptor.setService_descriptor_ID(serviceDescName);
         applicationDescriptor.setHost_descriptor_ID(hostDescName);
         em.merge(applicationDescriptor);
-        end();
+        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=1384144&r1=1384143&r2=1384144&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 Wed Sep 12 21:52:49 2012
@@ -23,11 +23,14 @@ package org.apache.airavata.persistance.
 import java.sql.Date;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.locks.Lock;
 
+import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
 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.Configuration;
 import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
@@ -91,7 +94,8 @@ public class ConfigurationResource exten
      */
     public List<Resource> populate(Object[] keys) {
         List<Resource> list = new ArrayList<Resource>();
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         QueryGenerator queryGenerator = new QueryGenerator(CONFIGURATION);
         queryGenerator.setParameter(ConfigurationConstants.CONFIG_KEY, keys[0]);
         Query q = queryGenerator.selectQuery(em);
@@ -104,7 +108,8 @@ public class ConfigurationResource exten
                 list.add(configurationResource);
             }
         }
-        end();
+        em.getTransaction().commit();
+        em.close();
         return list;
 
     }
@@ -131,17 +136,20 @@ public class ConfigurationResource exten
     /**
      *  save configuration to database
      */
-    public void save() {
-        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.persist(configuration);
-        end();
+    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();
     }
 
     /**

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=1384144&r1=1384143&r2=1384144&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 Wed Sep 12 21:52:49 2012
@@ -24,10 +24,12 @@ import java.sql.Date;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
 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.Experiment;
 import org.apache.airavata.persistance.registry.jpa.model.Gateway;
 import org.apache.airavata.persistance.registry.jpa.model.Project;
@@ -110,14 +112,16 @@ public class ExperimentResource extends 
      */
     public List<Resource> populate(Object[] keys) {
         List<Resource> list = new ArrayList<Resource>();
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         QueryGenerator queryGenerator = new QueryGenerator(EXPERIMENT);
         queryGenerator.setParameter(ExperimentConstants.EXPERIMENT_ID, keys[0]);
         Query q = queryGenerator.selectQuery(em);
         Experiment experiment = (Experiment)q.getSingleResult();
         ExperimentResource experimentResource =
                 (ExperimentResource)Utils.getResource(ResourceType.EXPERIMENT, experiment);
-        end();
+        em.getTransaction().commit();
+        em.close();
         list.add(experimentResource);
         return list;
 
@@ -137,7 +141,8 @@ public class ExperimentResource extends 
      * save experiment
      */
     public void save() {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         Experiment experiment = new Experiment();
         Project project = new Project();
         project.setProject_ID(this.project.getId());
@@ -151,7 +156,8 @@ public class ExperimentResource extends 
         experiment.setGateway(gateway);
         experiment.setSubmitted_date(submittedDate);
         em.merge(experiment);
-        end();
+        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=1384144&r1=1384143&r2=1384144&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 Wed Sep 12 21:52:49 2012
@@ -23,10 +23,12 @@ package org.apache.airavata.persistance.
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
 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.*;
 import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
@@ -134,7 +136,8 @@ public class GatewayResource extends Abs
      * @param name child resource name
      */
     public void remove(ResourceType type, Object name) {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         Query q;
         QueryGenerator generator;
         switch (type){
@@ -143,7 +146,6 @@ public class GatewayResource extends Abs
                 generator.setParameter(UserConstants.USERNAME, name);
                 q = generator.deleteQuery(em);
                 q.executeUpdate();
-                end();
                 break;
             case PUBLISHED_WORKFLOW:
                 generator = new QueryGenerator(PUBLISHED_WORKFLOW);
@@ -151,7 +153,6 @@ public class GatewayResource extends Abs
                 generator.setParameter(PublishedWorkflowConstants.GATEWAY_NAME, gatewayName);
                 q = generator.deleteQuery(em);
                 q.executeUpdate();
-                end();
                 break;
             case HOST_DESCRIPTOR:
                 generator = new QueryGenerator(HOST_DESCRIPTOR);
@@ -159,7 +160,6 @@ public class GatewayResource extends Abs
                 generator.setParameter(HostDescriptorConstants.GATEWAY_NAME, gatewayName);
                 q = generator.deleteQuery(em);
                 q.executeUpdate();
-                end();
                 break;
             case SERVICE_DESCRIPTOR:
                 generator = new QueryGenerator(SERVICE_DESCRIPTOR);
@@ -167,7 +167,6 @@ public class GatewayResource extends Abs
                 generator.setParameter(ServiceDescriptorConstants.GATEWAY_NAME, gatewayName);
                 q = generator.deleteQuery(em);
                 q.executeUpdate();
-                end();
                 break;
             case EXPERIMENT:
                 generator = new QueryGenerator(EXPERIMENT);
@@ -175,12 +174,14 @@ public class GatewayResource extends Abs
                 generator.setParameter(ExperimentConstants.GATEWAY_NAME, gatewayName);
                 q = generator.deleteQuery(em);
                 q.executeUpdate();
-                end();
                 break;
             default:
                 break;
 
         }
+
+        em.getTransaction().commit();
+        em.close();
     }
 
     /**
@@ -190,7 +191,8 @@ public class GatewayResource extends Abs
      * @return specific child resource type
      */
     public Resource get(ResourceType type, Object name) {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         QueryGenerator generator;
         Query q;
         switch (type) {
@@ -202,7 +204,8 @@ public class GatewayResource extends Abs
                 Users eUser = (Users) q.getSingleResult();
                 WorkerResource workerResource =
                         (WorkerResource)Utils.getResource(ResourceType.GATEWAY_WORKER, eUser);
-                end();
+                em.getTransaction().commit();
+                em.close();
                 return workerResource;
             case PUBLISHED_WORKFLOW:
                 generator = new QueryGenerator(PUBLISHED_WORKFLOW);
@@ -212,7 +215,8 @@ public class GatewayResource extends Abs
                 Published_Workflow ePub_workflow = (Published_Workflow) q.getSingleResult();
                 PublishWorkflowResource publishWorkflowResource =
                         (PublishWorkflowResource)Utils.getResource(ResourceType.PUBLISHED_WORKFLOW, ePub_workflow);
-                end();
+                em.getTransaction().commit();
+                em.close();
                 return publishWorkflowResource;
             case HOST_DESCRIPTOR:
                 generator = new QueryGenerator(HOST_DESCRIPTOR);
@@ -222,7 +226,8 @@ public class GatewayResource extends Abs
                 Host_Descriptor eHostDesc = (Host_Descriptor) q.getSingleResult();
                 HostDescriptorResource hostDescriptorResource =
                         (HostDescriptorResource)Utils.getResource(ResourceType.HOST_DESCRIPTOR, eHostDesc);
-                end();
+                em.getTransaction().commit();
+                em.close();
                 return hostDescriptorResource;
             case EXPERIMENT:
                 generator = new QueryGenerator(EXPERIMENT);
@@ -232,7 +237,8 @@ public class GatewayResource extends Abs
                 Experiment experiment = (Experiment)q.getSingleResult();
                 ExperimentResource experimentResource =
                         (ExperimentResource)Utils.getResource(ResourceType.EXPERIMENT, experiment);
-                end();
+                em.getTransaction().commit();
+                em.close();
                 return experimentResource;
             case SERVICE_DESCRIPTOR:
                 generator = new QueryGenerator(SERVICE_DESCRIPTOR);
@@ -242,10 +248,12 @@ public class GatewayResource extends Abs
                 Service_Descriptor eServiceDesc = (Service_Descriptor) q.getSingleResult();
                 ServiceDescriptorResource serviceDescriptorResource =
                         (ServiceDescriptorResource)Utils.getResource(ResourceType.SERVICE_DESCRIPTOR, eServiceDesc);
-                end();
+                em.getTransaction().commit();
+                em.close();
                 return serviceDescriptorResource;
             default:
-                end();
+                em.getTransaction().commit();
+                em.close();
                 throw new IllegalArgumentException("Unsupported resource type for gateway resource.");
 
         }
@@ -258,7 +266,8 @@ public class GatewayResource extends Abs
      */
     public List<Resource> get(ResourceType type) {
         List<Resource> resourceList = new ArrayList<Resource>();
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         Query q;
         QueryGenerator generator;
         List results;
@@ -362,9 +371,12 @@ public class GatewayResource extends Abs
                 }
                 break;
             default:
+                em.getTransaction().commit();
+                em.close();
                 throw new IllegalArgumentException("Unsupported resource type for gateway resource.");
         }
-        end();
+        em.getTransaction().commit();
+        em.close();
         return resourceList;
     }
 
@@ -372,12 +384,14 @@ public class GatewayResource extends Abs
      * save the gateway to the database
      */
     public void save() {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         Gateway gateway = new Gateway();
         gateway.setGateway_name(gatewayName);
         gateway.setOwner(owner);
         em.merge(gateway);
-        end();
+        em.getTransaction().commit();
+        em.close();
     }
 
     /**
@@ -387,7 +401,8 @@ public class GatewayResource extends Abs
      * @return true or false
      */
     public boolean isExists(ResourceType type, Object name) {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         Query q;
         Number count;
         QueryGenerator generator;
@@ -397,7 +412,8 @@ public class GatewayResource extends Abs
                 q.setParameter("gate_name", gatewayName);
                 q.setParameter("userName",name);
                 count = (Number) q.getSingleResult();
-                end();
+                em.getTransaction().commit();
+                em.close();
                 return count.intValue() != 0;
 //                generator = new QueryGenerator(GATEWAY_WORKER);
 //                generator.setParameter(GatewayWorkerConstants.GATEWAY_NAME, gatewayName);
@@ -411,7 +427,8 @@ public class GatewayResource extends Abs
                 q.setParameter("gate_name", gatewayName);
                 q.setParameter("pub_wf_name",name);
                 count = (Number) q.getSingleResult();
-                end();
+                em.getTransaction().commit();
+                em.close();
                 return count.intValue() != 0;
 //                generator = new QueryGenerator(PUBLISHED_WORKFLOW);
 //                generator.setParameter(PublishedWorkflowConstants.GATEWAY_NAME, gatewayName);
@@ -425,14 +442,16 @@ public class GatewayResource extends Abs
                 q.setParameter("gate_name", gatewayName);
                 q.setParameter("host_desc_name",name);
                 count = (Number) q.getSingleResult();
-                end();
+                em.getTransaction().commit();
+                em.close();
                 return count.intValue() != 0;
             case SERVICE_DESCRIPTOR:
                 q = em.createQuery("SELECT COUNT(p.service_descriptor_ID) FROM Service_Descriptor p WHERE p.gateway_name =:gate_name and p.service_descriptor_ID =:service_desc_name");
                 q.setParameter("gate_name", gatewayName);
                 q.setParameter("service_desc_name",name);
                 count = (Number) q.getSingleResult();
-                end();
+                em.getTransaction().commit();
+                em.close();
                 return count.intValue() != 0;
 //                generator = new QueryGenerator(SERVICE_DESCRIPTOR);
 //                generator.setParameter(ServiceDescriptorConstants.GATEWAY_NAME, gatewayName);
@@ -446,7 +465,8 @@ public class GatewayResource extends Abs
                 q.setParameter("gate_name", gatewayName);
                 q.setParameter("service_desc_name",name);
                 count = (Number) q.getSingleResult();
-                end();
+                em.getTransaction().commit();
+                em.close();
                 return count.intValue() != 0;
 //                generator = new QueryGenerator(APPLICATION_DESCRIPTOR);
 //                generator.setParameter(ApplicationDescriptorConstants.GATEWAY_NAME, gatewayName);
@@ -460,7 +480,8 @@ public class GatewayResource extends Abs
                 q.setParameter("gate_name", gatewayName);
                 q.setParameter("exp_name",name);
                 count = (Number) q.getSingleResult();
-                end();
+                em.getTransaction().commit();
+                em.close();
                 return count.intValue() != 0;
 //                generator = new QueryGenerator(EXPERIMENT);
 //                generator.setParameter(ExperimentConstants.GATEWAY_NAME, gatewayName);
@@ -470,7 +491,8 @@ public class GatewayResource extends Abs
 //                end();
 //                return experiment != null;
             default:
-                end();
+                em.getTransaction().commit();
+                em.close();
                 throw new IllegalArgumentException("Unsupported resource type for gateway resource.");
         }
     }
@@ -632,7 +654,8 @@ public class GatewayResource extends Abs
      * @return  list of application descriptors for the gateway
      */
     public List<ApplicationDescriptorResource> getApplicationDescriptorResources(String serviceName,String hostName){
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         String qString = "SELECT p FROM Application_Descriptor p WHERE " +
                 "p.gateway_name =:gate_name and p.service_descriptor_ID =:service_name";
         if (hostName!=null){
@@ -660,7 +683,8 @@ public class GatewayResource extends Abs
                 resourceList.add(applicationDescriptorResource);
             }
         }
-        end();
+        em.getTransaction().commit();
+        em.close();
         return resourceList;
     }
 

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=1384144&r1=1384143&r2=1384144&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 Wed Sep 12 21:52:49 2012
@@ -22,12 +22,14 @@ 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.utils.QueryGenerator;
 
+import javax.persistence.EntityManager;
 import javax.persistence.Query;
 import java.util.ArrayList;
 import java.util.List;
@@ -141,7 +143,8 @@ public class HostDescriptorResource exte
      */
     public List<Resource> populate(Object[] keys) {
         List<Resource> list = new ArrayList<Resource>();
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         QueryGenerator generator = new QueryGenerator(HOST_DESCRIPTOR);
         generator.setParameter(HostDescriptorConstants.GATEWAY_NAME, keys [0]);
         generator.setParameter(HostDescriptorConstants.HOST_DESC_ID, keys[1]);
@@ -149,7 +152,8 @@ public class HostDescriptorResource exte
         Host_Descriptor hostDescriptor = (Host_Descriptor)q.getSingleResult();
         HostDescriptorResource hostDescriptorResource =
                 (HostDescriptorResource)Utils.getResource(ResourceType.HOST_DESCRIPTOR, hostDescriptor);
-        end();
+        em.getTransaction().commit();
+        em.close();
         list.add(hostDescriptorResource);
         return list;
     }
@@ -162,7 +166,8 @@ public class HostDescriptorResource exte
     public List<Resource> get(ResourceType type) {
         List<Resource> resourceList = new ArrayList<Resource>();
         if (type == ResourceType.APPLICATION_DESCRIPTOR) {
-            begin();
+            EntityManager em = ResourceUtils.getEntityManager();
+            em.getTransaction().begin();
             QueryGenerator generator = new QueryGenerator(APPLICATION_DESCRIPTOR);
             generator.setParameter(ApplicationDescriptorConstants.GATEWAY_NAME, gatewayName);
             generator.setParameter(ApplicationDescriptorConstants.HOST_DESC_ID, getHostDescName());
@@ -177,7 +182,8 @@ public class HostDescriptorResource exte
                     resourceList.add(applicationDescriptorResource);
                 }
             }
-            end();
+            em.getTransaction().commit();
+            em.close();
         }
         return resourceList;
     }
@@ -186,7 +192,8 @@ public class HostDescriptorResource exte
      * save host descriptor to the database
      */
     public void save() {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         Host_Descriptor hostDescriptor = new Host_Descriptor();
         Gateway gateway = new Gateway();
         gateway.setGateway_name(gatewayName);
@@ -197,7 +204,8 @@ public class HostDescriptorResource exte
         hostDescriptor.setHost_descriptor_xml(content);
         hostDescriptor.setUser(user);
         em.merge(hostDescriptor);
-        end();
+        em.getTransaction().commit();
+        em.close();
 
     }
 

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.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/ProjectResource.java?rev=1384144&r1=1384143&r2=1384144&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java Wed Sep 12 21:52:49 2012
@@ -23,10 +23,12 @@ package org.apache.airavata.persistance.
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
 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.Experiment;
 import org.apache.airavata.persistance.registry.jpa.model.Gateway;
 import org.apache.airavata.persistance.registry.jpa.model.Project;
@@ -81,7 +83,8 @@ public class ProjectResource extends Abs
      * @param name child resource name
      */
     public void remove(ResourceType type, Object name) {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         if (type == ResourceType.EXPERIMENT) {
         	QueryGenerator generator = new QueryGenerator(EXPERIMENT);
         	generator.setParameter(ExperimentConstants.PROJECT_ID, id);
@@ -90,7 +93,8 @@ public class ProjectResource extends Abs
         	Query q = generator.deleteQuery(em);
         	q.executeUpdate();
         }
-        end();
+        em.getTransaction().commit();
+        em.close();
     }
 
     /**
@@ -100,7 +104,8 @@ public class ProjectResource extends Abs
      * @return child resource
      */
     public Resource get(ResourceType type, Object name) {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         if (type == ResourceType.EXPERIMENT) {
         	QueryGenerator generator = new QueryGenerator(EXPERIMENT);
         	generator.setParameter(ExperimentConstants.PROJECT_ID, id);
@@ -110,7 +115,8 @@ public class ProjectResource extends Abs
             Experiment experiment = (Experiment) q.getSingleResult();
             ExperimentResource experimentResource = (ExperimentResource)
                     Utils.getResource(ResourceType.EXPERIMENT, experiment);
-            end();
+            em.getTransaction().commit();
+            em.close();
             return experimentResource;
         }
         return null;
@@ -123,7 +129,8 @@ public class ProjectResource extends Abs
      */
     public List<Resource> populate(Object[] keys) {
         List<Resource> list = new ArrayList<Resource>();
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         QueryGenerator queryGenerator = new QueryGenerator(PROJECT);
         queryGenerator.setParameter(ProjectConstants.PROJECT_NAME, keys[0]);
         Query q = queryGenerator.selectQuery(em);
@@ -136,7 +143,8 @@ public class ProjectResource extends Abs
                 list.add(projectResource);
             }
         }
-        end();
+        em.getTransaction().commit();
+        em.close();
         return list;
     }
 
@@ -147,7 +155,8 @@ public class ProjectResource extends Abs
      */
     public List<Resource> get(ResourceType type) {
         List<Resource> resourceList = new ArrayList<Resource>();
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         if (type == ResourceType.EXPERIMENT) {
         	QueryGenerator generator = new QueryGenerator(EXPERIMENT);
         	generator.setParameter(ExperimentConstants.PROJECT_ID, id);
@@ -162,7 +171,8 @@ public class ProjectResource extends Abs
                 }
             }
         }
-        end();
+        em.getTransaction().commit();
+        em.close();
         return resourceList;
     }
 
@@ -170,7 +180,8 @@ public class ProjectResource extends Abs
      * save project to the database
      */
     public void save() {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         Project project = new Project();
         project.setProject_name(name);
         Gateway gatewayO = new Gateway();
@@ -183,7 +194,8 @@ public class ProjectResource extends Abs
         user.setUser_name(worker.getUser());
         project.setUsers(user);
         em.merge(project);
-        end();
+        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=1384144&r1=1384143&r2=1384144&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 Wed Sep 12 21:52:49 2012
@@ -22,11 +22,13 @@ 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.Gateway;
 import org.apache.airavata.persistance.registry.jpa.model.Published_Workflow;
 import org.apache.airavata.persistance.registry.jpa.model.Users;
 import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
+import javax.persistence.EntityManager;
 import javax.persistence.Query;
 import java.sql.Date;
 import java.util.ArrayList;
@@ -181,7 +183,8 @@ public class PublishWorkflowResource ext
      */
     public List<Resource> populate(Object[] keys) {
         List<Resource> list = new ArrayList<Resource>();
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         QueryGenerator generator = new QueryGenerator(PUBLISHED_WORKFLOW);
         generator.setParameter(PublishedWorkflowConstants.GATEWAY_NAME, keys[0]);
         generator.setParameter(PublishedWorkflowConstants.PUBLISH_WORKFLOW_NAME, keys[1]);
@@ -189,7 +192,8 @@ public class PublishWorkflowResource ext
         Published_Workflow publishedWorkflow = (Published_Workflow)q.getSingleResult();
         PublishWorkflowResource publishWorkflowResource = (PublishWorkflowResource)
                 Utils.getResource(ResourceType.PUBLISHED_WORKFLOW, publishedWorkflow);
-        end();
+        em.getTransaction().commit();
+        em.close();
         list.add(publishWorkflowResource);
         return list;
     }
@@ -208,7 +212,8 @@ public class PublishWorkflowResource ext
      * save published workflow to the database
      */
     public void save() {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         Published_Workflow publishedWorkflow = new Published_Workflow();
         publishedWorkflow.setPublish_workflow_name(getName());
         publishedWorkflow.setPublished_date(publishedDate);
@@ -221,7 +226,8 @@ public class PublishWorkflowResource ext
         user.setUser_name(createdUser);
         publishedWorkflow.setUser(user);
         em.merge(gateway);
-        end();
+        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=1384144&r1=1384143&r2=1384144&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 Wed Sep 12 21:52:49 2012
@@ -22,12 +22,14 @@ 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.utils.QueryGenerator;
 
+import javax.persistence.EntityManager;
 import javax.persistence.Query;
 import java.util.ArrayList;
 import java.util.List;
@@ -95,14 +97,16 @@ public class ServiceDescriptorResource e
 
     public List<Resource> populate(Object[] keys) {
         List<Resource> list = new ArrayList<Resource>();
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         QueryGenerator generator = new QueryGenerator(SERVICE_DESCRIPTOR);
         generator.setParameter(ServiceDescriptorConstants.GATEWAY_NAME, keys[0]);
         generator.setParameter(ServiceDescriptorConstants.SERVICE_DESC_ID, keys[1]);
         Query q = generator.selectQuery(em);
         Service_Descriptor serviceDescriptor = (Service_Descriptor)q.getSingleResult();
         ServiceDescriptorResource serviceDescriptorResource = (ServiceDescriptorResource)Utils.getResource(ResourceType.SERVICE_DESCRIPTOR, serviceDescriptor);
-        end();
+        em.getTransaction().commit();
+        em.close();
         list.add(serviceDescriptorResource);
         return list;
     }
@@ -110,7 +114,8 @@ public class ServiceDescriptorResource e
     public List<Resource> get(ResourceType type) {
         List<Resource> resourceList = new ArrayList<Resource>();
         if (type == ResourceType.APPLICATION_DESCRIPTOR) {
-            begin();
+            EntityManager em = ResourceUtils.getEntityManager();
+            em.getTransaction().begin();
             QueryGenerator queryGenerator = new QueryGenerator(APPLICATION_DESCRIPTOR);
             queryGenerator.setParameter(ApplicationDescriptorConstants.GATEWAY_NAME, gatewayName);
             queryGenerator.setParameter(ApplicationDescriptorConstants.SERVICE_DESC_ID, serviceDescName);
@@ -123,13 +128,15 @@ public class ServiceDescriptorResource e
                     resourceList.add(applicationDescriptorResource);
                 }
             }
-            end();
+            em.getTransaction().commit();
+            em.close();
         }
         return resourceList;
     }
 
     public void save() {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         Service_Descriptor serviceDescriptor = new Service_Descriptor();
         serviceDescriptor.setService_descriptor_ID(getServiceDescName());
         Gateway gateway = new Gateway();
@@ -140,7 +147,8 @@ public class ServiceDescriptorResource e
         user.setUser_name(userName);
         serviceDescriptor.setUser(user);
         em.merge(serviceDescriptor);
-        end();
+        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=1384144&r1=1384143&r2=1384144&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 Wed Sep 12 21:52:49 2012
@@ -24,8 +24,11 @@ import java.util.List;
 
 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.Users;
 
+import javax.persistence.EntityManager;
+
 public class UserResource extends AbstractResource {
     private String userName;
     private String password;
@@ -111,12 +114,14 @@ public class UserResource extends Abstra
      * save user to the database
      */
     public void save() {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         Users user = new Users();
         user.setUser_name(userName);
         user.setPassword(password);
         em.merge(user);
-        end();
+        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=1384144&r1=1384143&r2=1384144&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 Wed Sep 12 21:52:49 2012
@@ -22,11 +22,13 @@ 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.Gateway;
 import org.apache.airavata.persistance.registry.jpa.model.User_Workflow;
 import org.apache.airavata.persistance.registry.jpa.model.Users;
 import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
+import javax.persistence.EntityManager;
 import javax.persistence.Query;
 import java.sql.Date;
 import java.util.ArrayList;
@@ -100,7 +102,8 @@ public class UserWorkflowResource extend
      */
     public List<Resource> populate(Object[] keys) {
         List<Resource> list = new ArrayList<Resource>();
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         QueryGenerator queryGenerator = new QueryGenerator(USER_WORKFLOW);
         queryGenerator.setParameter(UserWorkflowConstants.GATEWAY_NAME, keys[0]);
         queryGenerator.setParameter(UserWorkflowConstants.OWNER, keys[1]);
@@ -109,7 +112,8 @@ public class UserWorkflowResource extend
         User_Workflow userWorkflow = (User_Workflow)q.getSingleResult();
         UserWorkflowResource userWorkflowResource = (UserWorkflowResource)Utils.getResource(
                 ResourceType.USER_WORKFLOW, userWorkflow);
-        end();
+        em.getTransaction().commit();
+        em.close();
         list.add(userWorkflowResource);
         return list;
     }
@@ -119,7 +123,8 @@ public class UserWorkflowResource extend
     }
 
     public void save() {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         User_Workflow userWorkflow = new User_Workflow();
         userWorkflow.setTemplate_name(name);
         userWorkflow.setLast_updated_date(lastUpdateDate);
@@ -132,7 +137,8 @@ public class UserWorkflowResource extend
         userWorkflow.setUser(user);
         userWorkflow.setPath(path);
         em.merge(userWorkflow);
-        end();
+        em.getTransaction().commit();
+        em.close();
     }
 
     public boolean isExists(ResourceType type, Object name) {

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=1384144&r1=1384143&r2=1384144&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 Wed Sep 12 21:52:49 2012
@@ -24,10 +24,12 @@ package org.apache.airavata.persistance.
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
 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.*;
 import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
@@ -82,7 +84,8 @@ public class WorkerResource extends Abst
      * @param name child resource name
      */
 	public void remove(ResourceType type, Object name) {
-		begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         Query q;
         QueryGenerator generator;
 		switch (type) {
@@ -112,7 +115,8 @@ public class WorkerResource extends Abst
 			default:
 				break;
 		}
-		end();
+        em.getTransaction().commit();
+        em.close();
 	}
 
     /**
@@ -123,7 +127,8 @@ public class WorkerResource extends Abst
      */
 	public Resource get(ResourceType type, Object name) {
 		Resource result = null;
-		begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         QueryGenerator generator;
         Query q;
 		switch (type) {
@@ -156,7 +161,8 @@ public class WorkerResource extends Abst
 			default:
 				break;
 		}
-		end();
+        em.getTransaction().commit();
+        em.close();
 		return result;
 	}
 
@@ -167,7 +173,8 @@ public class WorkerResource extends Abst
      */
     public List<Resource> get(ResourceType type) {
 		List<Resource> result = new ArrayList<Resource>();
-		begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         QueryGenerator generator;
         Query q;
 		switch (type) {
@@ -207,7 +214,8 @@ public class WorkerResource extends Abst
 			default:
 				break;
 		}
-		end();
+        em.getTransaction().commit();
+        em.close();
 		return result;
 	}
 
@@ -215,7 +223,8 @@ public class WorkerResource extends Abst
      * save gateway worker to database
      */
 	public void save() {
-        begin();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
         Gateway_Worker gatewayWorker = new Gateway_Worker();
         Users users = new Users();
         users.setUser_name(user);
@@ -225,7 +234,8 @@ public class WorkerResource extends Abst
         gatewaymodel.setOwner(gateway.getOwner());
         gatewayWorker.setGateway(gatewaymodel);
         em.merge(gatewayWorker);
-        end();
+        em.getTransaction().commit();
+        em.close();
 	}
 
     /**

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=1384144&r1=1384143&r2=1384144&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 Wed Sep 12 21:52:49 2012
@@ -2,10 +2,10 @@ package org.apache.airavata.persistance.
 
 import junit.framework.TestCase;
 import org.apache.airavata.persistance.registry.jpa.model.Project;
-import org.apache.airavata.persistance.registry.jpa.resources.GatewayResource;
-import org.apache.airavata.persistance.registry.jpa.resources.HostDescriptorResource;
-import org.apache.airavata.persistance.registry.jpa.resources.ProjectResource;
-import org.apache.airavata.persistance.registry.jpa.resources.WorkerResource;
+import org.apache.airavata.persistance.registry.jpa.resources.*;
+
+import java.util.Calendar;
+import java.util.List;
 
 public class GatewayResourceTest extends TestCase {
     private GatewayResource gatewayResource;
@@ -14,12 +14,54 @@ public class GatewayResourceTest extends
     public void setUp() throws Exception {
         super.setUp();
 
+
+
+
 //        gatewayResource = new GatewayResource();
 //        gatewayResource.setGatewayName("default");
 //        gatewayResource.setOwner("default");
+//        gatewayResource.save();
+//        UserResource userResource = (UserResource)gatewayResource.create(ResourceType.USER);
+//        userResource.setUserName("admin");
+//        userResource.setPassword("admin");
+//        userResource.save();
+//        WorkerResource workerResource = (WorkerResource)gatewayResource.create(ResourceType.GATEWAY_WORKER);
+//        workerResource.setUser(userResource.getUserName());
+//        workerResource.save();
+
     }
 
     public void testSave() throws Exception {
+//        List<HostDescriptorResource>  list = gatewayResource.getHostDescriptorResources();
+//        for(HostDescriptorResource resource : list) {
+//            System.out.println("Host Descriptor name :" +  resource.getHostDescName());
+//        }
+//        Thread t = new Thread(new Runnable() {
+//            @Override
+//            public void run() {
+//                while (true) {
+//                ResourceUtils.removeConfiguration("aa", "http://129.79.49.142:8080/axis2/services/WorkflowInterpretor");
+//                }
+//            }
+//        });
+//        Thread t2 = new Thread(new Runnable() {
+//            @Override
+//            public void run() {
+//                while (true) {
+//                    ConfigurationResource configurationResource = new ConfigurationResource();
+//                    configurationResource.setConfigKey("aa");
+//                    configurationResource.setConfigVal("http://129.79.49.142:8080/axis2/services/WorkflowInterpretor");
+//                    Calendar calendar = Calendar.getInstance();
+//                    //configurationResource.setExpireDate(calendar.);
+//                    configurationResource.save();
+//                }
+//            }
+//        });
+//        t.start();
+//        t2.start();
+//        while(true) {
+//            Thread.sleep(10000);
+//        }
 
     }
 

Modified: incubator/airavata/trunk/modules/xbaya-gui/src/main/resources/repository.properties
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/xbaya-gui/src/main/resources/repository.properties?rev=1384144&r1=1384143&r2=1384144&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/xbaya-gui/src/main/resources/repository.properties (original)
+++ incubator/airavata/trunk/modules/xbaya-gui/src/main/resources/repository.properties Wed Sep 12 21:52:49 2012
@@ -83,5 +83,5 @@ gateway.id=default
 registry.jdbc.driver=org.apache.derby.jdbc.EmbeddedDriver
 registry.jdbc.user=airavata
 registry.jdbc.password=airavata
-registry.jdbc.url=jdbc:mysql://140.182.128.203:3306/persistent_data_lahiru?user=airavata&password=airavata
+registry.jdbc.url=jdbc:mysql://localhost:3306/ppp
 



Mime
View raw message