Search in sources :

Example 1 with MwKeystore

use of com.intel.mtwilson.as.data.MwKeystore in project OpenAttestation by OpenAttestation.

the class MwKeystoreJpaController method findMwKeystoreByName.

/**
     *
     * @param name
     * @return the named MwKeystore, or null if it was not found
     */
public MwKeystore findMwKeystoreByName(String name) {
    //HashMap<String,Object> parameters = new HashMap<String,Object>();
    //parameters.put("name", name);
    //List<MwKeystore> list = searchByNamedQuery("MwKeystore.findByName", parameters);
    //if( list.isEmpty() ) {
    //    return null;
    //}
    //return list.get(0);
    MwKeystore mwKeystoreObj = null;
    EntityManager em = getEntityManager();
    Query query = em.createNamedQuery("MwKeystore.findByName");
    query.setParameter("name", name);
    query.setHint(QueryHints.REFRESH, HintValues.TRUE);
    query.setHint(QueryHints.CACHE_USAGE, CacheUsage.DoNotCheckCache);
    try {
        mwKeystoreObj = (MwKeystore) query.getSingleResult();
    } catch (javax.persistence.NoResultException e) {
        mwKeystoreObj = null;
    }
    return mwKeystoreObj;
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) MwKeystore(com.intel.mtwilson.as.data.MwKeystore)

Example 2 with MwKeystore

use of com.intel.mtwilson.as.data.MwKeystore in project OpenAttestation by OpenAttestation.

the class MwKeystoreJpaController method getMwKeystoreCount.

public int getMwKeystoreCount() {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<MwKeystore> rt = cq.from(MwKeystore.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) MwKeystore(com.intel.mtwilson.as.data.MwKeystore) CriteriaQuery(javax.persistence.criteria.CriteriaQuery)

Example 3 with MwKeystore

use of com.intel.mtwilson.as.data.MwKeystore in project OpenAttestation by OpenAttestation.

the class MwKeystoreJpaController method findMwKeystoreEntities.

private List<MwKeystore> findMwKeystoreEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(MwKeystore.class));
        Query q = em.createQuery(cq);
        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        return q.getResultList();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) MwKeystore(com.intel.mtwilson.as.data.MwKeystore) CriteriaQuery(javax.persistence.criteria.CriteriaQuery)

Example 4 with MwKeystore

use of com.intel.mtwilson.as.data.MwKeystore in project OpenAttestation by OpenAttestation.

the class MwKeystoreJpaController method destroy.

public void destroy(Integer id) throws NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        MwKeystore mwKeystore;
        try {
            mwKeystore = em.getReference(MwKeystore.class, id);
            mwKeystore.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The mwKeystore with id " + id + " no longer exists.", enfe);
        }
        em.remove(mwKeystore);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) MwKeystore(com.intel.mtwilson.as.data.MwKeystore) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Aggregations

MwKeystore (com.intel.mtwilson.as.data.MwKeystore)4 EntityManager (javax.persistence.EntityManager)4 Query (javax.persistence.Query)3 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)3 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1