Package dao

Source Code of dao.CompresiuneDao

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

import bo.HibernateUtil;
import bo.Compresiune;
import daoI.ICompresiuneDao;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

public class CompresiuneDao implements ICompresiuneDao {

    Session session = null;

    public Compresiune getCompresiuneByID(int cID) {

        Compresiune comp = null;
        List<Compresiune> compList = null;

        try {
            this.session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from Compresiune as lang where lang.idCompresiune='" + cID + "'");
            compList = (List<Compresiune>) q.list();
            comp = ((Compresiune) compList.get(0));
            //tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return comp;
    }

    public List<Compresiune> geCompresiuneByIDProba(int probaID) {
        Compresiune comp = null;
        List<Compresiune> compList = null;

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

    public void saveOrUpdate(Compresiune comp) {
        try {
            this.session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
            org.hibernate.Transaction tx = session.beginTransaction();
            if (comp.getIdCompresiune() == null) {
                session.save(comp);
            } else {
                Query q = session.createQuery("from Compresiune as lang where lang.proba.idProba='" + comp.getProba().getIdProba() + "'and land.sigma='" + comp.getSigma() + "'");
                List<Compresiune> compList = (List<Compresiune>) q.list();
                if (compList == null) {
                    session.merge(comp);
                }
            }
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
TOP

Related Classes of dao.CompresiuneDao

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.