Compare commits
No commits in common. "44131f2b65a3c9f37762f6c4b2b80fe995e639c6" and "12b301d8fb53d385754fe7d2cfdf66243742f7eb" have entirely different histories.
44131f2b65
...
12b301d8fb
@ -1,8 +1,12 @@
|
|||||||
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;
|
||||||
@ -18,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();
|
||||||
@ -39,21 +43,20 @@ 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 {
|
||||||
EntityManager gestorEntidades = null;
|
Transaction transaccion = null;
|
||||||
EntityTransaction transaccion = null;
|
Session sesion = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
transaccion = gestorEntidades.getTransaction();
|
transaccion = sesion.beginTransaction();
|
||||||
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) {
|
||||||
@ -62,10 +65,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 (gestorEntidades != null) {
|
if (sesion != null) {
|
||||||
gestorEntidades.close();
|
sesion.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -84,7 +87,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +103,8 @@ 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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,12 @@
|
|||||||
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;
|
||||||
@ -18,15 +22,15 @@ 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);
|
||||||
|
|
||||||
transaccion.commit();
|
transaccion.commit();
|
||||||
@ -39,7 +43,7 @@ public class ProyectoDaoJPA implements IProyectoDAO {
|
|||||||
if (gestorEntidades != null) {
|
if (gestorEntidades != null) {
|
||||||
gestorEntidades.close();
|
gestorEntidades.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -57,8 +61,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,16 +71,15 @@ public class ProyectoDaoJPA implements IProyectoDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actualizarEntidad(Proyecto entidad) throws ProyectosIESException {
|
public void actualizarEntidad(Proyecto entidad) throws ProyectosIESException {
|
||||||
EntityManager gestorEntidades = null;
|
Transaction transaccion = null;
|
||||||
EntityTransaction transaccion = null;
|
Session sesion = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
transaccion = gestorEntidades.getTransaction();
|
transaccion = sesion.beginTransaction();
|
||||||
transaccion.begin();
|
|
||||||
|
|
||||||
if (gestorEntidades.contains(entidad))
|
if (sesion.contains(entidad))
|
||||||
gestorEntidades.merge(entidad);
|
sesion.merge(entidad);
|
||||||
|
|
||||||
transaccion.commit();
|
transaccion.commit();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -85,10 +88,10 @@ 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 (gestorEntidades != null) {
|
if (sesion != null) {
|
||||||
gestorEntidades.close();
|
sesion.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -100,7 +103,7 @@ public class ProyectoDaoJPA implements IProyectoDAO {
|
|||||||
@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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user