Browse Source

Properties y conexiones a BBDD

master
Juanjo 1 year ago
parent
commit
520646df9b
5 changed files with 21 additions and 52 deletions
  1. +1
    -10
      src/main/java/es/fp/edu/conecta2/BDMariaDB.java
  2. +0
    -12
      src/main/java/es/fp/edu/conecta2/BDTempConfig.java
  3. +2
    -2
      src/main/java/es/fp/edu/conecta2/controladores/WebControlador.java
  4. +6
    -28
      src/main/resources/application.properties
  5. +12
    -0
      src/main/resources/templates/usuarios.html

+ 1
- 10
src/main/java/es/fp/edu/conecta2/BDMariaDB.java View File

@ -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;
} }
} }

+ 0
- 12
src/main/java/es/fp/edu/conecta2/BDTempConfig.java View File

@ -16,7 +16,6 @@ import javax.sql.DataSource;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@Configuration @Configuration
@EnableTransactionManagement @EnableTransactionManagement
@EnableJpaRepositories( @EnableJpaRepositories(
@ -34,10 +33,7 @@ public class BDTempConfig {
dataSource.setUrl(env.getProperty("temporal.datasource.url")); dataSource.setUrl(env.getProperty("temporal.datasource.url"));
dataSource.setUsername(env.getProperty("temporal.datasource.username")); dataSource.setUsername(env.getProperty("temporal.datasource.username"));
dataSource.setPassword(env.getProperty("temporal.datasource.password")); dataSource.setPassword(env.getProperty("temporal.datasource.password"));
dataSource.setDriverClassName(env.getProperty("temporal.datasource.driver-class-name"));
return dataSource; return dataSource;
} }
@Bean(name = "adminEntityManagerFactory") @Bean(name = "adminEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory() { public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
@ -45,15 +41,12 @@ public class BDTempConfig {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(userDatasource()); em.setDataSource(userDatasource());
em.setPackagesToScan("es.fp.edu.conecta2.modelo.admin"); em.setPackagesToScan("es.fp.edu.conecta2.modelo.admin");
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("temporal.jpa.hibernate.ddl-auto")); properties.put("hibernate.hbm2ddl.auto", env.getProperty("temporal.jpa.hibernate.ddl-auto"));
properties.put("hibernate.show-sql", env.getProperty("temporal.jpa.show-sql")); properties.put("hibernate.show-sql", env.getProperty("temporal.jpa.show-sql"));
properties.put("hibernate.dialect", env.getProperty("temporal.jpa.properties.hibernate.dialect")); properties.put("hibernate.dialect", env.getProperty("temporal.jpa.properties.hibernate.dialect"));
em.setJpaPropertyMap(properties); em.setJpaPropertyMap(properties);
return em; return em;
} }
@ -64,10 +57,5 @@ public class BDTempConfig {
transactionManager.setEntityManagerFactory(entityManagerFactory().getObject()); transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
return transactionManager; return transactionManager;
} }
} }

+ 2
- 2
src/main/java/es/fp/edu/conecta2/controladores/WebControlador.java View File

@ -1,6 +1,6 @@
package es.fp.edu.conecta2.controladores; package es.fp.edu.conecta2.controladores;
import es.fp.edu.conecta2.repo.user.IUserRepo;
import es.fp.edu.conecta2.servicios.UserService; import es.fp.edu.conecta2.servicios.UserService;
import io.micrometer.common.util.StringUtils; import io.micrometer.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -9,7 +9,7 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller @Controller
public class WebControlador { public class WebControlador {


+ 6
- 28
src/main/resources/application.properties View File

@ -1,5 +1,3 @@
server.port=9000 server.port=9000
spring.thymeleaf.cache=false spring.thymeleaf.cache=false
server.compression.enabled=true server.compression.enabled=true
@ -11,45 +9,25 @@ spring.data.rest.base-path=/api
persistente.datasource.url=jdbc:mariadb://localhost:3306/bolsa persistente.datasource.url=jdbc:mariadb://localhost:3306/bolsa
persistente.datasource.username=bolsa persistente.datasource.username=bolsa
persistente.datasource.password=1234 persistente.datasource.password=1234
persistente.datasource.driverClassName=org.mariadb.jdbc.Driver
persistente.jpa.show-sql=true persistente.jpa.show-sql=true
#JPA #JPA
# none, validate, update, create-drop # none, validate, update, create-drop
persistente.jpa.hibernate.ddl-auto=update persistente.jpa.hibernate.ddl-auto=update
persistente.datasource.testWhileIdle=true
persistente.datasource.validationQuery=SELECT 1
persistente.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect persistente.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect
persistente.jpa.database-platform=org.hibernate.dialect.MariaDBDialect
#persistente.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl #persistente.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl
#persistente.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy #persistente.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
persistente.sql.init.platform=mariadb
persistente.datasource.data=data.sql
persistente.jpa.defer-datasource-initialization=true
persistente.sql.init.mode=always
temporal.datasource.url=jdbc:h2:mem:test temporal.datasource.url=jdbc:h2:mem:test
temporal.h2.console.enabled=true
temporal.h2.console.settings.trace=false
temporal.h2.console.settings.web-allow-others=false
temporal.datasource.username=sa temporal.datasource.username=sa
temporal.datasource.password= temporal.datasource.password=
temporal.datasource.driver-class-name=org.h2.Driver
temporal.jpa.show-sql=true temporal.jpa.show-sql=true
temporal.jpa.hibernate.ddl-auto=update temporal.jpa.hibernate.ddl-auto=update
temporal.jpa.database-platform=org.hibernate.dialect.H2Dialect
redis.redis.port=9323
redis.redis.database=0
redis.redis.host=localhost
redis.redis.password=mypass
redis.redis.timeout=60000
mongo.data.mongodb.authentication-database=admin
mongo.data.mongodb.username=root
mongo.data.mongodb.password=root
mongo.data.mongodb.database=test_db
mongo.data.mongodb.port=27017
mongo.data.mongodb.host=localhost

+ 12
- 0
src/main/resources/templates/usuarios.html View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
Listado de usuarios.
</body>
</html>

Loading…
Cancel
Save