package dao;
import bo.HibernateUtil;
import bo.Strat;
import daoI.IStratDao;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
public class StratDao implements IStratDao {
Session session = null;
public List getAll(int idForaj) {
List<Strat> strat = null;
try {
this.session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
Query q = session.createQuery("from Strat as strat where strat.foraj.idForaj ='" + idForaj + "'");
strat = (List<Strat>) q.list();
} catch (Exception e) {
e.printStackTrace();
}
return strat;
}
public Strat geStratByID(int idStrat) {
Strat strat = null;
try {
this.session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
strat = (Strat) session.get(Strat.class, idStrat);
} catch (Exception e) {
e.printStackTrace();
}
return strat;
}
public void saveOrUpdate(Strat strat) {
try {
this.session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
if (strat.getIdStrat() == null) {
session.save(strat);
} else {
session.merge(strat);
}
tx.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
public void delete(int idStrat) {
try {
this.session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
Strat strat = (Strat) session.get(Strat.class, idStrat);
session.delete(strat);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
public void addNrStrat(int idStrat, int nrStrat) {
try {
this.session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
Strat strat = (Strat) session.get(Strat.class, idStrat);
strat.setNumarStrat(nrStrat);
session.update(strat);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
}