Add DMP Roadmap database configuration and Template table. Make entity manager Primary and name entityManager to avoid conflicts on bean initialization.
This commit is contained in:
parent
943f84384c
commit
eee9faee28
|
@ -16,7 +16,7 @@ import javax.persistence.PersistenceContext;
|
|||
@Repository("databaseCtx")
|
||||
public class DatabaseContext<T extends DataEntity> {
|
||||
|
||||
@PersistenceContext
|
||||
@PersistenceContext(unitName = "entityManager")
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Autowired
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.springframework.boot.jdbc.DataSourceBuilder;
|
|||
import org.springframework.context.annotation.*;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||
import org.springframework.orm.jpa.JpaVendorAdapter;
|
||||
|
@ -29,12 +30,14 @@ public class DevelDatabaseConfiguration {
|
|||
private Environment env;
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
|
||||
em.setDataSource(dataSource());
|
||||
em.setPackagesToScan(new String[]{"eu.eudat.data.entities"});
|
||||
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
|
||||
em.setJpaVendorAdapter(vendorAdapter);
|
||||
em.setPersistenceUnitName("entityManager");
|
||||
em.setJpaProperties(additionalProperties());
|
||||
return em;
|
||||
}
|
||||
|
@ -53,6 +56,7 @@ public class DevelDatabaseConfiguration {
|
|||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
|
||||
JpaTransactionManager transactionManager = new JpaTransactionManager();
|
||||
transactionManager.setEntityManagerFactory(emf);
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package eu.eudat.configurations;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.context.annotation.*;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
|
@ -32,18 +29,20 @@ public class ProductionDatabaseConfiguration {
|
|||
private Environment env;
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
|
||||
em.setDataSource(dataSource());
|
||||
em.setPackagesToScan(new String[]{"eu.eudat.data.entities"});
|
||||
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
|
||||
em.setJpaVendorAdapter(vendorAdapter);
|
||||
em.setPersistenceUnitName("entityManager");
|
||||
em.setJpaProperties(additionalProperties());
|
||||
|
||||
return em;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public DataSource dataSource() {
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
dataSource.setDriverClassName(env.getProperty("database.driver-class-name"));
|
||||
|
@ -54,6 +53,7 @@ public class ProductionDatabaseConfiguration {
|
|||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
|
||||
JpaTransactionManager transactionManager = new JpaTransactionManager();
|
||||
transactionManager.setEntityManagerFactory(emf);
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
|
||||
@Service("databaseRepository")
|
||||
|
@ -40,6 +41,7 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
|
|||
private NotificationDao notificationDao;
|
||||
private FileUploadDao fileUploadDao;
|
||||
|
||||
@PersistenceContext(unitName = "entityManager")
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Autowired
|
||||
|
@ -192,11 +194,6 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
|
|||
this.userRoleDao = userRoleDao;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setEntityManager(EntityManager entityManager) {
|
||||
this.entityManager = entityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDmpDao getUserDmpDao() {
|
||||
return userDmpDao;
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package eu.eudat.migration;
|
||||
|
||||
import eu.eudat.migration.dao.TemplateRepository;
|
||||
import eu.eudat.migration.entities.Template;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DMPRoadmapMigration implements CommandLineRunner {
|
||||
|
||||
private final TemplateRepository templateRepository;
|
||||
|
||||
@Autowired
|
||||
public DMPRoadmapMigration(TemplateRepository templateRepository) {
|
||||
this.templateRepository = templateRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
Template template = templateRepository.findById(1L).orElse(null);
|
||||
System.out.println("test");
|
||||
System.out.println(template.toString());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package eu.eudat.migration.configuration;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.sql.DataSource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
@Configuration
|
||||
@EnableJpaRepositories(
|
||||
basePackages = "eu.eudat.migration.dao",
|
||||
entityManagerFactoryRef = "roadmapEntityManagerFactory",
|
||||
transactionManagerRef = "roadmapTransactionManager"
|
||||
)
|
||||
public class DMPRoadmapConfiguration {
|
||||
|
||||
private final Environment env;
|
||||
|
||||
@Autowired
|
||||
public DMPRoadmapConfiguration(Environment env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
@Bean(name = "roadmapDataSource")
|
||||
public DataSource roadmapDataSource() {
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
dataSource.setDriverClassName(Objects.requireNonNull(env.getProperty("roadmap.database.driver")));
|
||||
dataSource.setUrl(env.getProperty("roadmap.database.url"));
|
||||
dataSource.setUsername(env.getProperty("roadmap.database.username"));
|
||||
dataSource.setPassword(env.getProperty("roadmap.database.password"));
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
@Bean(name = "roadmapEntityManagerFactory")
|
||||
public LocalContainerEntityManagerFactoryBean roadmapEntityManagerFactory(@Qualifier("roadmapDataSource") DataSource roadmapDataSource) {
|
||||
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
|
||||
em.setDataSource(roadmapDataSource);
|
||||
em.setPackagesToScan("eu.eudat.migration.entities");
|
||||
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
|
||||
em.setJpaVendorAdapter(vendorAdapter);
|
||||
HashMap<String, Object> properties = new HashMap<>();
|
||||
properties.put("hibernate.dialect", env.getProperty("roadmap.hibernate.dialect"));
|
||||
properties.put("hibernate.hbm2ddl.auto", "none");
|
||||
em.setJpaPropertyMap(properties);
|
||||
return em;
|
||||
}
|
||||
|
||||
@Bean(name = "roadmapTransactionManager")
|
||||
public PlatformTransactionManager roadmapTransactionManager(@Qualifier("roadmapEntityManagerFactory") LocalContainerEntityManagerFactoryBean roadmapEntityManagerFactory) {
|
||||
JpaTransactionManager transactionManager = new JpaTransactionManager();
|
||||
transactionManager.setEntityManagerFactory(roadmapEntityManagerFactory.getObject());
|
||||
return transactionManager;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package eu.eudat.migration.dao;
|
||||
|
||||
import eu.eudat.migration.entities.Template;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface TemplateRepository extends JpaRepository<Template, Long> {
|
||||
}
|
|
@ -0,0 +1,190 @@
|
|||
package eu.eudat.migration.entities;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "templates")
|
||||
public class Template {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
private String title;
|
||||
private String description;
|
||||
private String published;
|
||||
@Column(name = "org_id")
|
||||
private Long orgId;
|
||||
private String locale;
|
||||
@Column(name = "is_default")
|
||||
private String isDefault;
|
||||
@Column(name = "created_at")
|
||||
private java.sql.Timestamp createdAt;
|
||||
@Column(name = "updated_at")
|
||||
private java.sql.Timestamp updatedAt;
|
||||
private Long version;
|
||||
private Long visibility;
|
||||
@Column(name = "customization_of")
|
||||
private Long customizationOf;
|
||||
@Column(name = "family_id")
|
||||
private Long familyId;
|
||||
private String archived;
|
||||
private String links;
|
||||
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
|
||||
public String getPublished() {
|
||||
return published;
|
||||
}
|
||||
|
||||
public void setPublished(String published) {
|
||||
this.published = published;
|
||||
}
|
||||
|
||||
|
||||
public Long getOrgId() {
|
||||
return orgId;
|
||||
}
|
||||
|
||||
public void setOrgId(Long orgId) {
|
||||
this.orgId = orgId;
|
||||
}
|
||||
|
||||
|
||||
public String getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public void setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
|
||||
public String getIsDefault() {
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
public void setIsDefault(String isDefault) {
|
||||
this.isDefault = isDefault;
|
||||
}
|
||||
|
||||
|
||||
public java.sql.Timestamp getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(java.sql.Timestamp createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
|
||||
public java.sql.Timestamp getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(java.sql.Timestamp updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
|
||||
public Long getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
public void setVisibility(Long visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
|
||||
public Long getCustomizationOf() {
|
||||
return customizationOf;
|
||||
}
|
||||
|
||||
public void setCustomizationOf(Long customizationOf) {
|
||||
this.customizationOf = customizationOf;
|
||||
}
|
||||
|
||||
|
||||
public Long getFamilyId() {
|
||||
return familyId;
|
||||
}
|
||||
|
||||
public void setFamilyId(Long familyId) {
|
||||
this.familyId = familyId;
|
||||
}
|
||||
|
||||
|
||||
public String getArchived() {
|
||||
return archived;
|
||||
}
|
||||
|
||||
public void setArchived(String archived) {
|
||||
this.archived = archived;
|
||||
}
|
||||
|
||||
|
||||
public String getLinks() {
|
||||
return links;
|
||||
}
|
||||
|
||||
public void setLinks(String links) {
|
||||
this.links = links;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Template{" +
|
||||
"id=" + id +
|
||||
", title='" + title + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", published='" + published + '\'' +
|
||||
", orgId=" + orgId +
|
||||
", locale='" + locale + '\'' +
|
||||
", isDefault='" + isDefault + '\'' +
|
||||
", createdAt=" + createdAt +
|
||||
", updatedAt=" + updatedAt +
|
||||
", version=" + version +
|
||||
", visibility=" + visibility +
|
||||
", customizationOf=" + customizationOf +
|
||||
", familyId=" + familyId +
|
||||
", archived='" + archived + '\'' +
|
||||
", links='" + links + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -94,3 +94,10 @@ logging.config=classpath:logging/logback-${spring.profiles.active}.xml
|
|||
|
||||
#############PROMETHEUS#########
|
||||
endpoints.prometheus.sensitive: false
|
||||
|
||||
#################### DMP ROADMAP DATABASE CONFIGURATION (Postgres or MySQL) ##########
|
||||
roadmap.database.driver=org.postgresql.Driver
|
||||
roadmap.database.url=
|
||||
roadmap.database.username=
|
||||
roadmap.database.password=
|
||||
roadmap.hibernate.dialect=org.hibernate.dialect.PostgreSQL92Dialect
|
Loading…
Reference in New Issue