Пример #1
0
  public void AccreditDel(int adminid) throws Exception {
    // 打开线程安全的session对象
    Session session = HibernateUtil.currentSession();
    // 打开事务
    Transaction tx = session.beginTransaction();
    try {
      String sqlString = "delete from accredit where aid = :aid ";
      Query q = session.createSQLQuery(sqlString);
      q.setInteger("aid", adminid);
      q.executeUpdate();

      tx.commit();

    } catch (ConstraintViolationException cne) {
      tx.rollback();
      System.out.println(cne.getSQLException().getMessage());

      throw cne.getSQLException();
    } catch (org.hibernate.exception.SQLGrammarException e) {
      tx.rollback();
      System.out.println(e.getSQLException().getMessage());
      throw e.getSQLException();
    } catch (Exception e) {
      e.printStackTrace();
      tx.rollback();
      System.out.println(e.getMessage());
      throw e;
    } finally {
      HibernateUtil.closeSession();
    }
    return;
  }
Пример #2
0
 public List buscarSinTransaccion(Class object, Criteria criterio) {
   List<ObjetoPersitente> lista = null;
   try {
     lista = criterio.list();
   } catch (SQLGrammarException ex) {
     System.out.println(ex.getMessage());
   }
   return lista;
 }
Пример #3
0
 public List buscar(Class object, Criteria criterio) {
   Conexion.getInstancia().iniciarTX();
   List<ObjetoPersitente> lista = null;
   try {
     lista = criterio.list();
   } catch (SQLGrammarException ex) {
     System.out.println(ex.getMessage());
   }
   Conexion.getInstancia().confirmarTx();
   return lista;
 }
Пример #4
0
  public void AccreditMod(int adminid, int[] privilegeids) throws Exception {
    // 打开线程安全的session对象
    Session session = HibernateUtil.currentSession();
    // 打开事务
    Transaction tx = session.beginTransaction();
    try {
      String sqlString = "delete from accredit where aid = :aid ";
      Query q = session.createSQLQuery(sqlString);
      q.setInteger("aid", adminid);
      q.executeUpdate();

      AdminAccredit aa = new AdminAccredit();
      aa.setAid(adminid);
      aa.setPid(0);
      session.save(aa);
      if (privilegeids != null) {
        for (int i = 0; i < privilegeids.length; i++) {
          aa = new AdminAccredit();
          aa.setAid(adminid);
          aa.setPid(privilegeids[i]);
          session.save(aa);
        }
      }

      tx.commit();

    } catch (ConstraintViolationException cne) {
      tx.rollback();
      System.out.println(cne.getSQLException().getMessage());

      throw cne.getSQLException();
    } catch (org.hibernate.exception.SQLGrammarException e) {
      tx.rollback();
      System.out.println(e.getSQLException().getMessage());
      throw e.getSQLException();
    } catch (Exception e) {
      e.printStackTrace();
      tx.rollback();
      System.out.println(e.getMessage());
      throw e;
    } finally {
      HibernateUtil.closeSession();
    }
    return;
  }