MODIFICACIÓN - Decisión en el lector CSV
This commit is contained in:
@@ -8,34 +8,52 @@ import es.madrid.redmetro.rmr.model.Cochera;
|
||||
public class CocheraService {
|
||||
|
||||
private ICochera cocheraDAO = new CocheraJDBC();
|
||||
// en caso de que haya relación de fk: el service necesita también el dao de tren
|
||||
// private ITren trenDAO = new TrenJDBC();
|
||||
|
||||
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;
|
||||
public void insertarCochera(Cochera cochera) throws RedMetroException {
|
||||
Cochera cocheraEnBD = cocheraDAO.obtenerCocheraPorCodigo(cochera.getCodigoCochera());
|
||||
if (cocheraEnBD == null) {
|
||||
cocheraDAO.insertarCochera(cochera);
|
||||
System.out.println("Cochera " + cochera.getCodigoCochera() + " insertada c orrectamente.");
|
||||
} else {
|
||||
System.out.println("Cochera " + cochera.getCodigoCochera() + " ya existe.");
|
||||
}
|
||||
}
|
||||
|
||||
public void actualizarCochera(Cochera cochera) throws RedMetroException {
|
||||
cocheraDAO.actualizarCochera(cochera);
|
||||
System.out.println("Cocchera " + cochera.getCodigoCochera() + " actualizada");
|
||||
}
|
||||
|
||||
public void borrarCochera (int codigoCochera) throws RedMetroException {
|
||||
cocheraDAO.borrarCochera(codigoCochera);
|
||||
System.out.println("Cochera " + codigoCochera + " borrada.");
|
||||
}
|
||||
|
||||
// en caso de haber relación de fk: borra los trenesy la cochera en una transacción
|
||||
// public void borrarCocheraYSusTrenes(int codigoCochera) throws RedMetroException {
|
||||
// Connection conexion = null;
|
||||
// try {
|
||||
// conexion = GestorConexionBD.getConexion();
|
||||
// conexion.setAutoCommit(false);
|
||||
// trenDAO.borrarTrenesDeCochera(conexion, codigoCochera);
|
||||
// cocheraDAO.borrarCochera(conexion, codigoCochera);
|
||||
// conexion.commit();
|
||||
// System.out.println("Cochera " + codigoCochera + " y sus trenes borrados.");
|
||||
// } catch (SQLException | RedMetroException e) {
|
||||
// try {
|
||||
// if (conexion != null) conexion.rollback();
|
||||
// } catch (SQLException errorRollback) {
|
||||
// System.out.println("Error al deshacer: " + errorRollback.getMessage());
|
||||
// }
|
||||
// throw new RedMetroException("Error al borrar la cochera " + codigoCochera, e);
|
||||
// } finally {
|
||||
// try {
|
||||
// if (conexion != null) conexion.close();
|
||||
// } catch (SQLException errorCierre) {
|
||||
// System.out.println("Error al cerrar: " + errorCierre.getMessage());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -12,5 +12,4 @@ public class LineaService {
|
||||
public Linea obtenerLineaConColor (int codigoLinea) throws RedMetroException {
|
||||
return lineaDAO.obtenerLineaPorCodigo(codigoLinea);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user