Compare commits
2 Commits
12b301d8fb
...
44131f2b65
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44131f2b65 | ||
|
|
de0d013937 |
@ -1,12 +1,8 @@
|
|||||||
package es.palomafp.aadd.inm.dao.jpa;
|
package es.palomafp.aadd.inm.dao.jpa;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
|
|
||||||
import es.palomafp.aadd.inm.dao.IPatrocinadorDAO;
|
import es.palomafp.aadd.inm.dao.IPatrocinadorDAO;
|
||||||
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
import es.palomafp.aadd.inm.gestor.GestorEntityManagerJPA;
|
import es.palomafp.aadd.inm.gestor.GestorEntityManagerJPA;
|
||||||
import es.palomafp.aadd.inm.gestor.GestorSesionesHibernate;
|
|
||||||
import es.palomafp.aadd.inm.vo.Patrocinador;
|
import es.palomafp.aadd.inm.vo.Patrocinador;
|
||||||
import jakarta.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import jakarta.persistence.EntityTransaction;
|
import jakarta.persistence.EntityTransaction;
|
||||||
@ -22,14 +18,14 @@ import jakarta.persistence.TypedQuery;
|
|||||||
*/
|
*/
|
||||||
public class PatrocinadorDaoJPA implements IPatrocinadorDAO {
|
public class PatrocinadorDaoJPA implements IPatrocinadorDAO {
|
||||||
@Override
|
@Override
|
||||||
public void crearEntidad(Patrocinador entidad) throws ProyectosIESException{
|
public void crearEntidad(Patrocinador entidad) throws ProyectosIESException {
|
||||||
EntityManager gestorEntidades= null;
|
EntityManager gestorEntidades = null;
|
||||||
EntityTransaction transaccion = null;
|
EntityTransaction transaccion = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||||
transaccion = gestorEntidades.getTransaction();
|
transaccion = gestorEntidades.getTransaction();
|
||||||
transaccion .begin();
|
transaccion.begin();
|
||||||
|
|
||||||
gestorEntidades.persist(entidad);
|
gestorEntidades.persist(entidad);
|
||||||
|
|
||||||
@ -48,15 +44,16 @@ public class PatrocinadorDaoJPA implements IPatrocinadorDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actualizarEntidad(Patrocinador entidad) throws ProyectosIESException {
|
public void actualizarEntidad(Patrocinador entidad) throws ProyectosIESException {
|
||||||
Transaction transaccion = null;
|
EntityManager gestorEntidades = null;
|
||||||
Session sesion = null;
|
EntityTransaction transaccion = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sesion = GestorSesionesHibernate.getSession();
|
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||||
transaccion = sesion.beginTransaction();
|
transaccion = gestorEntidades.getTransaction();
|
||||||
|
transaccion.begin();
|
||||||
|
|
||||||
if(sesion.contains(entidad))
|
if (gestorEntidades.contains(entidad))
|
||||||
sesion.merge(entidad);
|
gestorEntidades.merge(entidad);
|
||||||
|
|
||||||
transaccion.commit();
|
transaccion.commit();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -65,8 +62,8 @@ public class PatrocinadorDaoJPA implements IPatrocinadorDAO {
|
|||||||
}
|
}
|
||||||
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_ACTUALIZACION);
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_ACTUALIZACION);
|
||||||
} finally {
|
} finally {
|
||||||
if (sesion != null) {
|
if (gestorEntidades != null) {
|
||||||
sesion.close();
|
gestorEntidades.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,7 +84,7 @@ public class PatrocinadorDaoJPA implements IPatrocinadorDAO {
|
|||||||
|
|
||||||
patrocinador = query.getSingleResult();
|
patrocinador = query.getSingleResult();
|
||||||
} catch (NoResultException e) { // no hace nada, devuelve null
|
} catch (NoResultException e) { // no hace nada, devuelve null
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_CONSULTA);
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_CONSULTA);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,5 +103,4 @@ public class PatrocinadorDaoJPA implements IPatrocinadorDAO {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,8 @@
|
|||||||
package es.palomafp.aadd.inm.dao.jpa;
|
package es.palomafp.aadd.inm.dao.jpa;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
|
|
||||||
import es.palomafp.aadd.inm.dao.IProyectoDAO;
|
import es.palomafp.aadd.inm.dao.IProyectoDAO;
|
||||||
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
import es.palomafp.aadd.inm.gestor.GestorEntityManagerJPA;
|
import es.palomafp.aadd.inm.gestor.GestorEntityManagerJPA;
|
||||||
import es.palomafp.aadd.inm.gestor.GestorSesionesHibernate;
|
|
||||||
import es.palomafp.aadd.inm.vo.Proyecto;
|
import es.palomafp.aadd.inm.vo.Proyecto;
|
||||||
import jakarta.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import jakarta.persistence.EntityTransaction;
|
import jakarta.persistence.EntityTransaction;
|
||||||
@ -22,14 +18,14 @@ import jakarta.persistence.TypedQuery;
|
|||||||
*/
|
*/
|
||||||
public class ProyectoDaoJPA implements IProyectoDAO {
|
public class ProyectoDaoJPA implements IProyectoDAO {
|
||||||
@Override
|
@Override
|
||||||
public void crearEntidad(Proyecto entidad) throws ProyectosIESException{
|
public void crearEntidad(Proyecto entidad) throws ProyectosIESException {
|
||||||
EntityManager gestorEntidades= null;
|
EntityManager gestorEntidades = null;
|
||||||
EntityTransaction transaccion = null;
|
EntityTransaction transaccion = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||||
transaccion = gestorEntidades.getTransaction();
|
transaccion = gestorEntidades.getTransaction();
|
||||||
transaccion .begin();
|
transaccion.begin();
|
||||||
|
|
||||||
gestorEntidades.persist(entidad);
|
gestorEntidades.persist(entidad);
|
||||||
|
|
||||||
@ -61,8 +57,8 @@ public class ProyectoDaoJPA implements IProyectoDAO {
|
|||||||
query.setParameter("nombre", nombreProyecto);
|
query.setParameter("nombre", nombreProyecto);
|
||||||
|
|
||||||
proyecto = query.getSingleResult();
|
proyecto = query.getSingleResult();
|
||||||
}catch (NoResultException e) { // no hace nada, devuelve null
|
} catch (NoResultException e) { // no hace nada, devuelve null
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_CONSULTA);
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_CONSULTA);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,15 +67,16 @@ public class ProyectoDaoJPA implements IProyectoDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actualizarEntidad(Proyecto entidad) throws ProyectosIESException {
|
public void actualizarEntidad(Proyecto entidad) throws ProyectosIESException {
|
||||||
Transaction transaccion = null;
|
EntityManager gestorEntidades = null;
|
||||||
Session sesion = null;
|
EntityTransaction transaccion = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sesion = GestorSesionesHibernate.getSession();
|
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||||
transaccion = sesion.beginTransaction();
|
transaccion = gestorEntidades.getTransaction();
|
||||||
|
transaccion.begin();
|
||||||
|
|
||||||
if (sesion.contains(entidad))
|
if (gestorEntidades.contains(entidad))
|
||||||
sesion.merge(entidad);
|
gestorEntidades.merge(entidad);
|
||||||
|
|
||||||
transaccion.commit();
|
transaccion.commit();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -88,8 +85,8 @@ public class ProyectoDaoJPA implements IProyectoDAO {
|
|||||||
}
|
}
|
||||||
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_ACTUALIZACION);
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_ACTUALIZACION);
|
||||||
} finally {
|
} finally {
|
||||||
if (sesion != null) {
|
if (gestorEntidades != null) {
|
||||||
sesion.close();
|
gestorEntidades.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user