/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dao;
import bo.HibernateUtil;
import bo.Compresibilitate;
import daoI.ICompresibilitateDao;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
public class CompresibilitateDao implements ICompresibilitateDao {
Session session = null;
public Compresibilitate getCompresibilitateByID(int metCID) {
Compresibilitate metC = null;
List<Compresibilitate> metCList = null;
try {
this.session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
Query q = session.createQuery("from Compresibilitate as lang where lang.idIncercare='" + metCID + "'");
metCList = (List<Compresibilitate>) q.list();
metC = ((Compresibilitate) metCList.get(0));
//tx.commit();
} catch (Exception e) {
e.printStackTrace();
}
return metC;
}
public List<Compresibilitate> geCompresibilitateByIDProba(int probaID) {
List<Compresibilitate> metCList = null;
try {
this.session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
Query q = session.createQuery("from Compresibilitate as lang where lang.proba.idProba='" + probaID + "'");
metCList = (List<Compresibilitate>) q.list();
//tx.commit();
} catch (Exception e) {
e.printStackTrace();
}
return metCList;
}
public List<Float> geSarciniByIDProba(int probaID) {
List<Float> sarcini = new ArrayList<Float>();
List<Compresibilitate> compList = null;
try {
session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
Query q = session.createQuery("select lang.sarcina from Compresibilitate as lang where lang.proba.idProba='" + probaID + "'");
sarcini = (List<Float>) q.list();
//tx.commit();
} catch (Exception e) {
e.printStackTrace();
}
return sarcini;
}
public Compresibilitate geCompresibilitateByIDProbaAndSarcina(int probaID, String sarcina) {
List<Compresibilitate> compList = null;
Compresibilitate comp = null;
try {
session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
Query q = session.createQuery("from Compresibilitate as lang where lang.proba.idProba='" + probaID + "'and lang.sarcina='" + sarcina + "' order by ora desc limit 1");
compList = (List<Compresibilitate>) q.list();
comp = ((Compresibilitate) compList.get(0));
//tx.commit();
} catch (Exception e) {
e.printStackTrace();
}
return comp;
}
public List<Compresibilitate> geCompresibilitateByIDProbaAndData(int probaID, String dataString) {
List<Compresibilitate> compList = null;
try {
session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
Date data = Date.valueOf(dataString);
Query q = session.createQuery("from Compresibilitate as lang where lang.proba.idProba='" + probaID + "'and lang.data='" + data + "' order by ora desc limit 1");
compList = (List<Compresibilitate>) q.list();
//tx.commit();
} catch (Exception e) {
e.printStackTrace();
}
return compList;
}
public List<Date> getDateByIDProba(int probaID) {
List<Date> sarcini = new ArrayList<Date>();
try {
session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
Query q = session.createQuery("select distinct lang.data from Compresibilitate as lang where lang.proba.idProba='" + probaID + "'");
sarcini = (List<Date>) q.list();
//tx.commit();
} catch (Exception e) {
e.printStackTrace();
}
return sarcini;
}
public void saveOrUpdate(Compresibilitate metC) {
try {
this.session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
if (metC.getIdIncercare() == null) {
session.save(metC);
} else {
session.merge(metC);
}
tx.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
}