airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scnakand...@apache.org
Subject airavata git commit: undoing registry java8 revert
Date Mon, 15 Aug 2016 20:14:21 GMT
Repository: airavata
Updated Branches:
  refs/heads/develop cfe62c3e8 -> c6a82a029


undoing registry java8 revert


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/c6a82a02
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/c6a82a02
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/c6a82a02

Branch: refs/heads/develop
Commit: c6a82a029635a1239ca0563e9019399f90ca714a
Parents: cfe62c3
Author: scnakandala <supun.nakandala@gmail.com>
Authored: Mon Aug 15 16:14:16 2016 -0400
Committer: scnakandala <supun.nakandala@gmail.com>
Committed: Mon Aug 15 16:14:16 2016 -0400

----------------------------------------------------------------------
 .../airavata/registry/core/Committer.java       |  29 ----
 .../apache/airavata/registry/core/JPAUtil.java  |  57 -------
 .../catalog/resources/ExperimentResource.java   | 148 +++++++++++++------
 3 files changed, 100 insertions(+), 134 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/c6a82a02/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/Committer.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/Committer.java
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/Committer.java
deleted file mode 100644
index 99b504b..0000000
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/Committer.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.airavata.registry.core;
-
-import org.apache.airavata.registry.cpi.RegistryException;
-
-@FunctionalInterface
-public interface Committer<T, R>  {
-
-   R commit(T t) throws RegistryException;
-}

http://git-wip-us.apache.org/repos/asf/airavata/blob/c6a82a02/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/JPAUtil.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/JPAUtil.java
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/JPAUtil.java
deleted file mode 100644
index 58988c6..0000000
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/JPAUtil.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.airavata.registry.core;
-
-import org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils;
-import org.apache.airavata.registry.cpi.ExperimentCatalogException;
-import org.apache.airavata.registry.cpi.RegistryException;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.function.Consumer;
-
-public class JPAUtil {
-
-    public static <R> R executeOnExpCatalog(Committer<EntityManager, R> committer)
throws RegistryException, ExperimentCatalogException {
-        EntityManager entityManager = ExpCatResourceUtils.getEntityManager();
-        try {
-            entityManager.getTransaction().begin();
-            R r = committer.commit(entityManager);
-            entityManager.getTransaction().commit();
-            return  r;
-        }finally {
-            if(entityManager != null && entityManager.isOpen()){
-                if (entityManager.getTransaction().isActive()) {
-                    entityManager.getTransaction().rollback();
-                }
-                entityManager.close();
-            }
-        }
-
-    }
-
-    public static void test() throws ExperimentCatalogException, RegistryException {
-        executeOnExpCatalog((em) -> "");
-    }
-}

http://git-wip-us.apache.org/repos/asf/airavata/blob/c6a82a02/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentResource.java
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentResource.java
index 7889839..174575f 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentResource.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ExperimentResource.java
@@ -22,8 +22,6 @@
 package org.apache.airavata.registry.core.experiment.catalog.resources;
 
 import org.apache.airavata.model.status.ExperimentState;
-import org.apache.airavata.registry.core.Committer;
-import org.apache.airavata.registry.core.JPAUtil;
 import org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils;
 import org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource;
 import org.apache.airavata.registry.core.experiment.catalog.ResourceType;
@@ -31,7 +29,6 @@ import org.apache.airavata.registry.core.experiment.catalog.model.*;
 import org.apache.airavata.registry.core.experiment.catalog.model.Process;
 import org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator;
 import org.apache.airavata.registry.cpi.RegistryException;
-import org.apache.openjpa.persistence.Generator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -267,65 +264,120 @@ public class ExperimentResource extends AbstractExpCatResource {
 
     
     public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException{
+        EntityManager em = null;
         try {
+            em = ExpCatResourceUtils.getEntityManager();
+            em.getTransaction().begin();
+            QueryGenerator generator;
+            Query q;
             switch (type) {
                 case EXPERIMENT_STATUS:
-                    return JPAUtil.executeOnExpCatalog(entityManager -> {
-                        QueryGenerator generator = new QueryGenerator(EXPERIMENT_STATUS);
-                        generator.setParameter(ExperimentStatusConstants.STATUS_ID, name);
-                        Query q = generator.selectQuery(entityManager);
-                        ExperimentStatus status = (ExperimentStatus) q.getSingleResult();
-                        return (ExperimentStatusResource) Utils.getResource(ResourceType.EXPERIMENT_STATUS,
status);
-                    });
+                    generator = new QueryGenerator(EXPERIMENT_STATUS);
+                    generator.setParameter(ExperimentStatusConstants.STATUS_ID, name);
+                    q = generator.selectQuery(em);
+                    ExperimentStatus status = (ExperimentStatus) q.getSingleResult();
+                    ExperimentStatusResource statusResource = (ExperimentStatusResource)
Utils.getResource(ResourceType.EXPERIMENT_STATUS, status);
+                    em.getTransaction().commit();
+                    if (em.isOpen()) {
+                        if (em.getTransaction().isActive()){
+                            em.getTransaction().rollback();
+                        }
+                        em.close();
+                    }
+                    return statusResource;
                 case EXPERIMENT_ERROR:
-                    return JPAUtil.executeOnExpCatalog(entityManager -> {
-                        QueryGenerator generator = new QueryGenerator(EXPERIMENT_ERROR);
-                        generator.setParameter(ExperimentErrorConstants.ERROR_ID, name);
-                        Query q = generator.selectQuery(entityManager);
-                        ExperimentError experimentError = (ExperimentError) q.getSingleResult();
-                        return (ExperimentErrorResource) Utils.getResource(ResourceType.EXPERIMENT_ERROR,
experimentError);
-                    });
+                    generator = new QueryGenerator(EXPERIMENT_ERROR);
+                    generator.setParameter(ExperimentErrorConstants.ERROR_ID, name);
+                    q = generator.selectQuery(em);
+                    ExperimentError experimentError = (ExperimentError) q.getSingleResult();
+                    ExperimentErrorResource processErrorResource = (ExperimentErrorResource)
Utils.getResource(ResourceType.EXPERIMENT_ERROR, experimentError);
+                    em.getTransaction().commit();
+                    if (em.isOpen()) {
+                        if (em.getTransaction().isActive()){
+                            em.getTransaction().rollback();
+                        }
+                        em.close();
+                    }
+                    return processErrorResource;
                 case EXPERIMENT_INPUT:
-                    return JPAUtil.executeOnExpCatalog(entityManager -> {
-                        QueryGenerator generator = new QueryGenerator(EXPERIMENT_INPUT);
-                        generator.setParameter(ExperimentInputConstants.INPUT_NAME, name);
-                        generator.setParameter(ExperimentInputConstants.EXPERIMENT_ID, experimentId);
-                        Query q = generator.selectQuery(entityManager);
-                        ExperimentInput experimentInput = (ExperimentInput) q.getSingleResult();
-                        return (ExperimentInputResource) Utils.getResource(ResourceType.EXPERIMENT_INPUT,
experimentInput);
-                    });
+                    generator = new QueryGenerator(EXPERIMENT_INPUT);
+                    generator.setParameter(ExperimentInputConstants.INPUT_NAME, name);
+                    generator.setParameter(ExperimentInputConstants.EXPERIMENT_ID, experimentId);
+                    q = generator.selectQuery(em);
+                    ExperimentInput experimentInput = (ExperimentInput) q.getSingleResult();
+                    ExperimentInputResource experimentInputResource = (ExperimentInputResource)
Utils.getResource(ResourceType.EXPERIMENT_INPUT, experimentInput);
+                    em.getTransaction().commit();
+                    if (em.isOpen()) {
+                        if (em.getTransaction().isActive()){
+                            em.getTransaction().rollback();
+                        }
+                        em.close();
+                    }
+                    return experimentInputResource;
                 case EXPERIMENT_OUTPUT:
-                    return JPAUtil.executeOnExpCatalog(entityManager -> {
-                        QueryGenerator generator = new QueryGenerator(EXPERIMENT_OUTPUT);
-                        generator.setParameter(ExperimentOutputConstants.OUTPUT_NAME, name);
-                        generator.setParameter(ExperimentInputConstants.EXPERIMENT_ID, experimentId);
-                        Query q = generator.selectQuery(entityManager);
-                        ExperimentOutput experimentOutput = (ExperimentOutput) q.getSingleResult();
-                        return (ExperimentOutputResource) Utils.getResource(ResourceType.EXPERIMENT_OUTPUT,
experimentOutput);
-                    });
+                    generator = new QueryGenerator(EXPERIMENT_OUTPUT);
+                    generator.setParameter(ExperimentOutputConstants.OUTPUT_NAME, name);
+                    generator.setParameter(ExperimentInputConstants.EXPERIMENT_ID, experimentId);
+                    q = generator.selectQuery(em);
+                    ExperimentOutput experimentOutput = (ExperimentOutput) q.getSingleResult();
+                    ExperimentOutputResource outputResource = (ExperimentOutputResource)
Utils.getResource(ResourceType.EXPERIMENT_OUTPUT, experimentOutput);
+                    em.getTransaction().commit();
+                    if (em.isOpen()) {
+                        if (em.getTransaction().isActive()){
+                            em.getTransaction().rollback();
+                        }
+                        em.close();
+                    }
+                    return outputResource;
                 case USER_CONFIGURATION_DATA:
-                    return JPAUtil.executeOnExpCatalog(entityManager -> {
-                        QueryGenerator generator = new QueryGenerator(USER_CONFIGURATION_DATA);
-                        generator.setParameter(UserConfigurationDataConstants.EXPERIMENT_ID,
name);
-                        Query q = generator.selectQuery(entityManager);
-                        UserConfigurationData configurationData = (UserConfigurationData)
q.getSingleResult();
-                        return (UserConfigurationDataResource)
-                                Utils.getResource(ResourceType.USER_CONFIGURATION_DATA, configurationData);
-                    });
+                    generator = new QueryGenerator(USER_CONFIGURATION_DATA);
+                    generator.setParameter(UserConfigurationDataConstants.EXPERIMENT_ID,
name);
+                    q = generator.selectQuery(em);
+                    UserConfigurationData configurationData = (UserConfigurationData) q.getSingleResult();
+                    UserConfigurationDataResource configurationDataResource = (UserConfigurationDataResource)
+                            Utils.getResource(ResourceType.USER_CONFIGURATION_DATA, configurationData);
+                    em.getTransaction().commit();
+                    if (em.isOpen()) {
+                        if (em.getTransaction().isActive()){
+                            em.getTransaction().rollback();
+                        }
+                        em.close();
+                    }
+                    return configurationDataResource;
                 case PROCESS:
-                    return JPAUtil.executeOnExpCatalog(entityManager -> {
-                        QueryGenerator generator = new QueryGenerator(PROCESS);
-                        generator.setParameter(ProcessConstants.PROCESS_ID, name);
-                        Query q = generator.selectQuery(entityManager);
-                        Process process = (Process) q.getSingleResult();
-                        return (ProcessResource) Utils.getResource(ResourceType.PROCESS,
process);
-                    });
+                    generator = new QueryGenerator(PROCESS);
+                    generator.setParameter(ProcessConstants.PROCESS_ID, name);
+                    q = generator.selectQuery(em);
+                    Process process = (Process) q.getSingleResult();
+                    ProcessResource processResource = (ProcessResource) Utils.getResource(ResourceType.PROCESS,
process);
+                    em.getTransaction().commit();
+                    if (em.isOpen()) {
+                        if (em.getTransaction().isActive()){
+                            em.getTransaction().rollback();
+                        }
+                        em.close();
+                    }
+                    return processResource;
                 default:
+                    em.getTransaction().commit();
+                    if (em.isOpen()) {
+                        if (em.getTransaction().isActive()){
+                            em.getTransaction().rollback();
+                        }
+                        em.close();
+                    }
                     logger.error("Unsupported resource type for experiment resource.", new
IllegalArgumentException());
                     throw new IllegalArgumentException("Unsupported resource type for experiment
resource.");
             }
         } catch (Exception e) {
             throw new RegistryException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
         }
     }
 


Mime
View raw message