diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/AbstractDbManager.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/AbstractDbManager.java index bc40688c..aa7e5ff6 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/AbstractDbManager.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/AbstractDbManager.java @@ -764,18 +764,18 @@ public abstract class AbstractDbManager implements CrudManager { * * @return session factory */ - protected final SessionFactory getFactory() { - return factory; + protected final Session getSession() { + return em.unwrap(org.hibernate.Session.class); } - /** - * Returns a StatelessSession that can be used for querying. - * - * @return stateless session - */ - protected final StatelessSession getStatelessSession() { - return factory.openStatelessSession(); - } +// /** +// * Returns a StatelessSession that can be used for querying. +// * +// * @return stateless session +// */ +// protected final StatelessSession getStatelessSession() { +// return factory.openStatelessSession(); +// } /** diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBDeviceGroupManager.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBDeviceGroupManager.java index fc46ed04..39dbe245 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBDeviceGroupManager.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBDeviceGroupManager.java @@ -155,10 +155,9 @@ public class DBDeviceGroupManager extends DBManager implements Devi throw new DeviceGroupManagerException("policy provided was null"); } - final SessionFactory factory = getFactory(); Set groups = new HashSet<>(); - Session session = factory.getCurrentSession(); + Session session = getSession(); Transaction tx = session.beginTransaction(); try { diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBDeviceManager.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBDeviceManager.java index d35e2ba8..bc85e229 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBDeviceManager.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBDeviceManager.java @@ -12,7 +12,6 @@ import org.apache.logging.log4j.Logger; import org.hibernate.Criteria; import org.hibernate.HibernateException; import org.hibernate.Session; -import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.query.Query; import org.springframework.stereotype.Service; @@ -113,7 +112,7 @@ public class DBDeviceManager extends DBManager implements throws DeviceManagerException { LOGGER.debug("updating all devices in list"); - Session session = getFactory().getCurrentSession(); + Session session = getSession(); Transaction tx = session.beginTransaction(); try { for (final Device device : deviceList) { @@ -256,7 +255,7 @@ public class DBDeviceManager extends DBManager implements public final List getDefaultDevices() throws DeviceManagerException { Transaction tx = null; - Session session = getFactory().getCurrentSession(); + Session session = getSession(); List devices = new ArrayList<>(); try { LOGGER.debug("retrieving defaults devices from db"); diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBPolicyManager.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBPolicyManager.java index fdabee13..d6c06c4a 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBPolicyManager.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBPolicyManager.java @@ -179,8 +179,7 @@ public class DBPolicyManager extends DBManager implements PolicyManager LOGGER.error("cannot set default policy on null appraiser"); throw new NullPointerException("appraiser"); } - final SessionFactory factory = getFactory(); - Session session = factory.getCurrentSession(); + Session session = getSession(); Transaction tx = session.beginTransaction(); try { CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder(); @@ -279,9 +278,8 @@ public class DBPolicyManager extends DBManager implements PolicyManager } Policy ret = null; - final SessionFactory factory = getFactory(); Transaction tx = null; - Session session = factory.getCurrentSession(); + Session session = getSession(); try { tx = session.beginTransaction(); LOGGER.debug("retrieving policy mapper from db where appraiser = {}", @@ -347,9 +345,8 @@ public class DBPolicyManager extends DBManager implements PolicyManager Preconditions.checkArgument(device != null, "Device must not be null"); Policy ret = null; - final SessionFactory factory = getFactory(); Transaction tx = null; - Session session = factory.getCurrentSession(); + Session session = getSession(); try { tx = session.beginTransaction(); LOGGER.debug("retrieving policy mapper from db where appraiser = " @@ -430,9 +427,8 @@ public class DBPolicyManager extends DBManager implements PolicyManager } Policy ret = null; - final SessionFactory factory = getFactory(); Transaction tx = null; - Session session = factory.getCurrentSession(); + Session session = getSession(); try { tx = session.beginTransaction(); LOGGER.debug("retrieving policy mapper from db where appraiser = " @@ -500,9 +496,8 @@ public class DBPolicyManager extends DBManager implements PolicyManager Preconditions.checkNotNull(appraiser, "Cannot set policy on null appraiser"); Preconditions.checkNotNull(deviceGroup, "Cannot set policy on null device group"); - final SessionFactory factory = getFactory(); Transaction tx = null; - Session session = factory.getCurrentSession(); + Session session = getSession(); try { tx = session.beginTransaction(); LOGGER.debug("Finding existing policy mapper from db where " @@ -565,9 +560,8 @@ public class DBPolicyManager extends DBManager implements PolicyManager int count = 0; if (policy != null) { - final SessionFactory factory = getFactory(); Transaction tx = null; - Session session = factory.getCurrentSession(); + Session session = getSession(); try { tx = session.beginTransaction(); LOGGER.debug("retrieving group use count for policy {}", policy); diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBReferenceEventManager.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBReferenceEventManager.java index 526016cf..8e2fb675 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBReferenceEventManager.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBReferenceEventManager.java @@ -73,7 +73,7 @@ public class DBReferenceEventManager extends DBManager ReferenceDigestValue dbRecord = null; Transaction tx = null; - Session session = getFactory().getCurrentSession(); + Session session = getSession(); try { LOGGER.debug("retrieving referenceDigestValue from db"); tx = session.beginTransaction(); @@ -143,7 +143,7 @@ public class DBReferenceEventManager extends DBManager ReferenceDigestValue dbRecord = null; Transaction tx = null; - Session session = getFactory().getCurrentSession(); + Session session = getSession(); try { LOGGER.debug("retrieving referenceDigestValue from db"); tx = session.beginTransaction(); @@ -185,7 +185,7 @@ public class DBReferenceEventManager extends DBManager ReferenceDigestValue dbRecord = null; Transaction tx = null; - Session session = getFactory().getCurrentSession(); + Session session = getSession(); try { LOGGER.debug("retrieving referenceDigestValue from db"); tx = session.beginTransaction(); diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBReportRequestStateManager.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBReportRequestStateManager.java index 88f037d2..b7361e0d 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBReportRequestStateManager.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBReportRequestStateManager.java @@ -42,7 +42,7 @@ public class DBReportRequestStateManager extends DBManager */ @Override public final ReportRequestState getState(final Device device) { - CriteriaBuilder builder = this.getFactory().getCriteriaBuilder(); + CriteriaBuilder builder = this.getSession().getCriteriaBuilder(); Root root = builder.createQuery(ReportRequestState.class) .from(ReportRequestState.class); @@ -63,7 +63,7 @@ public class DBReportRequestStateManager extends DBManager */ @Override public final List getLateDeviceStates() { - CriteriaBuilder builder = this.getFactory().getCriteriaBuilder(); + CriteriaBuilder builder = this.getSession().getCriteriaBuilder(); Root root = builder.createQuery(ReportRequestState.class) .from(ReportRequestState.class); diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBReportSummaryManager.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBReportSummaryManager.java index dda1db95..eafd89cd 100755 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBReportSummaryManager.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/DBReportSummaryManager.java @@ -137,7 +137,7 @@ public class DBReportSummaryManager extends DBManager List reportSummaryList = new ArrayList<>(); Transaction tx = null; - Session session = getFactory().getCurrentSession(); + Session session = getSession(); try { LOGGER.debug("retrieving objects from db"); tx = session.beginTransaction(); @@ -213,7 +213,7 @@ public class DBReportSummaryManager extends DBManager ReportSummary object; Transaction tx = null; - Session session = getFactory().getCurrentSession(); + Session session = getSession(); try { LOGGER.debug("retrieving objects from db"); tx = session.beginTransaction(); @@ -255,7 +255,7 @@ public class DBReportSummaryManager extends DBManager List reportSummaryList = new ArrayList<>(); Transaction tx = null; - Session session = getFactory().getCurrentSession(); + Session session = getSession(); try { LOGGER.debug("retrieving objects from db"); tx = session.beginTransaction(); @@ -359,7 +359,7 @@ public class DBReportSummaryManager extends DBManager ReportSummary object; Transaction tx = null; - Session session = getFactory().getCurrentSession(); + Session session = getSession(); try { LOGGER.debug("retrieving objects from db"); tx = session.beginTransaction();