Missed some additional refactors

This commit is contained in:
Cyrus 2022-07-25 12:04:11 -04:00
parent ea080ccd67
commit 43038310b4
7 changed files with 28 additions and 36 deletions

View File

@ -764,18 +764,18 @@ public abstract class AbstractDbManager<T> implements CrudManager<T> {
*
* @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();
// }
/**

View File

@ -155,10 +155,9 @@ public class DBDeviceGroupManager extends DBManager<DeviceGroup> implements Devi
throw new DeviceGroupManagerException("policy provided was null");
}
final SessionFactory factory = getFactory();
Set<DeviceGroup> groups = new HashSet<>();
Session session = factory.getCurrentSession();
Session session = getSession();
Transaction tx = session.beginTransaction();
try {

View File

@ -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<Device> 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<Device> implements
public final List<Device> getDefaultDevices() throws DeviceManagerException {
Transaction tx = null;
Session session = getFactory().getCurrentSession();
Session session = getSession();
List<Device> devices = new ArrayList<>();
try {
LOGGER.debug("retrieving defaults devices from db");

View File

@ -179,8 +179,7 @@ public class DBPolicyManager extends DBManager<Policy> 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<Policy> 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<Policy> 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<Policy> 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<Policy> 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<Policy> 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);

View File

@ -73,7 +73,7 @@ public class DBReferenceEventManager extends DBManager<ReferenceDigestValue>
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>
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>
ReferenceDigestValue dbRecord = null;
Transaction tx = null;
Session session = getFactory().getCurrentSession();
Session session = getSession();
try {
LOGGER.debug("retrieving referenceDigestValue from db");
tx = session.beginTransaction();

View File

@ -42,7 +42,7 @@ public class DBReportRequestStateManager extends DBManager<ReportRequestState>
*/
@Override
public final ReportRequestState getState(final Device device) {
CriteriaBuilder builder = this.getFactory().getCriteriaBuilder();
CriteriaBuilder builder = this.getSession().getCriteriaBuilder();
Root<ReportRequestState> root = builder.createQuery(ReportRequestState.class)
.from(ReportRequestState.class);
@ -63,7 +63,7 @@ public class DBReportRequestStateManager extends DBManager<ReportRequestState>
*/
@Override
public final List<ReportRequestState> getLateDeviceStates() {
CriteriaBuilder builder = this.getFactory().getCriteriaBuilder();
CriteriaBuilder builder = this.getSession().getCriteriaBuilder();
Root<ReportRequestState> root = builder.createQuery(ReportRequestState.class)
.from(ReportRequestState.class);

View File

@ -137,7 +137,7 @@ public class DBReportSummaryManager extends DBManager<ReportSummary>
List<ReportSummary> 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>
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<ReportSummary>
List<ReportSummary> 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>
ReportSummary object;
Transaction tx = null;
Session session = getFactory().getCurrentSession();
Session session = getSession();
try {
LOGGER.debug("retrieving objects from db");
tx = session.beginTransaction();