Commit inicial
This commit is contained in:
commit
21e005e3a2
41
.classpath
Normal file
41
.classpath
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/bin/
|
||||
*.class
|
||||
/target/
|
||||
23
.project
Normal file
23
.project
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>aadd_act5_3</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
2
.settings/org.eclipse.core.resources.prefs
Normal file
2
.settings/org.eclipse.core.resources.prefs
Normal file
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
8
.settings/org.eclipse.jdt.core.prefs
Normal file
8
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,8 @@
|
||||
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.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
|
||||
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
30
pom.xml
Normal file
30
pom.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<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>
|
||||
<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>
|
||||
<artifactId>mongodb-driver-sync</artifactId>
|
||||
<version>5.6.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
43
src/main/java/org/lapaloma/aadd/redmetro/AppRedMetro.java
Normal file
43
src/main/java/org/lapaloma/aadd/redmetro/AppRedMetro.java
Normal file
@ -0,0 +1,43 @@
|
||||
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.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
src/main/java/org/lapaloma/aadd/redmetro/dao/IColorDAO.java
Normal file
11
src/main/java/org/lapaloma/aadd/redmetro/dao/IColorDAO.java
Normal file
@ -0,0 +1,11 @@
|
||||
package org.lapaloma.aadd.redmetro.dao;
|
||||
|
||||
import org.lapaloma.aadd.redmetro.vo.Color;
|
||||
|
||||
public interface IColorDAO {
|
||||
Color obtenerColorPorID(int identificador);
|
||||
|
||||
void crearColor(Color color);
|
||||
|
||||
void actualizarColor(Color color);
|
||||
}
|
||||
16
src/main/java/org/lapaloma/aadd/redmetro/dao/ILineaDAO.java
Normal file
16
src/main/java/org/lapaloma/aadd/redmetro/dao/ILineaDAO.java
Normal file
@ -0,0 +1,16 @@
|
||||
package org.lapaloma.aadd.redmetro.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.lapaloma.aadd.redmetro.vo.Linea;
|
||||
|
||||
public interface ILineaDAO {
|
||||
Linea obtenerLineaPorID(int identificador);
|
||||
|
||||
List<Linea> obtenerListaLineas();
|
||||
|
||||
void crearLinea(Linea linea);
|
||||
|
||||
void actualizarLinea(Linea linea);
|
||||
|
||||
}
|
||||
@ -0,0 +1,75 @@
|
||||
package org.lapaloma.aadd.redmetro.dao.jpa;
|
||||
|
||||
import org.lapaloma.aadd.redmetro.dao.IColorDAO;
|
||||
import org.lapaloma.aadd.redmetro.gestores.GestorEntityManagerJPA;
|
||||
import org.lapaloma.aadd.redmetro.vo.Color;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
|
||||
public class ColorDaoJPA implements IColorDAO {
|
||||
@Override
|
||||
public Color obtenerColorPorID(int codigo) {
|
||||
Color color = null;
|
||||
|
||||
// try con recursos "cerrables": Session
|
||||
try (EntityManager gestorEntidades = GestorEntityManagerJPA.getEntityManager()) {
|
||||
color = gestorEntidades.find(Color.class, codigo);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void crearColor(Color color) {
|
||||
EntityManager gestorEntidades = null;
|
||||
EntityTransaction transaccion = null;
|
||||
|
||||
try {
|
||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||
transaccion = gestorEntidades.getTransaction();
|
||||
transaccion.begin();
|
||||
|
||||
gestorEntidades.persist(color);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (Exception e) {
|
||||
if (transaccion != null && transaccion.isActive()) {
|
||||
transaccion.rollback();
|
||||
}
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (gestorEntidades != null) {
|
||||
gestorEntidades.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actualizarColor(Color color) {
|
||||
EntityManager gestorEntidades = null;
|
||||
EntityTransaction transaccion = null;
|
||||
|
||||
try {
|
||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||
transaccion = gestorEntidades.getTransaction();
|
||||
transaccion.begin();
|
||||
|
||||
if (!gestorEntidades.contains(color))
|
||||
gestorEntidades.merge(color);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (Exception e) {
|
||||
if (transaccion != null && transaccion.isActive()) {
|
||||
transaccion.rollback();
|
||||
}
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (gestorEntidades != null) {
|
||||
gestorEntidades.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
package org.lapaloma.aadd.redmetro.dao.mgdb;
|
||||
|
||||
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.vo.Color;
|
||||
import org.lapaloma.aadd.redmetro.vo.Linea;
|
||||
|
||||
import com.mongodb.client.FindIterable;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
|
||||
import es.palomafp.aadd.inm.vo.Pais;
|
||||
|
||||
/**
|
||||
*
|
||||
* 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 idMongoDB = documentoPais.getInteger("_id"); int identificador =
|
||||
* documentoPais.getInteger("identificador"); String nombrePais =
|
||||
* documentoPais.getString("nombre"); String capital =
|
||||
* documentoPais.getString("capital");
|
||||
*
|
||||
* Document documentoColor= (Document) documentoPais.get("continente"); String
|
||||
* codigoContinente = documentoContinente.getString("codigo"); String
|
||||
* nombreContinente = documentoContinente.getString("nombre");
|
||||
*
|
||||
* Color color = new Color(); color.setCodigo(codigoContinente);
|
||||
* color.setNombreContinente(nombreContinente);
|
||||
*
|
||||
* linea = new Linea(); linea.setIdentificador(identificador);
|
||||
* linea.setNombrePais(nombrePais); linea.setCapital(capital);
|
||||
* linea.setColor(color);
|
||||
*/
|
||||
|
||||
return linea;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package org.lapaloma.aadd.redmetro.gestores;
|
||||
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
|
||||
/**
|
||||
*
|
||||
* GestorConexionMongoDB: Clase que realiza la gestión de Conexiones a MongoDB.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 30 enero 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class GestorConexionMongoDB {
|
||||
private static MongoDatabase mongoDBDatabase= null;
|
||||
|
||||
private GestorConexionMongoDB() { // Constructor privado para evitar instanciación
|
||||
}
|
||||
|
||||
// Carga la configuración desde META-INF/persistence.xml
|
||||
static {
|
||||
// Cadena de conexion con la base de datos MongoDB
|
||||
String uri = GestorFicheroConfiguracion.obtenerValor("url.conexion.mongodb");
|
||||
// Se abre la conexión con MongoDB
|
||||
MongoClient clienteMongo = MongoClients.create(uri);
|
||||
|
||||
// Obtener una base de datos MongoDB desde Java
|
||||
String bbddMongoDB= GestorFicheroConfiguracion.obtenerValor("bbdd.mongodb");
|
||||
mongoDBDatabase = clienteMongo.getDatabase(bbddMongoDB);
|
||||
}
|
||||
|
||||
public static MongoDatabase getMongoDatabase() {
|
||||
return mongoDBDatabase;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
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_PROYECTOSIES_ODB");
|
||||
} 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,39 @@
|
||||
/**
|
||||
* GestorFicheroConfiguracion: clase utilitaria para leer propiedades del archivo application.properties.
|
||||
* Provee un método estático que devuelve el valor asociado a una clave.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 25 nov 2025
|
||||
*/
|
||||
package org.lapaloma.aadd.redmetro.gestores;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
public class GestorFicheroConfiguracion {
|
||||
private static final Properties PROPIEDADES = new Properties();
|
||||
|
||||
static {
|
||||
try (InputStream is = GestorFicheroConfiguracion.class.getClassLoader()
|
||||
.getResourceAsStream("conf.properties")) {
|
||||
if (is != null) {
|
||||
PROPIEDADES.load(is);
|
||||
} else {
|
||||
throw new IllegalStateException("No se encontró application.properties en el classpath");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Error al cargar application.properties", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene el valor asociado a la clave especificada.
|
||||
*
|
||||
* @param clave la clave a buscar
|
||||
* @return el valor o {@code null} si no existe
|
||||
*/
|
||||
public static String obtenerValor(String clave) {
|
||||
return PROPIEDADES.getProperty(clave);
|
||||
}
|
||||
}
|
||||
63
src/main/java/org/lapaloma/aadd/redmetro/vo/Acceso.java
Normal file
63
src/main/java/org/lapaloma/aadd/redmetro/vo/Acceso.java
Normal file
@ -0,0 +1,63 @@
|
||||
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() {
|
||||
return codigo;
|
||||
}
|
||||
|
||||
public void setCodigo(int codigo) {
|
||||
this.codigo = codigo;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public boolean isAccesoDiscapacidad() {
|
||||
return accesoDiscapacidad;
|
||||
}
|
||||
|
||||
public void setAccesoDiscapacidad(boolean accesoDiscapacidad) {
|
||||
this.accesoDiscapacidad = accesoDiscapacidad;
|
||||
}
|
||||
|
||||
public Estacion getEstacion() {
|
||||
return estacion;
|
||||
}
|
||||
|
||||
public void setEstacion(Estacion estacion) {
|
||||
this.estacion = estacion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Acceso [codigo=" + codigo + ", nombre=" + nombre + ", accesoDiscapacidad=" + accesoDiscapacidad
|
||||
+ ", estacion=" + estacion + "]\n";
|
||||
}
|
||||
}
|
||||
65
src/main/java/org/lapaloma/aadd/redmetro/vo/Cochera.java
Normal file
65
src/main/java/org/lapaloma/aadd/redmetro/vo/Cochera.java
Normal file
@ -0,0 +1,65 @@
|
||||
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
|
||||
|
||||
|
||||
public int getCodigo() {
|
||||
return codigo;
|
||||
}
|
||||
|
||||
public void setCodigo(int codigo) {
|
||||
this.codigo = codigo;
|
||||
}
|
||||
|
||||
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 boolean isDeposito() {
|
||||
return deposito;
|
||||
}
|
||||
|
||||
public void setDeposito(boolean deposito) {
|
||||
this.deposito = deposito;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Cochera [codigo=" + codigo + ", nombre=" + nombre + ", direccion=" + direccion + ", deposito="
|
||||
+ deposito + "]\n";
|
||||
}
|
||||
|
||||
}
|
||||
51
src/main/java/org/lapaloma/aadd/redmetro/vo/Color.java
Normal file
51
src/main/java/org/lapaloma/aadd/redmetro/vo/Color.java
Normal file
@ -0,0 +1,51 @@
|
||||
package org.lapaloma.aadd.redmetro.vo;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
return codigo;
|
||||
}
|
||||
|
||||
public void setCodigo(int codigo) {
|
||||
this.codigo = codigo;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public String getCodHexadecimal() {
|
||||
return codHexadecimal;
|
||||
}
|
||||
|
||||
public void setCodHexadecimal(String codHexadecimal) {
|
||||
this.codHexadecimal = codHexadecimal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Color [codigo=" + codigo + ", nombre=" + nombre + ", codHexadecimal=" + codHexadecimal + "]\n";
|
||||
}
|
||||
|
||||
}
|
||||
51
src/main/java/org/lapaloma/aadd/redmetro/vo/Estacion.java
Normal file
51
src/main/java/org/lapaloma/aadd/redmetro/vo/Estacion.java
Normal file
@ -0,0 +1,51 @@
|
||||
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() {
|
||||
return codigo;
|
||||
}
|
||||
|
||||
public void setCodigo(int codigo) {
|
||||
this.codigo = codigo;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Estacion [codigo=" + codigo + ", nombre=" + nombre + ", direccion=" + direccion + "]\n";
|
||||
}
|
||||
|
||||
}
|
||||
89
src/main/java/org/lapaloma/aadd/redmetro/vo/Linea.java
Normal file
89
src/main/java/org/lapaloma/aadd/redmetro/vo/Linea.java
Normal file
@ -0,0 +1,89 @@
|
||||
package org.lapaloma.aadd.redmetro.vo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
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.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
/**
|
||||
* Entidad que representa la tabla T_LINEA.
|
||||
* Relación OneToOne con T_COLOR (código único).
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "T_LINEA")
|
||||
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;
|
||||
|
||||
// Relación OneToOne con T_COLOR (clave única)
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "cod_color", nullable = false, unique = true)
|
||||
private Color color;
|
||||
|
||||
@Column(name = "kilometros", nullable = false, precision = 5, scale = 2)
|
||||
private BigDecimal kilometros;
|
||||
|
||||
|
||||
public int getCodigo() {
|
||||
return codigo;
|
||||
}
|
||||
|
||||
public void setCodigo(int codigo) {
|
||||
this.codigo = codigo;
|
||||
}
|
||||
|
||||
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 BigDecimal getKilometros() {
|
||||
return kilometros;
|
||||
}
|
||||
|
||||
public void setKilometros(BigDecimal kilometros) {
|
||||
this.kilometros = kilometros;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Linea [codigo=" + codigo + ", nombreCorto=" + nombreCorto + ", nombreLargo=" + nombreLargo + ", color="
|
||||
+ color + ", kilometros=" + kilometros + "]\n";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
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() {
|
||||
}
|
||||
|
||||
public LineaEstacion(Linea linea, Estacion estacion, Integer orden) {
|
||||
this.linea = linea;
|
||||
this.estacion = estacion;
|
||||
this.orden = orden;
|
||||
this.id = new LineaEstacionId(linea.getCodigo(), estacion.getCodigo());
|
||||
}
|
||||
|
||||
public LineaEstacionId getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(LineaEstacionId id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getOrden() {
|
||||
return orden;
|
||||
}
|
||||
|
||||
public void setOrden(int orden) {
|
||||
this.orden = orden;
|
||||
}
|
||||
|
||||
public Linea getLinea() {
|
||||
return linea;
|
||||
}
|
||||
|
||||
public void setLinea(Linea linea) {
|
||||
this.linea = linea;
|
||||
}
|
||||
|
||||
public Estacion getEstacion() {
|
||||
return estacion;
|
||||
}
|
||||
|
||||
public void setEstacion(Estacion estacion) {
|
||||
this.estacion = estacion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LineaEstacion [id=" + id + ", orden=" + orden + ", linea=" + linea + ", estacion=" + estacion + "]\n";
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
package org.lapaloma.aadd.redmetro.vo;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.io.Serializable;
|
||||
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() {
|
||||
}
|
||||
|
||||
public LineaEstacionId(Integer codLinea, Integer codEstacion) {
|
||||
this.codigoLinea = codLinea;
|
||||
this.codigoEstacion = codEstacion;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
LineaEstacionId claveObjetoNuevo = (LineaEstacionId) o;
|
||||
return Objects.equals(codigoLinea, claveObjetoNuevo.codigoLinea) && Objects.equals(codigoEstacion, claveObjetoNuevo.codigoEstacion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(codigoLinea, codigoEstacion);
|
||||
}
|
||||
}
|
||||
97
src/main/java/org/lapaloma/aadd/redmetro/vo/Tren.java
Normal file
97
src/main/java/org/lapaloma/aadd/redmetro/vo/Tren.java
Normal file
@ -0,0 +1,97 @@
|
||||
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() {
|
||||
return codigo;
|
||||
}
|
||||
|
||||
public void setCodigo(int codigo) {
|
||||
this.codigo = codigo;
|
||||
}
|
||||
|
||||
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 [codigo=" + codigo + ", modelo=" + modelo + ", empresaConstructora=" + empresaConstructora
|
||||
+ ", fechaIncorporacion=" + fechaIncorporacion + ", cochera=" + cochera + ", linea=" + linea + "]\n";
|
||||
}
|
||||
|
||||
}
|
||||
33
src/main/resources/META-INF/persistence.xml
Normal file
33
src/main/resources/META-INF/persistence.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<?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/Mapamundi"/>
|
||||
<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>
|
||||
2
src/main/resources/conf.properties
Normal file
2
src/main/resources/conf.properties
Normal file
@ -0,0 +1,2 @@
|
||||
url.conexion.mongodb=mongodb://admin:mongodb_123@172.16.0.181:27017
|
||||
bbdd.mongodb=MapaMundi
|
||||
Loading…
Reference in New Issue
Block a user