Package maissocial.repositorio

Source Code of maissocial.repositorio.ProfPisRepositorio

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package maissocial.repositorio;

import java.util.List;
import maissocial.entidade.ProfPis;
import maissocial.util.HibernateUtil;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

/**
*
* @author luciano
*/
public class ProfPisRepositorio {

    SessionFactory factory = HibernateUtil.getSessionFactory();

    public void salvarProfPis(ProfPis pp){
        Session session = factory.openSession();
        Transaction trans = session.beginTransaction();

        trans.begin();
        session.save(pp);

        trans.commit();
        session.close();
    }

    public void deletarProfPis(int cod){
        Session session = factory.openSession();
        Transaction trans = session.beginTransaction();

        trans.begin();

        ProfPis pp = pesquisarProfPisPorCodigo(cod);
        session.delete(pp);

        trans.commit();
        session.close();
    }

    public void deletarProfPisPorObj(ProfPis pp){
        Session session = factory.openSession();
        Transaction trans = session.beginTransaction();

        trans.begin();

        session.delete(pp);

        trans.commit();
        session.close();
    }


    public ProfPis pesquisarProfPisPorCodigo(int cod){
        Session session = factory.openSession();
        SQLQuery query = session.createSQLQuery("SELECT {prof_pis.*} FROM prof_pis {prof_pis} WHERE cod_prof_pis = "+cod);

        query.addEntity("prof_pis", ProfPis.class);

        ProfPis pp = null;
        if(query.list().size() > 0){
            pp = (ProfPis) query.list().get(0);
        }
        session.close();
        return pp;
    }

     public ProfPis pesquisarProfPisPorCpf(String cpf){
        Session session = factory.openSession();
        SQLQuery query = session.createSQLQuery("SELECT {prof_pis.*} FROM prof_pis {prof_pis} WHERE cpf = "+cpf);

        query.addEntity("prof_pis", ProfPis.class);

        ProfPis pp = null;
        if(query.list().size() > 0){
            pp = (ProfPis) query.list().get(0);
        }
        session.close();
        return pp;
    }

    public ProfPis pesquisarProfPisPorNome(String nome){
        Session session = factory.openSession();
        SQLQuery query = session.createSQLQuery("SELECT {prof_pis.*} FROM prof_pis {prof_pis} WHERE nome like '"+nome+"'");

        query.addEntity("prof_pis", ProfPis.class);

        ProfPis pp = null;
        if(query.list().size() > 0){
            pp = (ProfPis) query.list().get(0);
        }
        session.close();
        return pp;
    }


    public List pesquisarProfPisTodos(){
        Session session = factory.openSession();
        SQLQuery query = session.createSQLQuery("SELECT {prof_pis.*} FROM prof_pis {prof_pis}");

        query.addEntity("prof_pis", ProfPis.class);

        List pp = query.list();

        session.close();
        return pp;
    }

    public void alterarProfPis(ProfPis pp){
        Session session = factory.openSession();
        Transaction trans = session.beginTransaction();

        trans.begin();

        ProfPis pp2 = pesquisarProfPisPorCodigo(pp.getCodProfPis());
        pp.setCodProfPis(pp2.getCodProfPis());
        session.update(pp);

        trans.commit();
        session.close();
    }



}
TOP

Related Classes of maissocial.repositorio.ProfPisRepositorio

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.