📄 pcroomdeptempdaoimpl.java
字号:
package yyxtong.hibernate.dao.operaterimpl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import yyxtong.hibernate.dao.baseimpl.PcroomDAOImpl;
import yyxtong.hibernate.dao.operater.IPcroomDeptEmpDAO;
import yyxtong.hibernate.pojo.Dept;
import yyxtong.hibernate.pojo.Emp;
import yyxtong.hibernate.pojo.Pcroom;
import yyxtong.hibernate.pojo.PcroomDeptEmp;
public class PcroomDeptEmpDAOImpl extends HibernateDaoSupport implements
IPcroomDeptEmpDAO {
private static final Log log = LogFactory.getLog(PcroomDAOImpl.class);
/*
* (non-Javadoc)
*
* @see yyxtong.hibernate.dao.operaterimpl.IPcroomDeptEmpDAO#findAll()
*/
public List findAll() {
log.debug("finding all Pcroom instances");
try {
String hql = "select p.id,p.name,d.name,e.name "
+ "from Pcroom p left outer join p.dept d "
+ "left outer join p.emp e";
List list = getHibernateTemplate().find(hql);
List list1 = new ArrayList();
Iterator it = list.iterator();
while (it.hasNext()) {
Object[] obj = (Object[]) it.next();
PcroomDeptEmp p = new PcroomDeptEmp();
p.setId((Integer) obj[0]);
p.setPname((String) obj[1]);
p.setDname((String) obj[2]);
p.setEname((String) obj[3]);
list1.add(p);
}
return list1;
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public List findAllDept() {
log.debug("finding all Dept instances");
try {
String hql = "select d.id,d.name from Dept d";
List list = getHibernateTemplate().find(hql);
List list1 = new ArrayList();
Iterator it = list.iterator();
while (it.hasNext()) {
Dept p = new Dept();
Object[] obj = (Object[]) it.next();
p.setId((Integer) obj[0]);
p.setName((String) obj[1]);
list1.add(p);
}
return list1;
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public List findAllEmp() {
log.debug("finding all Dept instances");
try {
String hql = "select e.id,e.name from Emp e";
List list = getHibernateTemplate().find(hql);
List list1 = new ArrayList();
Iterator it = list.iterator();
while (it.hasNext()) {
Emp e = new Emp();
Object[] obj = (Object[]) it.next();
e.setId((Integer) obj[0]);
e.setName((String) obj[1]);
list1.add(e);
}
return list1;
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public void addPcroom(Pcroom transientInstance) {
log.debug("saving Pcroom instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -