Search in sources :

Example 6 with NoResultException

use of javax.persistence.NoResultException in project OpenAttestation by OpenAttestation.

the class TblModuleManifestJpaController method findTblModuleManifestByUuid.

public TblModuleManifest findTblModuleManifestByUuid(String uuid) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblModuleManifest.findByUuidHex");
        query.setParameter("uuid_hex", uuid);
        TblModuleManifest pcrObj = (TblModuleManifest) query.getSingleResult();
        return pcrObj;
    } catch (NoResultException e) {
        log.error(String.format("Module information with UUID {} not found in the DB.", uuid));
        return null;
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) NoResultException(javax.persistence.NoResultException)

Example 7 with NoResultException

use of javax.persistence.NoResultException in project OpenAttestation by OpenAttestation.

the class TblModuleManifestJpaController method findByMleNameEventName.

/**
     * Modified By: Sudhir on June 21st to remove the throw of ASException. Instead the NoResultException is
     * being thrown, which is caught by the caller.
     * 
     * @param mleId
     * @param componentName
     * @param eventName
     * @return 
     */
public TblModuleManifest findByMleNameEventName(Integer mleId, String componentName, String eventName) {
    EntityManager em = getEntityManager();
    try {
        log.debug(String.format("Module Manifest for MLE: %d Component: %s Event: %s", mleId, componentName, eventName));
        Query query = em.createNamedQuery("TblModuleManifest.findByMleNameEventName");
        query.setParameter("name", componentName);
        query.setParameter("eventName", eventName);
        query.setParameter("mleId", mleId);
        query.setHint(QueryHints.REFRESH, HintValues.TRUE);
        query.setHint(QueryHints.CACHE_USAGE, CacheUsage.DoNotCheckCache);
        TblModuleManifest tblModuleManifest = (TblModuleManifest) query.getSingleResult();
        return tblModuleManifest;
    } catch (NoResultException e) {
        log.error(String.format("Module Manifest for MLE %d Component %s Event %s  Not found in Database ", mleId, componentName, eventName), e);
        return null;
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) NoResultException(javax.persistence.NoResultException)

Example 8 with NoResultException

use of javax.persistence.NoResultException in project OpenAttestation by OpenAttestation.

the class TblModuleManifestJpaController method findTblModuleManifestByMleUuid.

public List<TblModuleManifest> findTblModuleManifestByMleUuid(String mleUuid) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblModuleManifest.findByMleUuidHex");
        query.setParameter("mle_uuid_hex", mleUuid);
        List<TblModuleManifest> moduleList = query.getResultList();
        return moduleList;
    } catch (NoResultException e) {
        log.error(String.format("MLE information with UUID {} not found in the DB.", mleUuid));
        return null;
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) NoResultException(javax.persistence.NoResultException)

Example 9 with NoResultException

use of javax.persistence.NoResultException in project OpenAttestation by OpenAttestation.

the class TblOemJpaController method findTblOemByName.

public TblOem findTblOemByName(String name) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblOem.findByName");
        query.setParameter("name", name);
        TblOem tblOem = (TblOem) query.getSingleResult();
        return tblOem;
    } catch (NoResultException e) {
        log.info("NoResultException : OEM [{}] not found", name);
        return null;
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblOem(com.intel.mtwilson.as.data.TblOem) NoResultException(javax.persistence.NoResultException)

Example 10 with NoResultException

use of javax.persistence.NoResultException in project OpenAttestation by OpenAttestation.

the class TblLocationPcrJpaController method findTblLocationPcrByPcrValue.

public String findTblLocationPcrByPcrValue(String pcrValue) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblLocationPcr.findByPcrValue");
        query.setParameter("pcrValue", pcrValue);
        query.setHint(QueryHints.REFRESH, HintValues.TRUE);
        query.setHint(QueryHints.CACHE_USAGE, CacheUsage.DoNotCheckCache);
        try {
            TblLocationPcr locationPcr = (TblLocationPcr) query.getSingleResult();
            String location = locationPcr.getLocation();
            log.info("PCR Value  " + pcrValue + " location " + location);
            return location;
        } catch (NoResultException e) {
            log.info("NoResultException: Location does not exist for pcr value {} ", pcrValue);
            return null;
        }
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblLocationPcr(com.intel.mtwilson.as.data.TblLocationPcr) NoResultException(javax.persistence.NoResultException)

Aggregations

NoResultException (javax.persistence.NoResultException)356 Query (javax.persistence.Query)205 EntityManager (javax.persistence.EntityManager)69 NonUniqueResultException (javax.persistence.NonUniqueResultException)33 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)25 TypedQuery (javax.persistence.TypedQuery)22 Transactional (org.springframework.transaction.annotation.Transactional)20 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)19 Test (org.junit.Test)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)15 Session (org.hibernate.Session)13 UnitOfWork (com.google.inject.persist.UnitOfWork)12 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)11 PersistenceException (javax.persistence.PersistenceException)11 Date (java.util.Date)9 NotFoundException (org.opencastproject.util.NotFoundException)9 TblMle (com.intel.mtwilson.as.data.TblMle)8 List (java.util.List)8 NamedQuery (javax.persistence.NamedQuery)8