commit 1bc7e121d46eb18e2ce96100ebbd46e6e4e7c7af Author: rocio.montero1 Date: Fri Oct 30 19:12:21 2026 +0100 Actividad 2.3 - Manipulación de datos Continente DAO diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cbaae6f --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +# Eclipse +.classpath +.project +.settings/ + +# Compilación Java +bin/ +target/ +*.class + +# Logs +*.log + +# Sistema operativo +.DS_Store +Thumbs.db \ No newline at end of file diff --git a/config/application.properties b/config/application.properties new file mode 100644 index 0000000..984196f --- /dev/null +++ b/config/application.properties @@ -0,0 +1,5 @@ +# info de mi bbdd +sgdb.conexion.url=jdbc:mysql://10.100.11.134:3307/ +bbdd.nombre=Mapa_Mundi +bbdd.usuario=root +bbdd.pass=rootpass \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2a51d75 --- /dev/null +++ b/pom.xml @@ -0,0 +1,30 @@ + + 4.0.0 + Conectores_02 + Conectores_02 + 0.0.1-SNAPSHOT + + + + com.mysql + mysql-connector-j + 26.10.0 + compile + + + + src + + + maven-compiler-plugin + 3.13.0 + + 25 + + + + + \ No newline at end of file diff --git a/src/org/palomafp/aadd/rmr/AppPrincipal.java b/src/org/palomafp/aadd/rmr/AppPrincipal.java new file mode 100644 index 0000000..e7cfd4b --- /dev/null +++ b/src/org/palomafp/aadd/rmr/AppPrincipal.java @@ -0,0 +1,56 @@ +package org.palomafp.aadd.rmr; + +import java.util.List; + +import org.palomafp.aadd.rmr.excepciones.MapaMundiException; +import org.palomafp.aadd.rmr.model.Continente; +import org.palomafp.aadd.rmr.service.ContinenteService; + +public class AppPrincipal { + + public static void main(String[] args) { + + ContinenteService continenteService = new ContinenteService (); + + try { + + System.out.println("PARTE 1"); + System.out.println("CONTINENTES - Lista: "); + List listaDeContinentes = continenteService.obtenerContoinentes(); + + for (Continente continente : listaDeContinentes) { + System.out.println(continente); + } + + System.out.println("\nPARTE 2"); + System.out.println("CONTINENTE 4 - COnsulta: "); + Continente continenteAConsultar = continenteService.obtenerContinentePorCodigo("04"); + System.out.println(continenteAConsultar); + + if (continenteAConsultar != null) { + + System.out.println("\nPARTE 3"); + System.out.println("CONTINENTE 04 - Borrado: "); + continenteService.borrarContinente("04"); + System.out.println(continenteService.obtenerContinentePorCodigo("04")); + + System.out.println("\nPARTE 4"); + System.out.println("CONTINENTE 04 - Insertado: "); + continenteService.insertarContinente(continenteAConsultar); + System.out.println(continenteService.obtenerContinentePorCodigo("04")); + + System.out.println("\nPARTE 5"); + System.out.println("CONTINENTE 04 - Nombre actualizado: "); + continenteAConsultar.setNombre("Paneuropa"); + continenteService.actualizarContinente(continenteAConsultar); + System.out.println(continenteService.obtenerContinentePorCodigo("04")); + } + + } catch (MapaMundiException e) { + + System.out.println("Error: " + e.getMessage()); + + } + + } +} diff --git a/src/org/palomafp/aadd/rmr/config/ConexionBD.java b/src/org/palomafp/aadd/rmr/config/ConexionBD.java new file mode 100644 index 0000000..d184d1d --- /dev/null +++ b/src/org/palomafp/aadd/rmr/config/ConexionBD.java @@ -0,0 +1,40 @@ +package org.palomafp.aadd.rmr.config; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Properties; + +public class ConexionBD { + + private static final String FICHERO = "application.properties"; + + private static Properties cargarPropiedades() throws IOException { + Properties propiedades = new Properties(); + InputStream entrada = null; + try { + entrada = ConexionBD.class.getClassLoader().getResourceAsStream("application.properties"); + propiedades.load(entrada); + } catch (IOException e) { + e.getMessage(); + } finally { + if (entrada != null) { + entrada.close(); + } + } + return propiedades; + } + + public static Connection obtenerConexion() throws IOException, SQLException { + Properties propiedades = cargarPropiedades(); + + // estos nombres tienen que coincidir con el de application.properties + String url = propiedades.getProperty("sgdb.conexion.url") + propiedades.getProperty("bbdd.nombre"); + String usuario = propiedades.getProperty("bbdd.usuario"); + String pass = propiedades.getProperty("bbdd.pass"); + + return DriverManager.getConnection(url, usuario, pass); + } +} \ No newline at end of file diff --git a/src/org/palomafp/aadd/rmr/dao/IContinenteDAO.java b/src/org/palomafp/aadd/rmr/dao/IContinenteDAO.java new file mode 100644 index 0000000..00ac4d0 --- /dev/null +++ b/src/org/palomafp/aadd/rmr/dao/IContinenteDAO.java @@ -0,0 +1,16 @@ +package org.palomafp.aadd.rmr.dao; + +import java.util.List; + +import org.palomafp.aadd.rmr.excepciones.MapaMundiException; +import org.palomafp.aadd.rmr.model.Continente; + +public interface IContinenteDAO { + + List obtenerContinentes() throws MapaMundiException; + Continente obtenerContinentePorCodigo(String codigo) throws MapaMundiException; + void borrarContinente(String codigo) throws MapaMundiException; + void insertarContinente(Continente continente) throws MapaMundiException; + void actualizarContinente(Continente continente) throws MapaMundiException; + +} diff --git a/src/org/palomafp/aadd/rmr/dao/IPaisDAO.java b/src/org/palomafp/aadd/rmr/dao/IPaisDAO.java new file mode 100644 index 0000000..72e894f --- /dev/null +++ b/src/org/palomafp/aadd/rmr/dao/IPaisDAO.java @@ -0,0 +1,17 @@ +package org.palomafp.aadd.rmr.dao; + +import java.util.List; + +import org.palomafp.aadd.rmr.excepciones.MapaMundiException; +import org.palomafp.aadd.rmr.model.Pais; + +public interface IPaisDAO { + + List obtenerPaises() throws MapaMundiException; + Pais obtenerPaisPorId(int identificador) throws MapaMundiException; + void borrarPais(int identificador) throws MapaMundiException; + void insertarPais(Pais pais) throws MapaMundiException; + void actualizarPais(Pais pais) throws MapaMundiException; + void borrarPaisesDeUnContinente (String codigoContinente) throws MapaMundiException; + +} \ No newline at end of file diff --git a/src/org/palomafp/aadd/rmr/dao/impl/ContinenteJDBC.java b/src/org/palomafp/aadd/rmr/dao/impl/ContinenteJDBC.java new file mode 100644 index 0000000..e9c875a --- /dev/null +++ b/src/org/palomafp/aadd/rmr/dao/impl/ContinenteJDBC.java @@ -0,0 +1,136 @@ +package org.palomafp.aadd.rmr.dao.impl; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import org.palomafp.aadd.rmr.dao.IContinenteDAO; +import org.palomafp.aadd.rmr.excepciones.MapaMundiException; +import org.palomafp.aadd.rmr.model.Continente; + +public class ContinenteJDBC implements IContinenteDAO { + + private Connection conexion; + + public ContinenteJDBC(Connection conexion) { + this.conexion = conexion; + } + + @Override + public List obtenerContinentes() throws MapaMundiException { + + List listaDeContinentes = new ArrayList<>(); + try { + PreparedStatement sentencia = conexion + .prepareStatement("SELECT codigo, nombre_continente FROM T_CONTINENTE"); + ResultSet resultado = sentencia.executeQuery(); + + while (resultado.next()) { + String codigo = resultado.getString("codigo"); + String nombre = resultado.getString("nombre_continente"); + + Continente continente = new Continente(codigo, nombre); + listaDeContinentes.add(continente); + } + + resultado.close(); + sentencia.close(); + + } catch (SQLException e) { + throw new MapaMundiException("Error al consultar lso continentes: " + e); + } + return listaDeContinentes; + } + + @Override + public Continente obtenerContinentePorCodigo(String codigo) throws MapaMundiException { + Continente continente = null; + PreparedStatement sentencia = null; + ResultSet resultado = null; + + try { + + sentencia = conexion + .prepareStatement("SELECT codigo, nombre_continente FROM T_CONTINENTE WHERE codigo = ?"); + sentencia.setString(1, codigo); + resultado = sentencia.executeQuery(); + + if (resultado.next()) { + String nombre = resultado.getString("nombre_continente"); + continente = new Continente(codigo, nombre); + } + + } catch (SQLException e) { + throw new MapaMundiException("Error al consultar el continente: " + codigo + "por: " + e); + } finally { + try { + if (resultado != null) { + resultado.close(); + } + + if (sentencia != null) { + sentencia.close(); + } + } catch (SQLException e) { + System.out.println("Error al cerrar por: " + e.getMessage()); + } + } + return continente; + } + + @Override + public void borrarContinente(String codigo) throws MapaMundiException { + + try { + + PreparedStatement sentencia = conexion.prepareStatement("DELETE FROM T_CONTINENTE WHERE codigo = ?"); + sentencia.setString(1, codigo); + sentencia.executeUpdate(); + sentencia.close(); + } catch (SQLException e) { + throw new MapaMundiException("Error al borrar el continente: " + codigo + " por: " + e); + } + + } + + @Override + public void insertarContinente(Continente continente) throws MapaMundiException { + + try { + + PreparedStatement sentencia = conexion + .prepareStatement("INSERT INTO T_CONTINENTE (codigo, nombre_continente) VALUES (?, ?)"); + sentencia.setString(1, continente.getCodigo()); + sentencia.setString(2, continente.getNombre()); + sentencia.executeUpdate(); + sentencia.close(); + + } catch (SQLException e) { + throw new MapaMundiException("Error al insertar el continente: " + continente.getCodigo() + " por: " + e); + } + + } + + @Override + public void actualizarContinente(Continente continente) throws MapaMundiException { + + try { + + PreparedStatement sentencia = conexion.prepareStatement("UPDATE T_CONTINENTE SET nombre_continente = ? WHERE codigo = ?"); + sentencia.setString(1, continente.getNombre()); + sentencia.setString(2, continente.getCodigo()); + sentencia.executeUpdate(); + sentencia.close(); + + } catch (SQLException e) { + + throw new MapaMundiException("Error al actualizar el continente: " + continente.getCodigo()); + + } + + } + +} \ No newline at end of file diff --git a/src/org/palomafp/aadd/rmr/dao/impl/PaisJDBC.java b/src/org/palomafp/aadd/rmr/dao/impl/PaisJDBC.java new file mode 100644 index 0000000..48a1c3b --- /dev/null +++ b/src/org/palomafp/aadd/rmr/dao/impl/PaisJDBC.java @@ -0,0 +1,159 @@ +package org.palomafp.aadd.rmr.dao.impl; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import org.palomafp.aadd.rmr.dao.IPaisDAO; +import org.palomafp.aadd.rmr.excepciones.MapaMundiException; +import org.palomafp.aadd.rmr.model.Continente; +import org.palomafp.aadd.rmr.model.Pais; + +public class PaisJDBC implements IPaisDAO { + + private Connection conexion; + + public PaisJDBC(Connection conexion) { + this.conexion = conexion; + } + + public List obtenerPaises() throws MapaMundiException { + List listaDePaises = new ArrayList<>(); + try { + PreparedStatement sentencia = conexion.prepareStatement("SELECT p.identificador, p.nombre_pais, p.capital, c.codigo, c.nombre_continente FROM T_PAIS p JOIN T_CONTINENTE c ON p.cod_continente = c.codigo"); + ResultSet resultadoConsulta = sentencia.executeQuery(); + + while (resultadoConsulta.next()) { + int identificador = resultadoConsulta.getInt("identificador"); + String nombre = resultadoConsulta.getString("nombre_pais"); + String capital = resultadoConsulta.getString("capital"); + String codigoContinente = resultadoConsulta.getString("codigo"); + String nombreContinente = resultadoConsulta.getString("nombre_continente"); + + Continente continente = new Continente(codigoContinente, nombreContinente); + Pais pais = new Pais(identificador, nombre, capital, continente); + listaDePaises.add(pais); + + } + resultadoConsulta.close(); + sentencia.close(); + + } catch (SQLException e) { + throw new MapaMundiException("Error al consultar los países", e); + } + return listaDePaises; + } + + @Override + public Pais obtenerPaisPorId(int identificador) throws MapaMundiException{ // no puedo poner que lanza una excepción si no lo he declarado en la interfaz + Pais pais = null; + PreparedStatement sentencia = null; + ResultSet resultado = null; + + try { + + sentencia = conexion.prepareStatement("SELECT p.identificador, p.nombre_pais, p.capital, c.codigo, c.nombre_continente FROM T_PAIS p JOIN T_CONTINENTE c ON p.cod_continente = c.codigo WHERE p.identificador = ?"); + sentencia.setInt(1, identificador); + resultado = sentencia.executeQuery(); + + if (resultado.next()) { + String nombre = resultado.getString("nombre_pais"); + String capital = resultado.getString("capital"); + String codigoContinente = resultado.getString("codigo"); + String nombreContinente = resultado.getString("nombre_continente"); + + // mi clase pais guarda también un objeto continente. antes de crear el país + // hay que crear su continente con los dos datos que la consulta trae de t_continente (code + nombre) + Continente continente = new Continente (codigoContinente, nombreContinente); + pais = new Pais (identificador, nombre, capital, continente); // este id es el que le paso por parámetro + } + + } catch (SQLException e) { + throw new MapaMundiException("Error al consultar el país " + identificador, e); + } finally { + try { + if (resultado != null) { + resultado.close(); + } + if (sentencia != null) { + sentencia.close(); + } + } catch (SQLException e) { + System.out.println("Error al cerrar: " + e.getMessage()); + } + + } + + return pais; + } + + @Override + public void borrarPais(int identificador) throws MapaMundiException { + + try { + + PreparedStatement sentencia = conexion.prepareStatement("DELETE FROM T_PAIS WHERE identificador = ?"); + sentencia.setInt(1, identificador); + sentencia.executeUpdate(); + sentencia.close(); + + } catch (SQLException e) { + throw new MapaMundiException("Error al borrar el país " + identificador, e); + } + + } + + @Override + public void insertarPais(Pais pais) throws MapaMundiException { + + try { + PreparedStatement sentencia = conexion.prepareStatement("INSERT INTO T_PAIS (identificador, nombre_pais, capital, cod_continente) VALUES (?, ?, ?, ?)"); + + sentencia.setInt(1, pais.getIdentificador()); + sentencia.setString(2, pais.getNombre()); + sentencia.setString(3, pais.getCapital()); + sentencia.setString(4, pais.getContinente().getCodigo()); + sentencia.executeUpdate(); + + sentencia.close(); + + } catch (SQLException e) { + throw new MapaMundiException("Error al insertar el país " + pais.getIdentificador(), e); + } + + } + + public void actualizarPais (Pais pais) throws MapaMundiException { + + try { + + PreparedStatement sentencia = conexion.prepareStatement("UPDATE T_PAIS SET capital = ? WHERE identificador = ?"); + sentencia.setString(1, pais.getCapital()); + sentencia.setInt(2, pais.getIdentificador()); + sentencia.executeUpdate(); + sentencia.close(); + + } catch (SQLException e) { + throw new MapaMundiException("Error al actualizar el país " + pais.getIdentificador(), e); + } + } + + public void borrarPaisesDeUnContinente (String codigoContinente) throws MapaMundiException { + + try { + + PreparedStatement sentencia = conexion.prepareStatement("DELETE FROM T_PAIS WHERE cod_continente = ?"); + sentencia.setString(1, codigoContinente); + sentencia.executeUpdate(); + sentencia.close(); + + } catch (SQLException e) { + throw new MapaMundiException ("Error al borrar los países del contiennte. " + codigoContinente + " por: " + e); + } + } + +} \ No newline at end of file diff --git a/src/org/palomafp/aadd/rmr/excepciones/MapaMundiException.java b/src/org/palomafp/aadd/rmr/excepciones/MapaMundiException.java new file mode 100644 index 0000000..119c1cb --- /dev/null +++ b/src/org/palomafp/aadd/rmr/excepciones/MapaMundiException.java @@ -0,0 +1,13 @@ +package org.palomafp.aadd.rmr.excepciones; + +public class MapaMundiException extends Exception { // hereda de Exception y es checked (obliga a quien llame a un método que la lance a tratarla con try catch) + + public MapaMundiException (String mensaje) { + super(mensaje); + } + + public MapaMundiException (String mensaje, Throwable causa) { + super (mensaje, causa); + } + +} diff --git a/src/org/palomafp/aadd/rmr/model/Continente.java b/src/org/palomafp/aadd/rmr/model/Continente.java new file mode 100644 index 0000000..2ce2e77 --- /dev/null +++ b/src/org/palomafp/aadd/rmr/model/Continente.java @@ -0,0 +1,37 @@ +package org.palomafp.aadd.rmr.model; + +public class Continente { + + private String codigo; + private String nombre; + + public Continente(String codigo, String nombre) { + this.codigo = codigo; + this.nombre = nombre; + } + + + public String getCodigo() { + return codigo; + } + public void setCodigo(String codigo) { + this.codigo = codigo; + } + + + public String getNombre() { + return nombre; + } + public void setNombre(String nombre) { + this.nombre = nombre; + } + + + @Override + public String toString() { + return "Continente - Código: " + codigo + ", Nombre: " + nombre; + } + + + +} diff --git a/src/org/palomafp/aadd/rmr/model/Pais.java b/src/org/palomafp/aadd/rmr/model/Pais.java new file mode 100644 index 0000000..bfaf86a --- /dev/null +++ b/src/org/palomafp/aadd/rmr/model/Pais.java @@ -0,0 +1,59 @@ +package org.palomafp.aadd.rmr.model; + +public class Pais { + + private int identificador; + private String nombre; + private String capital; + private Continente continente; + + public Pais (int identificador, String nombre, String capital, Continente continente) { + this.identificador = identificador; + this.nombre = nombre; + this.capital = capital; + this.continente = continente; + } + + + public int getIdentificador() { + return identificador; + } + + public void setIdentificador(int identificador) { + this.identificador = identificador; + } + + + public String getNombre() { + return nombre; + } + + public void setNombre(String nombre) { + this.nombre = nombre; + } + + + public String getCapital() { + return capital; + } + + public void setCapital(String capital) { + this.capital = capital; + } + + + public Continente getContinente() { + return continente; + } + + public void setContinente(Continente continente) { + this.continente = continente; + } + + + @Override + public String toString() { + return "Pais - Identificador: " + identificador + ", Nombre: " + nombre + ", Capital: " + capital + ", Continente: " + + continente; + } +} \ No newline at end of file diff --git a/src/org/palomafp/aadd/rmr/service/ContinenteService.java b/src/org/palomafp/aadd/rmr/service/ContinenteService.java new file mode 100644 index 0000000..e4a7a35 --- /dev/null +++ b/src/org/palomafp/aadd/rmr/service/ContinenteService.java @@ -0,0 +1,114 @@ +package org.palomafp.aadd.rmr.service; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.List; + +import org.palomafp.aadd.rmr.config.ConexionBD; +import org.palomafp.aadd.rmr.dao.IContinenteDAO; +import org.palomafp.aadd.rmr.dao.IPaisDAO; +import org.palomafp.aadd.rmr.dao.impl.ContinenteJDBC; +import org.palomafp.aadd.rmr.dao.impl.PaisJDBC; +import org.palomafp.aadd.rmr.excepciones.MapaMundiException; +import org.palomafp.aadd.rmr.model.Continente; + +public class ContinenteService { + + public List obtenerContoinentes() throws MapaMundiException { + List listaDeContinentes = null; + + try (Connection conexion = ConexionBD.obtenerConexion()) { + IContinenteDAO continenteDAO = new ContinenteJDBC(conexion); + listaDeContinentes = continenteDAO.obtenerContinentes(); + } catch (IOException | SQLException e) { + throw new MapaMundiException ("Error al obtener lso continentes: " + e); + } + + return listaDeContinentes; + } + + public Continente obtenerContinentePorCodigo (String codigo) throws MapaMundiException { + Continente continente = null; + + try (Connection conexion = ConexionBD.obtenerConexion()) { + IContinenteDAO continenteDAO = new ContinenteJDBC(conexion); + continente = continenteDAO.obtenerContinentePorCodigo(codigo); + + } catch (IOException | SQLException e) { + throw new MapaMundiException ("Error al obtener el continente: " + codigo + " por: " + e); + } + + return continente; + } + + public void insertarContinente (Continente continente) throws MapaMundiException { + + try (Connection conexion = ConexionBD.obtenerConexion()) { + + IContinenteDAO continenteDAO = new ContinenteJDBC(conexion); + continenteDAO.insertarContinente(continente); + + } catch (IOException | SQLException e) { + System.out.println("Error al insertar el contintente: " + continente.getCodigo() + " por: " + e); + + } + + } + + public void actualizarContinente(Continente continente) throws MapaMundiException { + try (Connection conexion = ConexionBD.obtenerConexion()) { + + IContinenteDAO continenteDAO = new ContinenteJDBC(conexion); + continenteDAO.actualizarContinente(continente); + + } catch (IOException | SQLException e) { + throw new MapaMundiException ("Error al actualizar el continente: " + continente.getCodigo() + " por: " + e); + } + } + + public void borrarContinente (String codigo) throws MapaMundiException { + + Connection conexion = null; + + try { + + conexion = ConexionBD.obtenerConexion(); + conexion.setAutoCommit(false); + + IPaisDAO paisDAO = new PaisJDBC(conexion); + IContinenteDAO continenteDAO = new ContinenteJDBC (conexion); + + paisDAO.borrarPaisesDeUnContinente(codigo); + continenteDAO.borrarContinente(codigo); + + conexion.commit(); + + } catch (IOException | SQLException | MapaMundiException e) { + try { + if (conexion != null) { + conexion.rollback(); + } + } catch (SQLException s) { + System.out.println("Error al deshacer la transacción: " + s.getMessage()); + } + + throw new MapaMundiException ("Error al borrar el continente: " + codigo + " por: " + e); + + } finally { + try { + if (conexion != null) { + conexion.close(); + } + } catch (SQLException e) { + System.out.println("Error al cerrar la conexión: " + e.getMessage()); + } + } + + } + +} + + + + diff --git a/src/org/palomafp/aadd/rmr/service/PaisService.java b/src/org/palomafp/aadd/rmr/service/PaisService.java new file mode 100644 index 0000000..17aa9ce --- /dev/null +++ b/src/org/palomafp/aadd/rmr/service/PaisService.java @@ -0,0 +1,69 @@ +package org.palomafp.aadd.rmr.service; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.List; + +import org.palomafp.aadd.rmr.config.ConexionBD; +import org.palomafp.aadd.rmr.dao.IPaisDAO; +import org.palomafp.aadd.rmr.dao.impl.PaisJDBC; +import org.palomafp.aadd.rmr.excepciones.MapaMundiException; +import org.palomafp.aadd.rmr.model.Pais; + +public class PaisService { + + public List obtenerPaises() throws MapaMundiException { + List listaPaises = null; + + try (Connection conexion = ConexionBD.obtenerConexion()) { + IPaisDAO paisDAO = new PaisJDBC(conexion); + listaPaises = paisDAO.obtenerPaises(); + } catch (IOException | SQLException e) { + throw new MapaMundiException("Error al obtener los países por: " + e); + } + + return listaPaises; + } + + public Pais obtenerPaisPorId(int identificador) throws MapaMundiException { + Pais pais = null; + + try (Connection conexion = ConexionBD.obtenerConexion()) { + IPaisDAO paisDAO = new PaisJDBC(conexion); + pais = paisDAO.obtenerPaisPorId(identificador); + } catch (IOException | SQLException e) { + throw new MapaMundiException("Error al obtener el país " + identificador + " por: " + e); + } + + return pais; + } + + public void insertarPais(Pais pais) throws MapaMundiException { + try (Connection conexion = ConexionBD.obtenerConexion()) { + IPaisDAO paisDAO = new PaisJDBC(conexion); + paisDAO.insertarPais(pais); + } catch (IOException | SQLException e) { + throw new MapaMundiException("Error al insertar el país " + pais.getIdentificador() + " por: " + e); + } + } + + public void actualizarPais(Pais pais) throws MapaMundiException { + try (Connection conexion = ConexionBD.obtenerConexion()) { + IPaisDAO paisDAO = new PaisJDBC(conexion); + paisDAO.actualizarPais(pais); + } catch (IOException | SQLException e) { + throw new MapaMundiException("Error al actualizar el país " + pais.getIdentificador() + " por: " + e); + } + } + + public void borrarPais(int identificador) throws MapaMundiException { + try (Connection conexion = ConexionBD.obtenerConexion()) { + IPaisDAO paisDAO = new PaisJDBC(conexion); + paisDAO.borrarPais(identificador); + } catch (IOException | SQLException e) { + throw new MapaMundiException("Error al borrar el país " + identificador + " por: " + e); + } + } + +}