示例#1
0
  public void updateAdmin(Admin admin) throws DBException {
    Session session;
    Transaction tx = null;
    try {
      session = HibernateSessionFactory.currentSession();
      tx = session.beginTransaction();
      session.update(admin);
      tx.commit();
    } catch (HibernateException e) {

      try {
        tx.rollback();

      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
      e.printStackTrace();
      throw new DBException("获取对象失败!");
    } finally {
      try {
        HibernateSessionFactory.closeSession();
      } catch (HibernateException e) {
        e.printStackTrace();
      }
    }
  }
示例#2
0
  public void deleteAdmin(Long id) throws DBException {
    Session session;
    Admin admin = null;
    Transaction tx = null;
    try {
      session = HibernateSessionFactory.currentSession();
      tx = session.beginTransaction();
      admin = (Admin) session.load(Admin.class, id);
      session.delete(admin);
      tx.commit();
    } catch (HibernateException e) {

      try {
        tx.rollback();

      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
      e.printStackTrace();
      throw new DBException("更新对象失败!");
    } finally {
      try {
        HibernateSessionFactory.closeSession();
      } catch (HibernateException e) {
        e.printStackTrace();
      }
    }
  }
示例#3
0
 public Admin getAdminByName(String name) throws DBException {
   Session session;
   Admin admin = null;
   try {
     session = HibernateSessionFactory.currentSession();
     List list =
         session
             .createQuery("from com.bookstore.po.Admin admin where admin.name=:name")
             .setString("name", name)
             .list();
     if (list != null && list.size() > 0) {
       admin = (Admin) list.get(0);
     }
   } catch (HibernateException e) {
     e.printStackTrace();
     throw new DBException("获取对象失败!");
   } finally {
     try {
       HibernateSessionFactory.closeSession();
     } catch (HibernateException e) {
       e.printStackTrace();
     }
   }
   return admin;
 }
示例#4
0
  public List getAdminListByPage(int pagesize, int curpage) throws DBException {
    List list = null;
    int Firstroll = (pagesize - 1) * curpage;
    Session session;
    try {
      session = HibernateSessionFactory.currentSession();
      list =
          session
              .createQuery("from com.bookstore.po.Admin admin  ")
              .setFirstResult((curpage - 1) * pagesize)
              .setMaxResults(pagesize)
              .list();
      System.out.println(">>>>>>>>>>>>>>>>>" + list.size());

    } catch (HibernateException e) {
      e.printStackTrace();
      throw new DBException("获取对象失败!");
    } finally {
      try {
        HibernateSessionFactory.closeSession();
      } catch (HibernateException e) {
        e.printStackTrace();
        throw new DBException("关闭session失败!");
      }
    }
    return list;
  }
示例#5
0
 public Admin getAdmin(Long id) throws DBException {
   Session session;
   Admin admin = null;
   try {
     session = HibernateSessionFactory.currentSession();
     admin = (Admin) session.get(Admin.class, id);
   } catch (HibernateException e) {
     e.printStackTrace();
     throw new DBException("获取对象失败!");
   } finally {
     try {
       HibernateSessionFactory.closeSession();
     } catch (HibernateException e) {
       e.printStackTrace();
     }
   }
   return admin;
 }
示例#6
0
  public List getAdminList() throws DBException {
    List list = null;
    Session session;
    try {
      session = HibernateSessionFactory.currentSession();
      list = session.createQuery("from com.bookstore.po.Admin admin  ").list();
      System.out.println(">>>>>>>>>>>>>>>>>" + list.size());

    } catch (HibernateException e) {
      e.printStackTrace();
      throw new DBException("获取对象失败!");
    } finally {
      try {
        HibernateSessionFactory.closeSession();
      } catch (HibernateException e) {
        e.printStackTrace();
        throw new DBException("关闭session失败!");
      }
    }
    return list;
  }