Camnbios en PatrocinadorDaoJPA y ProyectoDaoJPA
This commit is contained in:
parent
12b301d8fb
commit
de0d013937
@ -22,15 +22,15 @@ 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);
|
||||||
|
|
||||||
transaccion.commit();
|
transaccion.commit();
|
||||||
@ -43,20 +43,21 @@ public class PatrocinadorDaoJPA implements IPatrocinadorDAO {
|
|||||||
if (gestorEntidades != null) {
|
if (gestorEntidades != null) {
|
||||||
gestorEntidades.close();
|
gestorEntidades.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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))
|
|
||||||
sesion.merge(entidad);
|
if (gestorEntidades.contains(entidad))
|
||||||
|
gestorEntidades.merge(entidad);
|
||||||
|
|
||||||
transaccion.commit();
|
transaccion.commit();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -65,10 +66,10 @@ 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -87,7 +88,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,8 +104,7 @@ public class PatrocinadorDaoJPA implements IPatrocinadorDAO {
|
|||||||
@Override
|
@Override
|
||||||
public void borrarEntidad(Integer clave) throws ProyectosIESException {
|
public void borrarEntidad(Integer clave) throws ProyectosIESException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,15 +71,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 +89,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