Commit inicial
This commit is contained in:
parent
239d7742e7
commit
f9adc3f592
2
.project
2
.project
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>aadd_act5_3</name>
|
||||
<name>aadd_act5_4</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=25
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=25
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=25
|
||||
|
||||
35
pom.xml
35
pom.xml
@ -1,24 +1,10 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.lapaloma.aadd</groupId>
|
||||
<artifactId>aadd_act3_3</artifactId>
|
||||
<groupId>aadd_act5.4</groupId>
|
||||
<artifactId>aadd_act5.4</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<!-- Source: https://mvnrepository.com/artifact/org.postgresql/postgresql -->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.7.8</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Hibernate Core -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate.orm</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>7.1.11.Final</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Source: https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-sync -->
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
@ -26,5 +12,20 @@
|
||||
<version>5.6.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>9.5.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/tools.jackson.dataformat/jackson-dataformat-xml -->
|
||||
<dependency>
|
||||
<groupId>tools.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<version>3.0.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -0,0 +1,62 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.lapaloma.aadd.redmetro;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.lapaloma.aadd.redmetro.dao.ILineaDAO;
|
||||
import org.lapaloma.aadd.redmetro.dao.jdbc.LineaDaoJDBC;
|
||||
import org.lapaloma.aadd.redmetro.dao.mongodb.LineaDaoMongoDB;
|
||||
import org.lapaloma.aadd.redmetro.procesador.ProcesadorURLs;
|
||||
import org.lapaloma.aadd.redmetro.vo.Linea;
|
||||
|
||||
/*
|
||||
Organización: Virgen de la Paloma
|
||||
Programador: Isidoro Nevares Martín
|
||||
Fecha: 6 febrero 2026
|
||||
*/
|
||||
public class AppPrincipalRedMetro {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
AppPrincipalRedMetro app = new AppPrincipalRedMetro();
|
||||
|
||||
// Tratamiento de Líneas - De MySQL a MongoDB
|
||||
app.tratarInformacionLinea();
|
||||
|
||||
// Tratamiento de Líneas Estaciones - De URLs (XML y JSON) a MongoDB
|
||||
ProcesadorURLs procesador= new ProcesadorURLs();
|
||||
procesador.procesarURLLineasEstacionesJSON();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void tratarInformacionLinea() {
|
||||
|
||||
ILineaDAO iLineaDAO = null;
|
||||
// Obtener información Lineas MySQL-JDBC
|
||||
iLineaDAO = new LineaDaoJDBC();
|
||||
List<Linea> listaLineas = iLineaDAO.obtenerListaLineas();
|
||||
System.out.println(listaLineas);
|
||||
|
||||
if (listaLineas != null && listaLineas.size() > 0) {
|
||||
iLineaDAO = new LineaDaoMongoDB();
|
||||
|
||||
// Grabar información Lineas MongoDB
|
||||
for (Linea linea : listaLineas) {
|
||||
Linea lineaMongoDB = iLineaDAO.obtenerLineaPorID(linea.getCodigo());
|
||||
if (lineaMongoDB == null) {
|
||||
iLineaDAO.crearLinea(linea);
|
||||
} else {
|
||||
iLineaDAO.actualizarLinea(linea);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
package org.lapaloma.aadd.redmetro;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.lapaloma.aadd.redmetro.dao.ILineaDAO;
|
||||
import org.lapaloma.aadd.redmetro.dao.jpa.LineaDaoJPA;
|
||||
import org.lapaloma.aadd.redmetro.dao.mgdb.LineaDaoMongoDB;
|
||||
import org.lapaloma.aadd.redmetro.gestores.GestorEntityManagerJPA;
|
||||
import org.lapaloma.aadd.redmetro.vo.Linea;
|
||||
|
||||
/**
|
||||
* Clase principal que inicia la sesión de Hibernate. Al iniciar la sesión,
|
||||
* Hibernate ejecutará hbm2ddl.auto=create y recreará la base de datos según las
|
||||
* entidades definidas.
|
||||
*/
|
||||
public class AppRedMetro {
|
||||
public static void main(String[] args) {
|
||||
AppRedMetro app = new AppRedMetro();
|
||||
// Obtiene la Session de forma estática
|
||||
GestorEntityManagerJPA.getEntityManager();
|
||||
|
||||
app.migrarMongoDBAPostgreSQL();
|
||||
}
|
||||
|
||||
private void migrarMongoDBAPostgreSQL() {
|
||||
ILineaDAO lineaDAO = new LineaDaoMongoDB();
|
||||
List<Linea> listaLineas = lineaDAO.obtenerListaLineas();
|
||||
if (listaLineas != null) {
|
||||
lineaDAO = new LineaDaoJPA();
|
||||
for (Linea linea : listaLineas) {
|
||||
// Se comprueba si existe la línea en PostgreSQL
|
||||
Linea lineaBBDD = lineaDAO.obtenerLineaPorID(linea.getCodigo());
|
||||
|
||||
// Si no existe la línea en PostgreSQL se inserta, caso contrario se actualiza.
|
||||
if (lineaBBDD == null) {
|
||||
lineaDAO.crearLinea(linea);
|
||||
} else {
|
||||
lineaDAO.actualizarLinea(linea);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,16 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.lapaloma.aadd.redmetro.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.lapaloma.aadd.redmetro.vo.Linea;
|
||||
|
||||
/**
|
||||
* @author Isidoro Nevares Martín (IES Virgen de la Paloma)
|
||||
* Fecha: 28 nov 2024
|
||||
*/
|
||||
public interface ILineaDAO {
|
||||
Linea obtenerLineaPorID(int identificador);
|
||||
|
||||
@ -12,5 +19,4 @@ public interface ILineaDAO {
|
||||
void crearLinea(Linea linea);
|
||||
|
||||
void actualizarLinea(Linea linea);
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.lapaloma.aadd.redmetro.dao;
|
||||
|
||||
import org.lapaloma.aadd.redmetro.excepciones.RedMetroException;
|
||||
import org.lapaloma.aadd.redmetro.vo.LineaEstacion;
|
||||
|
||||
/**
|
||||
* @author Isidoro Nevares Martín (IES Virgen de la Paloma)
|
||||
* Fecha: 06 febrero 2024
|
||||
*/
|
||||
public interface ILineaEstacionDAO {
|
||||
void crearLineaEstacion(LineaEstacion lineaEstacion) throws RedMetroException;
|
||||
}
|
||||
@ -0,0 +1,114 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.lapaloma.aadd.redmetro.dao.jdbc;
|
||||
|
||||
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.lapaloma.aadd.redmetro.dao.ILineaDAO;
|
||||
import org.lapaloma.aadd.redmetro.excepciones.RedMetroException;
|
||||
import org.lapaloma.aadd.redmetro.gestores.GestorConexionJDBC;
|
||||
import org.lapaloma.aadd.redmetro.vo.Color;
|
||||
import org.lapaloma.aadd.redmetro.vo.Linea;
|
||||
|
||||
/**
|
||||
* @author Isidoro Nevares Martín (IES Virgen de la Paloma) Fecha: 06 febrero
|
||||
* 2026
|
||||
*/
|
||||
public class LineaDaoJDBC implements ILineaDAO {
|
||||
public List<Linea> obtenerListaLineas() throws RedMetroException {
|
||||
List<Linea> listaLineas = null;
|
||||
|
||||
String sentenciaSQL = """
|
||||
SELECT * FROM T_COLOR color join T_LINEA linea
|
||||
ON linea.cod_color= color.cod_color
|
||||
""";
|
||||
try (Connection conexion = GestorConexionJDBC.getConexionSGDB();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
ResultSet resultadoSentencia = null;
|
||||
|
||||
resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
||||
if (resultadoSentencia != null)
|
||||
listaLineas = new ArrayList<Linea>();
|
||||
|
||||
while (resultadoSentencia.next()) {
|
||||
Linea linea = getLineaFromResultSet(resultadoSentencia);
|
||||
|
||||
listaLineas.add(linea);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RedMetroException(e, RedMetroException.ERROR_BUSQUEDA, getClass());
|
||||
}
|
||||
|
||||
return listaLineas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Linea obtenerLineaPorID(int idLinea) throws RedMetroException {
|
||||
Linea linea = null;
|
||||
|
||||
String sentenciaSQL = """
|
||||
SELECT * FROM T_COLOR color join T_LINEA linea
|
||||
ON linea.cod_color= color.cod_color
|
||||
where linea.cod_linea=?
|
||||
""";
|
||||
try (Connection conexion = GestorConexionJDBC.getConexionSGDB();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
sentenciaJDBCPreparada.setInt(1, idLinea);
|
||||
System.out.println(sentenciaJDBCPreparada);
|
||||
|
||||
ResultSet resultadoSentencia = null;
|
||||
resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
||||
|
||||
if (resultadoSentencia.next()) {
|
||||
linea = getLineaFromResultSet(resultadoSentencia);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RedMetroException(e, RedMetroException.ERROR_BUSQUEDA, getClass());
|
||||
}
|
||||
|
||||
return linea;
|
||||
|
||||
}
|
||||
|
||||
private Linea getLineaFromResultSet(ResultSet resultadoSentencia) throws SQLException {
|
||||
Linea linea = new Linea();
|
||||
|
||||
linea.setCodigo(resultadoSentencia.getInt("linea.cod_linea"));
|
||||
linea.setNombreCorto(resultadoSentencia.getString("linea.nombre_corto"));
|
||||
linea.setNombreLargo(resultadoSentencia.getString("linea.nombre_largo"));
|
||||
linea.setKilometros(resultadoSentencia.getBigDecimal("linea.kilometros"));
|
||||
|
||||
Color color = new Color();
|
||||
color.setCodigo(resultadoSentencia.getInt("color.cod_color"));
|
||||
color.setCodHexadecimal(resultadoSentencia.getString("color.cod_hexadecimal"));
|
||||
color.setNombre(resultadoSentencia.getString("color.nombre"));
|
||||
|
||||
linea.setColor(color);
|
||||
|
||||
return linea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actualizarLinea(Linea linea) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void crearLinea(Linea linea) throws RedMetroException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,83 +0,0 @@
|
||||
package org.lapaloma.aadd.redmetro.dao.jpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.lapaloma.aadd.redmetro.dao.ILineaDAO;
|
||||
import org.lapaloma.aadd.redmetro.gestores.GestorEntityManagerJPA;
|
||||
import org.lapaloma.aadd.redmetro.vo.Linea;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
|
||||
public class LineaDaoJPA implements ILineaDAO {
|
||||
@Override
|
||||
public Linea obtenerLineaPorID(int codigo) {
|
||||
Linea linea = null;
|
||||
|
||||
// try con recursos "cerrables": Session
|
||||
try (EntityManager gestorEntidades = GestorEntityManagerJPA.getEntityManager()) {
|
||||
linea = gestorEntidades.find(Linea.class, codigo);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return linea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void crearLinea(Linea linea) {
|
||||
EntityManager gestorEntidades = null;
|
||||
EntityTransaction transaccion = null;
|
||||
|
||||
try {
|
||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||
transaccion = gestorEntidades.getTransaction();
|
||||
transaccion.begin();
|
||||
|
||||
gestorEntidades.persist(linea);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (Exception e) {
|
||||
if (transaccion != null && transaccion.isActive()) {
|
||||
transaccion.rollback();
|
||||
}
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (gestorEntidades != null) {
|
||||
gestorEntidades.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actualizarLinea(Linea linea) {
|
||||
EntityManager gestorEntidades = null;
|
||||
EntityTransaction transaccion = null;
|
||||
|
||||
try {
|
||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||
transaccion = gestorEntidades.getTransaction();
|
||||
transaccion.begin();
|
||||
|
||||
if (!gestorEntidades.contains(linea))
|
||||
gestorEntidades.merge(linea);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (Exception e) {
|
||||
if (transaccion != null && transaccion.isActive()) {
|
||||
transaccion.rollback();
|
||||
}
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (gestorEntidades != null) {
|
||||
gestorEntidades.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Linea> obtenerListaLineas() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,101 +0,0 @@
|
||||
package org.lapaloma.aadd.redmetro.dao.mgdb;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.lapaloma.aadd.redmetro.dao.ILineaDAO;
|
||||
import org.lapaloma.aadd.redmetro.gestores.GestorConexionMongoDB;
|
||||
import org.lapaloma.aadd.redmetro.util.UtilidadesRedMetro;
|
||||
import org.lapaloma.aadd.redmetro.vo.Color;
|
||||
import org.lapaloma.aadd.redmetro.vo.Linea;
|
||||
|
||||
import com.mongodb.client.FindIterable;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
|
||||
/**
|
||||
*
|
||||
* ContinenteDaoMongoDB: Implentación MongoDB de las operaciones de
|
||||
* IContinenteDAO.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 30 enero 2026
|
||||
*/
|
||||
public class LineaDaoMongoDB implements ILineaDAO {
|
||||
private final static String COLECCION_PAIS = "c_linea";
|
||||
|
||||
@Override
|
||||
public Linea obtenerLineaPorID(int identificador) {
|
||||
Linea linea = null;
|
||||
|
||||
return linea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Linea> obtenerListaLineas() {
|
||||
List<Linea> listaLineas = null;
|
||||
// Obtener colección MongoDB
|
||||
MongoCollection<Document> coleccionMDb = GestorConexionMongoDB.getMongoDatabase().getCollection(COLECCION_PAIS);
|
||||
|
||||
FindIterable<Document> documentosEncontrados = null;
|
||||
documentosEncontrados = documentosEncontrados = coleccionMDb.find();
|
||||
if (documentosEncontrados != null) {
|
||||
listaLineas = new ArrayList<Linea>();
|
||||
for (Document documentoEncontrado : documentosEncontrados) {
|
||||
Linea linea = getLineaFromDocumentoLinea(documentoEncontrado);
|
||||
|
||||
listaLineas.add(linea);
|
||||
}
|
||||
}
|
||||
return listaLineas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void crearLinea(Linea linea) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actualizarLinea(Linea linea) {
|
||||
}
|
||||
|
||||
private Linea getLineaFromDocumentoLinea(Document documentoLinea) {
|
||||
Linea linea = null;
|
||||
|
||||
int codLinea = Integer.valueOf(documentoLinea.getString("cod_linea"));
|
||||
String urlImgLinea = documentoLinea.getString("url_img_tmp");
|
||||
byte[] imagenLinea= UtilidadesRedMetro.getBytesFromURL(urlImgLinea);
|
||||
Object kilometros = documentoLinea.get("kilometros");
|
||||
if (kilometros instanceof Double) {
|
||||
kilometros = BigDecimal.valueOf((Double) kilometros);
|
||||
} else if (kilometros instanceof Integer) {
|
||||
kilometros = BigDecimal.valueOf((Integer) kilometros);
|
||||
}
|
||||
// System.out.println("kilometros: " + kilometros);
|
||||
|
||||
Document documentoNombre = (Document) documentoLinea.get("nombre");
|
||||
String nombreCorto = documentoNombre.getString("nombre_corto");
|
||||
String nombreLargo = documentoNombre.getString("nombre_largo");
|
||||
|
||||
Document documentoColor = (Document) documentoLinea.get("color");
|
||||
int codigoColor = documentoColor.getInteger("cod_color");
|
||||
String nombreColor = documentoColor.getString("nombre");
|
||||
String codHexadecimal = documentoColor.getString("cod_hexadecimal");
|
||||
|
||||
Color color = new Color();
|
||||
color.setCodigo(codigoColor);
|
||||
color.setNombre(nombreColor);
|
||||
color.setCodHexadecimal(codHexadecimal);
|
||||
|
||||
linea = new Linea();
|
||||
linea.setCodigo(codLinea);
|
||||
linea.setNombreCorto(nombreCorto);
|
||||
linea.setNombreLargo(nombreLargo);
|
||||
linea.setKilometros((BigDecimal)kilometros);
|
||||
linea.setImagenLinea(imagenLinea);
|
||||
linea.setColor(color);
|
||||
|
||||
return linea;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,132 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.lapaloma.aadd.redmetro.dao.mongodb;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
import org.bson.types.Decimal128;
|
||||
import org.lapaloma.aadd.redmetro.dao.ILineaDAO;
|
||||
import org.lapaloma.aadd.redmetro.excepciones.RedMetroException;
|
||||
import org.lapaloma.aadd.redmetro.gestores.GestorConexionMongoDB;
|
||||
import org.lapaloma.aadd.redmetro.vo.Color;
|
||||
import org.lapaloma.aadd.redmetro.vo.Linea;
|
||||
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.model.Filters;
|
||||
|
||||
/**
|
||||
* @author Isidoro Nevares Martín (IES Virgen de la Paloma)
|
||||
* Fecha: 28 nov 2024
|
||||
*/
|
||||
public class LineaDaoMongoDB implements ILineaDAO{
|
||||
private final static String COLECCION = "c_linea";
|
||||
|
||||
@Override
|
||||
public void crearLinea(Linea linea) throws RedMetroException {
|
||||
MongoCollection<Document> coleccionMongoDB = null;
|
||||
|
||||
try {
|
||||
coleccionMongoDB = GestorConexionMongoDB.getMongoDatabase().getCollection(COLECCION);
|
||||
|
||||
// Insertar UN DOCUMENTO en la colección
|
||||
Document documentoLinea = new Document();
|
||||
documentoLinea.append("_id", linea.getCodigo())
|
||||
.append("nombre_corto", linea.getNombreCorto())
|
||||
.append("nombre_largo", linea.getNombreLargo())
|
||||
.append("kilometros", linea.getKilometros());
|
||||
|
||||
Document documentoColor = new Document();
|
||||
documentoColor.append("cod_color", linea.getColor().getCodigo())
|
||||
.append("nombre", linea.getColor().getNombre())
|
||||
.append("cod_hexadecimal", linea.getColor().getCodHexadecimal());
|
||||
|
||||
documentoLinea.append("color", documentoColor);
|
||||
|
||||
coleccionMongoDB.insertOne(documentoLinea);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RedMetroException(e, RedMetroException.ERROR_CREACION, getClass());
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public Linea obtenerLineaPorID(int identificador) {
|
||||
Linea linea = null;
|
||||
// Obtener o crear una colección MongoDB
|
||||
MongoCollection<Document> coleccionMDb = GestorConexionMongoDB.getMongoDatabase().getCollection(COLECCION);
|
||||
|
||||
// Consultar por ID
|
||||
Bson filtro = Filters.eq("_id", identificador);
|
||||
Document documentoEncontrado = coleccionMDb.find(filtro).first();
|
||||
|
||||
if (documentoEncontrado != null) {
|
||||
linea = getLineaFromDocumentoLinea(documentoEncontrado);
|
||||
}
|
||||
|
||||
return linea;
|
||||
}
|
||||
@Override
|
||||
public void actualizarLinea(Linea linea) {
|
||||
MongoCollection<Document> coleccionMongoDB = null;
|
||||
// Obtener o crear una colección MongoDB
|
||||
coleccionMongoDB = GestorConexionMongoDB.getMongoDatabase().getCollection(COLECCION);
|
||||
|
||||
// Actualizar UN Continente en la colección
|
||||
Bson filtro = Filters.eq("_id", linea.getCodigo());
|
||||
|
||||
// Contenido del documento con el que se va a actualizar el documento país
|
||||
// están todos los cmapos excepto _id e identificador.
|
||||
Document docLineaActualizado = new Document();
|
||||
docLineaActualizado.append("nombre_corto", linea.getNombreCorto())
|
||||
.append("nombre_largo", linea.getNombreLargo())
|
||||
.append("kilometros", linea.getKilometros());
|
||||
Document docColor= new Document();
|
||||
docColor.append("cod_color", linea.getColor().getCodigo())
|
||||
.append("nombre", linea.getColor().getNombre())
|
||||
.append("cod_hexxadecimal", linea.getColor().getCodHexadecimal());
|
||||
docLineaActualizado.append("color", docColor);
|
||||
|
||||
coleccionMongoDB.updateOne(filtro, new Document("$set", docLineaActualizado));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Linea> obtenerListaLineas() throws RedMetroException{
|
||||
List<Linea> listaLineas=null;
|
||||
|
||||
|
||||
return listaLineas;
|
||||
}
|
||||
|
||||
private Linea getLineaFromDocumentoLinea(Document documentoLinea) {
|
||||
Linea linea = null;
|
||||
int idMongoDB = documentoLinea.getInteger("_id");
|
||||
String nombreCorto = documentoLinea.getString("nombre_corto");
|
||||
String nombreLargo= documentoLinea.getString("nombre_corto");
|
||||
Decimal128 kilometrosDecimal128 = documentoLinea.get("kilometros", Decimal128.class);
|
||||
BigDecimal kilometros = kilometrosDecimal128.bigDecimalValue();
|
||||
|
||||
Document documentoColor= (Document) documentoLinea.get("color");
|
||||
int codigoColor = documentoColor.getInteger("cod_color");
|
||||
String nombreColor = documentoColor.getString("nombre");
|
||||
String codHexadecimal = documentoColor.getString("cod_hexadecimal");
|
||||
Color color = new Color();
|
||||
color.setCodigo(codigoColor);
|
||||
color.setNombre(nombreColor);
|
||||
color.setCodHexadecimal(codHexadecimal);
|
||||
|
||||
linea = new Linea();
|
||||
linea.setCodigo(idMongoDB);
|
||||
linea.setKilometros(kilometros);
|
||||
linea.setNombreCorto(nombreCorto);
|
||||
linea.setNombreLargo(nombreLargo);
|
||||
linea.setColor(color);
|
||||
|
||||
return linea;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,87 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.lapaloma.aadd.redmetro.dao.mongodb;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
import org.lapaloma.aadd.redmetro.dao.ILineaEstacionDAO;
|
||||
import org.lapaloma.aadd.redmetro.excepciones.RedMetroException;
|
||||
import org.lapaloma.aadd.redmetro.gestores.GestorConexionMongoDB;
|
||||
import org.lapaloma.aadd.redmetro.vo.LineaEstacion;
|
||||
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.model.Filters;
|
||||
import com.mongodb.client.model.Updates;
|
||||
|
||||
/**
|
||||
* @author Isidoro Nevares Martín (IES Virgen de la Paloma) Fecha: 6 febrero 2026
|
||||
*/
|
||||
public class LineaEstacionDaoMongoDB implements ILineaEstacionDAO {
|
||||
private final static String COLECCION = "c_linea_estaciones";
|
||||
|
||||
|
||||
@Override
|
||||
public void crearLineaEstacion(LineaEstacion lineaEstacion) throws RedMetroException {
|
||||
MongoCollection<Document> coleccionMongoDB = null;
|
||||
try {
|
||||
coleccionMongoDB = GestorConexionMongoDB.getMongoDatabase().getCollection(COLECCION);
|
||||
|
||||
// Consultar Colección con filtro = del documento
|
||||
Bson filtro = Filters.eq("_id", ""+lineaEstacion.getLinea().getCodigo());
|
||||
Document documentoMongoDB = coleccionMongoDB.find(filtro).first();
|
||||
|
||||
if (documentoMongoDB != null) {
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
List<Document> estaciones = (List<Document>) documentoMongoDB.get("estaciones");
|
||||
|
||||
boolean existeEstacion=false;
|
||||
for (Document estacion : estaciones) {
|
||||
int idEstacion = estacion.getInteger("id_estacion");
|
||||
if (idEstacion==lineaEstacion.getEstacion().getCodigo()) {
|
||||
existeEstacion=true;
|
||||
}
|
||||
System.out.println("Estación: " + estacion.getString("nombre"));
|
||||
}
|
||||
if(!existeEstacion) {
|
||||
Document documentoEstacion = new Document();
|
||||
documentoEstacion.append("id_estacion",lineaEstacion.getEstacion().getCodigo())
|
||||
.append("nombre", lineaEstacion.getEstacion().getNombre())
|
||||
.append("orden", lineaEstacion.getOrden());
|
||||
estaciones.add(documentoEstacion);
|
||||
|
||||
// Actualizar la lista de estaciones en el documento de la línea
|
||||
coleccionMongoDB.updateOne(
|
||||
filtro,
|
||||
Updates.set("estaciones", estaciones) // Sustituir la lista de estaciones
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Insertar UN DOCUMENTO en la colección
|
||||
Document documentoLinea = new Document();
|
||||
documentoLinea.append("_id", "" + lineaEstacion.getLinea().getCodigo()).append("nombre",
|
||||
lineaEstacion.getLinea().getNombreCorto());
|
||||
|
||||
List<Document> estaciones = new ArrayList<Document>();
|
||||
|
||||
Document documentoEstacion = new Document();
|
||||
documentoEstacion.append("id_estacion",lineaEstacion.getEstacion().getCodigo())
|
||||
.append("nombre", lineaEstacion.getEstacion().getNombre())
|
||||
.append("orden", lineaEstacion.getOrden());
|
||||
|
||||
estaciones.add(documentoEstacion);
|
||||
|
||||
documentoLinea.append("estaciones", estaciones);
|
||||
|
||||
coleccionMongoDB.insertOne(documentoLinea);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RedMetroException(e, RedMetroException.ERROR_CREACION, getClass());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package org.lapaloma.aadd.redmetro.excepciones;
|
||||
|
||||
public class RedMetroException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final long ERROR_BUSQUEDA = 0;
|
||||
public static final long ERROR_CREACION = 1;
|
||||
public static final long ERROR_ACTUALIZACION = 2;
|
||||
public static final long ERROR_ELIMINACION = 3;
|
||||
public static final long ERROR_OTRO = 4;
|
||||
|
||||
private long codigoError;
|
||||
private String nombreClase;
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public RedMetroException(Exception excepcion, long tipoError, Class clase) {
|
||||
super(excepcion);
|
||||
this.codigoError = tipoError;
|
||||
this.nombreClase = clase.getName();
|
||||
}
|
||||
|
||||
|
||||
public long getCodigoError() {
|
||||
return codigoError;
|
||||
}
|
||||
|
||||
|
||||
public void setCodigoError(long codigoError) {
|
||||
this.codigoError = codigoError;
|
||||
}
|
||||
|
||||
|
||||
public String getNombreClase() {
|
||||
return nombreClase;
|
||||
}
|
||||
|
||||
|
||||
public void setNombreClase(String nombreClase) {
|
||||
this.nombreClase = nombreClase;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package org.lapaloma.aadd.redmetro.gestores;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class GestorConexionJDBC {
|
||||
|
||||
// Evita que pueda construirse un objeto de la clase.
|
||||
private GestorConexionJDBC() {}
|
||||
|
||||
public static Connection getConexionSGDB(){
|
||||
Connection conexionSGDB = null;
|
||||
|
||||
// Datos URL
|
||||
String urlBBDD =GestorFicheroConfiguracion.obtenerValor("url.bbdd");
|
||||
|
||||
String usuario = GestorFicheroConfiguracion.obtenerValor("usuario.sgdb");
|
||||
String contrasenya =GestorFicheroConfiguracion.obtenerValor("clave.sgdb");
|
||||
|
||||
try {
|
||||
String claseDriver= GestorFicheroConfiguracion.obtenerValor("driver.sgdb");
|
||||
Class.forName(claseDriver);
|
||||
|
||||
conexionSGDB = DriverManager.getConnection(urlBBDD, usuario, contrasenya);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return conexionSGDB;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package org.lapaloma.aadd.redmetro.gestores;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.Persistence;
|
||||
|
||||
/**
|
||||
*
|
||||
* GestorEntityManagerJPA: Clase que realiza la gestión de EntityManagers de JPA.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 4 dic 2025
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class GestorEntityManagerJPA {
|
||||
private static EntityManagerFactory entityManagerFactory = null;
|
||||
|
||||
private GestorEntityManagerJPA() { // Constructor privado para evitar instanciación
|
||||
}
|
||||
|
||||
// Carga la configuración desde META-INF/persistence.xml
|
||||
static {
|
||||
try {
|
||||
entityManagerFactory = Persistence.createEntityManagerFactory("UP_REDMETRO_POSTGRESQL");
|
||||
} catch (Throwable ex) {
|
||||
System.err.println("Error en EntityManagerFactory: " + ex);
|
||||
throw new ExceptionInInitializerError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityManager getEntityManager() {
|
||||
return entityManagerFactory.createEntityManager();
|
||||
}
|
||||
|
||||
|
||||
public static void closeEntityManagerFactory() {
|
||||
entityManagerFactory.close();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.lapaloma.aadd.redmetro.gestores;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.net.http.HttpResponse.BodyHandlers;
|
||||
|
||||
/*
|
||||
Organización: Virgen de la Paloma
|
||||
Programador: Isidoro Nevares Martín
|
||||
Fecha: 12 dic 2024
|
||||
*/
|
||||
public class GestorURLs {
|
||||
|
||||
// Evita que pueda construirse un objeto de la clase.
|
||||
private GestorURLs() {
|
||||
}
|
||||
|
||||
public static String getTextoFromURL(String rutaURL) {
|
||||
String resultadoURL = null;
|
||||
|
||||
HttpClient cliente = HttpClient.newHttpClient();
|
||||
URI uriPrueba = URI.create(rutaURL);
|
||||
HttpRequest request = HttpRequest.newBuilder().uri(uriPrueba).GET().build();
|
||||
try {
|
||||
HttpResponse<String> respuesta = cliente.send(request, BodyHandlers.ofString());
|
||||
resultadoURL = respuesta.body();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return resultadoURL;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,135 @@
|
||||
package org.lapaloma.aadd.redmetro.procesador;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.lapaloma.aadd.redmetro.dao.ILineaDAO;
|
||||
import org.lapaloma.aadd.redmetro.dao.ILineaEstacionDAO;
|
||||
import org.lapaloma.aadd.redmetro.dao.mongodb.LineaDaoMongoDB;
|
||||
import org.lapaloma.aadd.redmetro.dao.mongodb.LineaEstacionDaoMongoDB;
|
||||
import org.lapaloma.aadd.redmetro.gestores.GestorFicheroConfiguracion;
|
||||
import org.lapaloma.aadd.redmetro.vo.Estacion;
|
||||
import org.lapaloma.aadd.redmetro.vo.Linea;
|
||||
import org.lapaloma.aadd.redmetro.vo.LineaEstacion;
|
||||
import org.lapaloma.aadd.redmetro.vo.LineaEstacionId;
|
||||
|
||||
import tools.jackson.databind.JsonNode;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.dataformat.xml.XmlMapper;
|
||||
|
||||
public class ProcesadorURLs {
|
||||
|
||||
public void procesarURLLineasEstacionesJSON() {
|
||||
List<Estacion> listaEstaciones = new ArrayList<Estacion>();
|
||||
cargarEstacionesXML(listaEstaciones);
|
||||
|
||||
String urlJSONLineasEstaciones = GestorFicheroConfiguracion.obtenerValor("url.json.lineaestacion");
|
||||
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URI(urlJSONLineasEstaciones).toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (URISyntaxException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Procesar con Jackson XML
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
try (InputStream is = url.openStream()) {
|
||||
JsonNode nodosLineasEstaciones = mapper.readTree(is);
|
||||
ILineaEstacionDAO lineaEstacionDAO = new LineaEstacionDaoMongoDB();
|
||||
for (JsonNode nodoLineaEstacion : nodosLineasEstaciones) {
|
||||
int idLinea = nodoLineaEstacion.path("idLinea").asInt();
|
||||
int idEstacion = nodoLineaEstacion.path("idEstacion").asInt();
|
||||
int orden = nodoLineaEstacion.path("orden").asInt();
|
||||
|
||||
ILineaDAO lineaDAO = new LineaDaoMongoDB();
|
||||
Linea lineaBBDD = lineaDAO.obtenerLineaPorID(idLinea);
|
||||
|
||||
Estacion estacionURL = getEstacionPorID(idEstacion, listaEstaciones);
|
||||
|
||||
// Si existen la línea y la estación, creamos la relación.
|
||||
if (lineaBBDD != null && estacionURL != null) {
|
||||
LineaEstacion lineaEstacion = new LineaEstacion();
|
||||
LineaEstacionId idLineaEstacion = new LineaEstacionId(idLinea, idEstacion);
|
||||
|
||||
lineaEstacion.setId(idLineaEstacion);
|
||||
lineaEstacion.setLinea(lineaBBDD);
|
||||
lineaEstacion.setEstacion(estacionURL);
|
||||
lineaEstacion.setOrden(orden);
|
||||
|
||||
System.out.println(lineaEstacion);
|
||||
|
||||
lineaEstacionDAO.crearLineaEstacion(lineaEstacion);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void cargarEstacionesXML(List<Estacion> listaEstaciones) {
|
||||
|
||||
String urlXMLEstaciones = GestorFicheroConfiguracion.obtenerValor("url.xml.estacion");
|
||||
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URI(urlXMLEstaciones).toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (URISyntaxException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Procesar con Jackson XML
|
||||
ObjectMapper mapper = new XmlMapper();
|
||||
|
||||
try (InputStream is = url.openStream()) {
|
||||
JsonNode root = mapper.readTree(is);
|
||||
JsonNode nodosEstacion = root.path("estaciones").path("estacion");
|
||||
for (JsonNode nodoEstacion : nodosEstacion) {
|
||||
String nombre = nodoEstacion.path("nombre").asString();
|
||||
String direccion = nodoEstacion.path("direccion").asString();
|
||||
int id = nodoEstacion.path("id").asInt();
|
||||
|
||||
Estacion estacion = new Estacion();
|
||||
estacion.setCodigo(id);
|
||||
estacion.setNombre(nombre);
|
||||
estacion.setDireccion(direccion);
|
||||
|
||||
listaEstaciones.add(estacion);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Estacion getEstacionPorID(int codEstacion, List<Estacion> listaEstaciones) {
|
||||
Estacion estacion = null;
|
||||
if (listaEstaciones != null) {
|
||||
for (Estacion estacionLista : listaEstaciones) {
|
||||
if (estacionLista.getCodigo() == codEstacion) {
|
||||
estacion = estacionLista;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return estacion;
|
||||
}
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
package org.lapaloma.aadd.redmetro.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
*
|
||||
* UtilidadesCine: Clase que realiza ....
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 23 ene 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class UtilidadesRedMetro {
|
||||
public static byte[] getBytesFromURL(String textoURL) {
|
||||
byte[] bytesImagen = null;
|
||||
URI url = null;
|
||||
try {
|
||||
url = new URI(textoURL);
|
||||
HttpURLConnection urlConnection = (HttpURLConnection) url.toURL().openConnection();
|
||||
urlConnection.addRequestProperty("User-Agent", "Mozilla");
|
||||
InputStream inputStream = urlConnection.getInputStream();
|
||||
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int len = 0;
|
||||
while ((len = inputStream.read(buffer)) != -1) {
|
||||
outStream.write(buffer, 0, len);
|
||||
}
|
||||
inputStream.close();
|
||||
bytesImagen = outStream.toByteArray();
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return bytesImagen;
|
||||
}
|
||||
|
||||
public static LocalDate parsearFecha(String fechaStr, String formato) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formato);
|
||||
|
||||
LocalDate fecha = LocalDate.parse(fechaStr, formatter);
|
||||
return fecha;
|
||||
}
|
||||
}
|
||||
@ -1,26 +1,15 @@
|
||||
package org.lapaloma.aadd.redmetro.vo;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
/**
|
||||
* Entidad que representa la tabla T_ACCESO.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "T_ACCESO")
|
||||
public class Acceso {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "cod_acceso")
|
||||
private int codigo;
|
||||
|
||||
@Column(name = "nombre", nullable = false, length = 100)
|
||||
private String nombre;
|
||||
|
||||
@Column(name = "acceso_discapacidad", columnDefinition = "int", nullable = false)
|
||||
private boolean accesoDiscapacidad;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "cod_estacion", nullable = false)
|
||||
private Estacion estacion;
|
||||
|
||||
public int getCodigo() {
|
||||
|
||||
@ -1,25 +1,15 @@
|
||||
package org.lapaloma.aadd.redmetro.vo;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
/**
|
||||
* Entidad que representa la tabla T_COCHERA.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "T_COCHERA")
|
||||
public class Cochera {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "cod_cochera")
|
||||
private int codigo;
|
||||
|
||||
@Column(name = "nombre", nullable = false, length = 255)
|
||||
private String nombre;
|
||||
|
||||
@Column(name = "direccion", nullable = false, length = 255)
|
||||
private String direccion;
|
||||
|
||||
@Column(name = "deposito", columnDefinition = "int")
|
||||
private boolean deposito; // 1 o 0
|
||||
|
||||
|
||||
|
||||
@ -1,25 +1,13 @@
|
||||
package org.lapaloma.aadd.redmetro.vo;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
/**
|
||||
* Entidad que representa la tabla T_COLOR.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "T_COLOR")
|
||||
public class Color {
|
||||
@Id
|
||||
// @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "cod_color")
|
||||
private int codigo;
|
||||
|
||||
@Column(name = "nombre", nullable = false, length = 100)
|
||||
private String nombre;
|
||||
|
||||
@Column(name = "cod_hexadecimal", nullable = false, length = 7)
|
||||
private String codHexadecimal;
|
||||
|
||||
public int getCodigo() {
|
||||
|
||||
@ -1,22 +1,13 @@
|
||||
package org.lapaloma.aadd.redmetro.vo;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
/**
|
||||
* Entidad que representa la tabla T_ESTACION.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "T_ESTACION")
|
||||
public class Estacion {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "cod_estacion")
|
||||
private int codigo;
|
||||
|
||||
@Column(name = "nombre", nullable = false, length = 100)
|
||||
private String nombre;
|
||||
|
||||
@Column(name = "direccion", nullable = false, length = 255)
|
||||
private String direccion;
|
||||
|
||||
public int getCodigo() {
|
||||
|
||||
@ -3,43 +3,21 @@ package org.lapaloma.aadd.redmetro.vo;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.UniqueConstraint;
|
||||
|
||||
/**
|
||||
* Entidad que representa la tabla T_LINEA.
|
||||
* Relación OneToOne con T_COLOR (código único).
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "T_LINEA", uniqueConstraints = @UniqueConstraint(columnNames = "cod_color"))
|
||||
public class Linea {
|
||||
@Id
|
||||
//@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "cod_linea")
|
||||
private int codigo;
|
||||
|
||||
@Column(name = "nombre_corto", nullable = false, length = 50)
|
||||
private String nombreCorto;
|
||||
|
||||
@Column(name = "nombre_largo", nullable = false, length = 100)
|
||||
private String nombreLargo;
|
||||
|
||||
@Column(name = "kilometros", nullable = false, precision = 5, scale = 2)
|
||||
private BigDecimal kilometros;
|
||||
|
||||
// Relación OneToOne con T_COLOR (clave única)
|
||||
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
|
||||
@JoinColumn(name = "cod_color", nullable = false)
|
||||
private Color color;
|
||||
|
||||
@Column(name = "imagen_linea", columnDefinition = "BYTEA")
|
||||
private byte[] imagenLinea;
|
||||
|
||||
public int getCodigo() {
|
||||
|
||||
@ -1,29 +1,17 @@
|
||||
package org.lapaloma.aadd.redmetro.vo;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
/**
|
||||
* Entidad que representa la tabla T_LINEA_ESTACION. Usa una clave primaria
|
||||
* compuesta mediante @EmbeddedId.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "T_LINEA_ESTACION")
|
||||
public class LineaEstacion {
|
||||
@EmbeddedId
|
||||
private LineaEstacionId id;
|
||||
|
||||
@Column(name = "orden", nullable = false)
|
||||
private int orden;
|
||||
|
||||
// Relaciones a T_LINEA y T_ESTACION mediante los campos de la clave compuesta
|
||||
@MapsId("codigoLinea")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "cod_linea", nullable = false)
|
||||
|
||||
private Linea linea;
|
||||
|
||||
@MapsId("codigoEstacion")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "cod_estacion", nullable = false)
|
||||
private Estacion estacion;
|
||||
|
||||
public LineaEstacion() {
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package org.lapaloma.aadd.redmetro.vo;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -8,14 +7,10 @@ import java.util.Objects;
|
||||
* Clase embebible que representa la clave primaria compuesta de
|
||||
* T_LINEA_ESTACION.
|
||||
*/
|
||||
@Embeddable
|
||||
public class LineaEstacionId implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column(name = "cod_linea")
|
||||
private Integer codigoLinea;
|
||||
|
||||
@Column(name = "cod_estacion")
|
||||
private Integer codigoEstacion;
|
||||
|
||||
public LineaEstacionId() {
|
||||
|
||||
@ -2,42 +2,20 @@ package org.lapaloma.aadd.redmetro.vo;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
/**
|
||||
* Entidad que representa la tabla T_TREN.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "T_TREN")
|
||||
public class Tren {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "cod_tren")
|
||||
private int codigo;
|
||||
|
||||
@Column(name = "modelo", nullable = false, length = 100)
|
||||
private String modelo;
|
||||
|
||||
@Column(name = "empresa_constructora", nullable = false, length = 255)
|
||||
private String empresaConstructora;
|
||||
|
||||
@Column(name = "fecha_incorporacion")
|
||||
private LocalDate fechaIncorporacion;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "cod_cochera", nullable = false)
|
||||
private Cochera cochera;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "cod_linea", nullable = false)
|
||||
private Linea linea;
|
||||
|
||||
public int getCodigo() {
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://xmlns.jcp.org/xml/ns/persistence
|
||||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
|
||||
version="2.1">
|
||||
|
||||
<persistence-unit name="UP_REDMETRO_POSTGRESQL" transaction-type="RESOURCE_LOCAL">
|
||||
<!-- Proveedor de persistencia JPA -->
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
|
||||
<!-- Clases a "mapear" -->
|
||||
<class>org.lapaloma.aadd.redmetro.vo.Cochera</class>
|
||||
<class>org.lapaloma.aadd.redmetro.vo.Color</class>
|
||||
<class>org.lapaloma.aadd.redmetro.vo.Linea</class>
|
||||
<class>org.lapaloma.aadd.redmetro.vo.Tren</class>
|
||||
<class>org.lapaloma.aadd.redmetro.vo.Estacion</class>
|
||||
<class>org.lapaloma.aadd.redmetro.vo.LineaEstacion</class>
|
||||
|
||||
<!-- Configuración de propiedades del SGDB (PostgreSQL) -->
|
||||
<properties>
|
||||
<property name="jakarta.persistence.jdbc.url" value="jdbc:postgresql://192.168.1.36:5432/red_metro_aadd"/>
|
||||
<property name="jakarta.persistence.jdbc.user" value="vdlp"/>
|
||||
<property name="jakarta.persistence.jdbc.password" value="postgresql_123"/>
|
||||
<property name="jakarta.persistence.jdbc.driver" value="org.postgresql.Driver"/>
|
||||
<!-- Configuración Hibernate -->
|
||||
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
|
||||
<property name="hibernate.show_sql" value="true"/>
|
||||
<property name="format_sql" value="true" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
@ -1,2 +1,16 @@
|
||||
url.conexion.mongodb=mongodb://admin:mongodb_123@192.168.1.36:27017
|
||||
bbdd.mongodb=red_metro_aadd
|
||||
# Información sobre la Base de datos MySQL
|
||||
driver.sgdb=com.mysql.cj.jdbc.Driver
|
||||
url.bbdd=jdbc:mysql://172.16.0.181:3306/red_metro
|
||||
usuario.sgdb=root
|
||||
clave.sgdb=mysql_123
|
||||
|
||||
# Información sobre la Base de datos MongoDB
|
||||
url.conexion.mongodb=mongodb://admin:mongodb_123@172.16.0.181:27017
|
||||
bbdd.mongodb=red_metro
|
||||
|
||||
# Información sobre Estaciones (XML)
|
||||
url.xml.estacion=https://dam2.decieloytierra.es/trenes_estaciones_accesos.xml
|
||||
|
||||
|
||||
# Información sobre Linea Estación (JSON)
|
||||
url.json.lineaestacion=https://dam2.decieloytierra.es/estaciones-lineas.json
|
||||
|
||||
Loading…
Reference in New Issue
Block a user