Package dao

Source Code of dao.CitiriAreometruDao

package dao;

import bo.HibernateUtil;
import bo.CitiriAreometru;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import daoI.ICitiriAreometruDao;

public class CitiriAreometruDao implements ICitiriAreometruDao {

    Session session = null;

    public CitiriAreometru getCitiriAreometruByID(int areometruID) {

        CitiriAreometru citiriA = null;

        try {
            this.session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
            org.hibernate.Transaction tx = session.beginTransaction();
            citiriA = (CitiriAreometru) session.get(CitiriAreometru.class, areometruID);

            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return citiriA;
    }

    public CitiriAreometru getCitiriAreometruByIDProba(int probaID) {

        CitiriAreometru citiriA = null;
        List<CitiriAreometru> citiriAList = null;

        try {
            this.session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
            session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from CitiriAreometru as lang where lang.proba.idProba='" + probaID + "'");
            citiriAList = (List<CitiriAreometru>) q.list();
            citiriA = ((CitiriAreometru) citiriAList.get(0));
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return citiriA;
    }

    public void saveOrUpdate(CitiriAreometru citiriAList) {
        try {
            this.session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
            session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
            org.hibernate.Transaction tx = session.beginTransaction();
            if (citiriAList.getIdSedimentare() == null) {
                session.save(citiriAList);
            } else {
                session.merge(citiriAList);
            }
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
TOP

Related Classes of dao.CitiriAreometruDao

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.