Search in sources :

Example 6 with EntityNotFoundException

use of javax.persistence.EntityNotFoundException 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 7 with EntityNotFoundException

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

the class TblModuleManifestLogJpaController method destroy.

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

Example 8 with EntityNotFoundException

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

the class TblHostsJpaController method destroy.

public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblHosts tblHosts;
        try {
            tblHosts = em.getReference(TblHosts.class, id);
            tblHosts.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The tblHosts with id " + id + " no longer exists.", enfe);
        }
        TblMle vmmMleId = tblHosts.getVmmMleId();
        if (vmmMleId != null) {
            vmmMleId.getTblHostsCollection().remove(tblHosts);
            em.merge(vmmMleId);
        }
        TblMle biosMleId = tblHosts.getBiosMleId();
        if (biosMleId != null) {
            biosMleId.getTblHostsCollection().remove(tblHosts);
            em.merge(biosMleId);
        }
        em.remove(tblHosts);
        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) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 9 with EntityNotFoundException

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

the class TblLocationPcrJpaController method destroy.

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

Example 10 with EntityNotFoundException

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

the class TblSamlAssertionJpaController method destroy.

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

Aggregations

EntityNotFoundException (javax.persistence.EntityNotFoundException)75 EntityManager (javax.persistence.EntityManager)20 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)18 ServiceException (gov.ca.cwds.rest.services.ServiceException)15 Transactional (org.springframework.transaction.annotation.Transactional)14 BusinessServiceException (sic.service.BusinessServiceException)11 Test (org.junit.Test)10 Calendar (java.util.Calendar)9 GregorianCalendar (java.util.GregorianCalendar)9 ArrayList (java.util.ArrayList)7 BooleanBuilder (com.querydsl.core.BooleanBuilder)6 TblMle (com.intel.mtwilson.as.data.TblMle)5 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)4 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)4 PersistenceException (javax.persistence.PersistenceException)4 Sort (org.springframework.data.domain.Sort)4 TblHosts (com.intel.mtwilson.as.data.TblHosts)3 OptimisticLockException (javax.persistence.OptimisticLockException)3 TblEventType (com.intel.mtwilson.as.data.TblEventType)2 TblHostSpecificManifest (com.intel.mtwilson.as.data.TblHostSpecificManifest)2