?? dbstudentimpl.java
字號:
package com.middle.graduate.biz.dao.impl;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import com.middle.graduate.biz.dao.DBStudentDao;
import com.middle.graduate.biz.entity.Student;
import com.middle.graduate.biz.entity.Topic;
import com.middle.graduate.biz.exce.DataException;
import com.middle.graduate.util.HbnUtil;
public class DBStudentImpl implements DBStudentDao {
public void changePassword(int studentId, String password) throws DataException {
Session session = HbnUtil.getSession();
try {
session.beginTransaction();
String sql = "update t_student set t_password = ? where t_studentId = ?";
session.createSQLQuery(sql).setString(0, password).setInteger(1, studentId).executeUpdate();
session.getTransaction().commit();
} catch (HibernateException e) {
e.printStackTrace();
session.getTransaction().rollback();
throw new DataException("db: student change password error");
} finally {
HbnUtil.closeSession();
}
}
public boolean login(int studentId, String password) throws DataException {
Session session = HbnUtil.getSession();
try {
session.beginTransaction();
String sql = "select t_password from t_student where t_studentId = ?";
String pwd = (String)session.createSQLQuery(sql).setInteger(0, studentId).uniqueResult();
if(pwd.equals(password)) {
return true;
} else {
return false;
}
} catch (HibernateException e) {
e.printStackTrace();
throw new DataException("student login error");
}
}
public List<Topic> queryAllTopic() throws DataException {
Session session = HbnUtil.getSession();
try {
session.beginTransaction();
String hql = "from Topic t order by t.topicId";
List<Topic> list = session.createQuery(hql).list();
return list;
} catch (HibernateException e) {
e.printStackTrace();
throw new DataException("db: student query all topic error");
}
}
public Student querySelectedTopic(int studentId) throws DataException {
Session session = HbnUtil.getSession();
try {
session.beginTransaction();
String hql = "from Student s where s.studentId = ?";
Student student = (Student)session.createQuery(hql).setInteger(0, studentId).uniqueResult();
return student;
} catch (HibernateException e) {
e.printStackTrace();
throw new DataException("db: student query topic by id error");
}
}
public void quitTopic(int studentId, int topicId) throws DataException {
Session session = HbnUtil.getSession();
try {
session.beginTransaction();
String sql = "update t_student, t_topic set f_topic = 0, t_topicState = 0 where t_studentId = ? and t_topicId = ?";
session.createSQLQuery(sql).setInteger(0, studentId).setInteger(1, topicId).executeUpdate();
session.getTransaction().commit();
} catch (HibernateException e) {
e.printStackTrace();
session.getTransaction().rollback();
throw new DataException("db: student quit topic error");
} finally {
HbnUtil.closeSession();
}
}
public void selectTopic(int studentId, int topicId) throws DataException {
Session session = HbnUtil.getSession();
try {
session.beginTransaction();
String sql = "update t_student, t_topic set f_topic = ?, t_topicState = 1 where t_studentId = ? and t_topicId = ?";
session.createSQLQuery(sql).setInteger(0, topicId).setInteger(1, studentId).setInteger(2, topicId).executeUpdate();
session.getTransaction().commit();
} catch (HibernateException e) {
e.printStackTrace();
session.getTransaction().rollback();
throw new DataException("db: student select topic error");
} finally {
HbnUtil.closeSession();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -