com.demo.impl.prevalidacionImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.demo.impl.prevalidacionImpl.java

Source

/*
 * 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.prevalidacionDao;
import com.demo.model.Prevalidacion;
import com.demo.util.HibernateUtil;
import com.demo.util.LogSistema;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author casiopea
 */
public class prevalidacionImpl implements prevalidacionDao, Serializable {

    @Override
    public boolean cargarDatosRemesa(List<Prevalidacion> lista) {
        boolean si = false;

        try {
            Iterator iter = lista.listIterator();

            while (iter.hasNext()) {
                Prevalidacion obj = (Prevalidacion) iter.next();
                Session session = HibernateUtil.getSessionFactory().openSession();
                Transaction tx = session.beginTransaction();
                session.save(tx);
                tx.commit();
                si = true;
            }

        } catch (NullPointerException e) {
            LogSistema.guardarlog("error al cargar CampaNas. Class CampagneImpl");
            System.out.println("PrevalidacionImpl : " + e.getMessage());
            si = false;
        } catch (HibernateException j) {
            LogSistema.guardarlog("error hibernate: CampagneImpl.Class");
            System.out.println("PrevalidacionImpl : " + j.getMessage());
            si = false;

        }

        return si;
    }

    @Override
    public List<Prevalidacion> obtenerRemesa() {

        List<Prevalidacion> lista = new ArrayList();
        try {

            Session session = HibernateUtil.getSessionFactory().openSession();
            Transaction tx = session.beginTransaction();
            lista = session.createSQLQuery("select * from prevalidacion;").addEntity(Prevalidacion.class).list();
            tx.commit();

        } catch (NullPointerException e) {
            LogSistema
                    .guardarlog(this.getClass().getName() + " Method: obtenerRemesa, Exception: " + e.getMessage());

        } catch (HibernateException j) {
            LogSistema
                    .guardarlog(this.getClass().getName() + " Method: obtenerRemesa, Exception: " + j.getMessage());
            System.out.println("PrevalidacionImpl : " + j.getMessage());

        }

        return lista;
    }

}