⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rootdaoimpl.java

📁 are are are are are are are are are are are are
💻 JAVA
字号:
/* * RootDaoImpl.java * * Created on 2006年5月20日, 下午7:54 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package enova.orm.hibernate.daoImpl;import enova.dao.*;import enova.pojo.*;import java.util.*;import org.hibernate.*;import enova.util.*;/** * * @author vlinux */public class RootDaoImpl implements RootDao{        public Root get(Integer id) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            List list = session.createQuery("from Root where id=:id").setParameter("id",id).list();            return list.isEmpty()?null:(Root)list.get(0);        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public void updateOrInsert(Root root) throws RecordExistException, DataAccessException{        try{            Session session = HibernateUtil.currentSession();            if( root.getId()==null ){                List list = session.createQuery("from Root where username=:username")                .setParameter("username",root.getUsername()).list();                if( !list.isEmpty() )                    throw new RecordExistException(" the root's username was existed.");            }            Transaction tran = session.beginTransaction();            session.saveOrUpdate(root);            tran.commit();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public void delete(Integer id) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            Transaction tran = session.beginTransaction();            session.createQuery("delete from Root where id=:id")            .executeUpdate();            tran.commit();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public List getAll() throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            return session.createQuery("from Root").list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public List getByUsername(String username) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            return session.createQuery("from Root where username=:username")            .setParameter("username",username).list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public Root loginVerify(String username,String password) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            List list = session.createQuery("from Root where username=:username and password=:password")            .setParameter("username",username)            .setParameter("password",password)            .list();            return list.isEmpty()?null:(Root)list.get(0);        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public void changePassword(String username,String oldPassword,String newPassword) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            Transaction tran = session.beginTransaction();            session.createQuery("update from Root set password=:newPassword where username=:username and password=:oldPassword")            .setParameter("newPassword",newPassword)            .setParameter("username",username)            .setParameter("oldPassword",oldPassword)            .executeUpdate();            tran.commit();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -