Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.demo.impl; import com.demo.dao.VirtCreditoLineasDao; import com.demo.model.VirtCreditoSfLtNtCt; import com.demo.util.HibernateUtil; import com.demo.util.LogSistema; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.Transaction; /** * * @author ivan */ public class VirtCreditoLineasImpl implements VirtCreditoLineasDao, Serializable { @Override public List<VirtCreditoSfLtNtCt> conservados() { try { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction t = session.beginTransaction(); String consulta = "select vct.* from Virt_Credito_SF_LT_NT_CT vct where \n" + "vct.CreditosII in (select ct.CreditosII from Credito_SF_LT_NT_CT ct where ct.Cat_Subestatus_Cuenta_Subestatus_Clv=5) order by vct.CreditosII;"; System.out.println("CONSULTA CONSERVADOS VIRTUALES : " + consulta); List<VirtCreditoSfLtNtCt> lista = session.createSQLQuery(consulta).addEntity(VirtCreditoSfLtNtCt.class) .list(); t.commit(); return lista; } catch (HibernateException he) { LogSistema .guardarlog(this.getClass().getName() + " Method: conservados, Exception: " + he.getMessage()); List<VirtCreditoSfLtNtCt> lista = new ArrayList<>(); return lista; } } @Override public List<VirtCreditoSfLtNtCt> regresan() { try { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction t = session.beginTransaction(); String consulta = "select vct.* from Virt_Credito_SF_LT_NT_CT vct where \n" + "vct.CreditosII in (select ct.CreditosII from Credito_SF_LT_NT_CT ct where ct.Cat_Subestatus_Cuenta_Subestatus_Clv!=5);"; List<VirtCreditoSfLtNtCt> lista = session.createSQLQuery(consulta).addEntity(VirtCreditoSfLtNtCt.class) .list(); t.commit(); return lista; } catch (HibernateException he) { LogSistema.guardarlog(this.getClass().getName() + " Method: regresan, Exception: " + he.getMessage()); List<VirtCreditoSfLtNtCt> lista = new ArrayList<>(); return lista; } } @Override public List<VirtCreditoSfLtNtCt> nuevosCreditos() { try { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction t = session.beginTransaction(); String consulta = "select vct.* from Virt_Credito_SF_LT_NT_CT vct, Virt_Datos_primarios vdp where \n" + "vct.CreditosII not in (select ct.CreditosII from Credito_SF_LT_NT_CT ct) and \n" + "vct.Virt_Datos_primarios_Folio=vdp.Folio and\n" + "vdp.Deudor in (select dp.Deudor from Datos_primarios dp);"; List<VirtCreditoSfLtNtCt> lista = session.createSQLQuery(consulta).addEntity(VirtCreditoSfLtNtCt.class) .list(); t.commit(); return lista; } catch (HibernateException he) { LogSistema.guardarlog( this.getClass().getName() + " Method: nuevosCreditos, Exception: " + he.getMessage()); List<VirtCreditoSfLtNtCt> lista = new ArrayList<>(); return lista; } } @Override public List<VirtCreditoSfLtNtCt> nuevosTotales() { try { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction t = session.beginTransaction(); String consulta = "select vct.* from Virt_Credito_SF_LT_NT_CT vct, Virt_Datos_primarios vdp where \n" + "vct.CreditosII not in (select ct.CreditosII from Credito_SF_LT_NT_CT ct) and \n" + "vct.Virt_Datos_primarios_Folio=vdp.Folio and\n" + "vdp.Deudor not in (select dp.Deudor from Datos_primarios dp);"; List<VirtCreditoSfLtNtCt> lista = session.createSQLQuery(consulta).addEntity(VirtCreditoSfLtNtCt.class) .list(); t.commit(); return lista; } catch (HibernateException he) { LogSistema.guardarlog( this.getClass().getName() + " Method: nuevosTotales, Exception: " + he.getMessage()); List<VirtCreditoSfLtNtCt> lista = new ArrayList<>(); return lista; } } @Override public boolean eliminarCreditos(List<VirtCreditoSfLtNtCt> creditoSfLtNtCts) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); int cont; try { VirtCreditoSfLtNtCt dp; for (cont = 0; cont < creditoSfLtNtCts.size(); cont++) { dp = creditoSfLtNtCts.get(cont); session.delete(dp); } tx.commit(); return true; } catch (HibernateException he) { tx.rollback(); LogSistema.guardarlog( this.getClass().getName() + " Method: eliminarCreditos, Exception: " + he.getMessage()); return false; } } }