br.com.dasa.sqdasa.alvaro.SqDasaDaoLabor.java Source code

Java tutorial

Introduction

Here is the source code for br.com.dasa.sqdasa.alvaro.SqDasaDaoLabor.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 br.com.dasa.sqdasa.alvaro;

import br.com.dasa.sqdasa.Informacao;
import br.com.hibernate.utils.SessionFactoriByDBName;
import br.com.utils.tipstricks.DateManipulador;
import br.com.utils.tipstricks.IOUtils;
import java.util.Date;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author f12684146896
 */
public class SqDasaDaoLabor {

    public List<Informacao> infoSqDasaRemarcacao(List<Informacao> listInformacao, String strDbName) {

        Session session = null;
        Transaction tx;

        try {
            session = SessionFactoriByDBName.getCurrentSession4FacesByDbName(strDbName);
            tx = session.beginTransaction();

            Query q = session.getNamedQuery("LogOsRemarcacao.RemarcacaoSqDasa");
            //            q.setString("dataInicio", dataInicial);
            //            q.setString("dataFinal", dataFinal);

            List result = q.list();
            tx.commit();

            if (result != null && !result.isEmpty()) {
                for (int i = 0; i < result.size(); i++) {

                    Informacao remarcacao = new Informacao();
                    Object[] tupla = (Object[]) result.get(i);
                    if (tupla[0] != null) {
                        remarcacao.setRequisicao(((Integer) tupla[0]).toString());
                    }
                    remarcacao.setMotivo((String) tupla[1]);
                    remarcacao.setDtEntrega((Date) tupla[2]);
                    remarcacao.setNomeFuncionario((String) tupla[3]);
                    remarcacao.setCpfFuncionario((String) tupla[4]);
                    remarcacao.setNomeCliente((String) tupla[5]);
                    if (tupla[6] != null) {
                        remarcacao.setDtNascimento((Date) tupla[6]);
                    }
                    remarcacao.setFato((String) tupla[7]);
                    remarcacao.setTelefone((String) tupla[8]);
                    remarcacao.setOrigemEmenda((String) tupla[9]);
                    remarcacao.setLocal((String) tupla[10]);
                    remarcacao.setTipoEmenda((String) tupla[11]);
                    remarcacao.setCentroCusto((String) tupla[12]);
                    remarcacao.setFatoNivel1((String) tupla[13]);
                    remarcacao.setFatoNivel2((String) tupla[14]);
                    remarcacao.setFatoNivel3((String) tupla[15]);
                    remarcacao.setExame((String) tupla[17]);
                    listInformacao.add(remarcacao);
                }
            }

        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }

        return listInformacao;
    }

    public List<Informacao> infoSqDasaRecoleta(List<Informacao> listInfoRecoleta, String strDbName) {

        Session session = null;
        Transaction tx;

        try {
            session = SessionFactoriByDBName.getCurrentSession4FacesByDbName(strDbName);
            tx = session.beginTransaction();

            Query q = session.getNamedQuery("NaRequisicao.Recoleta");

            List result = q.list();
            tx.commit();

            if (result != null && !result.isEmpty()) {
                for (int i = 0; i < result.size(); i++) {

                    Informacao recoleta = new Informacao();
                    Object[] tupla = (Object[]) result.get(i);

                    if (tupla[0] != null) {
                        recoleta.setRequisicao(((Integer) tupla[0]).toString());
                    }

                    if (tupla[1] != null) {
                        recoleta.setMotivo(IOUtils.convertRTF_to_String(new String((byte[]) tupla[1])));
                    }

                    recoleta.setDtEntrega((Date) tupla[2]);
                    recoleta.setNomeFuncionario((String) tupla[3]);
                    recoleta.setCpfFuncionario((String) tupla[4]);
                    recoleta.setNomeCliente((String) tupla[5]);

                    if (tupla[6] != null && !tupla[6].equals("")) {
                        recoleta.setDtNascimento(
                                DateManipulador.formatDateToPattern("yyyy-MM-dd", (String) tupla[6]));
                    }
                    recoleta.setFato((String) tupla[7]);
                    recoleta.setTelefone((String) tupla[8]);
                    recoleta.setOrigemEmenda((String) tupla[9]);
                    recoleta.setLocal((String) tupla[10]);
                    recoleta.setTipoEmenda((String) tupla[11]);
                    recoleta.setCentroCusto((String) tupla[12]);
                    recoleta.setFatoNivel1((String) tupla[13]);
                    recoleta.setFatoNivel2((String) tupla[14]);
                    recoleta.setFatoNivel3((String) tupla[15]);

                    recoleta.setExame((String) tupla[17]);

                    listInfoRecoleta.add(recoleta);
                }
            }

        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }

        return listInfoRecoleta;
    }

    public Date dbDataMySql(String strDbName) {

        Date dtMySql = null;

        Session session = null;
        Transaction tx = null;

        try {
            System.out.println("buscando session");
            session = SessionFactoriByDBName.getCurrentSession4FacesByDbName(strDbName);
            System.out.println("session ");
            tx = session.beginTransaction();
            Query q = session.createSQLQuery("select CURDATE()");
            List lDate = q.list();
            tx.commit();

            if (lDate != null && !lDate.isEmpty()) {
                dtMySql = (Date) lDate.get(0);
            }

        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }

        return dtMySql;
    }

}