mirror of
https://github.com/nsacyber/HIRS.git
synced 2025-01-22 04:18:20 +00:00
more refactor to get rid of sessionfactory
This commit is contained in:
parent
509907472a
commit
ea080ccd67
@ -98,7 +98,7 @@ public class AttestationCertificateAuthorityConfiguration implements WebMvcConfi
|
||||
*
|
||||
* @return session factory
|
||||
*/
|
||||
@Bean
|
||||
// @Bean
|
||||
public SessionFactory sessionFactory() {
|
||||
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(getSettings()).build();
|
||||
MetadataSources metadataSources = new MetadataSources(serviceRegistry);
|
||||
|
@ -4,10 +4,10 @@ import hirs.attestationca.persist.DBAppraiserManager;
|
||||
import hirs.attestationca.persist.DBDeviceGroupManager;
|
||||
import hirs.attestationca.persist.DBPolicyManager;
|
||||
import hirs.utils.HIRSProfiles;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
@ -25,11 +25,12 @@ public class InitializationListener implements ServletContextListener {
|
||||
context.refresh();
|
||||
|
||||
// obtain reference to hibernate session factory
|
||||
SessionFactory sessionFactory = context.getBean(LocalSessionFactoryBean.class).getObject();
|
||||
// SessionFactory sessionFactory = context.getBean(LocalSessionFactoryBean.class).getObject();
|
||||
EntityManager entityManager = context.getBean(EntityManagerFactory.class).createEntityManager();
|
||||
AcaDbInit.insertDefaultEntries(
|
||||
new DBAppraiserManager(sessionFactory),
|
||||
new DBDeviceGroupManager(sessionFactory),
|
||||
new DBPolicyManager(sessionFactory)
|
||||
new DBAppraiserManager(entityManager),
|
||||
new DBDeviceGroupManager(entityManager),
|
||||
new DBPolicyManager(entityManager)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,38 @@
|
||||
package hirs.attestationca.configuration;
|
||||
|
||||
import hirs.attestationca.AttestationCertificateAuthorityConfiguration;
|
||||
import hirs.attestationca.persist.DBCertificateManager;
|
||||
import hirs.attestationca.persist.DBDeviceGroupManager;
|
||||
import hirs.attestationca.persist.DBDeviceManager;
|
||||
import hirs.attestationca.persist.DBManager;
|
||||
import hirs.attestationca.persist.DBPolicyManager;
|
||||
import hirs.attestationca.persist.DBPortalInfoManager;
|
||||
import hirs.attestationca.persist.DBReferenceEventManager;
|
||||
import hirs.attestationca.persist.DBReferenceManifestManager;
|
||||
import hirs.attestationca.persist.DBReportManager;
|
||||
import hirs.attestationca.persist.DBReportRequestStateManager;
|
||||
import hirs.attestationca.persist.DBReportSummaryManager;
|
||||
import hirs.data.persist.SupplyChainValidationSummary;
|
||||
import hirs.persist.CertificateManager;
|
||||
import hirs.persist.CrudManager;
|
||||
import hirs.persist.DeviceGroupManager;
|
||||
import hirs.persist.DeviceManager;
|
||||
import hirs.persist.PolicyManager;
|
||||
import hirs.persist.PortalInfoManager;
|
||||
import hirs.persist.ReferenceEventManager;
|
||||
import hirs.persist.ReferenceManifestManager;
|
||||
import hirs.persist.ReportManager;
|
||||
import hirs.persist.ReportRequestStateManager;
|
||||
import hirs.persist.ReportSummaryManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
/**
|
||||
* Persistence Configuration for Spring enabled applications. Constructs a Hibernate SessionFactory
|
||||
* backed powered by a HikariCP connection pooled data source. Module-specific settings
|
||||
@ -7,168 +40,170 @@ package hirs.attestationca.configuration;
|
||||
* such as the HIRS_Portal uses this class and doesn't have a persistence-extended.properties
|
||||
* file, the default persistence file will be used instead.
|
||||
*/
|
||||
//@Configuration
|
||||
//@Import(AttestationCertificateAuthorityConfiguration.class)
|
||||
@Configuration
|
||||
@Import(AttestationCertificateAuthorityConfiguration.class)
|
||||
public class PersistenceConfiguration {
|
||||
|
||||
// /**
|
||||
// * The bean name to retrieve the default/general implementation of {@link }.
|
||||
// */
|
||||
// public static final String DEVICE_STATE_MANAGER_BEAN_NAME = "general_db_man_bean";
|
||||
//
|
||||
// @Autowired
|
||||
// private SessionFactory sessionFactory;
|
||||
//
|
||||
// @Autowired
|
||||
// private long retryWaitTimeMilliseconds;
|
||||
//
|
||||
// @Autowired
|
||||
// private int maxTransactionRetryAttempts;
|
||||
//
|
||||
// /**
|
||||
// * Creates a {@link hirs.persist.PolicyManager} ready to use.
|
||||
// *
|
||||
// * @return {@link hirs.persist.PolicyManager}
|
||||
// */
|
||||
// @Bean
|
||||
// public PolicyManager policyManager() {
|
||||
// DBPolicyManager manager = new DBPolicyManager(sessionFactory);
|
||||
// setDbManagerRetrySettings(manager);
|
||||
// return manager;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Creates a {@link hirs.persist.ReportManager} ready to use.
|
||||
// *
|
||||
// * @return {@link hirs.persist.ReportManager}
|
||||
// */
|
||||
// @Bean
|
||||
// public ReportManager reportManager() {
|
||||
// DBReportManager manager = new DBReportManager(sessionFactory);
|
||||
// setDbManagerRetrySettings(manager);
|
||||
// return manager;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Creates a {@link hirs.persist.DeviceManager} ready to use.
|
||||
// *
|
||||
// * @return {@link hirs.persist.DeviceManager}
|
||||
// */
|
||||
// @Bean
|
||||
// public DeviceManager deviceManager() {
|
||||
// DBDeviceManager manager = new DBDeviceManager(sessionFactory);
|
||||
// setDbManagerRetrySettings(manager);
|
||||
// return manager;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Creates a {@link hirs.persist.ReportSummaryManager} ready to use.
|
||||
// *
|
||||
// * @return {@link hirs.persist.ReportSummaryManager}
|
||||
// */
|
||||
// @Bean
|
||||
// public ReportSummaryManager reportSummaryManager() {
|
||||
// DBReportSummaryManager manager = new DBReportSummaryManager(sessionFactory);
|
||||
// setDbManagerRetrySettings(manager);
|
||||
// return manager;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Creates a {@link hirs.persist.DeviceGroupManager} ready to use.
|
||||
// *
|
||||
// * @return {@link hirs.persist.DeviceGroupManager}
|
||||
// */
|
||||
// @Bean
|
||||
// public DeviceGroupManager deviceGroupManager() {
|
||||
// DBDeviceGroupManager manager = new DBDeviceGroupManager(sessionFactory);
|
||||
// setDbManagerRetrySettings(manager);
|
||||
// return manager;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Creates a {@link hirs.persist.CertificateManager} ready to use.
|
||||
// *
|
||||
// * @return {@link hirs.persist.CertificateManager}
|
||||
// */
|
||||
// @Bean
|
||||
// public CertificateManager certificateManager() {
|
||||
// DBCertificateManager manager = new DBCertificateManager(sessionFactory);
|
||||
// manager.setRetryTemplate(maxTransactionRetryAttempts, retryWaitTimeMilliseconds);
|
||||
// return manager;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Creates a {@link hirs.persist.ReferenceManifestManager} ready to use.
|
||||
// *
|
||||
// * @return {@link hirs.persist.ReferenceManifestManager}
|
||||
// */
|
||||
// @Bean
|
||||
// public ReferenceManifestManager referenceManifestManager() {
|
||||
// DBReferenceManifestManager manager
|
||||
// = new DBReferenceManifestManager(sessionFactory);
|
||||
// setDbManagerRetrySettings(manager);
|
||||
// return manager;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Creates a {@link hirs.persist.ReferenceEventManager} ready to use.
|
||||
// *
|
||||
// * @return {@link hirs.persist.ReferenceEventManager}
|
||||
// */
|
||||
// @Bean
|
||||
// public ReferenceEventManager referenceEventManager() {
|
||||
// DBReferenceEventManager manager
|
||||
// = new DBReferenceEventManager(sessionFactory);
|
||||
// setDbManagerRetrySettings(manager);
|
||||
// return manager;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Creates a {@link hirs.persist.ReportRequestStateManager} ready to use.
|
||||
// *
|
||||
// * @return {@link hirs.persist.ReportRequestStateManager}
|
||||
// */
|
||||
// @Bean
|
||||
// public ReportRequestStateManager reportRequestStateManager() {
|
||||
// DBReportRequestStateManager manager
|
||||
// = new DBReportRequestStateManager(sessionFactory);
|
||||
// setDbManagerRetrySettings(manager);
|
||||
// return manager;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Creates a {@link hirs.persist.PortalInfoManager} ready to use.
|
||||
// *
|
||||
// * @return {@link hirs.persist.PortalInfoManager}
|
||||
// */
|
||||
// @Bean
|
||||
// public PortalInfoManager portalInfoManager() {
|
||||
// DBPortalInfoManager manager = new DBPortalInfoManager(sessionFactory);
|
||||
// setDbManagerRetrySettings(manager);
|
||||
// return manager;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Creates a {@link hirs.attestationca.persist.DBManager} for SupplyChainValidationSummary persistence, ready for use.
|
||||
// *
|
||||
// * @return {@link hirs.attestationca.persist.DBManager}
|
||||
// */
|
||||
// @Bean
|
||||
// public CrudManager<SupplyChainValidationSummary> supplyChainValidationSummaryManager() {
|
||||
// DBManager<SupplyChainValidationSummary> manager
|
||||
// = new DBManager<SupplyChainValidationSummary>(
|
||||
// SupplyChainValidationSummary.class,
|
||||
// sessionFactory
|
||||
// );
|
||||
// setDbManagerRetrySettings(manager);
|
||||
// return manager;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Apply the spring-wired retry template settings to the db manager.
|
||||
// * @param dbManager the manager to apply the retry settings to
|
||||
// */
|
||||
// private void setDbManagerRetrySettings(final DBManager dbManager) {
|
||||
// dbManager.setRetryTemplate(maxTransactionRetryAttempts, retryWaitTimeMilliseconds);
|
||||
// }
|
||||
/**
|
||||
* The bean name to retrieve the default/general implementation of {@link }.
|
||||
*/
|
||||
public static final String DEVICE_STATE_MANAGER_BEAN_NAME = "general_db_man_bean";
|
||||
|
||||
@Autowired
|
||||
EntityManagerFactory entityManagerFactory;
|
||||
@PersistenceContext
|
||||
EntityManager entityManager = entityManagerFactory.createEntityManager();
|
||||
|
||||
@Autowired
|
||||
private long retryWaitTimeMilliseconds;
|
||||
|
||||
@Autowired
|
||||
private int maxTransactionRetryAttempts;
|
||||
|
||||
/**
|
||||
* Creates a {@link hirs.persist.PolicyManager} ready to use.
|
||||
*
|
||||
* @return {@link hirs.persist.PolicyManager}
|
||||
*/
|
||||
@Bean
|
||||
public PolicyManager policyManager() {
|
||||
DBPolicyManager manager = new DBPolicyManager(entityManager);
|
||||
setDbManagerRetrySettings(manager);
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link hirs.persist.ReportManager} ready to use.
|
||||
*
|
||||
* @return {@link hirs.persist.ReportManager}
|
||||
*/
|
||||
@Bean
|
||||
public ReportManager reportManager() {
|
||||
DBReportManager manager = new DBReportManager(entityManager);
|
||||
setDbManagerRetrySettings(manager);
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link hirs.persist.DeviceManager} ready to use.
|
||||
*
|
||||
* @return {@link hirs.persist.DeviceManager}
|
||||
*/
|
||||
@Bean
|
||||
public DeviceManager deviceManager() {
|
||||
DBDeviceManager manager = new DBDeviceManager(entityManager);
|
||||
setDbManagerRetrySettings(manager);
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link hirs.persist.ReportSummaryManager} ready to use.
|
||||
*
|
||||
* @return {@link hirs.persist.ReportSummaryManager}
|
||||
*/
|
||||
@Bean
|
||||
public ReportSummaryManager reportSummaryManager() {
|
||||
DBReportSummaryManager manager = new DBReportSummaryManager(entityManager);
|
||||
setDbManagerRetrySettings(manager);
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link hirs.persist.DeviceGroupManager} ready to use.
|
||||
*
|
||||
* @return {@link hirs.persist.DeviceGroupManager}
|
||||
*/
|
||||
@Bean
|
||||
public DeviceGroupManager deviceGroupManager() {
|
||||
DBDeviceGroupManager manager = new DBDeviceGroupManager(entityManager);
|
||||
setDbManagerRetrySettings(manager);
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link hirs.persist.CertificateManager} ready to use.
|
||||
*
|
||||
* @return {@link hirs.persist.CertificateManager}
|
||||
*/
|
||||
@Bean
|
||||
public CertificateManager certificateManager() {
|
||||
DBCertificateManager manager = new DBCertificateManager(entityManager);
|
||||
manager.setRetryTemplate(maxTransactionRetryAttempts, retryWaitTimeMilliseconds);
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link hirs.persist.ReferenceManifestManager} ready to use.
|
||||
*
|
||||
* @return {@link hirs.persist.ReferenceManifestManager}
|
||||
*/
|
||||
@Bean
|
||||
public ReferenceManifestManager referenceManifestManager() {
|
||||
DBReferenceManifestManager manager
|
||||
= new DBReferenceManifestManager(entityManager);
|
||||
setDbManagerRetrySettings(manager);
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link hirs.persist.ReferenceEventManager} ready to use.
|
||||
*
|
||||
* @return {@link hirs.persist.ReferenceEventManager}
|
||||
*/
|
||||
@Bean
|
||||
public ReferenceEventManager referenceEventManager() {
|
||||
DBReferenceEventManager manager
|
||||
= new DBReferenceEventManager(entityManager);
|
||||
setDbManagerRetrySettings(manager);
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link hirs.persist.ReportRequestStateManager} ready to use.
|
||||
*
|
||||
* @return {@link hirs.persist.ReportRequestStateManager}
|
||||
*/
|
||||
@Bean
|
||||
public ReportRequestStateManager reportRequestStateManager() {
|
||||
DBReportRequestStateManager manager
|
||||
= new DBReportRequestStateManager(entityManager);
|
||||
setDbManagerRetrySettings(manager);
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link hirs.persist.PortalInfoManager} ready to use.
|
||||
*
|
||||
* @return {@link hirs.persist.PortalInfoManager}
|
||||
*/
|
||||
@Bean
|
||||
public PortalInfoManager portalInfoManager() {
|
||||
DBPortalInfoManager manager = new DBPortalInfoManager(entityManager);
|
||||
setDbManagerRetrySettings(manager);
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link hirs.attestationca.persist.DBManager} for SupplyChainValidationSummary persistence, ready for use.
|
||||
*
|
||||
* @return {@link hirs.attestationca.persist.DBManager}
|
||||
*/
|
||||
@Bean
|
||||
public CrudManager<SupplyChainValidationSummary> supplyChainValidationSummaryManager() {
|
||||
DBManager<SupplyChainValidationSummary> manager
|
||||
= new DBManager<SupplyChainValidationSummary>(
|
||||
SupplyChainValidationSummary.class,
|
||||
entityManager
|
||||
);
|
||||
setDbManagerRetrySettings(manager);
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the spring-wired retry template settings to the db manager.
|
||||
* @param dbManager the manager to apply the retry settings to
|
||||
*/
|
||||
private void setDbManagerRetrySettings(final DBManager dbManager) {
|
||||
dbManager.setRetryTemplate(maxTransactionRetryAttempts, retryWaitTimeMilliseconds);
|
||||
}
|
||||
}
|
||||
|
@ -12,15 +12,20 @@ import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.StatelessSession;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.criterion.Conjunction;
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.criterion.Disjunction;
|
||||
import org.hibernate.criterion.MatchMode;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
@ -50,30 +55,31 @@ public abstract class AbstractDbManager<T> implements CrudManager<T> {
|
||||
|
||||
private Class<T> clazz;
|
||||
|
||||
private SessionFactory factory;
|
||||
private EntityManager em;
|
||||
|
||||
/**
|
||||
* Creates a new <code>AbstractDbManager</code>.
|
||||
*
|
||||
* @param clazz Class to search for when doing Hibernate queries,
|
||||
* unfortunately class type of T cannot be determined using only T
|
||||
* @param sessionFactory the session factory to use to interact with the database
|
||||
* @param em the entity manager to use to interact with the database
|
||||
*/
|
||||
public AbstractDbManager(final Class<T> clazz, final SessionFactory sessionFactory) {
|
||||
public AbstractDbManager(final Class<T> clazz, final EntityManager em) {
|
||||
if (clazz == null) {
|
||||
LOGGER.error("AbstractDbManager cannot be instantiated with a null class");
|
||||
throw new IllegalArgumentException(
|
||||
"AbstractDbManager cannot be instantiated with a null class"
|
||||
);
|
||||
}
|
||||
if (sessionFactory == null) {
|
||||
if (em == null) {
|
||||
LOGGER.error("AbstractDbManager cannot be instantiated with a null SessionFactory");
|
||||
throw new IllegalArgumentException(
|
||||
"AbstractDbManager cannot be instantiated with a null SessionFactory"
|
||||
);
|
||||
}
|
||||
this.clazz = clazz;
|
||||
this.factory = sessionFactory;
|
||||
this.em = em;
|
||||
// this.factory = sessionFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -87,7 +93,7 @@ public abstract class AbstractDbManager<T> implements CrudManager<T> {
|
||||
* @return the configured database implementation
|
||||
*/
|
||||
protected DBManager.DBImpl getConfiguredImplementation() {
|
||||
String dialect = ((ServiceRegistryImplementor) factory).getParentServiceRegistry()
|
||||
String dialect = ((ServiceRegistryImplementor) em).getParentServiceRegistry()
|
||||
.getParentServiceRegistry().toString().toLowerCase();
|
||||
if (dialect.contains("hsql")) {
|
||||
return DBManager.DBImpl.HSQL;
|
||||
@ -122,7 +128,8 @@ public abstract class AbstractDbManager<T> implements CrudManager<T> {
|
||||
|
||||
boolean deleted = false;
|
||||
Transaction tx = null;
|
||||
Session session = factory.getCurrentSession();
|
||||
Session session = em.unwrap(org.hibernate.Session.class);
|
||||
//factory.getCurrentSession();
|
||||
try {
|
||||
LOGGER.debug("retrieving object from db");
|
||||
tx = session.beginTransaction();
|
||||
@ -167,7 +174,7 @@ public abstract class AbstractDbManager<T> implements CrudManager<T> {
|
||||
|
||||
boolean deleted = false;
|
||||
Transaction tx = null;
|
||||
Session session = factory.getCurrentSession();
|
||||
Session session = em.unwrap(org.hibernate.Session.class);
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
|
||||
try {
|
||||
@ -227,7 +234,7 @@ public abstract class AbstractDbManager<T> implements CrudManager<T> {
|
||||
}
|
||||
|
||||
Transaction tx = null;
|
||||
Session session = factory.getCurrentSession();
|
||||
Session session = em.unwrap(org.hibernate.Session.class);
|
||||
try {
|
||||
LOGGER.debug("deleting object from db");
|
||||
tx = session.beginTransaction();
|
||||
@ -255,7 +262,7 @@ public abstract class AbstractDbManager<T> implements CrudManager<T> {
|
||||
protected int doDeleteAll() throws DBManagerException {
|
||||
int numEntitiesDeleted = 0;
|
||||
Transaction tx = null;
|
||||
Session session = factory.getCurrentSession();
|
||||
Session session = em.unwrap(org.hibernate.Session.class);
|
||||
try {
|
||||
LOGGER.debug("Deleting instances of class: {}", this.clazz.getClass());
|
||||
tx = session.beginTransaction();
|
||||
@ -327,7 +334,7 @@ public abstract class AbstractDbManager<T> implements CrudManager<T> {
|
||||
}
|
||||
List<T> ret = new ArrayList<>();
|
||||
Transaction tx = null;
|
||||
Session session = factory.getCurrentSession();
|
||||
Session session = em.unwrap(org.hibernate.Session.class);
|
||||
try {
|
||||
LOGGER.debug("retrieving criteria from db");
|
||||
tx = session.beginTransaction();
|
||||
@ -385,7 +392,7 @@ public abstract class AbstractDbManager<T> implements CrudManager<T> {
|
||||
}
|
||||
|
||||
Transaction tx = null;
|
||||
Session session = factory.getCurrentSession();
|
||||
Session session = em.unwrap(org.hibernate.Session.class);
|
||||
try {
|
||||
LOGGER.debug("saving object in db");
|
||||
tx = session.beginTransaction();
|
||||
@ -419,7 +426,7 @@ public abstract class AbstractDbManager<T> implements CrudManager<T> {
|
||||
}
|
||||
|
||||
Transaction tx = null;
|
||||
Session session = factory.getCurrentSession();
|
||||
Session session = em.unwrap(org.hibernate.Session.class);
|
||||
try {
|
||||
LOGGER.debug("updating object in db");
|
||||
tx = session.beginTransaction();
|
||||
|
@ -6,9 +6,9 @@ import hirs.persist.AppraiserManagerException;
|
||||
import hirs.persist.DBManagerException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -24,10 +24,10 @@ public class DBAppraiserManager extends DBManager<Appraiser> implements Appraise
|
||||
* database. The default database is used to store all of the
|
||||
* <code>Appraiser</code>s.
|
||||
*
|
||||
* @param sessionFactory session factory used to access database connections
|
||||
* @param em entity manager used to access database connections
|
||||
*/
|
||||
public DBAppraiserManager(final SessionFactory sessionFactory) {
|
||||
super(Appraiser.class, sessionFactory);
|
||||
public DBAppraiserManager(final EntityManager em) {
|
||||
super(Appraiser.class, em);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,12 +6,12 @@ import hirs.persist.CertificateSelector;
|
||||
import hirs.persist.DBManagerException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.retry.RetryCallback;
|
||||
import org.springframework.retry.RetryContext;
|
||||
import org.springframework.retry.support.RetryTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@ -32,10 +32,10 @@ public class DBCertificateManager extends DBManager<Certificate>
|
||||
* Creates a new {@link DBCertificateManager} that uses the default
|
||||
* database.
|
||||
*
|
||||
* @param sessionFactory session factory used to access database connections
|
||||
* @param em entity manager used to access database connections
|
||||
*/
|
||||
public DBCertificateManager(final SessionFactory sessionFactory) {
|
||||
super(Certificate.class, sessionFactory);
|
||||
public DBCertificateManager(final EntityManager em) {
|
||||
super(Certificate.class, em);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,6 +17,7 @@ import org.hibernate.Transaction;
|
||||
import org.hibernate.query.Query;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
@ -40,10 +41,10 @@ public class DBDeviceGroupManager extends DBManager<DeviceGroup> implements Devi
|
||||
* Creates a new <code>DBDeviceGroupManager</code> and sets the
|
||||
* <code>SessionFactory</code> to the given instance.
|
||||
*
|
||||
* @param factory session factory used to access database connections
|
||||
* @param em session factory used to access database connections
|
||||
*/
|
||||
public DBDeviceGroupManager(final SessionFactory factory) {
|
||||
super(DeviceGroup.class, factory);
|
||||
public DBDeviceGroupManager(final EntityManager em) {
|
||||
super(DeviceGroup.class, em);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,6 +17,7 @@ import org.hibernate.Transaction;
|
||||
import org.hibernate.query.Query;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.JoinType;
|
||||
@ -45,10 +46,10 @@ public class DBDeviceManager extends DBManager<Device> implements
|
||||
* database. The default database is used to store all of the
|
||||
* <code>Device</code>s.
|
||||
*
|
||||
* @param sessionFactory session factory used to access database connections
|
||||
* @param em entity manager used to access database connections
|
||||
*/
|
||||
public DBDeviceManager(final SessionFactory sessionFactory) {
|
||||
super(Device.class, sessionFactory);
|
||||
public DBDeviceManager(final EntityManager em) {
|
||||
super(Device.class, em);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,6 +19,7 @@ import org.springframework.retry.policy.SimpleRetryPolicy;
|
||||
import org.springframework.retry.support.RetryTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
@ -68,11 +69,11 @@ public class DBManager<T> extends AbstractDbManager<T> {
|
||||
* default database is used to store all of the objects.
|
||||
*
|
||||
* @param clazz Class to search for when doing Hibernate queries
|
||||
* @param sessionFactory the session factory to use to connect to the database
|
||||
* @param em the entity manager to use to connect to the database
|
||||
* unfortunately class type of T cannot be determined using only T
|
||||
*/
|
||||
public DBManager(final Class<T> clazz, final SessionFactory sessionFactory) {
|
||||
super(clazz, sessionFactory);
|
||||
public DBManager(final Class<T> clazz, final EntityManager em) {
|
||||
super(clazz, em);
|
||||
setRetryTemplate(DEFAULT_MAX_RETRY_ATTEMPTS, DEFAULT_RETRY_WAIT_TIME_MS);
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ import org.hibernate.Transaction;
|
||||
import org.hibernate.query.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
@ -38,10 +39,10 @@ public class DBPolicyManager extends DBManager<Policy> implements PolicyManager
|
||||
* parameter is used to initialize a session factory to manage all hibernate
|
||||
* sessions.
|
||||
*
|
||||
* @param factory session factory to manage connections to hibernate db
|
||||
* @param em Entity Manager to manage connections to hibernate db
|
||||
*/
|
||||
public DBPolicyManager(final SessionFactory factory) {
|
||||
super(Policy.class, factory);
|
||||
public DBPolicyManager(final EntityManager em) {
|
||||
super(Policy.class, em);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,9 +7,9 @@ import hirs.persist.PortalInfoManager;
|
||||
import hirs.persist.PortalInfoManagerException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
@ -26,10 +26,10 @@ public class DBPortalInfoManager extends DBManager<PortalInfo> implements Portal
|
||||
* Creates a new <code>DBPortalInfoManager</code>. The optional SessionFactory parameter is
|
||||
* used to manage sessions with a hibernate db.
|
||||
*
|
||||
* @param factory a hibernate session
|
||||
* @param em a hibernate session
|
||||
*/
|
||||
public DBPortalInfoManager(final SessionFactory factory) {
|
||||
super(PortalInfo.class, factory);
|
||||
public DBPortalInfoManager(final EntityManager em) {
|
||||
super(PortalInfo.class, em);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,11 +11,11 @@ import hirs.persist.ReferenceEventManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.query.Query;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
@ -39,10 +39,10 @@ public class DBReferenceEventManager extends DBManager<ReferenceDigestValue>
|
||||
/**
|
||||
* Default Constructor.
|
||||
*
|
||||
* @param sessionFactory session factory used to access database connections
|
||||
* @param em entity manager used to access database connections
|
||||
*/
|
||||
public DBReferenceEventManager(final SessionFactory sessionFactory) {
|
||||
super(ReferenceDigestValue.class, sessionFactory);
|
||||
public DBReferenceEventManager(final EntityManager em) {
|
||||
super(ReferenceDigestValue.class, em);
|
||||
this.setClazz(ReferenceDigestValue.class);
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,9 @@ import hirs.persist.ReferenceManifestManager;
|
||||
import hirs.persist.ReferenceManifestSelector;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@ -24,10 +24,10 @@ public class DBReferenceManifestManager extends DBManager<ReferenceManifest>
|
||||
/**
|
||||
* Default Constructor.
|
||||
*
|
||||
* @param sessionFactory session factory used to access database connections
|
||||
* @param em entity manager used to access database connections
|
||||
*/
|
||||
public DBReferenceManifestManager(final SessionFactory sessionFactory) {
|
||||
super(ReferenceManifest.class, sessionFactory);
|
||||
public DBReferenceManifestManager(final EntityManager em) {
|
||||
super(ReferenceManifest.class, em);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,13 +6,13 @@ import hirs.persist.ReportManager;
|
||||
import hirs.persist.ReportManagerException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.criterion.Conjunction;
|
||||
import org.hibernate.criterion.Disjunction;
|
||||
import org.hibernate.criterion.MatchMode;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -32,10 +32,10 @@ public class DBReportManager extends DBManager<Report> implements ReportManager
|
||||
* Creates a new <code>DBReportManager</code> that uses the provided sessionFactory
|
||||
* to interact with a database.
|
||||
*
|
||||
* @param sessionFactory session factory used to access database connections
|
||||
* @param em entity manager used to access database connections
|
||||
*/
|
||||
public DBReportManager(final SessionFactory sessionFactory) {
|
||||
super(Report.class, sessionFactory);
|
||||
public DBReportManager(final EntityManager em) {
|
||||
super(Report.class, em);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,9 +5,9 @@ import hirs.data.persist.ReportRequestState;
|
||||
import hirs.persist.ReportRequestStateManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
@ -28,10 +28,10 @@ public class DBReportRequestStateManager extends DBManager<ReportRequestState>
|
||||
* Creates a new <code>DBReportRequestStateManager</code> that uses the default database. The
|
||||
* default database is used to store all of the <code>ReportRequestState</code>s.
|
||||
*
|
||||
* @param sessionFactory session factory used to access database connections
|
||||
* @param em entity manager used to access database connections
|
||||
*/
|
||||
public DBReportRequestStateManager(final SessionFactory sessionFactory) {
|
||||
super(ReportRequestState.class, sessionFactory);
|
||||
public DBReportRequestStateManager(final EntityManager em) {
|
||||
super(ReportRequestState.class, em);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,12 +6,12 @@ import hirs.persist.ReportSummaryManager;
|
||||
import hirs.persist.ReportSummaryManagerException;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.hibernate.query.Query;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
@ -39,10 +39,10 @@ public class DBReportSummaryManager extends DBManager<ReportSummary>
|
||||
* The default database is used to store all of the
|
||||
* <code>ReportSummary</code> objects.
|
||||
*
|
||||
* @param sessionFactory session factory used to access database connections
|
||||
* @param em entity manager used to access database connections
|
||||
*/
|
||||
public DBReportSummaryManager(final SessionFactory sessionFactory) {
|
||||
super(ReportSummary.class, sessionFactory);
|
||||
public DBReportSummaryManager(final EntityManager em) {
|
||||
super(ReportSummary.class, em);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,6 +3,7 @@
|
||||
persistence.db.url = jdbc:mariadb://localhost/hirs_db?autoReconnect=true&useSSL=true&requireSSL=true&enabledSslProtocolSuites=TLSv1&disableSslHostnameVerification=true
|
||||
persistence.db.username = hirs_db
|
||||
persistence.db.password = hirs_db
|
||||
# update?
|
||||
persistence.db.driverClass = org.mariadb.jdbc.Driver
|
||||
persistence.db.maximumPoolSize = 10
|
||||
persistence.db.connectionTimeout = 30000
|
||||
@ -17,3 +18,7 @@ hibernate.show_sql = true
|
||||
hibernate.format_sql = true
|
||||
persistence.hibernate.contextClass = org.springframework.orm.hibernate5.SpringSessionContext
|
||||
persistence.hibernate.provider = org.hibernate.hikaricp.internal.HikariCPConnectionProvider
|
||||
|
||||
|
||||
# caching the entity manager in a persistence
|
||||
# inject the entity manger in spring using context
|
Loading…
Reference in New Issue
Block a user