Commit inicial
This commit is contained in:
commit
3c1d61eff1
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_5</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
|
||||||
13
.settings/org.eclipse.jdt.core.prefs
Normal file
13
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=24
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=24
|
||||||
|
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=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=24
|
||||||
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
|
||||||
45
pom.xml
Normal file
45
pom.xml
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<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.coi.jjoo</groupId>
|
||||||
|
<artifactId>aadd_act5_5</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 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>
|
||||||
|
|
||||||
|
<!-- 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/org.hibernate.orm/hibernate-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate.orm</groupId>
|
||||||
|
<artifactId>hibernate-core</artifactId>
|
||||||
|
<version>7.1.11.Final</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>
|
||||||
|
|
||||||
|
<!-- Source: https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.42</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm;
|
||||||
|
|
||||||
|
import org.coi.juegosolimpicos.inm.gestores.GestorSesionHibernate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AppPrincipalJJOO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
GestorSesionHibernate.getSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
19
src/main/java/org/coi/juegosolimpicos/inm/dao/IAtleta.java
Normal file
19
src/main/java/org/coi/juegosolimpicos/inm/dao/IAtleta.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.dao;
|
||||||
|
|
||||||
|
import org.coi.juegosolimpicos.inm.excepcion.JuegosOlimpicosExcepcion;
|
||||||
|
import org.coi.juegosolimpicos.inm.vo.Atleta;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface IAtleta {
|
||||||
|
public Atleta obtenerAtletaPorID(int idAtleta) throws JuegosOlimpicosExcepcion;
|
||||||
|
public Atleta obtenerAtletaPorNombreApellidos(String nombre, String apellidos) throws JuegosOlimpicosExcepcion;
|
||||||
|
public void crearAtleta(Atleta atleta) throws JuegosOlimpicosExcepcion;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.dao;
|
||||||
|
|
||||||
|
import org.coi.juegosolimpicos.inm.excepcion.JuegosOlimpicosExcepcion;
|
||||||
|
import org.coi.juegosolimpicos.inm.vo.AtletaDisciplinaJuego;
|
||||||
|
import org.coi.juegosolimpicos.inm.vo.AtletaDisciplinaJuego.AtletaDisciplinaJuegoID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface IAtletaDisciplinaJuego {
|
||||||
|
public AtletaDisciplinaJuego obtenerAtletaDisciplinaJuegoPorId(AtletaDisciplinaJuegoID identificador) throws JuegosOlimpicosExcepcion;
|
||||||
|
public void crearAtletaDisciplinaJuego(AtletaDisciplinaJuego atletaDisciplinaJuego) throws JuegosOlimpicosExcepcion;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.coi.juegosolimpicos.inm.excepcion.JuegosOlimpicosExcepcion;
|
||||||
|
import org.coi.juegosolimpicos.inm.vo.Disciplina;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface IDisciplina {
|
||||||
|
public Disciplina obtenerDisciplinaPorCodigo(String codigoDisciplina) throws JuegosOlimpicosExcepcion;
|
||||||
|
public List<Disciplina> obtenerListaDisciplinas() throws JuegosOlimpicosExcepcion;
|
||||||
|
public void crearDisciplina(Disciplina disciplinaOlimpica)throws JuegosOlimpicosExcepcion;
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.dao;
|
||||||
|
|
||||||
|
import org.coi.juegosolimpicos.inm.excepcion.JuegosOlimpicosExcepcion;
|
||||||
|
import org.coi.juegosolimpicos.inm.vo.JuegoOlimpico;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface IJuegoOlimpico {
|
||||||
|
public JuegoOlimpico obtenerJuegoOlimpicoPorCodigo(String codigoJuegoOlimpico) throws JuegosOlimpicosExcepcion;
|
||||||
|
public void crearJuegoOlimpico(JuegoOlimpico juegoOlimpico) throws JuegosOlimpicosExcepcion;
|
||||||
|
}
|
||||||
17
src/main/java/org/coi/juegosolimpicos/inm/dao/IMascota.java
Normal file
17
src/main/java/org/coi/juegosolimpicos/inm/dao/IMascota.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.dao;
|
||||||
|
|
||||||
|
import org.coi.juegosolimpicos.inm.excepcion.JuegosOlimpicosExcepcion;
|
||||||
|
import org.coi.juegosolimpicos.inm.vo.Mascota;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface IMascota {
|
||||||
|
public Mascota obtenerMascotaPorId(int idMascota) throws JuegosOlimpicosExcepcion;
|
||||||
|
public void crearMascota(Mascota mascota) throws JuegosOlimpicosExcepcion;
|
||||||
|
}
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.dao.hbnt;
|
||||||
|
|
||||||
|
import org.coi.juegosolimpicos.inm.dao.IAtletaDisciplinaJuego;
|
||||||
|
import org.coi.juegosolimpicos.inm.excepcion.JuegosOlimpicosExcepcion;
|
||||||
|
import org.coi.juegosolimpicos.inm.gestores.GestorSesionHibernate;
|
||||||
|
import org.coi.juegosolimpicos.inm.vo.AtletaDisciplinaJuego;
|
||||||
|
import org.coi.juegosolimpicos.inm.vo.AtletaDisciplinaJuego.AtletaDisciplinaJuegoID;
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AtletaDisciplinaJuegoDaoHibernate implements IAtletaDisciplinaJuego {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearAtletaDisciplinaJuego(AtletaDisciplinaJuego atletaDisciplinaJuego)
|
||||||
|
throws JuegosOlimpicosExcepcion {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
|
||||||
|
Session sesion = null;
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
sesion.persist(atletaDisciplinaJuego);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
throw new JuegosOlimpicosExcepcion(e, JuegosOlimpicosExcepcion.ERROR_INSERCION, getClass());
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AtletaDisciplinaJuego obtenerAtletaDisciplinaJuegoPorId(AtletaDisciplinaJuegoID identificador)
|
||||||
|
throws JuegosOlimpicosExcepcion {
|
||||||
|
AtletaDisciplinaJuego atletaDJ = null;
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionHibernate.getSession();) {
|
||||||
|
atletaDJ = sesion.find(AtletaDisciplinaJuego.class, identificador);
|
||||||
|
} catch (HibernateException e) {
|
||||||
|
throw new JuegosOlimpicosExcepcion(e, JuegosOlimpicosExcepcion.ERROR_CONSULTA, getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
return atletaDJ;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.dao.hbnt;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.coi.juegosolimpicos.inm.dao.IDisciplina;
|
||||||
|
import org.coi.juegosolimpicos.inm.excepcion.JuegosOlimpicosExcepcion;
|
||||||
|
import org.coi.juegosolimpicos.inm.gestores.GestorSesionHibernate;
|
||||||
|
import org.coi.juegosolimpicos.inm.vo.Disciplina;
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DisciplinaDaoHibernate implements IDisciplina {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Disciplina> obtenerListaDisciplinas() throws JuegosOlimpicosExcepcion {
|
||||||
|
List<Disciplina> listaDisciplinasOlimpicas = null;
|
||||||
|
return listaDisciplinasOlimpicas;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearDisciplina(Disciplina disciplinaOlimpica) throws JuegosOlimpicosExcepcion {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
|
||||||
|
Session sesion = null;
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
sesion.persist(disciplinaOlimpica);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
throw new JuegosOlimpicosExcepcion(e, JuegosOlimpicosExcepcion.ERROR_INSERCION, getClass());
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Disciplina obtenerDisciplinaPorCodigo(String codigoDisciplina) throws JuegosOlimpicosExcepcion {
|
||||||
|
Disciplina disciplina = null;
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionHibernate.getSession();) {
|
||||||
|
disciplina = sesion.find(Disciplina.class, codigoDisciplina);
|
||||||
|
} catch (HibernateException e) {
|
||||||
|
throw new JuegosOlimpicosExcepcion(e, JuegosOlimpicosExcepcion.ERROR_CONSULTA, getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
return disciplina;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.dao.hbnt;
|
||||||
|
|
||||||
|
import org.coi.juegosolimpicos.inm.dao.IJuegoOlimpico;
|
||||||
|
import org.coi.juegosolimpicos.inm.excepcion.JuegosOlimpicosExcepcion;
|
||||||
|
import org.coi.juegosolimpicos.inm.gestores.GestorSesionHibernate;
|
||||||
|
import org.coi.juegosolimpicos.inm.vo.JuegoOlimpico;
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class JuegoOlimpicoDaoHibernate implements IJuegoOlimpico {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearJuegoOlimpico(JuegoOlimpico juegoOlimpico) throws JuegosOlimpicosExcepcion {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
|
||||||
|
Session sesion = null;
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
sesion.persist(juegoOlimpico);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
throw new JuegosOlimpicosExcepcion(e, JuegosOlimpicosExcepcion.ERROR_INSERCION, getClass());
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JuegoOlimpico obtenerJuegoOlimpicoPorCodigo(String codigoJuegoOlimpico) throws JuegosOlimpicosExcepcion {
|
||||||
|
JuegoOlimpico juegoOlimpico = null;
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionHibernate.getSession();) {
|
||||||
|
juegoOlimpico = sesion.find(JuegoOlimpico.class, codigoJuegoOlimpico);
|
||||||
|
} catch (HibernateException e) {
|
||||||
|
throw new JuegosOlimpicosExcepcion(e, JuegosOlimpicosExcepcion.ERROR_CONSULTA, getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
return juegoOlimpico;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.dao.hbnt;
|
||||||
|
|
||||||
|
import org.coi.juegosolimpicos.inm.dao.IMascota;
|
||||||
|
import org.coi.juegosolimpicos.inm.excepcion.JuegosOlimpicosExcepcion;
|
||||||
|
import org.coi.juegosolimpicos.inm.gestores.GestorSesionHibernate;
|
||||||
|
import org.coi.juegosolimpicos.inm.vo.Mascota;
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MascotaDaoHibernate implements IMascota {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearMascota(Mascota mascota) throws JuegosOlimpicosExcepcion {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
|
||||||
|
Session sesion = null;
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
sesion.persist(mascota);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
throw new JuegosOlimpicosExcepcion(e, JuegosOlimpicosExcepcion.ERROR_INSERCION, getClass());
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mascota obtenerMascotaPorId(int idMascota) throws JuegosOlimpicosExcepcion {
|
||||||
|
Mascota mascota = null;
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionHibernate.getSession();) {
|
||||||
|
mascota = sesion.find(Mascota.class, idMascota);
|
||||||
|
} catch (HibernateException e) {
|
||||||
|
throw new JuegosOlimpicosExcepcion(e, JuegosOlimpicosExcepcion.ERROR_CONSULTA, getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
return mascota;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,120 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.dao.jdbc;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.coi.juegosolimpicos.inm.dao.IAtleta;
|
||||||
|
import org.coi.juegosolimpicos.inm.excepcion.JuegosOlimpicosExcepcion;
|
||||||
|
import org.coi.juegosolimpicos.inm.gestores.GestorConexionJDBC;
|
||||||
|
import org.coi.juegosolimpicos.inm.vo.Atleta;
|
||||||
|
import org.coi.juegosolimpicos.inm.vo.Sexo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AtletaDaoJDBC implements IAtleta {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearAtleta(Atleta atleta) throws JuegosOlimpicosExcepcion {
|
||||||
|
|
||||||
|
String sentenciaSQL = """
|
||||||
|
INSERT INTO T_ATLETA (nombre, apellidos, fecha_nacimiento, sexo)
|
||||||
|
VALUES (?, ?, ?, ?)
|
||||||
|
""";
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Connection, Statement
|
||||||
|
try (Connection conexion = GestorConexionJDBC.getConexionSGDB();
|
||||||
|
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||||
|
|
||||||
|
sentenciaJDBCPreparada.setString(1, atleta.getNombre());
|
||||||
|
sentenciaJDBCPreparada.setString(2, atleta.getApellidos());
|
||||||
|
sentenciaJDBCPreparada.setDate(3, Date.valueOf(atleta.getFechaNacimiento()));
|
||||||
|
sentenciaJDBCPreparada.setString(4, atleta.getSexo().name());
|
||||||
|
System.out.println(sentenciaJDBCPreparada);
|
||||||
|
|
||||||
|
sentenciaJDBCPreparada.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new JuegosOlimpicosExcepcion(e, JuegosOlimpicosExcepcion.ERROR_INSERCION, getClass());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Atleta obtenerAtletaPorNombreApellidos(String nombre, String apellidos) throws JuegosOlimpicosExcepcion {
|
||||||
|
Atleta atleta = null;
|
||||||
|
|
||||||
|
String sentenciaSQL = """
|
||||||
|
SELECT * FROM T_ATLETA
|
||||||
|
where nombre=?
|
||||||
|
and apellidos=?
|
||||||
|
""";
|
||||||
|
try (Connection conexion = GestorConexionJDBC.getConexionSGDB();
|
||||||
|
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||||
|
sentenciaJDBCPreparada.setString(1, nombre);
|
||||||
|
sentenciaJDBCPreparada.setString(2, apellidos);
|
||||||
|
System.out.println(sentenciaJDBCPreparada);
|
||||||
|
|
||||||
|
ResultSet resultadoSentencia = null;
|
||||||
|
resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
||||||
|
|
||||||
|
// Asumo que sólo se espera un resultado, por lo que no es necesario un bucle while
|
||||||
|
if (resultadoSentencia.next()) {
|
||||||
|
atleta = getAtletaFromResultSet(resultadoSentencia);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new JuegosOlimpicosExcepcion(e, JuegosOlimpicosExcepcion.ERROR_CONSULTA, getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
return atleta;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Atleta obtenerAtletaPorID(int idAtleta) throws JuegosOlimpicosExcepcion {
|
||||||
|
Atleta atleta = null;
|
||||||
|
|
||||||
|
String sentenciaSQL = """
|
||||||
|
SELECT * FROM T_ATLETA
|
||||||
|
where identificador=?
|
||||||
|
""";
|
||||||
|
try (Connection conexion = GestorConexionJDBC.getConexionSGDB();
|
||||||
|
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||||
|
sentenciaJDBCPreparada.setInt(1, idAtleta);
|
||||||
|
System.out.println(sentenciaJDBCPreparada);
|
||||||
|
|
||||||
|
ResultSet resultadoSentencia = null;
|
||||||
|
resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
||||||
|
|
||||||
|
if (resultadoSentencia.next()) {
|
||||||
|
atleta = getAtletaFromResultSet(resultadoSentencia);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new JuegosOlimpicosExcepcion(e, JuegosOlimpicosExcepcion.ERROR_CONSULTA, getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
return atleta;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Atleta getAtletaFromResultSet(ResultSet resultadoSentencia) throws SQLException {
|
||||||
|
Atleta atleta = new Atleta();
|
||||||
|
|
||||||
|
atleta.setIdentificador(resultadoSentencia.getInt("identificador"));
|
||||||
|
atleta.setNombre(resultadoSentencia.getString("nombre"));
|
||||||
|
atleta.setApellidos(resultadoSentencia.getString("apellidos"));
|
||||||
|
atleta.setFechaNacimiento(resultadoSentencia.getDate("fecha_nacimiento").toLocalDate());
|
||||||
|
String sexo = resultadoSentencia.getString("sexo");
|
||||||
|
atleta.setSexo(Sexo.valueOf(sexo));
|
||||||
|
|
||||||
|
return atleta;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,72 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.dao.mngbd;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.coi.juegosolimpicos.inm.dao.IDisciplina;
|
||||||
|
import org.coi.juegosolimpicos.inm.excepcion.JuegosOlimpicosExcepcion;
|
||||||
|
import org.coi.juegosolimpicos.inm.gestores.GestorConexionMongoDB;
|
||||||
|
import org.coi.juegosolimpicos.inm.vo.Disciplina;
|
||||||
|
|
||||||
|
import com.mongodb.client.FindIterable;
|
||||||
|
import com.mongodb.client.MongoCollection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DisciplinaDaoMongoDB implements IDisciplina {
|
||||||
|
public final static String COLLECCION_DISCIPLINA="C_DISCIPLINA";
|
||||||
|
private final static String VALOR_SI="Sí";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Disciplina> obtenerListaDisciplinas() throws JuegosOlimpicosExcepcion {
|
||||||
|
final List<Disciplina> listaDisciplinasOlimpicas=new ArrayList<Disciplina>();
|
||||||
|
MongoCollection coleccionMongoDB = null;
|
||||||
|
try{
|
||||||
|
coleccionMongoDB= GestorConexionMongoDB.getMongoDatabase().getCollection(COLLECCION_DISCIPLINA);
|
||||||
|
|
||||||
|
FindIterable<Document> documentosIterables= coleccionMongoDB.find();
|
||||||
|
if(documentosIterables!=null) {
|
||||||
|
// Usando expresión Lambda
|
||||||
|
documentosIterables.forEach(documentoDisciplina -> listaDisciplinasOlimpicas.add(getDisciplinaFromDocumento(documentoDisciplina)));
|
||||||
|
}
|
||||||
|
}catch (Exception exc) {
|
||||||
|
throw new JuegosOlimpicosExcepcion(exc, JuegosOlimpicosExcepcion.ERROR_CONSULTA, DisciplinaDaoMongoDB.class);
|
||||||
|
}
|
||||||
|
return listaDisciplinasOlimpicas;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void crearDisciplina(Disciplina disciplinaOlimpica) throws JuegosOlimpicosExcepcion {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
private Disciplina getDisciplinaFromDocumento(Document docDisciplina) {
|
||||||
|
Disciplina disciplina=null;
|
||||||
|
if(docDisciplina!=null) {
|
||||||
|
String codigo= docDisciplina.getString("codigo");
|
||||||
|
String descripcion= docDisciplina.getString("descripcion");
|
||||||
|
String es_individual= docDisciplina.getString("es_individual");
|
||||||
|
|
||||||
|
disciplina=new Disciplina();
|
||||||
|
disciplina.setCodigo(codigo);
|
||||||
|
disciplina.setNombre(descripcion);
|
||||||
|
disciplina.setDisciplinaIndividual(false);
|
||||||
|
if (es_individual.equals(VALOR_SI)) {
|
||||||
|
disciplina.setDisciplinaIndividual(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return disciplina;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Disciplina obtenerDisciplinaPorCodigo(String codigoDisciplina) throws JuegosOlimpicosExcepcion {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
package org.coi.juegosolimpicos.inm.excepcion;
|
||||||
|
|
||||||
|
public class JuegosOlimpicosExcepcion extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public static final int ERROR_GENERAL = 0;
|
||||||
|
public static final int ERROR_GESTION_CONEXION = 1;
|
||||||
|
public static final int ERROR_CONSULTA = 2;
|
||||||
|
public static final int ERROR_INSERCION = 3;
|
||||||
|
public static final int ERROR_ACTUALIZACION = 4;
|
||||||
|
public static final int ERROR_BORRADO = 5;
|
||||||
|
|
||||||
|
private int codigoError;
|
||||||
|
private Class<?> claseOrigen;
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
public JuegosOlimpicosExcepcion(Exception excepcion, int tipoError, Class claseOrigenError) {
|
||||||
|
super(excepcion);
|
||||||
|
this.codigoError = tipoError;
|
||||||
|
this.claseOrigen = claseOrigenError;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCodigoError() {
|
||||||
|
return codigoError;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCodigoError(int codigoError) {
|
||||||
|
this.codigoError = codigoError;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<?> getClaseOrigen() {
|
||||||
|
return claseOrigen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClaseOrigen(Class<?> claseOrigen) {
|
||||||
|
this.claseOrigen = claseOrigen;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package org.coi.juegosolimpicos.inm.gestores;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.coi.juegosolimpicos.inm.excepcion.JuegosOlimpicosExcepcion;
|
||||||
|
|
||||||
|
public class GestorConexionJDBC {
|
||||||
|
|
||||||
|
// Evita que pueda construirse un objeto de la clase.
|
||||||
|
private GestorConexionJDBC() {}
|
||||||
|
|
||||||
|
public static Connection getConexionSGDB() throws JuegosOlimpicosExcepcion{
|
||||||
|
Connection conexionSGDB = null;
|
||||||
|
|
||||||
|
// Datos URL
|
||||||
|
String urlBBDD =GestorFicheroConfiguracion.obtenerValor("jdbc.url");
|
||||||
|
|
||||||
|
String usuario = GestorFicheroConfiguracion.obtenerValor("jdbc.usuario");
|
||||||
|
String contrasenya =GestorFicheroConfiguracion.obtenerValor("jdbc.password");
|
||||||
|
|
||||||
|
try {
|
||||||
|
String claseDriver= GestorFicheroConfiguracion.obtenerValor("jdbc.driver");
|
||||||
|
Class.forName(claseDriver);
|
||||||
|
|
||||||
|
conexionSGDB = DriverManager.getConnection(urlBBDD, usuario, contrasenya);
|
||||||
|
} catch (SQLException | ClassNotFoundException e) {
|
||||||
|
throw new JuegosOlimpicosExcepcion(e, JuegosOlimpicosExcepcion.ERROR_GESTION_CONEXION, GestorConexionJDBC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
return conexionSGDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
package org.coi.juegosolimpicos.inm.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("mongodb.url");
|
||||||
|
// Se abre la conexión con MongoDB
|
||||||
|
MongoClient clienteMongo = MongoClients.create(uri);
|
||||||
|
|
||||||
|
// Obtener una base de datos MongoDB desde Java
|
||||||
|
String bbddMongoDB= GestorFicheroConfiguracion.obtenerValor("mongodb.bbdd");
|
||||||
|
mongoDBDatabase = clienteMongo.getDatabase(bbddMongoDB);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MongoDatabase getMongoDatabase() {
|
||||||
|
return mongoDBDatabase;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.gestores;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GestorFicheroConfiguracion {
|
||||||
|
private static final Properties PROPIEDADES = new Properties();
|
||||||
|
|
||||||
|
static {
|
||||||
|
try (InputStream is = GestorFicheroConfiguracion.class.getClassLoader()
|
||||||
|
.getResourceAsStream("config.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
package org.coi.juegosolimpicos.inm.gestores;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.cfg.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* GestorSesionesHibernate: Clase que gestiona las sesiones de Hibernate
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GestorSesionHibernate {
|
||||||
|
private static SessionFactory sessionFactory = null;
|
||||||
|
|
||||||
|
private GestorSesionHibernate() {// Constructor privado para evitar instanciación
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga la configuración desde hibernate.cfg.xml
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
sessionFactory = new Configuration().configure().buildSessionFactory();
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
System.err.println("Error en SessionFactory: " + ex);
|
||||||
|
throw new ExceptionInInitializerError(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Session getSession() {
|
||||||
|
return sessionFactory.openSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Session getCurrentSession() {
|
||||||
|
return sessionFactory.getCurrentSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void cerrarFactoria() {
|
||||||
|
if (sessionFactory != null) {
|
||||||
|
sessionFactory.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/main/java/org/coi/juegosolimpicos/inm/vo/Atleta.java
Normal file
47
src/main/java/org/coi/juegosolimpicos/inm/vo/Atleta.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.vo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.EnumType;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@Table(name = "T_ATLETA")
|
||||||
|
public class Atleta implements Serializable{
|
||||||
|
private static final long serialVersionUID = 840837584782300608L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "identificador")
|
||||||
|
private int identificador;
|
||||||
|
|
||||||
|
@Column(name = "nombre")
|
||||||
|
private String nombre;
|
||||||
|
|
||||||
|
@Column(name = "apellidos")
|
||||||
|
private String apellidos;
|
||||||
|
|
||||||
|
@Column(name = "fecha_nacimiento")
|
||||||
|
private LocalDate fechaNacimiento;
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
@Column(name = "sexo", length = 1)
|
||||||
|
private Sexo sexo;
|
||||||
|
}
|
||||||
@ -0,0 +1,93 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.vo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Embeddable;
|
||||||
|
import jakarta.persistence.EmbeddedId;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.ForeignKey;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@Table(name="T_ATLETA_DISCIPLINA_JUEGO")
|
||||||
|
public class AtletaDisciplinaJuego implements Serializable {
|
||||||
|
private static final long serialVersionUID = -6178979684877622477L;
|
||||||
|
@EmbeddedId
|
||||||
|
private AtletaDisciplinaJuegoID idAtletaDisciplinaJuego;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name="cod_juego", insertable = false, updatable = false,
|
||||||
|
foreignKey = @ForeignKey(name = "FK_ATLETADISCIPLINAJUEGO_JUEGO"))
|
||||||
|
private JuegoOlimpico juego;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name="cod_disciplina", insertable = false, updatable = false,
|
||||||
|
foreignKey = @ForeignKey(name = "FK_ATLETADISCIPLINAJUEGO_DISCIPLINA"))
|
||||||
|
private Disciplina disciplina;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name="id_atleta", insertable = false, updatable = false,
|
||||||
|
foreignKey = @ForeignKey(name = "FK_ATLETADISCIPLINAJUEGO_ATLETA"))
|
||||||
|
private Atleta atleta;
|
||||||
|
|
||||||
|
@Column(name = "puesto_competicion")
|
||||||
|
private int puestoCompeticion;
|
||||||
|
|
||||||
|
/* getters y setters */
|
||||||
|
@Embeddable
|
||||||
|
public static class AtletaDisciplinaJuegoID implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1618574830712573193L;
|
||||||
|
|
||||||
|
@Column(name = "cod_juego")
|
||||||
|
private String codigoJuego;
|
||||||
|
|
||||||
|
@Column(name = "cod_disciplina")
|
||||||
|
private String codigoDisciplina;
|
||||||
|
|
||||||
|
@Column(name = "id_atleta")
|
||||||
|
private int idAtleta;
|
||||||
|
|
||||||
|
public AtletaDisciplinaJuegoID() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtletaDisciplinaJuegoID(int idAtleta, String codDisciplina, String codJuego) {
|
||||||
|
this.codigoJuego=codJuego;
|
||||||
|
this.codigoDisciplina=codDisciplina;
|
||||||
|
this.idAtleta=idAtleta;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(codigoDisciplina, codigoJuego, idAtleta);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
AtletaDisciplinaJuegoID other = (AtletaDisciplinaJuegoID) obj;
|
||||||
|
return Objects.equals(codigoDisciplina, other.codigoDisciplina)
|
||||||
|
&& Objects.equals(codigoJuego, other.codigoJuego) && idAtleta == other.idAtleta;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/main/java/org/coi/juegosolimpicos/inm/vo/Disciplina.java
Normal file
34
src/main/java/org/coi/juegosolimpicos/inm/vo/Disciplina.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.vo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@Table(name = "T_DISCIPLINA")
|
||||||
|
public class Disciplina implements Serializable {
|
||||||
|
private static final long serialVersionUID = -1495481881810609339L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "codigo")
|
||||||
|
private String codigo;
|
||||||
|
|
||||||
|
@Column(name = "nombre_disciplina")
|
||||||
|
private String nombre;
|
||||||
|
|
||||||
|
@Column(name = "disciplina_individual")
|
||||||
|
private boolean disciplinaIndividual;
|
||||||
|
}
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.vo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.ForeignKey;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Index;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.OneToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@Table(name = "T_JUEGO_OLIMPICO",
|
||||||
|
indexes = @Index(name="INDICE_MASCOTA", columnList="id_mascota", unique = true))
|
||||||
|
|
||||||
|
public class JuegoOlimpico implements Serializable{
|
||||||
|
private static final long serialVersionUID = -2198660627534301810L;
|
||||||
|
@Id
|
||||||
|
@Column(name="codigo", length = 6)
|
||||||
|
private String codigo;
|
||||||
|
|
||||||
|
@Column(name="anio")
|
||||||
|
private int anio;
|
||||||
|
|
||||||
|
@Column(name="ciudad", length = 50)
|
||||||
|
private String ciudad;
|
||||||
|
|
||||||
|
@Column(name="pais", length = 50)
|
||||||
|
private String pais;
|
||||||
|
|
||||||
|
@Column(name="juego_verano")
|
||||||
|
private boolean esJuegoVerano;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
@JoinColumn(name="id_mascota",referencedColumnName="identificador", nullable = false, updatable=false,
|
||||||
|
foreignKey = @ForeignKey(name = "FK_MASCOTA"))
|
||||||
|
private Mascota mascotaJuego;
|
||||||
|
}
|
||||||
40
src/main/java/org/coi/juegosolimpicos/inm/vo/Mascota.java
Normal file
40
src/main/java/org/coi/juegosolimpicos/inm/vo/Mascota.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.coi.juegosolimpicos.inm.vo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@Table(name = "T_MASCOTA")
|
||||||
|
public class Mascota implements Serializable{
|
||||||
|
private static final long serialVersionUID = -4937684627247126196L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "identificador")
|
||||||
|
private int identificador;
|
||||||
|
|
||||||
|
@Column(name = "nombre_mascota", length = 50)
|
||||||
|
private String nombre;
|
||||||
|
@Column(name = "url_mascota", length = 150)
|
||||||
|
private String urlImagen;
|
||||||
|
|
||||||
|
@Column(name = "imagen_mascota", columnDefinition="LONGBLOB")
|
||||||
|
private byte[] imagen;
|
||||||
|
|
||||||
|
}
|
||||||
15
src/main/java/org/coi/juegosolimpicos/inm/vo/Sexo.java
Normal file
15
src/main/java/org/coi/juegosolimpicos/inm/vo/Sexo.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package org.coi.juegosolimpicos.inm.vo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Sexo: Enumeración con los valores posibles para el sexo de un atleta (H, M)
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 feb 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public enum Sexo {
|
||||||
|
H, M;
|
||||||
|
}
|
||||||
9
src/main/resources/config.properties
Normal file
9
src/main/resources/config.properties
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Parámetros de conexión a la base de datos MapaMundi en SGDB MySQL
|
||||||
|
jdbc.driver = com.mysql.cj.jdbc.Driver
|
||||||
|
jdbc.url = jdbc:mysql://192.168.1.36:3306/juegos_olimpicos_inm
|
||||||
|
jdbc.usuario = root
|
||||||
|
jdbc.password = mysql_123
|
||||||
|
|
||||||
|
# Parámetros para la conexión con la base de datos de MongoDB
|
||||||
|
mongodb.url=mongodb://admin:mongodb_123@192.168.1.36:27017
|
||||||
|
mongodb.bbdd=juegos_olimpicos_inm
|
||||||
30
src/main/resources/hibernate.cfg.xml
Normal file
30
src/main/resources/hibernate.cfg.xml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<!DOCTYPE hibernate-configuration PUBLIC
|
||||||
|
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||||
|
|
||||||
|
<hibernate-configuration>
|
||||||
|
|
||||||
|
<session-factory>
|
||||||
|
|
||||||
|
<!-- JDBC Database connection settings -->
|
||||||
|
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
|
||||||
|
<property name="connection.url">jdbc:mysql://192.168.1.36:3306/juegos_olimpicos_inm</property>
|
||||||
|
<property name="connection.username">root</property>
|
||||||
|
<property name="connection.password">mysql_123</property>
|
||||||
|
|
||||||
|
<!-- DB schema will be updated if needed -->
|
||||||
|
<property name="hbm2ddl.auto">create-drop</property>
|
||||||
|
<property name="show_sql">true</property>
|
||||||
|
<property name="format_sql">true</property>
|
||||||
|
|
||||||
|
<!-- Set the current session context -->
|
||||||
|
<property name="current_session_context_class">thread</property>
|
||||||
|
|
||||||
|
<!-- Ficheros XML con los mapeos entre el modelo de clases de aplicación y el modelo físico E/R-->
|
||||||
|
<mapping class="org.coi.juegosolimpicos.inm.vo.Mascota"/>
|
||||||
|
<mapping class="org.coi.juegosolimpicos.inm.vo.JuegoOlimpico"/>
|
||||||
|
<mapping class="org.coi.juegosolimpicos.inm.vo.Disciplina"/>
|
||||||
|
<mapping class="org.coi.juegosolimpicos.inm.vo.Atleta"/>
|
||||||
|
<mapping class="org.coi.juegosolimpicos.inm.vo.AtletaDisciplinaJuego"/>
|
||||||
|
|
||||||
|
</session-factory>
|
||||||
|
</hibernate-configuration>
|
||||||
Loading…
Reference in New Issue
Block a user