Search in sources :

Example 11 with TblPackageNamespace

use of com.intel.mtwilson.as.data.TblPackageNamespace 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)

Example 12 with TblPackageNamespace

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

the class TblPackageNamespaceJpaController method findTblPackageNamespaceEntities.

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

Aggregations

TblPackageNamespace (com.intel.mtwilson.as.data.TblPackageNamespace)12 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)9 EntityManager (javax.persistence.EntityManager)9 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)6 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)6 TblEventType (com.intel.mtwilson.as.data.TblEventType)6 TblMle (com.intel.mtwilson.as.data.TblMle)6 ArrayList (java.util.ArrayList)6 TblHostSpecificManifest (com.intel.mtwilson.as.data.TblHostSpecificManifest)5 EntityNotFoundException (javax.persistence.EntityNotFoundException)5 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)3 NoResultException (javax.persistence.NoResultException)3 Query (javax.persistence.Query)3 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)3 ASException (com.intel.mountwilson.as.common.ASException)1 TblEventTypeJpaController (com.intel.mtwilson.as.controller.TblEventTypeJpaController)1 TblMleJpaController (com.intel.mtwilson.as.controller.TblMleJpaController)1 TblModuleManifestJpaController (com.intel.mtwilson.as.controller.TblModuleManifestJpaController)1 TblPackageNamespaceJpaController (com.intel.mtwilson.as.controller.TblPackageNamespaceJpaController)1 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)1