|
@ -1,5 +1,4 @@ |
|
|
package es.fp.edu.conecta2; |
|
|
package es.fp.edu.conecta2; |
|
|
|
|
|
|
|
|
import org.springframework.core.env.Environment; |
|
|
import org.springframework.core.env.Environment; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.context.annotation.Bean; |
|
|
import org.springframework.context.annotation.Bean; |
|
@ -11,7 +10,6 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; |
|
|
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; |
|
|
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; |
|
|
import org.springframework.transaction.PlatformTransactionManager; |
|
|
import org.springframework.transaction.PlatformTransactionManager; |
|
|
import org.springframework.transaction.annotation.EnableTransactionManagement; |
|
|
import org.springframework.transaction.annotation.EnableTransactionManagement; |
|
|
|
|
|
|
|
|
import javax.sql.DataSource; |
|
|
import javax.sql.DataSource; |
|
|
import java.util.HashMap; |
|
|
import java.util.HashMap; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
@ -32,35 +30,28 @@ public class BDMariaDB { |
|
|
dataSource.setUrl(env.getProperty("persistente.datasource.url")); |
|
|
dataSource.setUrl(env.getProperty("persistente.datasource.url")); |
|
|
dataSource.setUsername(env.getProperty("persistente.datasource.username")); |
|
|
dataSource.setUsername(env.getProperty("persistente.datasource.username")); |
|
|
dataSource.setPassword(env.getProperty("persistente.datasource.password")); |
|
|
dataSource.setPassword(env.getProperty("persistente.datasource.password")); |
|
|
dataSource.setDriverClassName(env.getProperty("persistente.datasource.driver-class-name")); |
|
|
|
|
|
|
|
|
|
|
|
return dataSource; |
|
|
return dataSource; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
@Bean(name = "userEntityManagerFactory") |
|
|
@Bean(name = "userEntityManagerFactory") |
|
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory() { |
|
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory() { |
|
|
// TODO: 27/01/2023 |
|
|
|
|
|
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); |
|
|
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); |
|
|
em.setDataSource(userDatasource()); |
|
|
em.setDataSource(userDatasource()); |
|
|
em.setPackagesToScan("es.fp.edu.conecta2.modelo.user"); |
|
|
em.setPackagesToScan("es.fp.edu.conecta2.modelo.user"); |
|
|
|
|
|
|
|
|
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); |
|
|
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); |
|
|
em.setJpaVendorAdapter(vendorAdapter); |
|
|
em.setJpaVendorAdapter(vendorAdapter); |
|
|
|
|
|
|
|
|
Map<String,Object> properties = new HashMap<>(); |
|
|
Map<String,Object> properties = new HashMap<>(); |
|
|
properties.put("hibernate.hbm2ddl.auto", env.getProperty("persistente.jpa.hibernate.ddl-auto")); |
|
|
properties.put("hibernate.hbm2ddl.auto", env.getProperty("persistente.jpa.hibernate.ddl-auto")); |
|
|
properties.put("hibernate.show-sql", env.getProperty("persistente.jpa.show-sql")); |
|
|
properties.put("hibernate.show-sql", env.getProperty("persistente.jpa.show-sql")); |
|
|
properties.put("hibernate.dialect", env.getProperty("persistente.jpa.properties.hibernate.dialect")); |
|
|
properties.put("hibernate.dialect", env.getProperty("persistente.jpa.properties.hibernate.dialect")); |
|
|
|
|
|
|
|
|
em.setJpaPropertyMap(properties); |
|
|
em.setJpaPropertyMap(properties); |
|
|
return em; |
|
|
return em; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Bean(name = "userTransactionManager") |
|
|
|
|
|
|
|
|
@Bean(name = "userTransactionManger") |
|
|
public PlatformTransactionManager transactionManager() { |
|
|
public PlatformTransactionManager transactionManager() { |
|
|
JpaTransactionManager transactionManager = new JpaTransactionManager(); |
|
|
JpaTransactionManager transactionManager = new JpaTransactionManager(); |
|
|
transactionManager.setEntityManagerFactory(entityManagerFactory().getObject()); |
|
|
transactionManager.setEntityManagerFactory(entityManagerFactory().getObject()); |
|
|
return transactionManager; |
|
|
return transactionManager; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |