📄 empbargaindaoimpl.java
字号:
package com.dao.impl;
import java.util.List;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import com.dao.EmpBargainDAO;
import com.entity.EmpBargain;
import com.entity.EmpRecord;
import com.hibernate.HibernateSessionFactory;
public class EmpBargainDAOImpl implements EmpBargainDAO {
public boolean addEmpBargain(EmpBargain empBargain) {
Session session = HibernateSessionFactory.openHibernateSession();
boolean state = false;
try {
Transaction tran = session.beginTransaction();
//System.out.print(empBargain.getEmpName());
session.save(empBargain);
tran.commit();
state = true;
} catch (HibernateException e) {
e.printStackTrace();
}
return state;
}
public boolean delEmpBargain(int barId) {
EmpBargain empBargain = null;
Session session = HibernateSessionFactory.openHibernateSession();
boolean state = false;
try {
Transaction tran = session.beginTransaction();
empBargain = queryEmpBargainByBarId(barId);
session.delete(empBargain);
tran.commit();
state = true;
} catch (HibernateException e) {
e.printStackTrace();
}
return state;
}
public List queryEmpBargain() {
Session session = HibernateSessionFactory.openHibernateSession();
Query query = null;
List result = null;
try {
query = session.createQuery("from EmpBargain");
result = query.list();
} catch (HibernateException e) {
e.printStackTrace();
}
return result;
}
public EmpBargain queryEmpBargainByBarId(int barId) {
Session session = HibernateSessionFactory.openHibernateSession();
EmpBargain empBargain = null;
try {
empBargain = (EmpBargain) session.get(EmpBargain.class, barId);
} catch (HibernateException e) {
e.printStackTrace();
}
return empBargain;
}
public EmpBargain queryEmpBargainByEmpId(int empId) {
Session session = HibernateSessionFactory.openHibernateSession();
EmpBargain empBargain = null;
Query query = null;
List list = null;
try {
query = session.createQuery("from EmpBargain e where e.empId="+empId+"");
list = query.list();
empBargain = (EmpBargain) list.get(0);
} catch (HibernateException e) {
e.printStackTrace();
}
return empBargain;
}
public boolean updateEmpBargain(EmpBargain empBargain) {
Session session = HibernateSessionFactory.openHibernateSession();
boolean state = false;
try {
Transaction tran = session.beginTransaction();
session.update(empBargain);
tran.commit();
state = true;
} catch (HibernateException e) {
e.printStackTrace();
}
return state;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -