Search in sources :

Example 21 with TblModuleManifest

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

the class TblHostSpecificManifestJpaController method create.

public void create(TblHostSpecificManifest tblHostSpecificManifest) {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblModuleManifest moduleManifestID = tblHostSpecificManifest.getModuleManifestID();
        if (moduleManifestID != null) {
            moduleManifestID = em.getReference(moduleManifestID.getClass(), moduleManifestID.getId());
            tblHostSpecificManifest.setModuleManifestID(moduleManifestID);
        }
        em.persist(tblHostSpecificManifest);
        if (moduleManifestID != null) {
            moduleManifestID.getTblHostSpecificManifestCollection().add(tblHostSpecificManifest);
            em.merge(moduleManifestID);
        }
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest)

Example 22 with TblModuleManifest

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

the class TblHostSpecificManifestJpaController method destroy.

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

Example 23 with TblModuleManifest

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

the class TblModuleManifestJpaController method getTblModuleManifestCount.

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

Example 24 with TblModuleManifest

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

the class TblModuleManifestJpaController method findByComponentVlaue.

public List<TblModuleManifest> findByComponentVlaue(String digestValue) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblModuleManifest.findByModuleValue");
        query.setParameter("digestValue", digestValue);
        List<TblModuleManifest> pcrList = query.getResultList();
        return pcrList;
    } catch (NoResultException e) {
        log.error(String.format("Module information with name {} not found in the DB.", digestValue));
        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 25 with TblModuleManifest

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

the class TblPackageNamespaceJpaController method create.

public void create(TblPackageNamespace tblPackageNamespace) {
    if (tblPackageNamespace.getTblModuleManifestCollection() == null) {
        tblPackageNamespace.setTblModuleManifestCollection(new ArrayList<TblModuleManifest>());
    }
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        Collection<TblModuleManifest> attachedTblModuleManifestCollection = new ArrayList<TblModuleManifest>();
        for (TblModuleManifest tblModuleManifestCollectionTblModuleManifestToAttach : tblPackageNamespace.getTblModuleManifestCollection()) {
            tblModuleManifestCollectionTblModuleManifestToAttach = em.getReference(tblModuleManifestCollectionTblModuleManifestToAttach.getClass(), tblModuleManifestCollectionTblModuleManifestToAttach.getId());
            attachedTblModuleManifestCollection.add(tblModuleManifestCollectionTblModuleManifestToAttach);
        }
        tblPackageNamespace.setTblModuleManifestCollection(attachedTblModuleManifestCollection);
        em.persist(tblPackageNamespace);
        for (TblModuleManifest tblModuleManifestCollectionTblModuleManifest : tblPackageNamespace.getTblModuleManifestCollection()) {
            TblPackageNamespace oldNameSpaceIDOfTblModuleManifestCollectionTblModuleManifest = tblModuleManifestCollectionTblModuleManifest.getNameSpaceID();
            tblModuleManifestCollectionTblModuleManifest.setNameSpaceID(tblPackageNamespace);
            tblModuleManifestCollectionTblModuleManifest = em.merge(tblModuleManifestCollectionTblModuleManifest);
            if (oldNameSpaceIDOfTblModuleManifestCollectionTblModuleManifest != null) {
                oldNameSpaceIDOfTblModuleManifestCollectionTblModuleManifest.getTblModuleManifestCollection().remove(tblModuleManifestCollectionTblModuleManifest);
                em.merge(oldNameSpaceIDOfTblModuleManifestCollectionTblModuleManifest);
            }
        }
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ArrayList(java.util.ArrayList) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) TblPackageNamespace(com.intel.mtwilson.as.data.TblPackageNamespace)

Aggregations

TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)28 EntityManager (javax.persistence.EntityManager)21 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)11 NoResultException (javax.persistence.NoResultException)10 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)9 TblEventType (com.intel.mtwilson.as.data.TblEventType)9 TblHostSpecificManifest (com.intel.mtwilson.as.data.TblHostSpecificManifest)9 TblPackageNamespace (com.intel.mtwilson.as.data.TblPackageNamespace)9 ArrayList (java.util.ArrayList)9 EntityNotFoundException (javax.persistence.EntityNotFoundException)9 Query (javax.persistence.Query)9 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)9 TblMle (com.intel.mtwilson.as.data.TblMle)7 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)5 TblModuleManifestJpaController (com.intel.mtwilson.as.controller.TblModuleManifestJpaController)3 ASException (com.intel.mountwilson.as.common.ASException)2 TblHostSpecificManifestJpaController (com.intel.mtwilson.as.controller.TblHostSpecificManifestJpaController)2 TblMleJpaController (com.intel.mtwilson.as.controller.TblMleJpaController)2 Measurement (com.intel.mtwilson.util.model.Measurement)2 PcrEventLog (com.intel.mtwilson.util.model.PcrEventLog)2