Return-Path: X-Original-To: apmail-incubator-airavata-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-airavata-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 86069DB77 for ; Wed, 12 Sep 2012 14:44:09 +0000 (UTC) Received: (qmail 63856 invoked by uid 500); 12 Sep 2012 14:44:09 -0000 Delivered-To: apmail-incubator-airavata-commits-archive@incubator.apache.org Received: (qmail 63821 invoked by uid 500); 12 Sep 2012 14:44:09 -0000 Mailing-List: contact airavata-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: airavata-dev@incubator.apache.org Delivered-To: mailing list airavata-commits@incubator.apache.org Received: (qmail 63807 invoked by uid 99); 12 Sep 2012 14:44:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Sep 2012 14:44:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Sep 2012 14:44:05 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id C0B2F23889DA; Wed, 12 Sep 2012 14:43:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1383979 - 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/resources/ main/resources/META-INF/ test/java... Date: Wed, 12 Sep 2012 14:43:20 -0000 To: airavata-commits@incubator.apache.org From: lahiru@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120912144320.C0B2F23889DA@eris.apache.org> Author: lahiru Date: Wed Sep 12 14:43:20 2012 New Revision: 1383979 URL: http://svn.apache.org/viewvc?rev=1383979&view=rev Log: adding patch by chathuri for AIRAVATA-562 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/resources/AbstractResource.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/resources/META-INF/persistence.xml 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=1383979&r1=1383978&r2=1383979&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 14:43:20 2012 @@ -24,10 +24,7 @@ import org.apache.airavata.persistance.r 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.resources.AbstractResource; -import org.apache.airavata.persistance.registry.jpa.resources.ConfigurationResource; -import org.apache.airavata.persistance.registry.jpa.resources.GatewayResource; -import org.apache.airavata.persistance.registry.jpa.resources.UserResource; +import org.apache.airavata.persistance.registry.jpa.resources.*; import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator; import javax.persistence.EntityManager; @@ -35,13 +32,31 @@ import javax.persistence.EntityManagerFa import javax.persistence.Persistence; import javax.persistence.Query; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class ResourceUtils { private static final String PERSISTENCE_UNIT_NAME = "airavata_data"; protected static EntityManagerFactory factory; protected static EntityManager em; + public static EntityManager getEntityManager(){ + Map properties = new HashMap(); + 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 = factory.createEntityManager(); + return em; + } + /** * @param gatewayName * @return @@ -61,15 +76,14 @@ public class ResourceUtils { * @return */ public static boolean isGatewayExist(String gatewayName) { - factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); - em = factory.createEntityManager(); + 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; } @@ -79,15 +93,14 @@ public class ResourceUtils { */ public static boolean removeGateway(String gatewayName) { try { - factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); - em = factory.createEntityManager(); + 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(); @@ -103,8 +116,7 @@ public class ResourceUtils { */ public static void addGatewayWorker(GatewayResource gatewayResource, UserResource userResource) { try { - factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); - em = factory.createEntityManager(); + em = getEntityManager(); em.getTransaction().begin(); Gateway gateway = new Gateway(); gateway.setGateway_name(gatewayResource.getGatewayName()); @@ -115,7 +127,7 @@ public class ResourceUtils { gatewayWorker.setUser(user); em.persist(gatewayWorker); em.getTransaction().commit(); - em.close(); +// em.close(); } catch (Exception e) { e.printStackTrace(); } @@ -129,8 +141,7 @@ public class ResourceUtils { */ public static boolean removeGatewayWorker(GatewayResource gatewayResource, UserResource userResource) { try { - factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); - em = factory.createEntityManager(); + em = getEntityManager(); em.getTransaction().begin(); QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY_WORKER); generator.setParameter(AbstractResource.GatewayWorkerConstants.GATEWAY_NAME, @@ -139,7 +150,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(); @@ -154,8 +165,7 @@ public class ResourceUtils { */ public static List getConfigurations(String configKey) { List list = new ArrayList(); - factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); - em = factory.createEntityManager(); + em = getEntityManager(); em.getTransaction().begin(); QueryGenerator generator = new QueryGenerator(AbstractResource.CONFIGURATION); generator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configKey); @@ -168,7 +178,7 @@ public class ResourceUtils { } } em.getTransaction().commit(); - em.close(); +// em.close(); return list; } @@ -219,8 +229,7 @@ public class ResourceUtils { * @param configValue */ public static void removeConfiguration(String configkey, String configValue) { - factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); - em = factory.createEntityManager(); + 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); @@ -231,7 +240,7 @@ public class ResourceUtils { Query q = queryGenerator.deleteQuery(em); q.executeUpdate(); em.getTransaction().commit(); - em.close(); +// em.close(); } @@ -239,14 +248,13 @@ public class ResourceUtils { * @param configkey */ public static void removeConfiguration(String configkey) { - factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); - em = factory.createEntityManager(); + 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(); +// em.close(); } } 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=1383979&r1=1383978&r2=1383979&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 14:43:20 2012 @@ -22,14 +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 javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Persistence; public abstract class AbstractResource implements Resource { - private static final String PERSISTENCE_UNIT_NAME = "airavata_data"; - protected EntityManagerFactory factory; protected EntityManager em; //table names @@ -137,16 +134,13 @@ public abstract class AbstractResource i } - protected AbstractResource() { - factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); - em = factory.createEntityManager(); + em = ResourceUtils.getEntityManager(); } protected void begin() { if(em == null){ - factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); - em = factory.createEntityManager(); + em = ResourceUtils.getEntityManager(); } em.getTransaction().begin(); } 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=1383979&r1=1383978&r2=1383979&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 Wed Sep 12 14:43:20 2012 @@ -24,9 +24,54 @@ import org.apache.airavata.persistance.r import org.apache.airavata.persistance.registry.jpa.ResourceType; import org.apache.airavata.persistance.registry.jpa.model.*; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + public class Utils { + public static Properties loadProperties(){ + URL resource = Utils.class.getClassLoader().getResource("repository.properties"); + Properties properties = new Properties(); + try { + properties.load(resource.openStream()); + } catch (IOException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + return properties; + } + + public static String getJDBCFullURL(){ + String jdbcUrl = null; + Properties properties = loadProperties(); + jdbcUrl = properties.getProperty("registry.jdbc.url"); + String jdbcUser = properties.getProperty("registry.jdbc.user"); + String jdbcPassword = properties.getProperty("registry.jdbc.password"); + jdbcUrl = jdbcUrl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword; + return jdbcUrl; + } + + public static String getJDBCURL(){ + Properties properties = loadProperties(); + return properties.getProperty("registry.jdbc.url"); + } + + public static String getJDBCUser(){ + Properties properties = loadProperties(); + return properties.getProperty("registry.jdbc.user"); + } + + public static String getJDBCPassword(){ + Properties properties = loadProperties(); + return properties.getProperty("registry.jdbc.password"); + } + + public static String getJDBCDriver(){ + Properties properties = loadProperties(); + return properties.getProperty("registry.jdbc.driver"); + } + /** * * @param type model type Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/META-INF/persistence.xml URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/META-INF/persistence.xml?rev=1383979&r1=1383978&r2=1383979&view=diff ============================================================================== --- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/META-INF/persistence.xml (original) +++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/META-INF/persistence.xml Wed Sep 12 14:43:20 2012 @@ -53,9 +53,9 @@ org.apache.airavata.persistance.registry.jpa.model.Service_Descriptor org.apache.airavata.persistance.registry.jpa.model.Application_Descriptor org.apache.airavata.persistance.registry.jpa.model.Experiment - + - \ No newline at end of file + 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=1383979&r1=1383978&r2=1383979&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 14:43:20 2012 @@ -14,9 +14,9 @@ public class GatewayResourceTest extends public void setUp() throws Exception { super.setUp(); - gatewayResource = new GatewayResource(); - gatewayResource.setGatewayName("default"); - gatewayResource.setOwner("default"); +// gatewayResource = new GatewayResource(); +// gatewayResource.setGatewayName("default"); +// gatewayResource.setOwner("default"); } public void testSave() throws Exception { @@ -24,30 +24,35 @@ public class GatewayResourceTest extends } public void testCreate() throws Exception { - boolean result; - HostDescriptorResource hostDescriptorResource = (HostDescriptorResource)gatewayResource.create(ResourceType.HOST_DESCRIPTOR); - hostDescriptorResource.setHostDescName("Localhost"); - hostDescriptorResource.setUserName("admin"); - hostDescriptorResource.save(); - result = gatewayResource.isExists(ResourceType.HOST_DESCRIPTOR, "Localhost"); - assertTrue("The result doesn't exists", result == true); - - ProjectResource projectResource = (ProjectResource)gatewayResource.create(ResourceType.PROJECT); - projectResource.setName("project1"); - WorkerResource workerResource = new WorkerResource(); - workerResource.setGateway(gatewayResource); - workerResource.setUser("admin"); - projectResource.setWorker(workerResource); - projectResource.save(); +// boolean result; +// HostDescriptorResource hostDescriptorResource = gatewayResource.createHostDescriptorResource("Localhost"); +//// hostDescriptorResource.setHostDescName("Localhost"); +// hostDescriptorResource.setUserName("admin"); +// hostDescriptorResource.setContent("\n" + +// " LocalHost\n" + +// " 127.0.0.1\n" + +// ""); +// hostDescriptorResource.save(); +// result = gatewayResource.isExists(ResourceType.HOST_DESCRIPTOR, "Localhost"); +// assertTrue("The result doesn't exists", result == true); + + +// ProjectResource projectResource = (ProjectResource)gatewayResource.create(ResourceType.PROJECT); +// projectResource.setName("project1"); +// WorkerResource workerResource = new WorkerResource(); +// workerResource.setGateway(gatewayResource); +// workerResource.setUser("admin"); +// projectResource.setWorker(workerResource); +// projectResource.save(); // result = workerResource.isProjectExists("project1"); // assertTrue("The result doesn't exists", result == true); } public void testIsExists() throws Exception { - boolean result = gatewayResource.isExists(ResourceType.HOST_DESCRIPTOR, "Localhost"); - - assertTrue("The result doesn't exists", result == true); +// boolean result = gatewayResource.isExists(ResourceType.HOST_DESCRIPTOR, "Localhost"); +// +// assertTrue("The result doesn't exists", result == true); // result = gatewayResource.isExists(ResourceType.USER, "admin"); //