use of com.intel.mtwilson.as.data.TblHosts 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();
}
}
use of com.intel.mtwilson.as.data.TblHosts in project OpenAttestation by OpenAttestation.
the class TblHostsJpaController method edit.
public void edit(TblHosts tblHosts) throws IllegalOrphanException, NonexistentEntityException, ASDataException {
EntityManager em = getEntityManager();
try {
em.getTransaction().begin();
TblHosts persistentTblHosts = em.find(TblHosts.class, tblHosts.getId());
TblMle vmmMleIdOld = persistentTblHosts.getVmmMleId();
TblMle vmmMleIdNew = tblHosts.getVmmMleId();
TblMle biosMleIdOld = persistentTblHosts.getBiosMleId();
TblMle biosMleIdNew = tblHosts.getBiosMleId();
if (vmmMleIdNew != null) {
vmmMleIdNew = em.getReference(vmmMleIdNew.getClass(), vmmMleIdNew.getId());
tblHosts.setVmmMleId(vmmMleIdNew);
}
if (biosMleIdNew != null) {
biosMleIdNew = em.getReference(biosMleIdNew.getClass(), biosMleIdNew.getId());
tblHosts.setBiosMleId(biosMleIdNew);
}
// encrypt addon connection string, persist, then restore the plaintext
String addOnConnectionString = tblHosts.getAddOnConnectionInfo();
if (addOnConnectionString != null) {
tblHosts = em.merge(tblHosts);
} else {
tblHosts = em.merge(tblHosts);
}
if (vmmMleIdOld != null && !vmmMleIdOld.equals(vmmMleIdNew)) {
vmmMleIdOld.getTblHostsCollection().remove(tblHosts);
vmmMleIdOld = em.merge(vmmMleIdOld);
}
if (vmmMleIdNew != null && !vmmMleIdNew.equals(vmmMleIdOld)) {
vmmMleIdNew.getTblHostsCollection().add(tblHosts);
em.merge(vmmMleIdNew);
}
if (biosMleIdOld != null && !biosMleIdOld.equals(biosMleIdNew)) {
biosMleIdOld.getTblHostsCollection().remove(tblHosts);
biosMleIdOld = em.merge(biosMleIdOld);
}
if (biosMleIdNew != null && !biosMleIdNew.equals(biosMleIdOld)) {
biosMleIdNew.getTblHostsCollection().add(tblHosts);
em.merge(biosMleIdNew);
}
em.getTransaction().commit();
} catch (Exception ex) {
String msg = ex.getLocalizedMessage();
if (msg == null || msg.length() == 0) {
Integer id = tblHosts.getId();
if (findTblHosts(id) == null) {
throw new NonexistentEntityException("The tblHosts with id " + id + " no longer exists.");
}
}
throw new ASDataException(ex);
} finally {
em.close();
}
}
use of com.intel.mtwilson.as.data.TblHosts in project OpenAttestation by OpenAttestation.
the class TblHostsJpaController method findTblHostsEntities.
private List<TblHosts> findTblHostsEntities(boolean all, int maxResults, int firstResult) {
EntityManager em = getEntityManager();
try {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
cq.select(cq.from(TblHosts.class));
Query q = em.createQuery(cq);
if (!all) {
q.setMaxResults(maxResults);
q.setFirstResult(firstResult);
}
List<TblHosts> results = q.getResultList();
return results;
} finally {
em.close();
}
}
use of com.intel.mtwilson.as.data.TblHosts in project OpenAttestation by OpenAttestation.
the class TblHostsJpaController method getTblHostsCount.
public int getTblHostsCount() {
EntityManager em = getEntityManager();
try {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
Root<TblHosts> rt = cq.from(TblHosts.class);
cq.select(em.getCriteriaBuilder().count(rt));
Query q = em.createQuery(cq);
return ((Long) q.getSingleResult()).intValue();
} finally {
em.close();
}
}
use of com.intel.mtwilson.as.data.TblHosts 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();
}
}
Aggregations