cambios en properties
This commit is contained in:
parent
d81bc6dc9d
commit
d91e2446d5
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,7 @@
|
|||||||
/bin/
|
/bin/
|
||||||
*.class
|
*.class
|
||||||
/target/
|
/target/
|
||||||
|
# Eclipse
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.settings/
|
||||||
@ -1,6 +1,7 @@
|
|||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
encoding//src/main/java=UTF-8
|
encoding//src/main/java=UTF-8
|
||||||
encoding//src/main/resources=UTF-8
|
encoding//src/main/resources=UTF-8
|
||||||
|
encoding//src/main/resources/application.properties=UTF-8
|
||||||
encoding//src/test/java=UTF-8
|
encoding//src/test/java=UTF-8
|
||||||
encoding//src/test/resources=UTF-8
|
encoding//src/test/resources=UTF-8
|
||||||
encoding/<project>=UTF-8
|
encoding/<project>=UTF-8
|
||||||
|
|||||||
4
pom.xml
4
pom.xml
@ -10,11 +10,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>4.0.1</version>
|
<version>4.0.1</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<java.version>23</java.version>
|
<java.version>23</java.version>
|
||||||
<junit.version>6.0.3</junit.version>
|
<junit.version>6.0.3</junit.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|||||||
@ -26,7 +26,7 @@ public class ContinenteController {
|
|||||||
public ContinenteController(ContinenteService continenteService) {
|
public ContinenteController(ContinenteService continenteService) {
|
||||||
this.continenteService = continenteService;
|
this.continenteService = continenteService;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET /api/continentes - listar todos los continentes
|
// GET /api/continentes - listar todos los continentes
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public List<Continente> getAll() {
|
public List<Continente> getAll() {
|
||||||
|
|||||||
@ -5,10 +5,15 @@ import java.util.List;
|
|||||||
import org.lapaloma.mapamundi.vo.Continente;
|
import org.lapaloma.mapamundi.vo.Continente;
|
||||||
|
|
||||||
public interface IContinenteDAO {
|
public interface IContinenteDAO {
|
||||||
public Continente obtenerContinentePorClave(String codigo) ;
|
public Continente obtenerContinentePorClave(String codigo);
|
||||||
public void actualizarContinente(Continente continente) ;
|
|
||||||
public void crearContinente(Continente continente);
|
public void actualizarContinente(Continente continente);
|
||||||
public void borrarContinente(Continente continente);
|
|
||||||
public List<Continente> obtenerListaContinentes();
|
public void crearContinente(Continente continente);
|
||||||
public List<Continente> obtenerContinentePorNombre(String nombre);
|
|
||||||
|
public void borrarContinente(Continente continente);
|
||||||
|
|
||||||
|
public List<Continente> obtenerListaContinentes();
|
||||||
|
|
||||||
|
public List<Continente> obtenerContinentePorNombre(String nombre);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,173 +15,173 @@ import org.springframework.stereotype.Repository;
|
|||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public class ContinenteDaoJDBC implements IContinenteDAO {
|
public class ContinenteDaoJDBC implements IContinenteDAO {
|
||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
|
|
||||||
// Spring inyecta el DataSource configurado automáticamente
|
// Spring inyecta el DataSource configurado automáticamente
|
||||||
public ContinenteDaoJDBC(DataSource dataSource) {
|
public ContinenteDaoJDBC(DataSource dataSource) {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Continente obtenerContinentePorClave(String codigo) {
|
public Continente obtenerContinentePorClave(String codigo) {
|
||||||
Continente continente = null;
|
Continente continente = null;
|
||||||
|
|
||||||
String sentenciaSQL = """
|
String sentenciaSQL = """
|
||||||
SELECT * FROM T_CONTINENTE
|
SELECT * FROM T_CONTINENTE
|
||||||
WHERE codigo=?
|
WHERE codigo=?
|
||||||
""";
|
""";
|
||||||
|
|
||||||
try (Connection conexion = dataSource.getConnection();
|
try (Connection conexion = dataSource.getConnection();
|
||||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||||
|
|
||||||
sentenciaJDBCPreparada.setString(1, codigo);
|
sentenciaJDBCPreparada.setString(1, codigo);
|
||||||
System.out.println(sentenciaJDBCPreparada);
|
System.out.println(sentenciaJDBCPreparada);
|
||||||
|
|
||||||
ResultSet resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
ResultSet resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
||||||
|
|
||||||
if (resultadoSentencia.next()) {
|
if (resultadoSentencia.next()) {
|
||||||
continente = getLineaFromResultSet(resultadoSentencia);
|
continente = getLineaFromResultSet(resultadoSentencia);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return continente;
|
return continente;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actualizarContinente(Continente continente) {
|
public void actualizarContinente(Continente continente) {
|
||||||
|
|
||||||
String sentenciaSQL = """
|
String sentenciaSQL = """
|
||||||
UPDATE T_CONTINENTE
|
UPDATE T_CONTINENTE
|
||||||
SET nombre_continente=?
|
SET nombre_continente=?
|
||||||
WHERE codigo=?
|
WHERE codigo=?
|
||||||
""";
|
""";
|
||||||
|
|
||||||
try (Connection conexion = dataSource.getConnection();
|
try (Connection conexion = dataSource.getConnection();
|
||||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||||
|
|
||||||
sentenciaJDBCPreparada.setString(1, continente.getNombre());
|
sentenciaJDBCPreparada.setString(1, continente.getNombre());
|
||||||
sentenciaJDBCPreparada.setString(2, continente.getCodigo());
|
sentenciaJDBCPreparada.setString(2, continente.getCodigo());
|
||||||
|
|
||||||
System.out.println(sentenciaJDBCPreparada);
|
System.out.println(sentenciaJDBCPreparada);
|
||||||
|
|
||||||
sentenciaJDBCPreparada.executeUpdate();
|
sentenciaJDBCPreparada.executeUpdate();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void crearContinente(Continente continente) {
|
public void crearContinente(Continente continente) {
|
||||||
|
|
||||||
String sentenciaSQL = """
|
String sentenciaSQL = """
|
||||||
INSERT INTO T_CONTINENTE (codigo, nombre_continente)
|
INSERT INTO T_CONTINENTE (codigo, nombre_continente)
|
||||||
VALUES (?, ?)
|
VALUES (?, ?)
|
||||||
""";
|
""";
|
||||||
|
|
||||||
try (Connection conexion = dataSource.getConnection();
|
try (Connection conexion = dataSource.getConnection();
|
||||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||||
|
|
||||||
sentenciaJDBCPreparada.setString(1, continente.getCodigo());
|
sentenciaJDBCPreparada.setString(1, continente.getCodigo());
|
||||||
sentenciaJDBCPreparada.setString(2, continente.getNombre());
|
sentenciaJDBCPreparada.setString(2, continente.getNombre());
|
||||||
|
|
||||||
System.out.println(sentenciaJDBCPreparada);
|
System.out.println(sentenciaJDBCPreparada);
|
||||||
|
|
||||||
sentenciaJDBCPreparada.executeUpdate();
|
sentenciaJDBCPreparada.executeUpdate();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void borrarContinente(Continente continente) {
|
public void borrarContinente(Continente continente) {
|
||||||
|
|
||||||
String sentenciaSQL = """
|
String sentenciaSQL = """
|
||||||
DELETE FROM T_CONTINENTE
|
DELETE FROM T_CONTINENTE
|
||||||
WHERE codigo=?
|
WHERE codigo=?
|
||||||
""";
|
""";
|
||||||
|
|
||||||
try (Connection conexion = dataSource.getConnection();
|
try (Connection conexion = dataSource.getConnection();
|
||||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||||
|
|
||||||
sentenciaJDBCPreparada.setString(1, continente.getCodigo());
|
sentenciaJDBCPreparada.setString(1, continente.getCodigo());
|
||||||
|
|
||||||
sentenciaJDBCPreparada.executeUpdate();
|
sentenciaJDBCPreparada.executeUpdate();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Continente> obtenerListaContinentes() {
|
public List<Continente> obtenerListaContinentes() {
|
||||||
|
|
||||||
List<Continente> lista = new ArrayList<>();
|
List<Continente> lista = new ArrayList<>();
|
||||||
|
|
||||||
String sentenciaSQL = """
|
String sentenciaSQL = """
|
||||||
SELECT * FROM T_CONTINENTE
|
SELECT * FROM T_CONTINENTE
|
||||||
""";
|
""";
|
||||||
|
|
||||||
try (Connection conexion = dataSource.getConnection();
|
try (Connection conexion = dataSource.getConnection();
|
||||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||||
|
|
||||||
System.out.println(sentenciaJDBCPreparada);
|
System.out.println(sentenciaJDBCPreparada);
|
||||||
|
|
||||||
ResultSet resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
ResultSet resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
||||||
|
|
||||||
while (resultadoSentencia.next()) {
|
while (resultadoSentencia.next()) {
|
||||||
lista.add(getLineaFromResultSet(resultadoSentencia));
|
lista.add(getLineaFromResultSet(resultadoSentencia));
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return lista;
|
return lista;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Continente> obtenerContinentePorNombre(String nombre) {
|
public List<Continente> obtenerContinentePorNombre(String nombre) {
|
||||||
|
|
||||||
List<Continente> lista = new ArrayList<>();
|
List<Continente> lista = new ArrayList<>();
|
||||||
|
|
||||||
String sentenciaSQL = """
|
String sentenciaSQL = """
|
||||||
SELECT * FROM T_CONTINENTE
|
SELECT * FROM T_CONTINENTE
|
||||||
WHERE nombre_continente LIKE ?
|
WHERE nombre_continente LIKE ?
|
||||||
""";
|
""";
|
||||||
|
|
||||||
try (Connection conexion = dataSource.getConnection();
|
try (Connection conexion = dataSource.getConnection();
|
||||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||||
|
|
||||||
sentenciaJDBCPreparada.setString(1, "%" + nombre + "%");
|
sentenciaJDBCPreparada.setString(1, "%" + nombre + "%");
|
||||||
|
|
||||||
System.out.println(sentenciaJDBCPreparada);
|
System.out.println(sentenciaJDBCPreparada);
|
||||||
|
|
||||||
ResultSet resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
ResultSet resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
||||||
|
|
||||||
while (resultadoSentencia.next()) {
|
while (resultadoSentencia.next()) {
|
||||||
lista.add(getLineaFromResultSet(resultadoSentencia));
|
lista.add(getLineaFromResultSet(resultadoSentencia));
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return lista;
|
return lista;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Continente getLineaFromResultSet(ResultSet resultadoSentencia) throws SQLException {
|
private Continente getLineaFromResultSet(ResultSet resultadoSentencia) throws SQLException {
|
||||||
|
|
||||||
Continente continente = new Continente();
|
Continente continente = new Continente();
|
||||||
|
|
||||||
continente.setCodigo(resultadoSentencia.getString("codigo"));
|
continente.setCodigo(resultadoSentencia.getString("codigo"));
|
||||||
continente.setNombre(resultadoSentencia.getString("nombre_continente"));
|
continente.setNombre(resultadoSentencia.getString("nombre_continente"));
|
||||||
|
|
||||||
return continente;
|
return continente;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,12 +1,12 @@
|
|||||||
package org.lapaloma.mapamundi.excepcion;
|
package org.lapaloma.mapamundi.excepcion;
|
||||||
|
|
||||||
public class ContinenteNoEncontradoException extends RuntimeException {
|
public class ContinenteNoEncontradoException extends RuntimeException {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -3344627619585104664L;
|
private static final long serialVersionUID = -3344627619585104664L;
|
||||||
|
|
||||||
public ContinenteNoEncontradoException(String mensaje) {
|
public ContinenteNoEncontradoException(String mensaje) {
|
||||||
super(mensaje);
|
super(mensaje);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,40 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.lapaloma.mapamundi.gestores;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
|
||||||
* @date 20 feb 2026
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class GestorFicheroConfiguracion {
|
|
||||||
private static final Properties PROPIEDADES = new Properties();
|
|
||||||
|
|
||||||
static {
|
|
||||||
try (InputStream is = GestorFicheroConfiguracion.class.getClassLoader()
|
|
||||||
.getResourceAsStream("config.properties")) {
|
|
||||||
if (is != null) {
|
|
||||||
PROPIEDADES.load(is);
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("No se encontró application.properties en el classpath");
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new IllegalStateException("Error al cargar application.properties", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtiene el valor asociado a la clave especificada.
|
|
||||||
*
|
|
||||||
* @param clave la clave a buscar
|
|
||||||
* @return el valor o {@code null} si no existe
|
|
||||||
*/
|
|
||||||
public static String obtenerValor(String clave) {
|
|
||||||
return PROPIEDADES.getProperty(clave);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -2,7 +2,7 @@ package org.lapaloma.mapamundi.vo;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Coche: Clase de persistencia que representa un coche de un concesionario.
|
* Continente: Clase de persistencia que representa un Continente de un Mapa Mundi.
|
||||||
*
|
*
|
||||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
* @date 03 marzo 2026
|
* @date 03 marzo 2026
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
spring.datasource.url=${DB_URL}
|
# Puerto en que escucha Spring Boot
|
||||||
spring.datasource.username=${DB_USER}
|
server.port=8080
|
||||||
spring.datasource.password=${DB_PASSWORD}
|
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
|
||||||
|
|
||||||
# Parámetros del Pool de conexiones HikariCP
|
# Servicio de la base de datos.
|
||||||
|
# Ejemplo url base dator:
|
||||||
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
|
spring.datasource.url=jdbc:mysql://${DB_HOST:192.168.1.36}:${DB_PORT:3306}/${DB_NAME:mapa_mundi}
|
||||||
|
spring.datasource.username=${DB_USER:root}
|
||||||
|
spring.datasource.password=${DB_PASSWORD:mysql_123}
|
||||||
|
|
||||||
|
# Parámetros del Pool de conexiones HikariCP
|
||||||
spring.datasource.hikari.maximum-pool-size=10
|
spring.datasource.hikari.maximum-pool-size=10
|
||||||
spring.datasource.hikari.minimum-idle=2
|
spring.datasource.hikari.minimum-idle=2
|
||||||
Loading…
Reference in New Issue
Block a user