Commit Inicial
This commit is contained in:
commit
6c96d49ca8
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_act3_9</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
|
||||||
91
ficheros/info_directores.xml
Normal file
91
ficheros/info_directores.xml
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<directores>
|
||||||
|
<director_cine>
|
||||||
|
<nombre>Pedro Almodóvar Caballero</nombre>
|
||||||
|
<fecha_nacimiento>25/09/1949</fecha_nacimiento>
|
||||||
|
<pais>152</pais>
|
||||||
|
<tematica>Drama, Comedia</tematica>
|
||||||
|
<email>pedro.almodovar@cine.es</email>
|
||||||
|
<imagen>
|
||||||
|
<formato>jpg</formato>
|
||||||
|
<url>https://es.wikipedia.org/wiki/Pedro_Almod%C3%B3var#/media/Archivo:Pedro_Almod%C3%B3var-69698.jpg</url>
|
||||||
|
</imagen>
|
||||||
|
</director_cine>
|
||||||
|
<director_cine>
|
||||||
|
<nombre>Alejandro Amenábar Gabilondo</nombre>
|
||||||
|
<fecha_nacimiento>09/03/1972</fecha_nacimiento>
|
||||||
|
<pais>152</pais>
|
||||||
|
<tematica>Drama, Thriller, Ciencia Ficción</tematica>
|
||||||
|
<email>alejandro.amenabar@cine.es</email>
|
||||||
|
<imagen>
|
||||||
|
<formato>jpg</formato>
|
||||||
|
<url>https://upload.wikimedia.org/wikipedia/commons/thumb/b/b5/Amenabar_%2822022306905%29_%28cropped%29.jpg/330px-Amenabar_%2822022306905%29_%28cropped%29.jpg</url>
|
||||||
|
</imagen>
|
||||||
|
</director_cine>
|
||||||
|
<director_cine>
|
||||||
|
<nombre>François Truffaut</nombre>
|
||||||
|
<fecha_nacimiento>06/02/1932</fecha_nacimiento>
|
||||||
|
<pais>155</pais>
|
||||||
|
<tematica>Drama, Romance, Suspense</tematica>
|
||||||
|
<email>francois.truffaut@cine.fr</email>
|
||||||
|
<imagen>
|
||||||
|
<formato>jpg</formato>
|
||||||
|
<url>https://upload.wikimedia.org/wikipedia/commons/thumb/6/6e/Fran%C3%A7ois_Truffaut_%281965%29.jpg/330px-Fran%C3%A7ois_Truffaut_%281965%29.jpg</url>
|
||||||
|
</imagen>
|
||||||
|
</director_cine>
|
||||||
|
<director_cine>
|
||||||
|
<nombre>Juan José Campanella</nombre>
|
||||||
|
<fecha_nacimiento>19/07/1959</fecha_nacimiento>
|
||||||
|
<pais>57</pais>
|
||||||
|
<tematica>Drama, Comedia, Thriller</tematica>
|
||||||
|
<email>juan.campanella@cine.com</email>
|
||||||
|
<imagen>
|
||||||
|
<formato>jpg</formato>
|
||||||
|
<url>https://upload.wikimedia.org/wikipedia/commons/thumb/7/7f/Juan_Jos%C3%A9_Camapanella_2019.jpg/330px-Juan_Jos%C3%A9_Camapanella_2019.jpg</url>
|
||||||
|
</imagen>
|
||||||
|
</director_cine>
|
||||||
|
<director_cine>
|
||||||
|
<nombre>Ousmane Sembène</nombre>
|
||||||
|
<fecha_nacimiento>01/01/1923</fecha_nacimiento>
|
||||||
|
<pais>41</pais>
|
||||||
|
<tematica>Drama, Social, Histórico</tematica>
|
||||||
|
<email>ousmane.sembene@cine.com</email>
|
||||||
|
<imagen>
|
||||||
|
<formato>jpg</formato>
|
||||||
|
<url>https://upload.wikimedia.org/wikipedia/commons/1/1a/Ousmane_Semb%C3%A8ne_%281987%29_by_Guenter_Prust.jpg</url>
|
||||||
|
</imagen>
|
||||||
|
</director_cine>
|
||||||
|
<director_cine>
|
||||||
|
<nombre>Hayao Miyazaki</nombre>
|
||||||
|
<fecha_nacimiento>05/01/1941</fecha_nacimiento>
|
||||||
|
<pais>111</pais>
|
||||||
|
<tematica>Animación, Fantasía, Aventura</tematica>
|
||||||
|
<email>hayao.miyazaki@cine.com</email>
|
||||||
|
<imagen>
|
||||||
|
<formato>jpg</formato>
|
||||||
|
<url>https://upload.wikimedia.org/wikipedia/commons/thumb/e/e2/Hayao_Miyazaki_cropped_1_Hayao_Miyazaki_201211.jpg/330px-Hayao_Miyazaki_cropped_1_Hayao_Miyazaki_201211.jpg</url>
|
||||||
|
</imagen>
|
||||||
|
</director_cine>
|
||||||
|
<director_cine>
|
||||||
|
<nombre>George Miller</nombre>
|
||||||
|
<fecha_nacimiento>03/03/1945</fecha_nacimiento>
|
||||||
|
<pais>185</pais>
|
||||||
|
<tematica>Acción, Ciencia Ficción, Drama</tematica>
|
||||||
|
<email>george.miller@cine.com</email>
|
||||||
|
<imagen>
|
||||||
|
<formato>jpg</formato>
|
||||||
|
<url>https://upload.wikimedia.org/wikipedia/commons/thumb/1/13/George_Miller_%2835706244922%29.jpg/330px-George_Miller_%2835706244922%29.jpg</url>
|
||||||
|
</imagen>
|
||||||
|
</director_cine>
|
||||||
|
<director_cine>
|
||||||
|
<nombre>Peter Jackson</nombre>
|
||||||
|
<fecha_nacimiento>31/10/1961</fecha_nacimiento>
|
||||||
|
<pais>192</pais>
|
||||||
|
<tematica>Fantástico, Aventura, Acción</tematica>
|
||||||
|
<email>peter.jackson@cine.com</email>
|
||||||
|
<imagen>
|
||||||
|
<formato>jpg</formato>
|
||||||
|
<url>https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Peter_Jackson_SDCC_2014.jpg/375px-Peter_Jackson_SDCC_2014.jpg</url>
|
||||||
|
</imagen>
|
||||||
|
</director_cine>
|
||||||
|
</directores>
|
||||||
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.cine</groupId>
|
||||||
|
<artifactId>aadd_act3_7</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- 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>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
32
src/main/java/org/lapaloma/aadd/cine/AppCine.java
Normal file
32
src/main/java/org/lapaloma/aadd/cine/AppCine.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package org.lapaloma.aadd.cine;
|
||||||
|
|
||||||
|
import org.lapaloma.aadd.cine.gestores.GestorEntityManagerJPA;
|
||||||
|
import org.lapaloma.aadd.cine.procesos.ProcesadorDirectoresXML;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* AppMapaMundi: Clase que realiza ....
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 5 dic 2025
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class AppCine {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
AppCine app = new AppCine();
|
||||||
|
|
||||||
|
GestorEntityManagerJPA.getEntityManager();
|
||||||
|
|
||||||
|
app.procesarFicheroDirectores();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void procesarFicheroDirectores() {
|
||||||
|
ProcesadorDirectoresXML procesador = new ProcesadorDirectoresXML();
|
||||||
|
procesador.procesarFicheroInformacionDirectores();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
18
src/main/java/org/lapaloma/aadd/cine/dao/IActorDAO.java
Normal file
18
src/main/java/org/lapaloma/aadd/cine/dao/IActorDAO.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package org.lapaloma.aadd.cine.dao;
|
||||||
|
|
||||||
|
import org.lapaloma.aadd.cine.vo.Actor;
|
||||||
|
|
||||||
|
public interface IActorDAO extends IOperacionesDAOEntidad<Actor, Integer> {
|
||||||
|
void borrarActor(Integer identificador) throws Exception;
|
||||||
|
|
||||||
|
void borrarActoresReferenciasPais(Integer idPais) throws Exception;
|
||||||
|
|
||||||
|
void borrarActoresReferenciasContinente(String codigoContinente) throws Exception;
|
||||||
|
|
||||||
|
Actor obtenerActorPorNombre(String nombre);
|
||||||
|
|
||||||
|
void actualizarActor(Actor actor) throws Exception;
|
||||||
|
|
||||||
|
void insertarActor(Actor actor) throws Exception;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package org.lapaloma.aadd.cine.dao;
|
||||||
|
|
||||||
|
import org.lapaloma.aadd.cine.vo.Continente;
|
||||||
|
|
||||||
|
public interface IContinenteDAO extends IOperacionesDAOEntidad<Continente, String> {
|
||||||
|
void borrarContinente(String codigo) throws Exception;
|
||||||
|
}
|
||||||
17
src/main/java/org/lapaloma/aadd/cine/dao/IDirectorDAO.java
Normal file
17
src/main/java/org/lapaloma/aadd/cine/dao/IDirectorDAO.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package org.lapaloma.aadd.cine.dao;
|
||||||
|
|
||||||
|
import org.lapaloma.aadd.cine.vo.Director;
|
||||||
|
|
||||||
|
public interface IDirectorDAO extends IOperacionesDAOEntidad<Director, Integer> {
|
||||||
|
void borrarDirector(Integer identificador) throws Exception;
|
||||||
|
|
||||||
|
void borrarDirectoresReferenciasPais(Integer idPais) throws Exception;
|
||||||
|
|
||||||
|
void borrarDirectoresReferenciasContinente(String codigoContinente) throws Exception;
|
||||||
|
|
||||||
|
Director obtenerDirectorPorNombre(String nombre);
|
||||||
|
|
||||||
|
void actualizarDirector(Director director) throws Exception;
|
||||||
|
|
||||||
|
void insertarDirector(Director director) throws Exception;
|
||||||
|
}
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
package org.lapaloma.aadd.cine.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* IOperacionesBasicas: Clase que realiza ....
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 14 dic 2025
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface IOperacionesDAOEntidad<T, ID> {
|
||||||
|
T obtenerEntidadPorClave(ID clave);
|
||||||
|
List<T> obtenerListaTodasEntidades();
|
||||||
|
void crearEntidad(T entidad);
|
||||||
|
void actualizarEntidad(T entidad);
|
||||||
|
void borrarEntidadPorClave(ID clave);
|
||||||
|
}
|
||||||
|
|
||||||
8
src/main/java/org/lapaloma/aadd/cine/dao/IPaisDAO.java
Normal file
8
src/main/java/org/lapaloma/aadd/cine/dao/IPaisDAO.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package org.lapaloma.aadd.cine.dao;
|
||||||
|
|
||||||
|
import org.lapaloma.aadd.cine.vo.Pais;
|
||||||
|
|
||||||
|
public interface IPaisDAO extends IOperacionesDAOEntidad<Pais, Integer> {
|
||||||
|
void borrarPais(Integer identificador) throws Exception;
|
||||||
|
void borrarPaisesContinente(String codigoContinente) throws Exception;
|
||||||
|
}
|
||||||
19
src/main/java/org/lapaloma/aadd/cine/dao/IPeliculaDAO.java
Normal file
19
src/main/java/org/lapaloma/aadd/cine/dao/IPeliculaDAO.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package org.lapaloma.aadd.cine.dao;
|
||||||
|
|
||||||
|
import org.lapaloma.aadd.cine.vo.Pelicula;
|
||||||
|
|
||||||
|
public interface IPeliculaDAO extends IOperacionesDAOEntidad<Pelicula, Integer> {
|
||||||
|
void borrarPelicula(Integer identificador) throws Exception;
|
||||||
|
|
||||||
|
void borrarPeliculasDirector(Integer idDirector) throws Exception;
|
||||||
|
|
||||||
|
void borrarPeliculasReferenciasPais(Integer idPais) throws Exception;
|
||||||
|
|
||||||
|
void borrarPeliculasReferenciasContinente(String codigoContinente) throws Exception;
|
||||||
|
|
||||||
|
Pelicula obtenerPeliculaPorTitulo(String titulo) throws Exception;
|
||||||
|
|
||||||
|
void actualizarPelicula(Pelicula pelicula) throws Exception;
|
||||||
|
|
||||||
|
void insertarPelicula(Pelicula pelicula) throws Exception;
|
||||||
|
}
|
||||||
20
src/main/java/org/lapaloma/aadd/cine/dao/IRepartoDAO.java
Normal file
20
src/main/java/org/lapaloma/aadd/cine/dao/IRepartoDAO.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package org.lapaloma.aadd.cine.dao;
|
||||||
|
|
||||||
|
import org.lapaloma.aadd.cine.vo.Reparto;
|
||||||
|
import org.lapaloma.aadd.cine.vo.RepartoId;
|
||||||
|
|
||||||
|
public interface IRepartoDAO extends IOperacionesDAOEntidad<Reparto, RepartoId> {
|
||||||
|
void borrarRepartoActor(Integer idActor) throws Exception;
|
||||||
|
|
||||||
|
void borrarRepartoPelicula(Integer idPelicula) throws Exception;
|
||||||
|
|
||||||
|
void borrarRepartoPeliculasDirector(Integer idDirector) throws Exception;
|
||||||
|
|
||||||
|
void borrarRepartoReferenciasPais(Integer idPais) throws Exception;
|
||||||
|
|
||||||
|
void borrarRepartoReferenciasContinente(String codigoContinente) throws Exception;
|
||||||
|
|
||||||
|
void insertarReparto(Reparto reparto) throws Exception;
|
||||||
|
|
||||||
|
void actualizarReparto(Reparto reparto) throws Exception;
|
||||||
|
}
|
||||||
@ -0,0 +1,191 @@
|
|||||||
|
package org.lapaloma.aadd.cine.dao.hbnt;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.query.MutationQuery;
|
||||||
|
import org.hibernate.query.SelectionQuery;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IActorDAO;
|
||||||
|
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.vo.Actor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ActorDaoHibernate: Clase que implementa las operaciones del interfaz
|
||||||
|
* IOperacionesDAOEntidad de Actor para Hibernate.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 14 dic 2025
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ActorDaoHibernate implements IActorDAO {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Actor obtenerEntidadPorClave(Integer clave) {
|
||||||
|
Actor actor = null;
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||||
|
actor = sesion.find(Actor.class, clave);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return actor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Actor> obtenerListaTodasEntidades() {
|
||||||
|
List<Actor> listaActores = null;
|
||||||
|
String sentenciaHQL = "SELECT a FROM Actor a";
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||||
|
|
||||||
|
SelectionQuery<Actor> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Actor.class);
|
||||||
|
listaActores = sentenciaConsulta.getResultList();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return listaActores;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(Actor entidad) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
sesion.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarEntidad(Actor entidad) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
if (!sesion.contains(entidad))
|
||||||
|
sesion.merge(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarEntidadPorClave(Integer clave) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
// Borrado de Actor
|
||||||
|
Actor actor = sesion.find(Actor.class, clave);
|
||||||
|
sesion.remove(actor);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarActor(Integer identificador) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de Actor
|
||||||
|
String sentenciaBorradoActorHQL = "DELETE FROM Actor a WHERE a.identificador = :identificador";
|
||||||
|
MutationQuery senteciaBorradoActor = sesion.createMutationQuery(sentenciaBorradoActorHQL);
|
||||||
|
senteciaBorradoActor.setParameter("identificador", identificador);
|
||||||
|
senteciaBorradoActor.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarActoresReferenciasPais(Integer idPais) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de los actores cuyo país de nacimiento es en el país a borrar
|
||||||
|
String sentenciaBorradoActorPaisHQL = "DELETE FROM Actor a WHERE a.pais.identificador = :identificador";
|
||||||
|
MutationQuery senteciaBorradoActoresPais = sesion.createMutationQuery(sentenciaBorradoActorPaisHQL);
|
||||||
|
senteciaBorradoActoresPais.setParameter("identificador", idPais);
|
||||||
|
senteciaBorradoActoresPais.executeUpdate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarActoresReferenciasContinente(String codigoContinente) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de los actores cuyo país de nacimiento es en un país del continente a
|
||||||
|
// borrar
|
||||||
|
String sentenciaBorradoActorPaisHQL = "DELETE FROM Actor a WHERE a.pais.continente.codigo = :codigo";
|
||||||
|
MutationQuery senteciaBorradoActoresPais = sesion.createMutationQuery(sentenciaBorradoActorPaisHQL);
|
||||||
|
senteciaBorradoActoresPais.setParameter("codigo", codigoContinente);
|
||||||
|
senteciaBorradoActoresPais.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Actor obtenerActorPorNombre(String nombre) {
|
||||||
|
Actor actor = null;
|
||||||
|
|
||||||
|
String sentenciaHQL = "SELECT a FROM Actor a WHERE a.nombre = :nombre";
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
SelectionQuery<Actor> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Actor.class);
|
||||||
|
sentenciaConsulta.setParameter("nombre", nombre);
|
||||||
|
actor = sentenciaConsulta.getSingleResultOrNull();
|
||||||
|
|
||||||
|
return actor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarActor(Actor actor) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
if (!sesion.contains(actor))
|
||||||
|
sesion.merge(actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertarActor(Actor actor) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
sesion.persist(actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,141 @@
|
|||||||
|
package org.lapaloma.aadd.cine.dao.hbnt;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.query.MutationQuery;
|
||||||
|
import org.hibernate.query.SelectionQuery;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IContinenteDAO;
|
||||||
|
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.vo.Continente;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ContinenteDaoHibernate: Clase que implementa las operaciones del interfaz IOperacionesDAOEntidad
|
||||||
|
* de Continente para Hibernate.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 14 dic 2025
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ContinenteDaoHibernate implements IContinenteDAO {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Continente obtenerEntidadPorClave(String clave) {
|
||||||
|
Continente continente = null;
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||||
|
continente = sesion.find(Continente.class, clave);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Continente> obtenerListaTodasEntidades() {
|
||||||
|
List<Continente> listaContinentes = null;
|
||||||
|
String sentenciaHQL = "SELECT c FROM Continente c";
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||||
|
|
||||||
|
SelectionQuery<Continente> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Continente.class);
|
||||||
|
listaContinentes = sentenciaConsulta.getResultList();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return listaContinentes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(Continente entidad) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
sesion.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarEntidad(Continente entidad) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
if (!sesion.contains(entidad))
|
||||||
|
sesion.merge(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarEntidadPorClave(String clave) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
Continente continente = sesion.find(Continente.class, clave);
|
||||||
|
sesion.remove(continente);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarContinente(String codigo) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
String sentenciaBorradoContinenteHQL = "DELETE FROM Continente WHERE codigo= :codigo";
|
||||||
|
MutationQuery sentenciaBorradoContinente = sesion.createMutationQuery(sentenciaBorradoContinenteHQL);
|
||||||
|
sentenciaBorradoContinente.setParameter("codigo", codigo);
|
||||||
|
sentenciaBorradoContinente.executeUpdate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,191 @@
|
|||||||
|
package org.lapaloma.aadd.cine.dao.hbnt;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.query.MutationQuery;
|
||||||
|
import org.hibernate.query.SelectionQuery;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IDirectorDAO;
|
||||||
|
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.vo.Director;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* DirectorDAO: Clase que implementa las operaciones del interfaz
|
||||||
|
* IOperacionesDAOEntidad de Director para Hibernate.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 14 dic 2025
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DirectorDaoHibernate implements IDirectorDAO {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Director obtenerEntidadPorClave(Integer clave) {
|
||||||
|
Director director = null;
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||||
|
director = sesion.find(Director.class, clave);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return director;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Director> obtenerListaTodasEntidades() {
|
||||||
|
List<Director> listaDirectores = null;
|
||||||
|
String sentenciaHQL = "SELECT d FROM Director d";
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||||
|
|
||||||
|
SelectionQuery<Director> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Director.class);
|
||||||
|
listaDirectores = sentenciaConsulta.getResultList();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return listaDirectores;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(Director entidad) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
sesion.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarEntidad(Director entidad) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
if (!sesion.contains(entidad))
|
||||||
|
sesion.merge(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarEntidadPorClave(Integer clave) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
Director director = sesion.find(Director.class, clave);
|
||||||
|
sesion.remove(director);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarDirector(Integer identificador) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
String sentenciaBorradoDirectoresHQL = "DELETE FROM Director d WHERE d.identificador = :identificador";
|
||||||
|
MutationQuery senteciaBorradoDirectores = sesion.createMutationQuery(sentenciaBorradoDirectoresHQL);
|
||||||
|
senteciaBorradoDirectores.setParameter("identificador", identificador);
|
||||||
|
senteciaBorradoDirectores.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarDirectoresReferenciasPais(Integer idPais) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de los directores cuyo país de nacimiento es en un país del
|
||||||
|
// continente a borrar
|
||||||
|
String sentenciaBorradoDirectoresPaisHQL = "DELETE FROM Director d WHERE d.pais.identificador = :identificador";
|
||||||
|
MutationQuery senteciaBorradoDirectoresPais = sesion.createMutationQuery(sentenciaBorradoDirectoresPaisHQL);
|
||||||
|
senteciaBorradoDirectoresPais.setParameter("identificador", idPais);
|
||||||
|
senteciaBorradoDirectoresPais.executeUpdate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarDirectoresReferenciasContinente(String codigoContinente) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de los directores cuyo país de nacimiento es en un país del
|
||||||
|
// continente a borrar
|
||||||
|
String sentenciaBorradoDirectoresPaisHQL = "DELETE FROM Director d WHERE d.pais.continente.codigo = :codigo";
|
||||||
|
MutationQuery senteciaBorradoDirectoresPais = sesion.createMutationQuery(sentenciaBorradoDirectoresPaisHQL);
|
||||||
|
senteciaBorradoDirectoresPais.setParameter("codigo", codigoContinente);
|
||||||
|
senteciaBorradoDirectoresPais.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Director obtenerDirectorPorNombre(String nombre) {
|
||||||
|
Director director = null;
|
||||||
|
String sentenciaHQL = "SELECT d FROM Director d WHERE d.nombre = :nombre";
|
||||||
|
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
SelectionQuery<Director> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Director.class);
|
||||||
|
sentenciaConsulta.setParameter("nombre", nombre);
|
||||||
|
director = sentenciaConsulta.getSingleResultOrNull();
|
||||||
|
|
||||||
|
return director;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarDirector(Director director) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
if (!sesion.contains(director))
|
||||||
|
sesion.merge(director);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertarDirector(Director director) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
sesion.persist(director);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,153 @@
|
|||||||
|
package org.lapaloma.aadd.cine.dao.hbnt;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.query.MutationQuery;
|
||||||
|
import org.hibernate.query.SelectionQuery;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IPaisDAO;
|
||||||
|
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.vo.Pais;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* PaisDaoHibernate: Clase que implementa las operaciones del interfaz
|
||||||
|
* IOperacionesDAOEntidad de Pais para Hibernate.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 14 dic 2025
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class PaisDaoHibernate implements IPaisDAO {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pais obtenerEntidadPorClave(Integer clave) {
|
||||||
|
Pais pais = null;
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||||
|
pais = sesion.find(Pais.class, clave);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pais> obtenerListaTodasEntidades() {
|
||||||
|
List<Pais> listaPaises = null;
|
||||||
|
String sentenciaHQL = "SELECT p FROM Pais p";
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||||
|
|
||||||
|
SelectionQuery<Pais> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Pais.class);
|
||||||
|
listaPaises = sentenciaConsulta.getResultList();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return listaPaises;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(Pais entidad) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
sesion.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarEntidad(Pais entidad) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
if (!sesion.contains(entidad))
|
||||||
|
sesion.merge(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarEntidadPorClave(Integer clave) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
Pais pais = sesion.find(Pais.class, clave);
|
||||||
|
sesion.remove(pais);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarPais(Integer identificador) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de los países del continente a borrar
|
||||||
|
String sentenciaBorradoPaiseesHQL = "DELETE FROM Pais p WHERE p.identificador = :identificador";
|
||||||
|
MutationQuery senteciaBorradoPaises = sesion.createMutationQuery(sentenciaBorradoPaiseesHQL);
|
||||||
|
senteciaBorradoPaises.setParameter("identificador", identificador);
|
||||||
|
senteciaBorradoPaises.executeUpdate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarPaisesContinente(String codigoContinente) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de los países del continente a borrar
|
||||||
|
String sentenciaBorradoPaiseesHQL = "DELETE FROM Pais p WHERE p.continente.codigo = :codigo";
|
||||||
|
MutationQuery senteciaBorradoPaises = sesion.createMutationQuery(sentenciaBorradoPaiseesHQL);
|
||||||
|
senteciaBorradoPaises.setParameter("codigo", codigoContinente);
|
||||||
|
senteciaBorradoPaises.executeUpdate();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,214 @@
|
|||||||
|
package org.lapaloma.aadd.cine.dao.hbnt;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.query.MutationQuery;
|
||||||
|
import org.hibernate.query.SelectionQuery;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IPeliculaDAO;
|
||||||
|
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.vo.Actor;
|
||||||
|
import org.lapaloma.aadd.cine.vo.Pelicula;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* PeliculaDAO: Clase que implementa las operaciones del interfaz
|
||||||
|
* IOperacionesDAOEntidad de Pelicula para Hibernate.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 14 dic 2025
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class PeliculaDaoHibernate implements IPeliculaDAO {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pelicula obtenerEntidadPorClave(Integer clave) {
|
||||||
|
Pelicula pelicula = null;
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||||
|
pelicula = sesion.find(Pelicula.class, clave);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return pelicula;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pelicula> obtenerListaTodasEntidades() {
|
||||||
|
List<Pelicula> listaPeliculas = null;
|
||||||
|
String sentenciaHQL = "SELECT d FROM Pelicula d";
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||||
|
|
||||||
|
SelectionQuery<Pelicula> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Pelicula.class);
|
||||||
|
listaPeliculas = sentenciaConsulta.getResultList();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return listaPeliculas;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(Pelicula entidad) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
sesion.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarEntidad(Pelicula entidad) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
if (!sesion.contains(entidad))
|
||||||
|
sesion.merge(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarEntidadPorClave(Integer clave) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
// Borrado de Actor
|
||||||
|
Actor actor = sesion.find(Actor.class, clave);
|
||||||
|
sesion.remove(actor);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarPelicula(Integer identificador) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de Películas de una Película
|
||||||
|
String sentenciaBorradoPeliculasHQL = "DELETE FROM Pelicula p WHERE identificador = :identificador";
|
||||||
|
MutationQuery senteciaBorradoPeliculas = sesion.createMutationQuery(sentenciaBorradoPeliculasHQL);
|
||||||
|
senteciaBorradoPeliculas.setParameter("identificador", identificador);
|
||||||
|
senteciaBorradoPeliculas.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarPeliculasDirector(Integer idDirector) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de Películas de un director
|
||||||
|
String sentenciaBorradoPeliculasHQL = "DELETE FROM Pelicula p WHERE p.director.identificador = :identificador";
|
||||||
|
MutationQuery senteciaBorradoPeliculas = sesion.createMutationQuery(sentenciaBorradoPeliculasHQL);
|
||||||
|
senteciaBorradoPeliculas.setParameter("identificador", idDirector);
|
||||||
|
senteciaBorradoPeliculas.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarPeliculasReferenciasPais(Integer idPais) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de las películas cuyo país de Loclaización nacimiento es en un país
|
||||||
|
// del continente
|
||||||
|
// a borrar
|
||||||
|
String sentenciaBorradoPeliculasPaisHQL = """
|
||||||
|
DELETE FROM Pelicula p
|
||||||
|
WHERE (p.paisLocalizacion.identificador = :identificador
|
||||||
|
OR p.director.pais.identificador = :identificador)
|
||||||
|
""";
|
||||||
|
MutationQuery senteciaBorradoRepartosPeliculasPais = sesion
|
||||||
|
.createMutationQuery(sentenciaBorradoPeliculasPaisHQL);
|
||||||
|
senteciaBorradoRepartosPeliculasPais.setParameter("identificador", idPais);
|
||||||
|
senteciaBorradoRepartosPeliculasPais.executeUpdate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarPeliculasReferenciasContinente(String codigoContinente) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de las Películas cuyo país de nacimiento es en un país del continente
|
||||||
|
// a borrar
|
||||||
|
String sentenciaBorradoPeliculasPaisHQL = """
|
||||||
|
DELETE FROM Pelicula p WHERE (p.paisLocalizacion.continente.codigo = :codigo
|
||||||
|
OR p.director.pais.continente.codigo = :codigo)
|
||||||
|
""";
|
||||||
|
MutationQuery senteciaBorradoRepartosPeliculasPais = sesion
|
||||||
|
.createMutationQuery(sentenciaBorradoPeliculasPaisHQL);
|
||||||
|
senteciaBorradoRepartosPeliculasPais.setParameter("codigo", codigoContinente);
|
||||||
|
senteciaBorradoRepartosPeliculasPais.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pelicula obtenerPeliculaPorTitulo(String titulo) {
|
||||||
|
Pelicula pelicula = null;
|
||||||
|
|
||||||
|
String sentenciaHQL = "SELECT p FROM Pelicula p WHERE p.titulo = :titulo";
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
SelectionQuery<Pelicula> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Pelicula.class);
|
||||||
|
sentenciaConsulta.setParameter("titulo", titulo);
|
||||||
|
pelicula = sentenciaConsulta.getSingleResultOrNull();
|
||||||
|
|
||||||
|
return pelicula;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarPelicula(Pelicula pelicula) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
if (!sesion.contains(pelicula))
|
||||||
|
sesion.merge(pelicula);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertarPelicula(Pelicula pelicula) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
sesion.persist(pelicula);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,198 @@
|
|||||||
|
package org.lapaloma.aadd.cine.dao.hbnt;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.query.MutationQuery;
|
||||||
|
import org.hibernate.query.SelectionQuery;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IRepartoDAO;
|
||||||
|
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.vo.Reparto;
|
||||||
|
import org.lapaloma.aadd.cine.vo.RepartoId;
|
||||||
|
|
||||||
|
public class RepartoDaoHibernate implements IRepartoDAO {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Reparto obtenerEntidadPorClave(RepartoId clave) {
|
||||||
|
Reparto reparto = null;
|
||||||
|
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||||
|
reparto = sesion.find(Reparto.class, clave);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return reparto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Reparto> obtenerListaTodasEntidades() {
|
||||||
|
List<Reparto> listaReparto = null;
|
||||||
|
String sentenciaHQL = "SELECT r FROM Reparto r";
|
||||||
|
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||||
|
SelectionQuery<Reparto> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Reparto.class);
|
||||||
|
listaReparto = sentenciaConsulta.getResultList();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return listaReparto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(Reparto entidad) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
sesion.persist(entidad);
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarEntidad(Reparto entidad) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
if (!sesion.contains(entidad))
|
||||||
|
sesion.merge(entidad);
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarEntidadPorClave(RepartoId clave) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
Reparto reparto = sesion.find(Reparto.class, clave);
|
||||||
|
if (reparto != null) {
|
||||||
|
sesion.remove(reparto);
|
||||||
|
}
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarRepartoActor(Integer idActor) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de Repartos de un Actor
|
||||||
|
String sentenciaBorradoRepartosHQL = "DELETE FROM Reparto r WHERE r.actor.identificador = :identificador";
|
||||||
|
MutationQuery senteciaBorradoRepartos = sesion.createMutationQuery(sentenciaBorradoRepartosHQL);
|
||||||
|
senteciaBorradoRepartos.setParameter("identificador", idActor);
|
||||||
|
senteciaBorradoRepartos.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarRepartoPelicula(Integer idPelicula) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de Repartos de una Película
|
||||||
|
String sentenciaBorradoRepartosHQL = "DELETE FROM Reparto r WHERE r.pelicula.identificador = :identificador";
|
||||||
|
MutationQuery senteciaBorradoRepartos = sesion.createMutationQuery(sentenciaBorradoRepartosHQL);
|
||||||
|
senteciaBorradoRepartos.setParameter("identificador", idPelicula);
|
||||||
|
senteciaBorradoRepartos.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarRepartoPeliculasDirector(Integer idDirector) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de Repartos de películas un director
|
||||||
|
String sentenciaBorradoRepartosHQL = "DELETE FROM Reparto r WHERE r.pelicula.director.identificador = :identificador";
|
||||||
|
MutationQuery senteciaBorradoRepartos = sesion.createMutationQuery(sentenciaBorradoRepartosHQL);
|
||||||
|
senteciaBorradoRepartos.setParameter("identificador", idDirector);
|
||||||
|
senteciaBorradoRepartos.executeUpdate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarRepartoReferenciasPais(Integer idPais) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de repartos en los que la localización de la película es en el país a
|
||||||
|
// borrar
|
||||||
|
// Borrado de repartos en los que el país de nacimiento del actor es en el país
|
||||||
|
// a borrar
|
||||||
|
// Borrado de repartos en los que el país de nacimiento del director de la
|
||||||
|
// película es en el país a borrar
|
||||||
|
String sentenciaBorradoRepartosPaisHQL = """
|
||||||
|
DELETE FROM Reparto r
|
||||||
|
WHERE (r.pelicula.paisLocalizacion.identificador = :identificador
|
||||||
|
OR r.actor.pais.identificador = :identificador
|
||||||
|
OR r.pelicula.director.pais.identificador = :identificador)
|
||||||
|
""";
|
||||||
|
MutationQuery senteciaBorradoRepartosPais = sesion.createMutationQuery(sentenciaBorradoRepartosPaisHQL);
|
||||||
|
senteciaBorradoRepartosPais.setParameter("identificador", idPais);
|
||||||
|
senteciaBorradoRepartosPais.executeUpdate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarRepartoReferenciasContinente(String codigoContinente) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
|
||||||
|
// Borrado de repartos en los que la localización de la película es en un país
|
||||||
|
// del continente a borrar
|
||||||
|
// Borrado de repartos en los que el país de nacimiento del actor es en un país
|
||||||
|
// del continente a borrar
|
||||||
|
// Borrado de repartos en los que el país de nacimiento del director de la
|
||||||
|
// película es en un país del continente a borrar
|
||||||
|
String sentenciaBorradoRepartosPaisHQL = """
|
||||||
|
DELETE FROM Reparto r
|
||||||
|
WHERE (r.pelicula.paisLocalizacion.continente.codigo = :codigo
|
||||||
|
OR r.actor.pais.continente.codigo = :codigo
|
||||||
|
OR r.pelicula.director.pais.continente.codigo = :codigo)
|
||||||
|
""";
|
||||||
|
MutationQuery senteciaBorradoRepartosPais = sesion.createMutationQuery(sentenciaBorradoRepartosPaisHQL);
|
||||||
|
senteciaBorradoRepartosPais.setParameter("codigo", codigoContinente);
|
||||||
|
senteciaBorradoRepartosPais.executeUpdate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertarReparto(Reparto reparto) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
sesion.persist(reparto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarReparto(Reparto reparto) throws Exception {
|
||||||
|
Session sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
if (!sesion.contains(reparto))
|
||||||
|
sesion.merge(reparto);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
145
src/main/java/org/lapaloma/aadd/cine/dao/jpa/DirectorDaoJPA.java
Normal file
145
src/main/java/org/lapaloma/aadd/cine/dao/jpa/DirectorDaoJPA.java
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
package org.lapaloma.aadd.cine.dao.jpa;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.lapaloma.aadd.cine.dao.IDirectorDAO;
|
||||||
|
import org.lapaloma.aadd.cine.gestores.GestorEntityManagerJPA;
|
||||||
|
import org.lapaloma.aadd.cine.vo.Director;
|
||||||
|
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.EntityTransaction;
|
||||||
|
import jakarta.persistence.NoResultException;
|
||||||
|
import jakarta.persistence.TypedQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* PaisDaoJPA: Clase que implementa el interfaz IPaisDAO
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 31 oct 2025
|
||||||
|
*/
|
||||||
|
public class DirectorDaoJPA implements IDirectorDAO {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Director obtenerEntidadPorClave(Integer clave) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Director> obtenerListaTodasEntidades() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(Director entidad) {
|
||||||
|
EntityManager gestorEntidades = null;
|
||||||
|
EntityTransaction transaccion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||||
|
transaccion = gestorEntidades.getTransaction();
|
||||||
|
transaccion.begin();
|
||||||
|
|
||||||
|
gestorEntidades.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (gestorEntidades != null) {
|
||||||
|
gestorEntidades.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarEntidad(Director entidad) {
|
||||||
|
EntityManager gestorEntidades = null;
|
||||||
|
EntityTransaction transaccion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||||
|
transaccion = gestorEntidades.getTransaction();
|
||||||
|
transaccion.begin();
|
||||||
|
|
||||||
|
if (!gestorEntidades.contains(entidad))
|
||||||
|
gestorEntidades.merge(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (gestorEntidades != null) {
|
||||||
|
gestorEntidades.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarEntidadPorClave(Integer clave) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarDirector(Integer identificador) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarDirectoresReferenciasPais(Integer idPais) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarDirectoresReferenciasContinente(String codigoContinente) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Director obtenerDirectorPorNombre(String nombre) {
|
||||||
|
Director director = null;
|
||||||
|
|
||||||
|
String sentenciaJPQL = """
|
||||||
|
SELECT d FROM Director d
|
||||||
|
WHERE d.nombre= :nombre
|
||||||
|
""";
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (EntityManager entityManager = GestorEntityManagerJPA.getEntityManager();) {
|
||||||
|
TypedQuery<Director> query = entityManager.createQuery(sentenciaJPQL, Director.class);
|
||||||
|
query.setParameter("nombre", nombre);
|
||||||
|
|
||||||
|
director = query.getSingleResult();
|
||||||
|
}catch (NoResultException e) { // no hace nada, devuelve null
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return director;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarDirector(Director director) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertarDirector(Director director) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
70
src/main/java/org/lapaloma/aadd/cine/dao/jpa/PaisDaoJPA.java
Normal file
70
src/main/java/org/lapaloma/aadd/cine/dao/jpa/PaisDaoJPA.java
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
package org.lapaloma.aadd.cine.dao.jpa;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.lapaloma.aadd.cine.dao.IPaisDAO;
|
||||||
|
import org.lapaloma.aadd.cine.gestores.GestorEntityManagerJPA;
|
||||||
|
import org.lapaloma.aadd.cine.vo.Pais;
|
||||||
|
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* PaisDaoJPA: Clase que implementa el interfaz IPaisDAO
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 31 oct 2025
|
||||||
|
*/
|
||||||
|
public class PaisDaoJPA implements IPaisDAO {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pais obtenerEntidadPorClave(Integer clave) {
|
||||||
|
Pais pais = null;
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (EntityManager gestorEntidades = GestorEntityManagerJPA.getEntityManager()) {
|
||||||
|
pais = gestorEntidades.find(Pais.class, clave);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pais> obtenerListaTodasEntidades() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(Pais entidad) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarEntidad(Pais entidad) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarEntidadPorClave(Integer clave) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarPais(Integer identificador) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarPaisesContinente(String codigoContinente) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
package org.lapaloma.aadd.cine.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_CINE_MYSQL");
|
||||||
|
} 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,45 @@
|
|||||||
|
package org.lapaloma.aadd.cine.gestores;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* GestorConfiguracion: Clase que se encarga de gestionar la configuración de
|
||||||
|
* los ficheros.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 10 oct 2025
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GestorFicheroConfiguracion {
|
||||||
|
private final static String RUTA_FICHERO_CONFIGURACION = "conf.properties";
|
||||||
|
private static Properties propiedades = null;
|
||||||
|
|
||||||
|
private GestorFicheroConfiguracion() {
|
||||||
|
// Constructor privado para evitar instanciación
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bloque estático que se ejecuta una única vez al cargar la clase
|
||||||
|
static {
|
||||||
|
cargarPropiedadesFichero();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void cargarPropiedadesFichero() {
|
||||||
|
propiedades = new Properties();
|
||||||
|
try {
|
||||||
|
propiedades
|
||||||
|
.load(GestorFicheroConfiguracion.class.getClassLoader()
|
||||||
|
.getResourceAsStream(RUTA_FICHERO_CONFIGURACION));
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getValorfromClave(String clave) {
|
||||||
|
return propiedades.getProperty(clave);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
package org.lapaloma.aadd.cine.gestores;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.cfg.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* GestorSesionesHibernate: Clase que realiza ....
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 4 dic 2025
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GestorSesionesHibernate {
|
||||||
|
private static SessionFactory sessionFactory = null;
|
||||||
|
|
||||||
|
private GestorSesionesHibernate() {// 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,76 @@
|
|||||||
|
package org.lapaloma.aadd.cine.procesos;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
import org.lapaloma.aadd.cine.dao.IDirectorDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IPaisDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.jpa.DirectorDaoJPA;
|
||||||
|
import org.lapaloma.aadd.cine.dao.jpa.PaisDaoJPA;
|
||||||
|
import org.lapaloma.aadd.cine.gestores.GestorFicheroConfiguracion;
|
||||||
|
import org.lapaloma.aadd.cine.util.UtilidadesCine;
|
||||||
|
import org.lapaloma.aadd.cine.vo.Director;
|
||||||
|
import org.lapaloma.aadd.cine.vo.Pais;
|
||||||
|
|
||||||
|
import tools.jackson.databind.JsonNode;
|
||||||
|
import tools.jackson.databind.ObjectMapper;
|
||||||
|
import tools.jackson.dataformat.xml.XmlMapper;
|
||||||
|
|
||||||
|
public class ProcesadorDirectoresXML {
|
||||||
|
|
||||||
|
public void procesarFicheroInformacionDirectores() {
|
||||||
|
String rutaFichero = GestorFicheroConfiguracion.getValorfromClave("directores.fichero.xml.ruta");
|
||||||
|
File fichero = new File(rutaFichero);
|
||||||
|
|
||||||
|
IPaisDAO paisDAO = new PaisDaoJPA();
|
||||||
|
IDirectorDAO directorDAO = new DirectorDaoJPA();
|
||||||
|
|
||||||
|
// Se asume que la información de Paises es correcta y ya existe en la BD
|
||||||
|
ObjectMapper mapper = new XmlMapper();
|
||||||
|
JsonNode root = mapper.readTree(fichero);
|
||||||
|
JsonNode nodoDirectores = root.get("director_cine");
|
||||||
|
|
||||||
|
// Procesar cada película enviada por el festival
|
||||||
|
if (nodoDirectores != null && nodoDirectores.isArray()) {
|
||||||
|
for (JsonNode nodoDirector : nodoDirectores) {
|
||||||
|
String nombreDirector = nodoDirector.get("nombre").asString();
|
||||||
|
int pais = nodoDirector.get("pais").asInt();
|
||||||
|
String urlFoto = nodoDirector.get("imagen").get("url").asString();
|
||||||
|
|
||||||
|
String fechaNacimientoStr = nodoDirector.get("fecha_nacimiento").asString();
|
||||||
|
LocalDate fechaNacimiento = UtilidadesCine.parsearFecha(fechaNacimientoStr, "dd/MM/yyyy");
|
||||||
|
|
||||||
|
// Se asume que el país ya existe en la BD
|
||||||
|
Pais paisNacimiento = paisDAO.obtenerEntidadPorClave(pais);
|
||||||
|
|
||||||
|
// Crear y guardar el director
|
||||||
|
Director directorBBDD = directorDAO.obtenerDirectorPorNombre(nombreDirector);
|
||||||
|
if (directorBBDD == null) {
|
||||||
|
Director director = new Director();
|
||||||
|
director.setNombre(nombreDirector);
|
||||||
|
director.setFechaNacimiento(fechaNacimiento);
|
||||||
|
director.setPais(paisNacimiento);
|
||||||
|
|
||||||
|
// Descargar la foto del director
|
||||||
|
byte[] fotoBytes = UtilidadesCine.getBytesFromURL(urlFoto);
|
||||||
|
director.setFoto(fotoBytes);
|
||||||
|
|
||||||
|
directorDAO.crearEntidad(director);
|
||||||
|
|
||||||
|
System.out.println("Director guardado: " + nombreDirector);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
directorBBDD.setFechaNacimiento(fechaNacimiento);
|
||||||
|
directorBBDD.setPais(paisNacimiento);
|
||||||
|
|
||||||
|
// Descargar la foto del director
|
||||||
|
byte[] fotoBytes = UtilidadesCine.getBytesFromURL(urlFoto);
|
||||||
|
directorBBDD.setFoto(fotoBytes);
|
||||||
|
|
||||||
|
directorDAO.actualizarEntidad(directorBBDD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
package org.lapaloma.aadd.cine.servicio;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IActorDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IRepartoDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.ActorDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.RepartoDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||||
|
|
||||||
|
public class ActorService {
|
||||||
|
public void borrarActorYReferencias(Integer idActor) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
// Borrado de Repartos de un Actor
|
||||||
|
IRepartoDAO iRepartoDAO = new RepartoDaoHibernate();
|
||||||
|
iRepartoDAO.borrarRepartoActor(idActor);
|
||||||
|
|
||||||
|
// Borrado de Actor
|
||||||
|
IActorDAO iActorDAO = new ActorDaoHibernate();
|
||||||
|
iActorDAO.borrarActor(idActor);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,66 @@
|
|||||||
|
package org.lapaloma.aadd.cine.servicio;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IActorDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IContinenteDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IDirectorDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IPaisDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IPeliculaDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IRepartoDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.ActorDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.ContinenteDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.DirectorDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.PaisDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.PeliculaDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.RepartoDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||||
|
|
||||||
|
public class ContinenteService {
|
||||||
|
public void borrarContinenteYReferencias(String codigoContinente) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
// Borrado de Repartos en que haya relaciones con un Continente (Actor, Película
|
||||||
|
// o Director de la película)
|
||||||
|
IRepartoDAO iRepartoDAO = new RepartoDaoHibernate();
|
||||||
|
iRepartoDAO.borrarRepartoReferenciasContinente(codigoContinente);
|
||||||
|
|
||||||
|
// Borrado de Actores que nacieron en un país del continente a borrar
|
||||||
|
IActorDAO iActorDAO = new ActorDaoHibernate();
|
||||||
|
iActorDAO.borrarActoresReferenciasContinente(codigoContinente);
|
||||||
|
|
||||||
|
// Borrado de Películas en que haya relaciones con un país (Localización
|
||||||
|
// Película o Director de la película)
|
||||||
|
IPeliculaDAO iPeliculaDAO = new PeliculaDaoHibernate();
|
||||||
|
iPeliculaDAO.borrarPeliculasReferenciasContinente(codigoContinente);
|
||||||
|
|
||||||
|
// Borrado de los directores cuyo país de nacimiento es en un país del
|
||||||
|
// continente a borrar
|
||||||
|
IDirectorDAO iDirectorDAO = new DirectorDaoHibernate();
|
||||||
|
iDirectorDAO.borrarDirectoresReferenciasContinente(codigoContinente);
|
||||||
|
|
||||||
|
// Borrado de los paises del continente
|
||||||
|
IPaisDAO iPaisDAO = new PaisDaoHibernate();
|
||||||
|
iPaisDAO.borrarPaisesContinente(codigoContinente);
|
||||||
|
|
||||||
|
// Borrado del continente
|
||||||
|
IContinenteDAO iContinenteDAO = new ContinenteDaoHibernate();
|
||||||
|
iContinenteDAO.borrarContinente(codigoContinente);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
package org.lapaloma.aadd.cine.servicio;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IDirectorDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IPeliculaDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IRepartoDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.DirectorDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.PeliculaDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.RepartoDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||||
|
|
||||||
|
public class DirectorService {
|
||||||
|
public void borrarDirectorYReferencias(Integer idDirector) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
// Borrado de Repartos de un Actor
|
||||||
|
IRepartoDAO iRepartoDAO = new RepartoDaoHibernate();
|
||||||
|
iRepartoDAO.borrarRepartoPeliculasDirector(idDirector);
|
||||||
|
|
||||||
|
// Borrado de Películas de un Director
|
||||||
|
IPeliculaDAO iPeliculaDAO = new PeliculaDaoHibernate();
|
||||||
|
iPeliculaDAO.borrarPeliculasDirector(idDirector);
|
||||||
|
|
||||||
|
// Borrado del director
|
||||||
|
IDirectorDAO iDirectorDAO = new DirectorDaoHibernate();
|
||||||
|
iDirectorDAO.borrarDirector(idDirector);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
package org.lapaloma.aadd.cine.servicio;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IActorDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IDirectorDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IPaisDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IPeliculaDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IRepartoDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.ActorDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.DirectorDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.PaisDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.PeliculaDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.RepartoDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||||
|
|
||||||
|
public class PaisService {
|
||||||
|
public void borrarPaisYReferencias(Integer idPais) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
// Borrado de Repartos en que haya relaciones con un país (Actor, Película o
|
||||||
|
// Director de la película)
|
||||||
|
IRepartoDAO iRepartoDAO = new RepartoDaoHibernate();
|
||||||
|
iRepartoDAO.borrarRepartoReferenciasPais(idPais);
|
||||||
|
|
||||||
|
// Borrado de Actores que nacieron en un país
|
||||||
|
IActorDAO iActorDAO = new ActorDaoHibernate();
|
||||||
|
iActorDAO.borrarActoresReferenciasPais(idPais);
|
||||||
|
|
||||||
|
// Borrado de Películas en que haya relaciones con un país (Localización
|
||||||
|
// Película o Director de la película)
|
||||||
|
IPeliculaDAO iPeliculaDAO = new PeliculaDaoHibernate();
|
||||||
|
iPeliculaDAO.borrarPeliculasReferenciasPais(idPais);
|
||||||
|
|
||||||
|
// Borrado de los directores cuyo país de nacimiento es en un país del
|
||||||
|
// continente a borrar
|
||||||
|
IDirectorDAO iDirectorDAO = new DirectorDaoHibernate();
|
||||||
|
iDirectorDAO.borrarDirectoresReferenciasPais(idPais);
|
||||||
|
|
||||||
|
// Borrado de los paises
|
||||||
|
IPaisDAO iPaisDAO = new PaisDaoHibernate();
|
||||||
|
iPaisDAO.borrarPais(idPais);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
package org.lapaloma.aadd.cine.servicio;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IPeliculaDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.IRepartoDAO;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.PeliculaDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.dao.hbnt.RepartoDaoHibernate;
|
||||||
|
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||||
|
|
||||||
|
public class PeliculaService {
|
||||||
|
public void borrarPeliculaYReferencias(Integer idPelicula) {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getCurrentSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
// Borrado de Repartos de una Película
|
||||||
|
IRepartoDAO iRepartoDAO = new RepartoDaoHibernate();
|
||||||
|
iRepartoDAO.borrarRepartoPelicula(idPelicula);
|
||||||
|
|
||||||
|
// Borrado de Actor
|
||||||
|
IPeliculaDAO iPeliculaDAO = new PeliculaDaoHibernate();
|
||||||
|
iPeliculaDAO.borrarPelicula(idPelicula);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
package org.lapaloma.aadd.cine.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 UtilidadesCine {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
56
src/main/java/org/lapaloma/aadd/cine/vo/Actor.java
Normal file
56
src/main/java/org/lapaloma/aadd/cine/vo/Actor.java
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package org.lapaloma.aadd.cine.vo;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "actor")
|
||||||
|
public class Actor {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name="identificador")
|
||||||
|
private Integer identificador;
|
||||||
|
|
||||||
|
@Column(name="nombre", length = 50)
|
||||||
|
private String nombre;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
|
@JoinColumn(name = "id_pais")
|
||||||
|
private Pais pais;
|
||||||
|
|
||||||
|
public Integer getIdentificador() {
|
||||||
|
return identificador;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdentificador(Integer identificador) {
|
||||||
|
this.identificador = identificador;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pais getPais() {
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPais(Pais pais) {
|
||||||
|
this.pais = pais;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Actor [identificador=" + identificador + ", nombre=" + nombre + ", pais=" + pais + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/main/java/org/lapaloma/aadd/cine/vo/Continente.java
Normal file
39
src/main/java/org/lapaloma/aadd/cine/vo/Continente.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package org.lapaloma.aadd.cine.vo;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "continente")
|
||||||
|
public class Continente {
|
||||||
|
@Id
|
||||||
|
@Column(name = "codigo", columnDefinition = "char(2)")
|
||||||
|
private String codigo;
|
||||||
|
|
||||||
|
@Column(name = "nombre_continente ", length = 50)
|
||||||
|
private String nombre;
|
||||||
|
|
||||||
|
public String getCodigo() {
|
||||||
|
return codigo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCodigo(String codigo) {
|
||||||
|
this.codigo = codigo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Continente [codigo=" + codigo + ", nombre=" + nombre + "]\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
80
src/main/java/org/lapaloma/aadd/cine/vo/Director.java
Normal file
80
src/main/java/org/lapaloma/aadd/cine/vo/Director.java
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
package org.lapaloma.aadd.cine.vo;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "director")
|
||||||
|
public class Director {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name="identificador")
|
||||||
|
private Integer identificador;
|
||||||
|
|
||||||
|
@Column(name="nombre", length = 50)
|
||||||
|
private String nombre;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
|
@JoinColumn(name = "id_pais")
|
||||||
|
private Pais pais;
|
||||||
|
|
||||||
|
@Column(name="fecha_nacimiento")
|
||||||
|
private LocalDate fechaNacimiento;
|
||||||
|
|
||||||
|
@Lob
|
||||||
|
@Column(name="foto", columnDefinition="LONGBLOB")
|
||||||
|
private byte[] foto;
|
||||||
|
|
||||||
|
public Integer getIdentificador() {
|
||||||
|
return identificador;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdentificador(Integer identificador) {
|
||||||
|
this.identificador = identificador;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pais getPais() {
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPais(Pais pais) {
|
||||||
|
this.pais = pais;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getFechaNacimiento() {
|
||||||
|
return fechaNacimiento;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFechaNacimiento(LocalDate fechaNacimiento) {
|
||||||
|
this.fechaNacimiento = fechaNacimiento;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public byte[] getFoto() {
|
||||||
|
return foto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setFoto(byte[] foto) {
|
||||||
|
this.foto = foto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Director [identificador=" + identificador + ", nombre=" + nombre + ", pais=" + pais
|
||||||
|
+ ", fechaNacimiento=" + fechaNacimiento + ", foto=" + Arrays.toString(foto) + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
60
src/main/java/org/lapaloma/aadd/cine/vo/Pais.java
Normal file
60
src/main/java/org/lapaloma/aadd/cine/vo/Pais.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package org.lapaloma.aadd.cine.vo;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "pais")
|
||||||
|
public class Pais {
|
||||||
|
@Id
|
||||||
|
@Column(name = "identificador")
|
||||||
|
private Integer identificador;
|
||||||
|
|
||||||
|
@Column(name = "nombre_pais" , length = 50)
|
||||||
|
private String nombrePais;
|
||||||
|
|
||||||
|
@Column(name = "capital" , length = 20)
|
||||||
|
private String capital;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
|
@JoinColumn(name = "cod_continente")
|
||||||
|
private Continente continente;
|
||||||
|
|
||||||
|
public Integer getIdentificador() {
|
||||||
|
return identificador;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdentificador(Integer identificador) {
|
||||||
|
this.identificador = identificador;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNombrePais() {
|
||||||
|
return nombrePais;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombrePais(String nombrePais) {
|
||||||
|
this.nombrePais = nombrePais;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCapital() {
|
||||||
|
return capital;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCapital(String capital) {
|
||||||
|
this.capital = capital;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Continente getContinente() {
|
||||||
|
return continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContinente(Continente continente) {
|
||||||
|
this.continente = continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Pais [identificador=" + identificador + ", nombrePais=" + nombrePais + ", capital=" + capital
|
||||||
|
+ ", continente=" + continente + "]\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
108
src/main/java/org/lapaloma/aadd/cine/vo/Pelicula.java
Normal file
108
src/main/java/org/lapaloma/aadd/cine/vo/Pelicula.java
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
package org.lapaloma.aadd.cine.vo;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "pelicula")
|
||||||
|
public class Pelicula {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name="identificador")
|
||||||
|
private Integer identificador;
|
||||||
|
|
||||||
|
@Column(name="titulo")
|
||||||
|
private String titulo;
|
||||||
|
|
||||||
|
@Column(name="anyo", nullable = false)
|
||||||
|
private Integer anyo;
|
||||||
|
|
||||||
|
@Column(name="idioma", length = 50)
|
||||||
|
private String idioma;
|
||||||
|
|
||||||
|
@Column(name="color", columnDefinition = "boolean")
|
||||||
|
private Boolean color;
|
||||||
|
|
||||||
|
@Column(name="observ")
|
||||||
|
private String observacion;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
|
@JoinColumn(name = "id_pais")
|
||||||
|
private Pais paisLocalizacion;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
|
@JoinColumn(name = "id_director", nullable = false)
|
||||||
|
private Director director;
|
||||||
|
|
||||||
|
public Integer getIdentificador() {
|
||||||
|
return identificador;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdentificador(Integer identificador) {
|
||||||
|
this.identificador = identificador;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitulo() {
|
||||||
|
return titulo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitulo(String titulo) {
|
||||||
|
this.titulo = titulo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getAnyo() {
|
||||||
|
return anyo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAnyo(Integer anyo) {
|
||||||
|
this.anyo = anyo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIdioma() {
|
||||||
|
return idioma;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdioma(String idioma) {
|
||||||
|
this.idioma = idioma;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(Boolean color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getObservacion() {
|
||||||
|
return observacion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setObservacion(String observacion) {
|
||||||
|
this.observacion = observacion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pais getPaisLocalizacion() {
|
||||||
|
return paisLocalizacion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPaisLocalizacion(Pais paisLocalizacion) {
|
||||||
|
this.paisLocalizacion = paisLocalizacion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Director getDirector() {
|
||||||
|
return director;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDirector(Director director) {
|
||||||
|
this.director = director;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Pelicula [identificador=" + identificador + ", titulo=" + titulo + ", anyo=" + anyo + ", idioma="
|
||||||
|
+ idioma + ", color=" + color + ", observacion=" + observacion + ", paisLocalizacion="
|
||||||
|
+ paisLocalizacion + ", director=" + director + "]\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
60
src/main/java/org/lapaloma/aadd/cine/vo/Reparto.java
Normal file
60
src/main/java/org/lapaloma/aadd/cine/vo/Reparto.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package org.lapaloma.aadd.cine.vo;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "reparto")
|
||||||
|
public class Reparto {
|
||||||
|
|
||||||
|
@EmbeddedId
|
||||||
|
private RepartoId idReparto;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
|
@MapsId("idActor") // Esto mapea a idActor en RepartoId
|
||||||
|
@JoinColumn(name = "id_actor")
|
||||||
|
private Actor actor;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
|
@MapsId("idPelicula") // Esto mapea a idPelicula en RepartoId
|
||||||
|
@JoinColumn(name = "id_pelicula")
|
||||||
|
private Pelicula pelicula;
|
||||||
|
|
||||||
|
@Column(name = "personaje", length = 50, nullable = false)
|
||||||
|
private String personaje;
|
||||||
|
|
||||||
|
public Actor getActor() {
|
||||||
|
return actor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActor(Actor actor) {
|
||||||
|
this.actor = actor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pelicula getPelicula() {
|
||||||
|
return pelicula;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPelicula(Pelicula pelicula) {
|
||||||
|
this.pelicula = pelicula;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPersonaje() {
|
||||||
|
return personaje;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPersonaje(String personaje) {
|
||||||
|
this.personaje = personaje;
|
||||||
|
}
|
||||||
|
public RepartoId getIdReparto() {
|
||||||
|
return idReparto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdReparto(RepartoId idReparto) {
|
||||||
|
this.idReparto = idReparto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Reparto [actor=" + actor + ", pelicula=" + pelicula + ", personaje=" + personaje + "]\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
60
src/main/java/org/lapaloma/aadd/cine/vo/RepartoId.java
Normal file
60
src/main/java/org/lapaloma/aadd/cine/vo/RepartoId.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package org.lapaloma.aadd.cine.vo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Embeddable;
|
||||||
|
|
||||||
|
|
||||||
|
@Embeddable
|
||||||
|
public class RepartoId implements Serializable {
|
||||||
|
private static final long serialVersionUID = 6142631595518522640L;
|
||||||
|
|
||||||
|
@Column(name = "id_actor")
|
||||||
|
private Integer idActor;
|
||||||
|
|
||||||
|
@Column(name = "id_pelicula")
|
||||||
|
private Integer idPelicula;
|
||||||
|
|
||||||
|
public RepartoId() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public RepartoId(Integer idActor, Integer idPelicula) {
|
||||||
|
this.idActor = idActor;
|
||||||
|
this.idPelicula = idPelicula;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
RepartoId idReparto= (RepartoId) o;
|
||||||
|
return Objects.equals(idActor, idReparto.idActor) && Objects.equals(idPelicula, idReparto.idPelicula);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(idActor, idPelicula);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getIdActor() {
|
||||||
|
return idActor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdActor(Integer idActor) {
|
||||||
|
this.idActor = idActor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getIdPelicula() {
|
||||||
|
return idPelicula;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdPelicula(Integer idPelicula) {
|
||||||
|
this.idPelicula = idPelicula;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "RepartoId [idActor=" + idActor + ", idPelicula=" + idPelicula + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
32
src/main/resources/META-INF/persistence.xml
Normal file
32
src/main/resources/META-INF/persistence.xml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?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_CINE_MYSQL" transaction-type="RESOURCE_LOCAL">
|
||||||
|
<!-- Proveedor de persistencia JPA -->
|
||||||
|
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||||
|
|
||||||
|
<!-- Mapeo de clases -->
|
||||||
|
<class>org.lapaloma.aadd.cine.vo.Continente</class>
|
||||||
|
<class>org.lapaloma.aadd.cine.vo.Pais</class>
|
||||||
|
<class>org.lapaloma.aadd.cine.vo.Director</class>
|
||||||
|
|
||||||
|
<!-- Configuración de propiedades del SGDB (MySQL) -->
|
||||||
|
<properties>
|
||||||
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:mysql://192.168.1.36:3306/Cine"/>
|
||||||
|
<property name="jakarta.persistence.jdbc.user" value="root"/>
|
||||||
|
<property name="jakarta.persistence.jdbc.password" value="mysql_123"/>
|
||||||
|
<property name="jakarta.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/>
|
||||||
|
<!-- Configuración Hibernate -->
|
||||||
|
<property name="hibernate.hbm2ddl.auto" value="update"/>
|
||||||
|
<property name="hibernate.show_sql" value="true"/>
|
||||||
|
<property name="format_sql" value="true" />
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</persistence-unit>
|
||||||
|
|
||||||
|
</persistence>
|
||||||
4
src/main/resources/conf.properties
Normal file
4
src/main/resources/conf.properties
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Información sobre directores XML
|
||||||
|
directores.fichero.xml.ruta=ficheros/info_directores.xml
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user