Search in sources :

Example 26 with EntityManager

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

the class TblMleJpaController method getTblMleCount.

public int getTblMleCount() {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<TblMle> rt = cq.from(TblMle.class);
        cq.select(em.getCriteriaBuilder().count(rt));
        Query q = em.createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblMle(com.intel.mtwilson.as.data.TblMle) CriteriaQuery(javax.persistence.criteria.CriteriaQuery)

Example 27 with EntityManager

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

the class TblMleJpaController method findTblMleByUUID.

public TblMle findTblMleByUUID(String uuid_hex) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblMle.findByUUID_Hex");
        query.setParameter("uuid_hex", uuid_hex);
        TblMle tblOem = (TblMle) query.getSingleResult();
        return tblOem;
    } catch (NoResultException e) {
        log.error("NoResultException : MLE with UUID {} not found", uuid_hex);
        return null;
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblMle(com.intel.mtwilson.as.data.TblMle) NoResultException(javax.persistence.NoResultException)

Example 28 with EntityManager

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

the class TblMleJpaController method findMleById.

public TblMle findMleById(Integer id) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblMle.findById");
        query.setParameter("id", id);
        query.setHint(QueryHints.REFRESH, HintValues.TRUE);
        query.setHint(QueryHints.CACHE_USAGE, CacheUsage.DoNotCheckCache);
        TblMle mle = (TblMle) query.getSingleResult();
        return mle;
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblMle(com.intel.mtwilson.as.data.TblMle)

Example 29 with EntityManager

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

the class TblModuleManifestJpaController method findByMleId.

public List<TblModuleManifest> findByMleId(Integer mleId) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblModuleManifest.findByMleId");
        query.setParameter("mleId", mleId);
        query.setHint(QueryHints.REFRESH, HintValues.TRUE);
        query.setHint(QueryHints.CACHE_USAGE, CacheUsage.DoNotCheckCache);
        List<TblModuleManifest> tblModuleManifestList = query.getResultList();
        return tblModuleManifestList;
    } 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)

Example 30 with EntityManager

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

the class TblModuleManifestJpaController method findTblModuleManifestByHardwareUuid.

public List<TblModuleManifest> findTblModuleManifestByHardwareUuid(String uuid) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblModuleManifest.findByHardwareUuid");
        query.setParameter("uuid_hex", uuid);
        List<TblModuleManifest> moduleList = query.getResultList();
        return moduleList;
    } 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)

Aggregations

EntityManager (javax.persistence.EntityManager)1395 Test (org.junit.Test)876 Priority (org.hibernate.envers.test.Priority)249 Query (javax.persistence.Query)200 TestForIssue (org.hibernate.testing.TestForIssue)97 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)87 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)79 List (java.util.List)69 NoResultException (javax.persistence.NoResultException)65 AbstractMetamodelSpecificTest (org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)63 EntityManagerFactory (javax.persistence.EntityManagerFactory)56 HashMap (java.util.HashMap)50 StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)50 ArrayList (java.util.ArrayList)41 PersistenceException (javax.persistence.PersistenceException)40 EntityNotFoundException (javax.persistence.EntityNotFoundException)39 Transactional (com.google.inject.persist.Transactional)38 EntityTransaction (javax.persistence.EntityTransaction)36 Item (org.hibernate.jpa.test.Item)36 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)34