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

📄 studentdaoimpl.java

📁 are are are are are are are are are are are are
💻 JAVA
字号:
/* * StudentDaoImpl.java * * Created on 2006年5月21日, 上午12:02 * * 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 StudentDaoImpl implements StudentDao{        public Student get(Integer id) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            List list = session.createQuery("from Student where id=:id")            .setParameter("id",id)            .list();            return list.isEmpty()?null:(Student)list.get(0);        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public void updateOrInsert(Student student)  throws RecordExistException, DataAccessException{        try{            Session session = HibernateUtil.currentSession();            if( student.getId()==null ){                List list = session.createQuery("from Student where number=:number")                .setParameter("number",student.getNumber())                .list();                if( !list.isEmpty() )                    throw new RecordExistException("the student's number was exist.");            }            Transaction tran = session.beginTransaction();            session.saveOrUpdate(student);            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 Student where id=:id")            .setParameter("id",id)            .executeUpdate();            tran.commit();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public Student loginVerify(String number,String password) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            List list = session.createQuery("from Student where number=:number and password=:password")            .setParameter("number",number)            .setParameter("password",password)            .list();            return list.isEmpty()?null:(Student)list.get(0);        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public void changePassword(String number,String oldPassword,String newPassword) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            Transaction tran = session.beginTransaction();            session.createQuery("update from Student set password=:newPassword where number=:number and password=:oldPassword")            .setParameter("newPassword",newPassword)            .setParameter("oldPassword",oldPassword)            .setParameter("number",number)            .executeUpdate();            tran.commit();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public List getByClassIdSortNumber(Integer classId) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            return session.createQuery("from Student where CLASS_ID=:classId order by number")            .setParameter("classId",classId)            .list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public List getByName(String name) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            return session.createQuery("from Student where name like :name")            .setParameter("name","%"+name+"%")            .list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public List getByClassIdAndName(Integer classId,String name) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            return session.createQuery("from Student where CLASS_ID=:classId and name like :name")            .setParameter("classId",classId)            .setParameter("name","%"+name+"%")            .list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }        public List getByNumber(String number) throws DataAccessException{        try{            Session session = HibernateUtil.currentSession();            return session.createQuery("from Student where number=:number")            .setParameter("number",number)            .list();        }catch(HibernateException he){            throw new DataAccessException(he.toString());        }finally{            HibernateUtil.closeSession();        }    }}

⌨️ 快捷键说明

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