Add DMP Roadmap database configuration and Template table. Make entity manager Primary and name entityManager to avoid conflicts on bean initialization.
parent
943f84384c
commit
eee9faee28
@ -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 + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue