From 9865dbd9c555ac436edb797c38c6264fdd0ad7a8 Mon Sep 17 00:00:00 2001 From: "rocio.montero1" Date: Sat, 7 Nov 2026 13:14:22 +0100 Subject: [PATCH] SIMULACRO EXAMEN - Red Metro --- .gitignore | 16 +++ config/app.properties | 11 ++ ficheros/operaciones-cocherasRM.csv | 31 +++++ ficheros/red_metro_rmr.xml | 53 +++++++++ ficheros/trenes_estaciones_accesos.xml | 107 ++++++++++++++++++ pom.xml | 30 +++++ src/es/madrid/redmetro/rmr/Main.java | 68 +++++++++++ src/es/madrid/redmetro/rmr/dao/ICochera.java | 13 +++ src/es/madrid/redmetro/rmr/dao/IColor.java | 9 ++ src/es/madrid/redmetro/rmr/dao/ILinea.java | 10 ++ src/es/madrid/redmetro/rmr/dao/ITren.java | 13 +++ .../redmetro/rmr/dao/impl/CocheraJDBC.java | 98 ++++++++++++++++ .../redmetro/rmr/dao/impl/ColorJDBC.java | 14 +++ .../redmetro/rmr/dao/impl/LineaJDBC.java | 51 +++++++++ .../redmetro/rmr/dao/impl/TrenJDBC.java | 94 +++++++++++++++ .../rmr/exception/RedMetroException.java | 21 ++++ .../rmr/fichero/EscritorTrenesXML.java | 95 ++++++++++++++++ .../rmr/fichero/LectorCocherasCSV.java | 53 +++++++++ .../redmetro/rmr/fichero/LectorTrenesXML.java | 74 ++++++++++++ .../rmr/gestores/GestorConexionBD.java | 23 ++++ .../rmr/gestores/GestorConfiguracion.java | 24 ++++ src/es/madrid/redmetro/rmr/model/Cochera.java | 48 ++++++++ src/es/madrid/redmetro/rmr/model/Color.java | 39 +++++++ src/es/madrid/redmetro/rmr/model/Linea.java | 57 ++++++++++ src/es/madrid/redmetro/rmr/model/Tren.java | 70 ++++++++++++ .../redmetro/rmr/service/CocheraService.java | 41 +++++++ .../redmetro/rmr/service/LineaService.java | 16 +++ .../redmetro/rmr/service/TrenService.java | 22 ++++ 28 files changed, 1201 insertions(+) create mode 100644 .gitignore create mode 100644 config/app.properties create mode 100644 ficheros/operaciones-cocherasRM.csv create mode 100644 ficheros/red_metro_rmr.xml create mode 100644 ficheros/trenes_estaciones_accesos.xml create mode 100644 pom.xml create mode 100644 src/es/madrid/redmetro/rmr/Main.java create mode 100644 src/es/madrid/redmetro/rmr/dao/ICochera.java create mode 100644 src/es/madrid/redmetro/rmr/dao/IColor.java create mode 100644 src/es/madrid/redmetro/rmr/dao/ILinea.java create mode 100644 src/es/madrid/redmetro/rmr/dao/ITren.java create mode 100644 src/es/madrid/redmetro/rmr/dao/impl/CocheraJDBC.java create mode 100644 src/es/madrid/redmetro/rmr/dao/impl/ColorJDBC.java create mode 100644 src/es/madrid/redmetro/rmr/dao/impl/LineaJDBC.java create mode 100644 src/es/madrid/redmetro/rmr/dao/impl/TrenJDBC.java create mode 100644 src/es/madrid/redmetro/rmr/exception/RedMetroException.java create mode 100644 src/es/madrid/redmetro/rmr/fichero/EscritorTrenesXML.java create mode 100644 src/es/madrid/redmetro/rmr/fichero/LectorCocherasCSV.java create mode 100644 src/es/madrid/redmetro/rmr/fichero/LectorTrenesXML.java create mode 100644 src/es/madrid/redmetro/rmr/gestores/GestorConexionBD.java create mode 100644 src/es/madrid/redmetro/rmr/gestores/GestorConfiguracion.java create mode 100644 src/es/madrid/redmetro/rmr/model/Cochera.java create mode 100644 src/es/madrid/redmetro/rmr/model/Color.java create mode 100644 src/es/madrid/redmetro/rmr/model/Linea.java create mode 100644 src/es/madrid/redmetro/rmr/model/Tren.java create mode 100644 src/es/madrid/redmetro/rmr/service/CocheraService.java create mode 100644 src/es/madrid/redmetro/rmr/service/LineaService.java create mode 100644 src/es/madrid/redmetro/rmr/service/TrenService.java 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/app.properties b/config/app.properties new file mode 100644 index 0000000..ca3fe1f --- /dev/null +++ b/config/app.properties @@ -0,0 +1,11 @@ +# conexión a la base de datos +url=jdbc:mysql://192.168.1.143:3307/red_metro_rmr +usuario=root +password=rootpass + +# ficheros de entrada +fichero.cocheras=ficheros/operaciones-cocherasRM.csv +fichero.trenes=ficheros/trenes_estaciones_accesos.xml + +# fichero de salida +fichero.salida=ficheros/red_metro_rmr.xml \ No newline at end of file diff --git a/ficheros/operaciones-cocherasRM.csv b/ficheros/operaciones-cocherasRM.csv new file mode 100644 index 0000000..53db8c0 --- /dev/null +++ b/ficheros/operaciones-cocherasRM.csv @@ -0,0 +1,31 @@ +OPERACION;COD_COCHERA;DEPOSITO;DENOMINACION;LOCALIZACION +1;1;1;PUEEEEEEEEEEERTA DE ARGANDA;CARRETERA M-203 KM 2,300 (CAMINO DE VALLECAS A MEJORADA) +1;2;1;UNIVERSIDAD REY JUAN CARLOS;AVENIDA ALCALDE DE MÓSTOLES Nº 35 +1;3;1;EL BERCIAL;PRÓXIMO A CARRETERA DE TURQUÍA (BARRIO DE EL BERCIAL) +1;4;1;ARGANZUELA - PLANETARIO;C/ BRONCE Nº 1 +1;5;1;CIUDAD UNIVERSITARIA;PLAZA RAMÓN Y CAJAL +1;6;1;MIGUEL HERNANDEZ;AVENIDA DE LA ALBUFERA ESQ. CALLE RAFAEL ALBERTI +0;7;1;ARGÜELLES;C/ PRINCESA Nº 56 +1;8;1;ALMENDRALES;AVENIDA DE CÓRDOBA, 21 +1;9;1;MONCLOA;C/ PRINCESA, 96 +1;10;1;NUEVOS MINISTERIOS;PASEO DE LA CASTELLANA Nº 67 +0;11;0;CUATRO CAMINOS;VIRGEN DE NIEVA S/N +1;12;0;VENTAS;ALMERÍA 6 +1;13;0;PLAZA DE CASTILLA;SAN BENITO S/N +1;14;0;CANILLEJAS;NECTAR S/N +1;15;0;ALUCHE;AVDA. DE LOS POBLADOS Nº 11 +1;16;0;FUENCARRAL;AVENIDA CAMPO DE CALATRAVA Nº 86 +0;17;0;SACEDAL;VENTISQUERO DE LA CONDESA S/N +1;18;0;LAGUNA;GOTAREDURA Nº 3 +1;19;0;HORTALEZA;C/ MANUEL AZAÑA +1;20;0;CUATRO VIENTOS CUATRO;CRTA. DE CANALEJAS y DE QUIEN LO MATO S/N +1;21;0;LORANCA;AVDA. DE LA ALEGRÍA (FUENLABRADA) +1;22;0;VALDECARROS;AVENIDA CERRO MILANO 0103 ENSANCHE DE VALLECAS, 73 +1;23;0;VILLAVERDE;AVENIDA REAL DE PINTO +2;1;1;PUERTA DE ARGANDA;CARRETERA M-203 KM 2,300 (CAMINO DE VALLECAS A MEJORADA) +0;14;0;CANILLEJAS;NECTAR S/N +0;15;0;ALUCHE;AVDA. DE LOS POBLADOS Nº 11 +0;16;0;FUENCARRAL;AVENIDA CAMPO DE CALATRAVA Nº 86 +0;17;0;SACEDAL;VENTISQUERO DE LA CONDESA S/N +0;18;0;LAGUNA;GOTAREDURA Nº 3 +3;13;0;PLAZA DE CASTILLA;SAN BENITO S/N \ No newline at end of file diff --git a/ficheros/red_metro_rmr.xml b/ficheros/red_metro_rmr.xml new file mode 100644 index 0000000..120efc5 --- /dev/null +++ b/ficheros/red_metro_rmr.xml @@ -0,0 +1,53 @@ + + + + + Serie 2000-A + 2000 + CAF + 15 + + Arguelles - Pinar de Chamartín + + Marrón + + + + + Serie 2000-B + 2005 + CAF + 15 + + Arguelles - Pinar de Chamartín + + Marrón + + + + + Serie 3000 + 2010 + CAF + 15 + + Arguelles - Pinar de Chamartín + + Marrón + + + + + Serie 5000 + 2010 + CAF + 1 + + Nuevos Ministerios - Aeropuerto + + Rosa + + + + + diff --git a/ficheros/trenes_estaciones_accesos.xml b/ficheros/trenes_estaciones_accesos.xml new file mode 100644 index 0000000..f2a6ed0 --- /dev/null +++ b/ficheros/trenes_estaciones_accesos.xml @@ -0,0 +1,107 @@ + + + + + + Serie 2000-A + 2000 + CAF + 15 + 5 + + + Serie 2000-B + 2005 + CAF + 15 + 5 + + + Serie 3000 + 2010 + CAF + 15 + 5 + + + Serie 5000 + 2010 + CAF + 1 + 9 + + + + + + + + Alameda de Osuna + C/ de la Corbeta,14 + + + Corbeta: C/ de la Corbeta,14 (esquina calle de La Rioja) + 0 + + + Ascensor: C/ de la Corbeta,14 (esquina calle de La Rioja) + 1 + + + + + Pueblo Nuevo + C/. Alcalá, 373 + + + Hermanos de Pablo: Alcalá, 373 (próx. Hnos. de Pablo) + 0 + + + Emilio Ferrari: Alcalá, 364 + 0 + + + Ascensor: Alcalá, 366 + 1 + + + + + Avenida de América + Avenida de América nº 25 + + + Intercambiador: Avenida de América frente al nº 25 + 1 + + + Pedro Valdivia: Pedro Valdivia, 31 (Francisco Silvela - Príncipe de Vergara) + 0 + + + + + Núñez de Balboa + C/. Núñez de Balboa, 85 + + + Núñez de Balboa: Núñez de Balboa, 85 (Esq. Juan Bravo, 13) + 1 + + + Velázquez: Velázquez, 92 (Esq. Juan Bravo, 11) + 0 + + + Aparcamiento: Aparcamiento Pza. Marqués de Salamanca (Sólo entrada) + 1 + + + Pza. Marqués de Salamanca: Pza. Marqués de Salamanca, 10 + 0 + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5129167 --- /dev/null +++ b/pom.xml @@ -0,0 +1,30 @@ + + 4.0.0 + SimulacionExamen + SimulacionExamen + 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/es/madrid/redmetro/rmr/Main.java b/src/es/madrid/redmetro/rmr/Main.java new file mode 100644 index 0000000..2e6ab5e --- /dev/null +++ b/src/es/madrid/redmetro/rmr/Main.java @@ -0,0 +1,68 @@ +package es.madrid.redmetro.rmr; + +import java.util.Scanner; + +import es.madrid.redmetro.rmr.exception.RedMetroException; +import es.madrid.redmetro.rmr.fichero.EscritorTrenesXML; +import es.madrid.redmetro.rmr.fichero.LectorCocherasCSV; +import es.madrid.redmetro.rmr.fichero.LectorTrenesXML; +import es.madrid.redmetro.rmr.model.Linea; +import es.madrid.redmetro.rmr.service.LineaService; + +public class Main { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + System.out.println("Introduzca la operación a realizar: "); + String operacion = sc.nextLine().toUpperCase(); + + try { + switch (operacion) { + case "A": + mostrarColorLinea(sc); + break; + case "B": + new LectorCocherasCSV().tratarFichero(); + System.out.println("El tratamiento del fichero ha acabado"); + break; + case "C": + new LectorTrenesXML().tratarFichero(); + break; + case "D": + new EscritorTrenesXML().generarFichero(); + break; + default: + System.out.println("Operación inválida."); + } + } catch (RedMetroException e) { + System.out.println(e.getMessage()); + } + sc.close(); + + } + + private static void mostrarColorLinea(Scanner sc) { + System.out.println("Introduce el identificador de la línea: "); + int codigoLinea = Integer.parseInt(sc.nextLine().trim()); + + try { + + LineaService lineaService = new LineaService(); + Linea lineaYColor = lineaService.obtenerLineaConColor(codigoLinea); + + if (lineaYColor == null) { + System.out.println("La linea: " + codigoLinea + " no existe."); + } else { + System.out.println("El color de la línea " + lineaYColor.getCodigoLinea() + " (" + + lineaYColor.getNombreLargo() + "), que tiene una longitud de " + lineaYColor.getKilometros() + + " kilómetros, es " + lineaYColor.getColor().getNombre() + " (" + + lineaYColor.getColor().getCodigoHexadecimal() + ")."); + } + + } catch (RedMetroException e) { + System.out.println(e.getMessage()); + } + } + +} diff --git a/src/es/madrid/redmetro/rmr/dao/ICochera.java b/src/es/madrid/redmetro/rmr/dao/ICochera.java new file mode 100644 index 0000000..54a8153 --- /dev/null +++ b/src/es/madrid/redmetro/rmr/dao/ICochera.java @@ -0,0 +1,13 @@ +package es.madrid.redmetro.rmr.dao; + +import es.madrid.redmetro.rmr.exception.RedMetroException; +import es.madrid.redmetro.rmr.model.Cochera; + +public interface ICochera { + + Cochera obtenerCocheraPorCodigo (int codigoCochera) throws RedMetroException; + void insertarCochera (Cochera cochera) throws RedMetroException; + void actualizarCochera (Cochera cochera) throws RedMetroException; + void borrarCochera (int codigoCochera) throws RedMetroException; + +} \ No newline at end of file diff --git a/src/es/madrid/redmetro/rmr/dao/IColor.java b/src/es/madrid/redmetro/rmr/dao/IColor.java new file mode 100644 index 0000000..ae44b1e --- /dev/null +++ b/src/es/madrid/redmetro/rmr/dao/IColor.java @@ -0,0 +1,9 @@ +package es.madrid.redmetro.rmr.dao; + +import es.madrid.redmetro.rmr.model.Color; + +public interface IColor { + + Color obtenerColorPorCodigo (int idColor); + +} diff --git a/src/es/madrid/redmetro/rmr/dao/ILinea.java b/src/es/madrid/redmetro/rmr/dao/ILinea.java new file mode 100644 index 0000000..53f9cef --- /dev/null +++ b/src/es/madrid/redmetro/rmr/dao/ILinea.java @@ -0,0 +1,10 @@ +package es.madrid.redmetro.rmr.dao; + +import es.madrid.redmetro.rmr.exception.RedMetroException; +import es.madrid.redmetro.rmr.model.Linea; + +public interface ILinea { + + Linea obtenerLineaPorCodigo (int codigoLinea) throws RedMetroException; + +} diff --git a/src/es/madrid/redmetro/rmr/dao/ITren.java b/src/es/madrid/redmetro/rmr/dao/ITren.java new file mode 100644 index 0000000..2858d70 --- /dev/null +++ b/src/es/madrid/redmetro/rmr/dao/ITren.java @@ -0,0 +1,13 @@ +package es.madrid.redmetro.rmr.dao; + +import java.util.List; + +import es.madrid.redmetro.rmr.exception.RedMetroException; +import es.madrid.redmetro.rmr.model.Tren; + +public interface ITren { + + void insertarTren(Tren tren) throws RedMetroException; + List obtenerTodosLosTrenes() throws RedMetroException; + +} diff --git a/src/es/madrid/redmetro/rmr/dao/impl/CocheraJDBC.java b/src/es/madrid/redmetro/rmr/dao/impl/CocheraJDBC.java new file mode 100644 index 0000000..e25f163 --- /dev/null +++ b/src/es/madrid/redmetro/rmr/dao/impl/CocheraJDBC.java @@ -0,0 +1,98 @@ +package es.madrid.redmetro.rmr.dao.impl; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import es.madrid.redmetro.rmr.dao.ICochera; +import es.madrid.redmetro.rmr.exception.RedMetroException; +import es.madrid.redmetro.rmr.gestores.GestorConexionBD; +import es.madrid.redmetro.rmr.model.Cochera; + +public class CocheraJDBC implements ICochera { + + @Override + public Cochera obtenerCocheraPorCodigo(int codigoCochera) throws RedMetroException { + + Cochera cocheraEncontrada = null; + String consulta = "SELECT cod_cochera, nombre, direccion, deposito FROM T_COCHERA WHERE cod_cochera = ?"; + + try (Connection conexion = GestorConexionBD.getConexion(); + PreparedStatement sentencia = conexion.prepareStatement(consulta)) { + + sentencia.setInt(1, codigoCochera); + ResultSet resultado = sentencia.executeQuery(); + + if (resultado.next()) { + cocheraEncontrada = new Cochera(); + cocheraEncontrada.setCodigoCochera(resultado.getInt("cod_cochera")); + cocheraEncontrada.setNombre(resultado.getString("nombre")); + cocheraEncontrada.setDireccion(resultado.getString("direccion")); + cocheraEncontrada.setDeposito(resultado.getInt("deposito")); + } + + } catch (SQLException e) { + throw new RedMetroException ("Error al obtener la cochera: " + codigoCochera, e); + } + + return cocheraEncontrada; + + } + + @Override + public void insertarCochera(Cochera cochera) throws RedMetroException { + + String consulta = "INSERT INTO T_COCHERA (cod_cochera, nombre, direccion, deposito) VALUES (?, ?, ?, ?)"; + + try (Connection conexion = GestorConexionBD.getConexion(); + PreparedStatement sentencia = conexion.prepareStatement(consulta)) { + + sentencia.setInt(1, cochera.getCodigoCochera()); + sentencia.setString(2, cochera.getNombre()); + sentencia.setString(3, cochera.getDireccion()); + sentencia.setInt(4, cochera.getDeposito());; + sentencia.executeUpdate(); + + } catch (SQLException e) { + throw new RedMetroException ("Error al insertar la cochera: " + cochera.getCodigoCochera(), e); + } + + } + + @Override + public void actualizarCochera(Cochera cochera) throws RedMetroException { + String consulta = "UPDATE T_COCHERA SET nombre = ?, direccion = ?, deposito = ? WHERE cod_cochera = ?"; + + try (Connection conexion = GestorConexionBD.getConexion(); + PreparedStatement sentencia = conexion.prepareStatement(consulta)) { + + sentencia.setString(1, cochera.getNombre()); + sentencia.setString(2, cochera.getDireccion()); + sentencia.setInt(3, cochera.getDeposito()); + sentencia.setInt(4, cochera.getCodigoCochera()); + sentencia.executeUpdate(); + + } catch (SQLException e) { + throw new RedMetroException ("Error al actualizar la cochera: " + cochera.getCodigoCochera(), e); + } + + } + + @Override + public void borrarCochera(int codigoCochera) throws RedMetroException { + + String consulta = "DELETE FROM T_COCHERA WHERE cod_cochera = ?"; + + try (Connection conexion = GestorConexionBD.getConexion(); + PreparedStatement sentencia = conexion.prepareStatement(consulta)) { + + sentencia.setInt(1, codigoCochera); + sentencia.executeUpdate(); + + } catch (SQLException e) { + throw new RedMetroException ("Error al borrar la cochera: " + codigoCochera, e); + } + + } +} \ No newline at end of file diff --git a/src/es/madrid/redmetro/rmr/dao/impl/ColorJDBC.java b/src/es/madrid/redmetro/rmr/dao/impl/ColorJDBC.java new file mode 100644 index 0000000..1a09007 --- /dev/null +++ b/src/es/madrid/redmetro/rmr/dao/impl/ColorJDBC.java @@ -0,0 +1,14 @@ +package es.madrid.redmetro.rmr.dao.impl; + +import es.madrid.redmetro.rmr.dao.IColor; +import es.madrid.redmetro.rmr.model.Color; + +public class ColorJDBC implements IColor { + + @Override + public Color obtenerColorPorCodigo(int idColor) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/es/madrid/redmetro/rmr/dao/impl/LineaJDBC.java b/src/es/madrid/redmetro/rmr/dao/impl/LineaJDBC.java new file mode 100644 index 0000000..24951cc --- /dev/null +++ b/src/es/madrid/redmetro/rmr/dao/impl/LineaJDBC.java @@ -0,0 +1,51 @@ +package es.madrid.redmetro.rmr.dao.impl; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import es.madrid.redmetro.rmr.dao.ILinea; +import es.madrid.redmetro.rmr.exception.RedMetroException; +import es.madrid.redmetro.rmr.gestores.GestorConexionBD; +import es.madrid.redmetro.rmr.model.Color; +import es.madrid.redmetro.rmr.model.Linea; + +public class LineaJDBC implements ILinea { + + @Override + public Linea obtenerLineaPorCodigo(int codigoLinea) throws RedMetroException { + + Linea lineaEncontrada = null; + String consulta = "SELECT l.cod_linea, l.nombre_corto, l.nombre_largo, l.kilometros, " + + "c.cod_color, c.nombre, c.cod_hexadecimal " + + "FROM T_LINEA l JOIN T_COLOR c ON l.cod_color = c.cod_color " + "WHERE l.cod_linea = ?"; + + try (Connection conexion = GestorConexionBD.getConexion(); + PreparedStatement sentencia = conexion.prepareStatement(consulta)) { + + sentencia.setInt(1, codigoLinea); + ResultSet resultado = sentencia.executeQuery(); + + if (resultado.next()) { + lineaEncontrada = new Linea(); + lineaEncontrada.setCodigoLinea(resultado.getInt("cod_linea")); + lineaEncontrada.setNombreCorto(resultado.getString("nombre_corto")); + lineaEncontrada.setNombreLargo(resultado.getString("nombre_largo")); + lineaEncontrada.setKilometros(resultado.getFloat("kilometros")); + + Color colorLinea = new Color(); + colorLinea.setCodigoColor(resultado.getInt("cod_color")); + colorLinea.setNombre(resultado.getString("nombre")); + colorLinea.setCodigoHexadecimal(resultado.getString("cod_hexadecimal")); + + lineaEncontrada.setColor(colorLinea); + } + + } catch (SQLException e) { + throw new RedMetroException("Error al obtener la línea: " + codigoLinea + " por: " + e); + } + + return lineaEncontrada; + } +} diff --git a/src/es/madrid/redmetro/rmr/dao/impl/TrenJDBC.java b/src/es/madrid/redmetro/rmr/dao/impl/TrenJDBC.java new file mode 100644 index 0000000..6156dd0 --- /dev/null +++ b/src/es/madrid/redmetro/rmr/dao/impl/TrenJDBC.java @@ -0,0 +1,94 @@ +package es.madrid.redmetro.rmr.dao.impl; + +import java.sql.Connection; +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import es.madrid.redmetro.rmr.dao.ITren; +import es.madrid.redmetro.rmr.exception.RedMetroException; +import es.madrid.redmetro.rmr.gestores.GestorConexionBD; +import es.madrid.redmetro.rmr.model.Cochera; +import es.madrid.redmetro.rmr.model.Color; +import es.madrid.redmetro.rmr.model.Linea; +import es.madrid.redmetro.rmr.model.Tren; + +public class TrenJDBC implements ITren { + + @Override + public void insertarTren(Tren tren) throws RedMetroException { + + String consulta = "INSERT INTO T_TREN (cod_tren, modelo, empresa_constructora, fecha_incorporacion, cod_cochera, cod_linea) " + + "VALUES (?, ?, ?, ?, ?, ?)"; + + try (Connection conexion = GestorConexionBD.getConexion(); + PreparedStatement sentencia = conexion.prepareStatement(consulta)) { + + sentencia.setInt(1, tren.getCodigoTren()); + sentencia.setString(2, tren.getModelo()); + sentencia.setString(3, tren.getEmpresaConstructora()); + sentencia.setDate(4, Date.valueOf(tren.getFechaIncorporacion())); + sentencia.setInt(5, tren.getCochera().getCodigoCochera()); + sentencia.setInt(6, tren.getLinea().getCodigoLinea()); + sentencia.executeUpdate(); + + } catch (SQLException e) { + throw new RedMetroException("Error al insertar el tren: " + tren.getCodigoTren(), e); + } + + } + + @Override + public List obtenerTodosLosTrenes() throws RedMetroException { + List listaTrenes = new ArrayList<>(); + + String consulta = "SELECT t.cod_tren, t.modelo, t.empresa_constructora, t.fecha_incorporacion, t.cod_cochera, " + + "l.cod_linea, l.nombre_largo, " + + "c.cod_color, c.nombre, c.cod_hexadecimal " + + "FROM T_TREN t " + + "JOIN T_LINEA l ON t.cod_linea = l.cod_linea " + + "JOIN T_COLOR c ON l.cod_color = c.cod_color"; + + try (Connection conexion = GestorConexionBD.getConexion(); + PreparedStatement sentencia = conexion.prepareStatement(consulta)) { + + ResultSet resultado = sentencia.executeQuery(); + + while (resultado.next()) { + Tren trenLeido = new Tren(); + trenLeido.setCodigoTren(resultado.getInt("cod_tren")); + trenLeido.setModelo(resultado.getString("modelo")); + trenLeido.setEmpresaConstructora(resultado.getString("empresa_constructora")); + trenLeido.setFechaIncorporacion(resultado.getDate("fecha_incorporacion").toLocalDate()); + + Cochera cocheraDelTren = new Cochera(); + cocheraDelTren.setCodigoCochera(resultado.getInt("cod_cochera")); + trenLeido.setCochera(cocheraDelTren); + + Linea lineaDelTren = new Linea(); + lineaDelTren.setCodigoLinea(resultado.getInt("cod_linea")); + lineaDelTren.setNombreLargo(resultado.getString("nombre_largo")); + + Color colorLinea = new Color(); + colorLinea.setCodigoColor(resultado.getInt("cod_color")); + colorLinea.setNombre(resultado.getString("nombre")); + colorLinea.setCodigoHexadecimal(resultado.getString("cod_hexadecimal")); + + lineaDelTren.setColor(colorLinea); + trenLeido.setLinea(lineaDelTren); + + listaTrenes.add(trenLeido); + + } + } catch (SQLException e) { + throw new RedMetroException ("Error al obtener la lista de trenes", e); + } + + return listaTrenes; + + } + +} diff --git a/src/es/madrid/redmetro/rmr/exception/RedMetroException.java b/src/es/madrid/redmetro/rmr/exception/RedMetroException.java new file mode 100644 index 0000000..fc4465d --- /dev/null +++ b/src/es/madrid/redmetro/rmr/exception/RedMetroException.java @@ -0,0 +1,21 @@ +package es.madrid.redmetro.rmr.exception; + +public class RedMetroException extends Exception { // crea mi propia excepción. lo hereda de la de java + + // este primer constructor crea la excepción sol ocon un texto. + // lo uso cuando detecto yo el problema + public RedMetroException (String mensaje) { + super(mensaje); + } + + // este sirve para crear la excepción con un texto y el error original. + // lo uso cuando java me da un error (como el sqlexception) y lo convierto + // en mi excepción sin perder lo que pasó + public RedMetroException (String mensaje, Throwable causa) { + super (mensaje, causa); + } + + // super llama al constructor de exception y le pasa el mensaje y la causa. + // exception lo guarda. + +} diff --git a/src/es/madrid/redmetro/rmr/fichero/EscritorTrenesXML.java b/src/es/madrid/redmetro/rmr/fichero/EscritorTrenesXML.java new file mode 100644 index 0000000..d655653 --- /dev/null +++ b/src/es/madrid/redmetro/rmr/fichero/EscritorTrenesXML.java @@ -0,0 +1,95 @@ +package es.madrid.redmetro.rmr.fichero; + +import java.io.File; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import es.madrid.redmetro.rmr.exception.RedMetroException; +import es.madrid.redmetro.rmr.gestores.GestorConfiguracion; +import es.madrid.redmetro.rmr.model.Color; +import es.madrid.redmetro.rmr.model.Linea; +import es.madrid.redmetro.rmr.model.Tren; +import es.madrid.redmetro.rmr.service.TrenService; + +public class EscritorTrenesXML { + + private TrenService trenService = new TrenService(); + + public void generarFichero() throws RedMetroException { + + List listaTrenes = trenService.obtenerTodosLosTrenes(); + String rutaFichero = GestorConfiguracion.obtenerValor("fichero.salida"); + + try { + + DocumentBuilderFactory fabrica = DocumentBuilderFactory.newInstance(); + DocumentBuilder constructor = fabrica.newDocumentBuilder(); + Document documentoXML = constructor.newDocument(); + + Element raiz = documentoXML.createElement("info-trenes-linea-color"); + documentoXML.appendChild(raiz); + + Element elementoTrenes = documentoXML.createElement("trenes"); + raiz.appendChild(elementoTrenes); + + for (Tren tren : listaTrenes) { + Element elementoTren = documentoXML.createElement("tren"); + elementoTren.setAttribute("id", String.valueOf(tren.getCodigoTren())); + elementoTrenes.appendChild(elementoTren); + + añadirEtiqueta(documentoXML, elementoTren, "modelo", tren.getModelo()); + añadirEtiqueta(documentoXML, elementoTren, "anyo_incorporacion", String.valueOf(tren.getFechaIncorporacion().getYear())); + añadirEtiqueta(documentoXML, elementoTren, "empresa_constructora", tren.getEmpresaConstructora()); + añadirEtiqueta(documentoXML, elementoTren, "cod_cochera", String.valueOf(tren.getCochera().getCodigoCochera())); + + Linea lineaTren = tren.getLinea(); + Color colorLinea = lineaTren.getColor(); + + Element elementoLinea = documentoXML.createElement("linea"); + elementoLinea.setAttribute("id_linea", String.valueOf(lineaTren.getCodigoLinea())); + elementoTren.appendChild(elementoLinea); + + añadirEtiqueta (documentoXML, elementoLinea, "nombre_l", lineaTren.getNombreLargo()); + + Element elementoColor = documentoXML.createElement("color"); + elementoColor.setAttribute("id", String.valueOf(colorLinea.getCodigoColor())); + elementoColor.setAttribute("cod_hex", colorLinea.getCodigoHexadecimal()); + elementoLinea.appendChild(elementoColor); + + añadirEtiqueta(documentoXML, elementoColor, "descripcion", colorLinea.getNombre()); + + } + + TransformerFactory fabricaTrans = TransformerFactory.newInstance(); + Transformer transformador = fabricaTrans.newTransformer(); + transformador.setOutputProperty(OutputKeys.INDENT, "yes"); + transformador.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + + transformador.transform(new DOMSource(documentoXML), new StreamResult(new File(rutaFichero))); + System.out.println("Fichero: " + rutaFichero + " generado OK."); + + } catch (ParserConfigurationException | TransformerException e) { + throw new RedMetroException ("Error al generar el fichero de trenes", e); + } + } + + // este método recibe 4 cosas: el documento xml que estamos construyendo, padre (etiqueta dentro de la cual va la nueva o sea tren) + // nombreEtiqueta es cómo se llama la nueva, y texto, l oque va dentro. + private void añadirEtiqueta (Document documento, Element padre, String nombreEtiqueta, String texto) { + Element etiqueta = documento.createElement(nombreEtiqueta); // creop la etiqueta modelo + etiqueta.setTextContent(texto); // le meto dentro el texto + padre.appendChild(etiqueta); // la cuelgo dentro del tren + } +} diff --git a/src/es/madrid/redmetro/rmr/fichero/LectorCocherasCSV.java b/src/es/madrid/redmetro/rmr/fichero/LectorCocherasCSV.java new file mode 100644 index 0000000..3f399bb --- /dev/null +++ b/src/es/madrid/redmetro/rmr/fichero/LectorCocherasCSV.java @@ -0,0 +1,53 @@ +package es.madrid.redmetro.rmr.fichero; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +import es.madrid.redmetro.rmr.exception.RedMetroException; +import es.madrid.redmetro.rmr.gestores.GestorConfiguracion; +import es.madrid.redmetro.rmr.model.Cochera; +import es.madrid.redmetro.rmr.service.CocheraService; + +public class LectorCocherasCSV { + + private CocheraService cocheraService = new CocheraService(); + + public void tratarFichero() throws RedMetroException { + String rutaFichero = GestorConfiguracion.obtenerValor("fichero.cocheras"); + + + try (BufferedReader lector = new BufferedReader (new FileReader(rutaFichero))) { + + lector.readLine(); // me salto la cabecera!!!!! importante!!!!!!!!! + + String lineaLeida; + while ((lineaLeida = lector.readLine()) != null) { + + if (lineaLeida.trim().isEmpty()) { + continue; + } + + String[] trozos = lineaLeida.split(";"); + + int codigo = Integer.parseInt(trozos[0].trim()); + + Cochera cocheraLeida = new Cochera(); + cocheraLeida.setCodigoCochera(Integer.parseInt(trozos[1].trim())); + cocheraLeida.setDeposito(Integer.parseInt(trozos[2].trim())); + cocheraLeida.setNombre(trozos[3].trim()); + cocheraLeida.setDireccion(trozos[4].trim()); + + try { + cocheraService.procesarOperacion(codigo, cocheraLeida); + } catch (RedMetroException e) { + System.out.println(e.getMessage()); + } + } + + } catch (IOException e) { + throw new RedMetroException ("Error al leer el fichero de cocheras", e); + } + } + +} diff --git a/src/es/madrid/redmetro/rmr/fichero/LectorTrenesXML.java b/src/es/madrid/redmetro/rmr/fichero/LectorTrenesXML.java new file mode 100644 index 0000000..f05f7c6 --- /dev/null +++ b/src/es/madrid/redmetro/rmr/fichero/LectorTrenesXML.java @@ -0,0 +1,74 @@ +package es.madrid.redmetro.rmr.fichero; + +import java.io.File; +import java.io.IOException; +import java.time.LocalDate; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import es.madrid.redmetro.rmr.exception.RedMetroException; +import es.madrid.redmetro.rmr.gestores.GestorConfiguracion; +import es.madrid.redmetro.rmr.model.Cochera; +import es.madrid.redmetro.rmr.model.Linea; +import es.madrid.redmetro.rmr.model.Tren; +import es.madrid.redmetro.rmr.service.TrenService; + +public class LectorTrenesXML { + + private TrenService trenService = new TrenService(); + + public void tratarFichero() throws RedMetroException { + String rutaFichero = GestorConfiguracion.obtenerValor("fichero.trenes"); + + try { + + DocumentBuilderFactory fabrica = DocumentBuilderFactory.newInstance(); + DocumentBuilder constructor = fabrica.newDocumentBuilder(); + Document documentoXML = constructor.parse(new File(rutaFichero)); + + NodeList listaTrenes = documentoXML.getElementsByTagName("tren"); + + for (int i = 0; i < listaTrenes.getLength(); i++) { + Element elementoTren = (Element) listaTrenes.item(i); // el (element) es porque lla lista devuelve node y hay que decirle que es una etiqueta + + Tren trenLeido = new Tren(); + trenLeido.setCodigoTren(Integer.parseInt(elementoTren.getAttribute("id"))); + trenLeido.setModelo(leerEtiqueta(elementoTren, "modelo")); + trenLeido.setEmpresaConstructora(leerEtiqueta(elementoTren, "empresa_constructora"));; + + int añoIncorporacion = Integer.parseInt(leerEtiqueta(elementoTren, "anyo_incorporacion")); + trenLeido.setFechaIncorporacion(LocalDate.of(añoIncorporacion, 2, 1)); // convierto el año del xml en la fecha que pide la bd + + Cochera cocheraDelTren = new Cochera(); + cocheraDelTren.setCodigoCochera(Integer.parseInt(leerEtiqueta(elementoTren, "cod_cochera"))); + trenLeido.setCochera(cocheraDelTren); + + Linea lineaDelTren = new Linea(); + lineaDelTren.setCodigoLinea(Integer.parseInt(leerEtiqueta(elementoTren, "id_linea"))); + trenLeido.setLinea(lineaDelTren); + + try { + trenService.insertarTren(trenLeido); + System.out.println("Tren " + trenLeido.getCodigoTren() + " insertado."); + } catch (RedMetroException e) { + System.out.println(e.getMessage() + " - " + e.getCause()); + } + + } + + } catch (ParserConfigurationException | SAXException | IOException e) { + throw new RedMetroException ("Error al leer el fichero XML de trenes", e); + } + } + + private String leerEtiqueta (Element elemento, String nombreEtiqueta) { + return elemento.getElementsByTagName(nombreEtiqueta).item(0).getTextContent().trim(); + } +} diff --git a/src/es/madrid/redmetro/rmr/gestores/GestorConexionBD.java b/src/es/madrid/redmetro/rmr/gestores/GestorConexionBD.java new file mode 100644 index 0000000..1effe75 --- /dev/null +++ b/src/es/madrid/redmetro/rmr/gestores/GestorConexionBD.java @@ -0,0 +1,23 @@ +package es.madrid.redmetro.rmr.gestores; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +import es.madrid.redmetro.rmr.exception.RedMetroException; + +public class GestorConexionBD { + + public static Connection getConexion() throws RedMetroException { + String urlBaseDatos = GestorConfiguracion.obtenerValor("url"); + String usuarioBaseDatos = GestorConfiguracion.obtenerValor("usuario"); + String passBaseDatos = GestorConfiguracion.obtenerValor("password"); + + try { + return DriverManager.getConnection(urlBaseDatos, usuarioBaseDatos, passBaseDatos); + } catch (SQLException e) { + throw new RedMetroException ("No se ha podido conectar con la BBDD: " + e); + } + } + +} diff --git a/src/es/madrid/redmetro/rmr/gestores/GestorConfiguracion.java b/src/es/madrid/redmetro/rmr/gestores/GestorConfiguracion.java new file mode 100644 index 0000000..53c26c9 --- /dev/null +++ b/src/es/madrid/redmetro/rmr/gestores/GestorConfiguracion.java @@ -0,0 +1,24 @@ +package es.madrid.redmetro.rmr.gestores; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Properties; + +import es.madrid.redmetro.rmr.exception.RedMetroException; + +public class GestorConfiguracion { + + private static final String RUTA_FICHERO_CONFIG = "config/app.properties"; + + public static String obtenerValor (String clave) throws RedMetroException { + Properties propiedadesConfig = new Properties(); + + try (FileInputStream ficheroConfiguracion = new FileInputStream(RUTA_FICHERO_CONFIG)) { + propiedadesConfig.load(ficheroConfiguracion); + return propiedadesConfig.getProperty(clave); + } catch (IOException e) { + throw new RedMetroException ("No se puede leer el fichero de configuración: " + e); + } + } + +} diff --git a/src/es/madrid/redmetro/rmr/model/Cochera.java b/src/es/madrid/redmetro/rmr/model/Cochera.java new file mode 100644 index 0000000..2abac90 --- /dev/null +++ b/src/es/madrid/redmetro/rmr/model/Cochera.java @@ -0,0 +1,48 @@ +package es.madrid.redmetro.rmr.model; + +public class Cochera { + + private int codigoCochera; + private String nombre; + private String direccion; + private int deposito; + + public int getCodigoCochera() { + return codigoCochera; + } + + public void setCodigoCochera(int codigoCochera) { + this.codigoCochera = codigoCochera; + } + + public String getNombre() { + return nombre; + } + + public void setNombre(String nombre) { + this.nombre = nombre; + } + + public String getDireccion() { + return direccion; + } + + public void setDireccion(String direccion) { + this.direccion = direccion; + } + + public int getDeposito() { + return deposito; + } + + public void setDeposito(int deposito) { + this.deposito = deposito; + } + + @Override + public String toString() { + return "Cochera [codigoCochera=" + codigoCochera + ", nombre=" + nombre + ", direccion=" + direccion + + ", deposito=" + deposito + "]"; + } + +} diff --git a/src/es/madrid/redmetro/rmr/model/Color.java b/src/es/madrid/redmetro/rmr/model/Color.java new file mode 100644 index 0000000..f386024 --- /dev/null +++ b/src/es/madrid/redmetro/rmr/model/Color.java @@ -0,0 +1,39 @@ +package es.madrid.redmetro.rmr.model; + +public class Color { + + private int codigoColor; + private String nombre; + private String codigoHexadecimal; + + public int getCodigoColor() { + return codigoColor; + } + + public void setCodigoColor(int codigoColor) { + this.codigoColor = codigoColor; + } + + public String getNombre() { + return nombre; + } + + public void setNombre(String nombre) { + this.nombre = nombre; + } + + public String getCodigoHexadecimal() { + return codigoHexadecimal; + } + + public void setCodigoHexadecimal(String codigoHexadecimal) { + this.codigoHexadecimal = codigoHexadecimal; + } + + @Override + public String toString() { + return "Color [codigoColor=" + codigoColor + ", nombre=" + nombre + ", codigoHexadecimal=" + codigoHexadecimal + + "]"; + } + +} \ No newline at end of file diff --git a/src/es/madrid/redmetro/rmr/model/Linea.java b/src/es/madrid/redmetro/rmr/model/Linea.java new file mode 100644 index 0000000..74e33ad --- /dev/null +++ b/src/es/madrid/redmetro/rmr/model/Linea.java @@ -0,0 +1,57 @@ +package es.madrid.redmetro.rmr.model; + +public class Linea { + + private int codigoLinea; + private String nombreCorto; + private String nombreLargo; + private Color color; + private float kilometros; + + public int getCodigoLinea() { + return codigoLinea; + } + + public void setCodigoLinea(int codigoLinea) { + this.codigoLinea = codigoLinea; + } + + public String getNombreCorto() { + return nombreCorto; + } + + public void setNombreCorto(String nombreCorto) { + this.nombreCorto = nombreCorto; + } + + public String getNombreLargo() { + return nombreLargo; + } + + public void setNombreLargo(String nombreLargo) { + this.nombreLargo = nombreLargo; + } + + public Color getColor() { + return color; + } + + public void setColor(Color color) { + this.color = color; + } + + public float getKilometros() { + return kilometros; + } + + public void setKilometros(float kilometros) { + this.kilometros = kilometros; + } + + @Override + public String toString() { + return "Linea [codigoLinea=" + codigoLinea + ", nombreCorto=" + nombreCorto + ", nombreLargo=" + nombreLargo + + ", color=" + color + ", kilometros=" + kilometros + "]"; + } + +} \ No newline at end of file diff --git a/src/es/madrid/redmetro/rmr/model/Tren.java b/src/es/madrid/redmetro/rmr/model/Tren.java new file mode 100644 index 0000000..7ad82e6 --- /dev/null +++ b/src/es/madrid/redmetro/rmr/model/Tren.java @@ -0,0 +1,70 @@ +package es.madrid.redmetro.rmr.model; + +import java.time.LocalDate; + +public class Tren { + + private int codigoTren; + private String modelo; + private String empresaConstructora; + private LocalDate fechaIncorporacion; + private Cochera cochera; + private Linea linea; + + public int getCodigoTren() { + return codigoTren; + } + + public void setCodigoTren(int codigoTren) { + this.codigoTren = codigoTren; + } + + public String getModelo() { + return modelo; + } + + public void setModelo(String modelo) { + this.modelo = modelo; + } + + public String getEmpresaConstructora() { + return empresaConstructora; + } + + public void setEmpresaConstructora(String empresaConstructora) { + this.empresaConstructora = empresaConstructora; + } + + public LocalDate getFechaIncorporacion() { + return fechaIncorporacion; + } + + public void setFechaIncorporacion(LocalDate fechaIncorporacion) { + this.fechaIncorporacion = fechaIncorporacion; + } + + public Cochera getCochera() { + return cochera; + } + + public void setCochera(Cochera cochera) { + this.cochera = cochera; + } + + public Linea getLinea() { + return linea; + } + + public void setLinea(Linea linea) { + this.linea = linea; + } + + @Override + public String toString() { + return "Tren [codigoTren=" + codigoTren + ", modelo=" + modelo + ", empresaConstructora=" + empresaConstructora + + ", fechaIncorporacion=" + fechaIncorporacion + ", cochera=" + cochera + ", linea=" + linea + "]"; + } + + + +} diff --git a/src/es/madrid/redmetro/rmr/service/CocheraService.java b/src/es/madrid/redmetro/rmr/service/CocheraService.java new file mode 100644 index 0000000..dff66c4 --- /dev/null +++ b/src/es/madrid/redmetro/rmr/service/CocheraService.java @@ -0,0 +1,41 @@ +package es.madrid.redmetro.rmr.service; + +import es.madrid.redmetro.rmr.dao.ICochera; +import es.madrid.redmetro.rmr.dao.impl.CocheraJDBC; +import es.madrid.redmetro.rmr.exception.RedMetroException; +import es.madrid.redmetro.rmr.model.Cochera; + +public class CocheraService { + + private ICochera cocheraDAO = new CocheraJDBC(); + + public void procesarOperacion(int codigoOperacion, Cochera cochera) throws RedMetroException { + + switch (codigoOperacion) { + + case 1: + Cochera cocheraEnBD = cocheraDAO.obtenerCocheraPorCodigo(codigoOperacion); + if (cocheraEnBD == null) { + cocheraDAO.insertarCochera(cochera); + System.out.println("Cochera " + cochera.getCodigoCochera()+ " insertada correctamente."); + } else { + System.out.println("Cochera " + cochera.getCodigoCochera() + " ya existe."); + } + break; + + case 2: + cocheraDAO.actualizarCochera(cochera); + System.out.println("Cochera " + cochera.getCodigoCochera() + " actualizada."); + break; + + case 3: + cocheraDAO.borrarCochera(cochera.getCodigoCochera()); + System.out.println("Cochera " + cochera.getCodigoCochera() + " borrada."); + break; + + default: // default es 0 + break; + } + } + +} diff --git a/src/es/madrid/redmetro/rmr/service/LineaService.java b/src/es/madrid/redmetro/rmr/service/LineaService.java new file mode 100644 index 0000000..7c7d8a7 --- /dev/null +++ b/src/es/madrid/redmetro/rmr/service/LineaService.java @@ -0,0 +1,16 @@ +package es.madrid.redmetro.rmr.service; + +import es.madrid.redmetro.rmr.dao.ILinea; +import es.madrid.redmetro.rmr.dao.impl.LineaJDBC; +import es.madrid.redmetro.rmr.exception.RedMetroException; +import es.madrid.redmetro.rmr.model.Linea; + +public class LineaService { + + private ILinea lineaDAO = new LineaJDBC(); + + public Linea obtenerLineaConColor (int codigoLinea) throws RedMetroException { + return lineaDAO.obtenerLineaPorCodigo(codigoLinea); + } + +} diff --git a/src/es/madrid/redmetro/rmr/service/TrenService.java b/src/es/madrid/redmetro/rmr/service/TrenService.java new file mode 100644 index 0000000..b97d8dd --- /dev/null +++ b/src/es/madrid/redmetro/rmr/service/TrenService.java @@ -0,0 +1,22 @@ +package es.madrid.redmetro.rmr.service; + +import java.util.List; + +import es.madrid.redmetro.rmr.dao.ITren; +import es.madrid.redmetro.rmr.dao.impl.TrenJDBC; +import es.madrid.redmetro.rmr.exception.RedMetroException; +import es.madrid.redmetro.rmr.model.Tren; + +public class TrenService { + + private ITren trenDAO = new TrenJDBC(); + + public void insertarTren (Tren tren) throws RedMetroException { + trenDAO.insertarTren(tren); + } + + public List obtenerTodosLosTrenes() throws RedMetroException { + return trenDAO.obtenerTodosLosTrenes(); + } + +}