Quitar AADD Color
This commit is contained in:
parent
e0f8aa1698
commit
239d7742e7
@ -1,11 +0,0 @@
|
|||||||
package org.lapaloma.aadd.redmetro.dao;
|
|
||||||
|
|
||||||
import org.lapaloma.aadd.redmetro.vo.Color;
|
|
||||||
|
|
||||||
public interface IColorDAO {
|
|
||||||
Color obtenerColorPorID(int identificador);
|
|
||||||
|
|
||||||
void crearColor(Color color);
|
|
||||||
|
|
||||||
void actualizarColor(Color color);
|
|
||||||
}
|
|
||||||
@ -1,75 +0,0 @@
|
|||||||
package org.lapaloma.aadd.redmetro.dao.jpa;
|
|
||||||
|
|
||||||
import org.lapaloma.aadd.redmetro.dao.IColorDAO;
|
|
||||||
import org.lapaloma.aadd.redmetro.gestores.GestorEntityManagerJPA;
|
|
||||||
import org.lapaloma.aadd.redmetro.vo.Color;
|
|
||||||
|
|
||||||
import jakarta.persistence.EntityManager;
|
|
||||||
import jakarta.persistence.EntityTransaction;
|
|
||||||
|
|
||||||
public class ColorDaoJPA implements IColorDAO {
|
|
||||||
@Override
|
|
||||||
public Color obtenerColorPorID(int codigo) {
|
|
||||||
Color color = null;
|
|
||||||
|
|
||||||
// try con recursos "cerrables": Session
|
|
||||||
try (EntityManager gestorEntidades = GestorEntityManagerJPA.getEntityManager()) {
|
|
||||||
color = gestorEntidades.find(Color.class, codigo);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void crearColor(Color color) {
|
|
||||||
EntityManager gestorEntidades = null;
|
|
||||||
EntityTransaction transaccion = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
|
||||||
transaccion = gestorEntidades.getTransaction();
|
|
||||||
transaccion.begin();
|
|
||||||
|
|
||||||
gestorEntidades.persist(color);
|
|
||||||
|
|
||||||
transaccion.commit();
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (transaccion != null && transaccion.isActive()) {
|
|
||||||
transaccion.rollback();
|
|
||||||
}
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (gestorEntidades != null) {
|
|
||||||
gestorEntidades.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actualizarColor(Color color) {
|
|
||||||
EntityManager gestorEntidades = null;
|
|
||||||
EntityTransaction transaccion = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
|
||||||
transaccion = gestorEntidades.getTransaction();
|
|
||||||
transaccion.begin();
|
|
||||||
|
|
||||||
if (!gestorEntidades.contains(color))
|
|
||||||
gestorEntidades.merge(color);
|
|
||||||
|
|
||||||
transaccion.commit();
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (transaccion != null && transaccion.isActive()) {
|
|
||||||
transaccion.rollback();
|
|
||||||
}
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (gestorEntidades != null) {
|
|
||||||
gestorEntidades.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user