LinkHibernateImpl.java
上传用户:yunfeng252
上传日期:2022-07-23
资源大小:12403k
文件大小:2k
源码类别:
Jsp/Servlet
开发平台:
Java
- package org.yufeng.dao.hibernate;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.hibernate.Query;
- import org.hibernate.SessionFactory;
- import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
- import org.yufeng.dao.ILeavesDao;
- import org.yufeng.dao.ILinkDao;
- import org.yufeng.domains.Link;
- public class LinkHibernateImpl extends HibernateDaoSupport implements ILinkDao {
- private ILinkDao linkDao;
- public ILinkDao getLinkDao() {
- return linkDao;
- }
- public List browseLink() throws Exception {
- return this.getHibernateTemplate().find("From Link a order by a.id");
- }
- public Link loadLink(Integer id) throws Exception {
- return (Link) this.getHibernateTemplate().load(Link.class,
- id);
- }
- public boolean delLink(Link link) throws Exception {
- boolean flag = false;
- try {
- this.getHibernateTemplate().delete(link);
- flag = true;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return flag;
- }
- public boolean delLink(int id) throws Exception {
- boolean flag = false;
- try {
- Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(
- "delete from Link link where link.id=?");
- query.setInteger(0, id);
- query.executeUpdate();
- flag = true;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return flag;
- }
- public boolean addLink(Link link) throws Exception {
- boolean flag = false;
- try {
- this.getHibernateTemplate().save(link);
- flag = true;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return flag;
- }
- public boolean updateLink(Link link) throws Exception {
- boolean flag = false;
- try {
- this.getHibernateTemplate().update(link);
- flag = true;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return flag;
- }
- }