cambios en properties
This commit is contained in:
parent
d81bc6dc9d
commit
d91e2446d5
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,7 @@
|
||||
/bin/
|
||||
*.class
|
||||
/target/
|
||||
# Eclipse
|
||||
.classpath
|
||||
.project
|
||||
.settings/
|
||||
@ -1,6 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=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/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
|
||||
4
pom.xml
4
pom.xml
@ -10,11 +10,11 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>4.0.1</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
<version>4.0.1</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>23</java.version>
|
||||
<junit.version>6.0.3</junit.version>
|
||||
</properties>
|
||||
|
||||
@ -5,10 +5,15 @@ import java.util.List;
|
||||
import org.lapaloma.mapamundi.vo.Continente;
|
||||
|
||||
public interface IContinenteDAO {
|
||||
public Continente obtenerContinentePorClave(String codigo) ;
|
||||
public void actualizarContinente(Continente continente) ;
|
||||
public void crearContinente(Continente continente);
|
||||
public void borrarContinente(Continente continente);
|
||||
public List<Continente> obtenerListaContinentes();
|
||||
public List<Continente> obtenerContinentePorNombre(String nombre);
|
||||
public Continente obtenerContinentePorClave(String codigo);
|
||||
|
||||
public void actualizarContinente(Continente continente);
|
||||
|
||||
public void crearContinente(Continente continente);
|
||||
|
||||
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
|
||||
public class ContinenteDaoJDBC implements IContinenteDAO {
|
||||
private final DataSource dataSource;
|
||||
private final DataSource dataSource;
|
||||
|
||||
// Spring inyecta el DataSource configurado automáticamente
|
||||
public ContinenteDaoJDBC(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
// Spring inyecta el DataSource configurado automáticamente
|
||||
public ContinenteDaoJDBC(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Continente obtenerContinentePorClave(String codigo) {
|
||||
Continente continente = null;
|
||||
@Override
|
||||
public Continente obtenerContinentePorClave(String codigo) {
|
||||
Continente continente = null;
|
||||
|
||||
String sentenciaSQL = """
|
||||
SELECT * FROM T_CONTINENTE
|
||||
WHERE codigo=?
|
||||
""";
|
||||
String sentenciaSQL = """
|
||||
SELECT * FROM T_CONTINENTE
|
||||
WHERE codigo=?
|
||||
""";
|
||||
|
||||
try (Connection conexion = dataSource.getConnection();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
try (Connection conexion = dataSource.getConnection();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
sentenciaJDBCPreparada.setString(1, codigo);
|
||||
System.out.println(sentenciaJDBCPreparada);
|
||||
sentenciaJDBCPreparada.setString(1, codigo);
|
||||
System.out.println(sentenciaJDBCPreparada);
|
||||
|
||||
ResultSet resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
||||
ResultSet resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
||||
|
||||
if (resultadoSentencia.next()) {
|
||||
continente = getLineaFromResultSet(resultadoSentencia);
|
||||
}
|
||||
if (resultadoSentencia.next()) {
|
||||
continente = getLineaFromResultSet(resultadoSentencia);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return continente;
|
||||
}
|
||||
return continente;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actualizarContinente(Continente continente) {
|
||||
@Override
|
||||
public void actualizarContinente(Continente continente) {
|
||||
|
||||
String sentenciaSQL = """
|
||||
UPDATE T_CONTINENTE
|
||||
SET nombre_continente=?
|
||||
WHERE codigo=?
|
||||
""";
|
||||
String sentenciaSQL = """
|
||||
UPDATE T_CONTINENTE
|
||||
SET nombre_continente=?
|
||||
WHERE codigo=?
|
||||
""";
|
||||
|
||||
try (Connection conexion = dataSource.getConnection();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
try (Connection conexion = dataSource.getConnection();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
sentenciaJDBCPreparada.setString(1, continente.getNombre());
|
||||
sentenciaJDBCPreparada.setString(2, continente.getCodigo());
|
||||
sentenciaJDBCPreparada.setString(1, continente.getNombre());
|
||||
sentenciaJDBCPreparada.setString(2, continente.getCodigo());
|
||||
|
||||
System.out.println(sentenciaJDBCPreparada);
|
||||
System.out.println(sentenciaJDBCPreparada);
|
||||
|
||||
sentenciaJDBCPreparada.executeUpdate();
|
||||
sentenciaJDBCPreparada.executeUpdate();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void crearContinente(Continente continente) {
|
||||
@Override
|
||||
public void crearContinente(Continente continente) {
|
||||
|
||||
String sentenciaSQL = """
|
||||
INSERT INTO T_CONTINENTE (codigo, nombre_continente)
|
||||
VALUES (?, ?)
|
||||
""";
|
||||
String sentenciaSQL = """
|
||||
INSERT INTO T_CONTINENTE (codigo, nombre_continente)
|
||||
VALUES (?, ?)
|
||||
""";
|
||||
|
||||
try (Connection conexion = dataSource.getConnection();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
try (Connection conexion = dataSource.getConnection();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
sentenciaJDBCPreparada.setString(1, continente.getCodigo());
|
||||
sentenciaJDBCPreparada.setString(2, continente.getNombre());
|
||||
sentenciaJDBCPreparada.setString(1, continente.getCodigo());
|
||||
sentenciaJDBCPreparada.setString(2, continente.getNombre());
|
||||
|
||||
System.out.println(sentenciaJDBCPreparada);
|
||||
System.out.println(sentenciaJDBCPreparada);
|
||||
|
||||
sentenciaJDBCPreparada.executeUpdate();
|
||||
sentenciaJDBCPreparada.executeUpdate();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void borrarContinente(Continente continente) {
|
||||
@Override
|
||||
public void borrarContinente(Continente continente) {
|
||||
|
||||
String sentenciaSQL = """
|
||||
DELETE FROM T_CONTINENTE
|
||||
WHERE codigo=?
|
||||
""";
|
||||
String sentenciaSQL = """
|
||||
DELETE FROM T_CONTINENTE
|
||||
WHERE codigo=?
|
||||
""";
|
||||
|
||||
try (Connection conexion = dataSource.getConnection();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
try (Connection conexion = dataSource.getConnection();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
sentenciaJDBCPreparada.setString(1, continente.getCodigo());
|
||||
sentenciaJDBCPreparada.setString(1, continente.getCodigo());
|
||||
|
||||
sentenciaJDBCPreparada.executeUpdate();
|
||||
sentenciaJDBCPreparada.executeUpdate();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Continente> obtenerListaContinentes() {
|
||||
@Override
|
||||
public List<Continente> obtenerListaContinentes() {
|
||||
|
||||
List<Continente> lista = new ArrayList<>();
|
||||
List<Continente> lista = new ArrayList<>();
|
||||
|
||||
String sentenciaSQL = """
|
||||
SELECT * FROM T_CONTINENTE
|
||||
""";
|
||||
String sentenciaSQL = """
|
||||
SELECT * FROM T_CONTINENTE
|
||||
""";
|
||||
|
||||
try (Connection conexion = dataSource.getConnection();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
try (Connection conexion = dataSource.getConnection();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
System.out.println(sentenciaJDBCPreparada);
|
||||
System.out.println(sentenciaJDBCPreparada);
|
||||
|
||||
ResultSet resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
||||
ResultSet resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
||||
|
||||
while (resultadoSentencia.next()) {
|
||||
lista.add(getLineaFromResultSet(resultadoSentencia));
|
||||
}
|
||||
while (resultadoSentencia.next()) {
|
||||
lista.add(getLineaFromResultSet(resultadoSentencia));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return lista;
|
||||
}
|
||||
return lista;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Continente> obtenerContinentePorNombre(String nombre) {
|
||||
@Override
|
||||
public List<Continente> obtenerContinentePorNombre(String nombre) {
|
||||
|
||||
List<Continente> lista = new ArrayList<>();
|
||||
List<Continente> lista = new ArrayList<>();
|
||||
|
||||
String sentenciaSQL = """
|
||||
SELECT * FROM T_CONTINENTE
|
||||
WHERE nombre_continente LIKE ?
|
||||
""";
|
||||
String sentenciaSQL = """
|
||||
SELECT * FROM T_CONTINENTE
|
||||
WHERE nombre_continente LIKE ?
|
||||
""";
|
||||
|
||||
try (Connection conexion = dataSource.getConnection();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
try (Connection conexion = dataSource.getConnection();
|
||||
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()) {
|
||||
lista.add(getLineaFromResultSet(resultadoSentencia));
|
||||
}
|
||||
while (resultadoSentencia.next()) {
|
||||
lista.add(getLineaFromResultSet(resultadoSentencia));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
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.setNombre(resultadoSentencia.getString("nombre_continente"));
|
||||
continente.setCodigo(resultadoSentencia.getString("codigo"));
|
||||
continente.setNombre(resultadoSentencia.getString("nombre_continente"));
|
||||
|
||||
return continente;
|
||||
}
|
||||
return continente;
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,12 @@
|
||||
package org.lapaloma.mapamundi.excepcion;
|
||||
|
||||
public class ContinenteNoEncontradoException extends RuntimeException {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -3344627619585104664L;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -3344627619585104664L;
|
||||
|
||||
public ContinenteNoEncontradoException(String mensaje) {
|
||||
super(mensaje);
|
||||
}
|
||||
public ContinenteNoEncontradoException(String 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
|
||||
* @date 03 marzo 2026
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
spring.datasource.url=${DB_URL}
|
||||
spring.datasource.username=${DB_USER}
|
||||
spring.datasource.password=${DB_PASSWORD}
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
# Puerto en que escucha Spring Boot
|
||||
server.port=8080
|
||||
|
||||
# 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.minimum-idle=2
|
||||
Loading…
Reference in New Issue
Block a user