br.com.wservice.LabRequisicaoFixingDatas.java Source code

Java tutorial

Introduction

Here is the source code for br.com.wservice.LabRequisicaoFixingDatas.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.wservice;

import br.com.hibernate.entities.*;
import br.com.hibernate.utils.SessionFactoriByDBName;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.Query;
import org.hibernate.criterion.Disjunction;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author eros
 */
public class LabRequisicaoFixingDatas {

    /**
     * Pega LabRequisicao e a lista de LabDetalheRequisicao de novos exame  e faz o
     * update nas datas de Fatura
     *
     * @param reqStCodigo
     * @param xmlSolicitacao
     */
    public static void arrumandoDatas(String reqStCodigo, List<LabDetalheRequisicao> listNewExames,
            String strDbName) {
        if (listNewExames != null && !listNewExames.isEmpty()) {
            Session session = null;
            try {
                session = SessionFactoriByDBName.getCurrentSession4FacesByDbName(strDbName);
                Transaction tx = session.beginTransaction();
                LabRequisicao labRequisicao = (LabRequisicao) session.get(LabRequisicao.class,
                        new Long(reqStCodigo));
                //                if(labRequisicao.isSalvoNoDb()){}

                for (LabDetalheRequisicao labDetalheRequisicao : listNewExames) {
                    labDetalheRequisicao.setDerDtFatura(labRequisicao.getReqDtCadastro());
                    labDetalheRequisicao.setReqDtCadastro(labRequisicao.getReqDtCadastro());
                    session.update(labDetalheRequisicao);
                }
                tx.commit();
            } catch (HibernateException xcp) {
                xcp.printStackTrace();
            } finally {
                if (session != null) {
                    session.close();
                }
            }
        } else {
            System.out.println("No h novos exames para arrumar a data da fatura.");
        }

    }

}