Search in sources :

Example 1 with TblPcrManifest

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

the class TblPcrManifestJpaController method findTblPcrManifestEntities.

private List<TblPcrManifest> findTblPcrManifestEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(TblPcrManifest.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) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest)

Example 2 with TblPcrManifest

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

the class TblPcrManifestJpaController method destroy.

public void destroy(Integer id) throws NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblPcrManifest tblPcrManifest;
        try {
            tblPcrManifest = em.getReference(TblPcrManifest.class, id);
            tblPcrManifest.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The tblPcrManifest with id " + id + " no longer exists.", enfe);
        }
        // @since 1.1 we are relying on the audit log for "created on", "created by", etc. type information
        /*
            TblDbPortalUser updatedBy = tblPcrManifest.getUpdatedBy();
            if (updatedBy != null) {
                updatedBy.getTblPcrManifestCollection().remove(tblPcrManifest);
                em.merge(updatedBy);
            }
            TblDbPortalUser createdBy = tblPcrManifest.getCreatedBy();
            if (createdBy != null) {
                createdBy.getTblPcrManifestCollection().remove(tblPcrManifest);
                em.merge(createdBy);
            }
            */
        TblMle mleId = tblPcrManifest.getMleId();
        if (mleId != null) {
            mleId.getTblPcrManifestCollection().remove(tblPcrManifest);
            em.merge(mleId);
        }
        em.remove(tblPcrManifest);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblMle(com.intel.mtwilson.as.data.TblMle) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest)

Example 3 with TblPcrManifest

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

the class TblPcrManifestJpaController method getTblPcrManifestCount.

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

Example 4 with TblPcrManifest

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

the class TblMleJpaController method create.

public void create(TblMle tblMle) {
    if (tblMle.getTblHostsCollection() == null) {
        tblMle.setTblHostsCollection(new ArrayList<TblHosts>());
    }
    if (tblMle.getTblHostsCollection1() == null) {
        tblMle.setTblHostsCollection1(new ArrayList<TblHosts>());
    }
    if (tblMle.getTblPcrManifestCollection() == null) {
        tblMle.setTblPcrManifestCollection(new ArrayList<TblPcrManifest>());
    }
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        Collection<TblHosts> attachedTblHostsCollection = new ArrayList<TblHosts>();
        for (TblHosts tblHostsCollectionTblHostsToAttach : tblMle.getTblHostsCollection()) {
            tblHostsCollectionTblHostsToAttach = em.getReference(tblHostsCollectionTblHostsToAttach.getClass(), tblHostsCollectionTblHostsToAttach.getId());
            attachedTblHostsCollection.add(tblHostsCollectionTblHostsToAttach);
        }
        tblMle.setTblHostsCollection(attachedTblHostsCollection);
        Collection<TblHosts> attachedTblHostsCollection1 = new ArrayList<TblHosts>();
        for (TblHosts tblHostsCollection1TblHostsToAttach : tblMle.getTblHostsCollection1()) {
            tblHostsCollection1TblHostsToAttach = em.getReference(tblHostsCollection1TblHostsToAttach.getClass(), tblHostsCollection1TblHostsToAttach.getId());
            attachedTblHostsCollection1.add(tblHostsCollection1TblHostsToAttach);
        }
        tblMle.setTblHostsCollection1(attachedTblHostsCollection1);
        Collection<TblPcrManifest> attachedTblPcrManifestCollection = new ArrayList<TblPcrManifest>();
        for (TblPcrManifest tblPcrManifestCollectionTblPcrManifestToAttach : tblMle.getTblPcrManifestCollection()) {
            tblPcrManifestCollectionTblPcrManifestToAttach = em.getReference(tblPcrManifestCollectionTblPcrManifestToAttach.getClass(), tblPcrManifestCollectionTblPcrManifestToAttach.getId());
            attachedTblPcrManifestCollection.add(tblPcrManifestCollectionTblPcrManifestToAttach);
        }
        tblMle.setTblPcrManifestCollection(attachedTblPcrManifestCollection);
        em.persist(tblMle);
        for (TblHosts tblHostsCollectionTblHosts : tblMle.getTblHostsCollection()) {
            TblMle oldVmmMleIdOfTblHostsCollectionTblHosts = tblHostsCollectionTblHosts.getVmmMleId();
            tblHostsCollectionTblHosts.setVmmMleId(tblMle);
            tblHostsCollectionTblHosts = em.merge(tblHostsCollectionTblHosts);
            if (oldVmmMleIdOfTblHostsCollectionTblHosts != null) {
                oldVmmMleIdOfTblHostsCollectionTblHosts.getTblHostsCollection().remove(tblHostsCollectionTblHosts);
                em.merge(oldVmmMleIdOfTblHostsCollectionTblHosts);
            }
        }
        for (TblHosts tblHostsCollection1TblHosts : tblMle.getTblHostsCollection1()) {
            TblMle oldBiosMleIdOfTblHostsCollection1TblHosts = tblHostsCollection1TblHosts.getBiosMleId();
            tblHostsCollection1TblHosts.setBiosMleId(tblMle);
            tblHostsCollection1TblHosts = em.merge(tblHostsCollection1TblHosts);
            if (oldBiosMleIdOfTblHostsCollection1TblHosts != null) {
                oldBiosMleIdOfTblHostsCollection1TblHosts.getTblHostsCollection1().remove(tblHostsCollection1TblHosts);
                em.merge(oldBiosMleIdOfTblHostsCollection1TblHosts);
            }
        }
        for (TblPcrManifest tblPcrManifestCollectionTblPcrManifest : tblMle.getTblPcrManifestCollection()) {
            TblMle oldMleIdOfTblPcrManifestCollectionTblPcrManifest = tblPcrManifestCollectionTblPcrManifest.getMleId();
            tblPcrManifestCollectionTblPcrManifest.setMleId(tblMle);
            tblPcrManifestCollectionTblPcrManifest = em.merge(tblPcrManifestCollectionTblPcrManifest);
            if (oldMleIdOfTblPcrManifestCollectionTblPcrManifest != null) {
                oldMleIdOfTblPcrManifestCollectionTblPcrManifest.getTblPcrManifestCollection().remove(tblPcrManifestCollectionTblPcrManifest);
                em.merge(oldMleIdOfTblPcrManifestCollectionTblPcrManifest);
            }
        }
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblHosts(com.intel.mtwilson.as.data.TblHosts) TblMle(com.intel.mtwilson.as.data.TblMle) ArrayList(java.util.ArrayList) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest)

Example 5 with TblPcrManifest

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

the class TblPcrManifestJpaController method findPcrManifestById.

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

Aggregations

TblPcrManifest (com.intel.mtwilson.as.data.TblPcrManifest)34 TblMle (com.intel.mtwilson.as.data.TblMle)18 Matchers.anyString (org.mockito.Matchers.anyString)12 ArrayList (java.util.ArrayList)9 EntityManager (javax.persistence.EntityManager)9 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)8 TblHosts (com.intel.mtwilson.as.data.TblHosts)7 Test (org.junit.Test)7 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)6 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)6 TblOem (com.intel.mtwilson.as.data.TblOem)6 TblOs (com.intel.mtwilson.as.data.TblOs)6 NoResultException (javax.persistence.NoResultException)5 ASException (com.intel.mountwilson.as.common.ASException)4 IManifest (com.intel.mountwilson.manifest.data.IManifest)4 PcrManifest (com.intel.mountwilson.manifest.data.PcrManifest)4 HashMap (java.util.HashMap)4 EntityNotFoundException (javax.persistence.EntityNotFoundException)4 Query (javax.persistence.Query)4 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)4