日期:2014-05-19 浏览次数:20905 次
public class BaseDAO { private SessionFactory sessionFactory; public SessionFactory getSessionFactory() { return sessionFactory; } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } public Session getSession() { Session session = sessionFactory.openSession(); return session; } }
public Integer countBack(int forum_id) { Session session = getSession(); String hql = "select forum.countback from Forum forum where forum.id=?"; Query query = session.createQuery(hql); query.setParameter(0, forum_id); List coutbacklist = query.list(); session.close(); int coutback = (Integer) coutbacklist.get(0); return coutback; }
public boolean delete(int reforum_id, int forum_id) { try { String hql = "delete from Reforum reforum where reforum.id="+reforum_id; Session session = getSession(); Transaction tx = session.beginTransaction(); Query querydeleteReforum = session.createQuery(hql); int b=querydeleteReforum.executeUpdate(); tx.commit(); session.close(); ForumDAO fdao = new ForumDAO(); int countback = fdao.countBack(forum_id); fdao.removeCountBack(countback, forum_id); if (b != 0) { return true; } else { return false; } } catch (Exception e) { e.printStackTrace(); } return false; }
public void deleteReforum(int reforum_id, int forum_id) { try { rfdao.delete(reforum_id, forum_id); } catch (Exception e) { e.printStackTrace(); } }
public String deleteReforum() { try { //Map request = (Map) ActionContext.getContext().get("request"); forumservice.deleteReforum(Integer.parseInt(request.getParameter("reforum_id")), Integer.parseInt(request.getParameter("forum_id"))); forum_id = Integer.parseInt(request.getParameter("forum_id")); } catch (Exception e) { e.printStackTrace(); } return "success"; }
public Session getSession() { Session session = sessio