public AppCatalogResource get(Object identifier) throws AppCatalogException {
   EntityManager em = null;
   try {
     em = AppCatalogJPAUtils.getEntityManager();
     em.getTransaction().begin();
     AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GLOBUS_SUBMISSION);
     generator.setParameter(GlobusJobSubmissionConstants.SUBMISSION_ID, identifier);
     Query q = generator.selectQuery(em);
     GlobusJobSubmission globusJobSubmission = (GlobusJobSubmission) q.getSingleResult();
     GlobusJobSubmissionResource globusJobSubmissionResource =
         (GlobusJobSubmissionResource)
             AppCatalogJPAUtils.getResource(
                 AppCatalogResourceType.GLOBUS_SUBMISSION, globusJobSubmission);
     em.getTransaction().commit();
     em.close();
     return globusJobSubmissionResource;
   } catch (ApplicationSettingsException e) {
     logger.error(e.getMessage(), e);
     throw new AppCatalogException(e);
   } finally {
     if (em != null && em.isOpen()) {
       if (em.getTransaction().isActive()) {
         em.getTransaction().rollback();
       }
       em.close();
     }
   }
 }
  public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
      em = AppCatalogJPAUtils.getEntityManager();
      GlobusJobSubmission existingGlobusSubmission =
          em.find(GlobusJobSubmission.class, submissionID);
      em.close();

      em = AppCatalogJPAUtils.getEntityManager();
      em.getTransaction().begin();
      if (existingGlobusSubmission != null) {
        existingGlobusSubmission.setSubmissionID(submissionID);
        existingGlobusSubmission.setResourceJobManager(resourceJobManager);
        existingGlobusSubmission.setSecurityProtocol(securityProtocol);
        em.merge(existingGlobusSubmission);
      } else {
        GlobusJobSubmission globusJobSubmission = new GlobusJobSubmission();
        globusJobSubmission.setSubmissionID(submissionID);
        globusJobSubmission.setSecurityProtocol(securityProtocol);
        globusJobSubmission.setResourceJobManager(resourceJobManager);
        em.persist(globusJobSubmission);
      }
      em.getTransaction().commit();
      em.close();
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
      throw new AppCatalogException(e);
    } finally {
      if (em != null && em.isOpen()) {
        if (em.getTransaction().isActive()) {
          em.getTransaction().rollback();
        }
        em.close();
      }
    }
  }
 public boolean isExists(Object identifier) throws AppCatalogException {
   EntityManager em = null;
   try {
     em = AppCatalogJPAUtils.getEntityManager();
     GlobusJobSubmission globusJobSubmission = em.find(GlobusJobSubmission.class, identifier);
     em.close();
     return globusJobSubmission != null;
   } catch (ApplicationSettingsException e) {
     logger.error(e.getMessage(), e);
     throw new AppCatalogException(e);
   } finally {
     if (em != null && em.isOpen()) {
       if (em.getTransaction().isActive()) {
         em.getTransaction().rollback();
       }
       em.close();
     }
   }
 }
 public void remove(Object identifier) throws AppCatalogException {
   EntityManager em = null;
   try {
     em = AppCatalogJPAUtils.getEntityManager();
     em.getTransaction().begin();
     AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GLOBUS_SUBMISSION);
     generator.setParameter(GlobusJobSubmissionConstants.SUBMISSION_ID, identifier);
     Query q = generator.deleteQuery(em);
     q.executeUpdate();
     em.getTransaction().commit();
     em.close();
   } catch (ApplicationSettingsException e) {
     logger.error(e.getMessage(), e);
     throw new AppCatalogException(e);
   } finally {
     if (em != null && em.isOpen()) {
       if (em.getTransaction().isActive()) {
         em.getTransaction().rollback();
       }
       em.close();
     }
   }
 }
 public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
   List<AppCatalogResource> globusSubmissionResourceList = new ArrayList<AppCatalogResource>();
   EntityManager em = null;
   try {
     em = AppCatalogJPAUtils.getEntityManager();
     em.getTransaction().begin();
     Query q;
     AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GLOBUS_SUBMISSION);
     List results;
     if (fieldName.equals(GlobusJobSubmissionConstants.RESOURCE_JOB_MANAGER)) {
       generator.setParameter(GlobusJobSubmissionConstants.RESOURCE_JOB_MANAGER, value);
       q = generator.selectQuery(em);
       results = q.getResultList();
       if (results.size() != 0) {
         for (Object result : results) {
           GlobusJobSubmission globusJobSubmission = (GlobusJobSubmission) result;
           GlobusJobSubmissionResource globusJobSubmissionResource =
               (GlobusJobSubmissionResource)
                   AppCatalogJPAUtils.getResource(
                       AppCatalogResourceType.GLOBUS_SUBMISSION, globusJobSubmission);
           globusSubmissionResourceList.add(globusJobSubmissionResource);
         }
       }
     } else if (fieldName.equals(GlobusJobSubmissionConstants.SECURITY_PROTOCAL)) {
       generator.setParameter(GlobusJobSubmissionConstants.SECURITY_PROTOCAL, value);
       q = generator.selectQuery(em);
       results = q.getResultList();
       if (results.size() != 0) {
         for (Object result : results) {
           GlobusJobSubmission globusJobSubmission = (GlobusJobSubmission) result;
           GlobusJobSubmissionResource globusJobSubmissionResource =
               (GlobusJobSubmissionResource)
                   AppCatalogJPAUtils.getResource(
                       AppCatalogResourceType.GLOBUS_SUBMISSION, globusJobSubmission);
           globusSubmissionResourceList.add(globusJobSubmissionResource);
         }
       }
     } else {
       em.getTransaction().commit();
       em.close();
       logger.error(
           "Unsupported field name for Globus submission resource.",
           new IllegalArgumentException());
       throw new IllegalArgumentException(
           "Unsupported field name for Globus Submission resource.");
     }
     em.getTransaction().commit();
     em.close();
   } catch (Exception e) {
     logger.error(e.getMessage(), e);
     throw new AppCatalogException(e);
   } finally {
     if (em != null && em.isOpen()) {
       if (em.getTransaction().isActive()) {
         em.getTransaction().rollback();
       }
       em.close();
     }
   }
   return globusSubmissionResourceList;
 }