Ejemplo n.º 1
0
  @Override
  public ArrayList<User> getAllUsers() throws Exception {
    dLog.info("Entering method getAllUsers");
    ArrayList<User> result = new ArrayList<User>();
    Session session = null;

    try {
      session = getSession();
      session.clear();
      Transaction tranx = session.beginTransaction();

      String hql = "select from User";
      Query query = session.createQuery(hql);
      List<?> list = query.list();

      for (int n = 0; n < list.size(); n++) {
        result.add((User) list.get(n));
      }

      tranx.commit();
      session.flush();
      session.evict(User.class);
    } catch (Exception e) {
      dLog.error("Exception in getAllUsers", e);
    } finally {
      // ensure that session is close regardless of the errors in try/catch
      if (session != null) {
        session.close();
      }
    }

    return result;
  }
Ejemplo n.º 2
0
  @Override
  public boolean deleteUser(Integer id) throws Exception {
    dLog.info("Entering method deleteUser | User ID:" + id);
    boolean result = false;
    Session session = null;

    try {
      session = getSession();
      String hql = "delete from User where id = " + id.toString();
      Query query = session.createQuery(hql);
      int row = query.executeUpdate();

      if (row > 0) {
        result = true;
      }
    } catch (Exception e) {
      dLog.error("Exception in deleteUser", e);
    } finally {
      // ensure that session is close regardless of the errors in try/catch
      if (session != null) {
        session.close();
      }
    }

    return result;
  }
Ejemplo n.º 3
0
  @SuppressWarnings("unchecked")
  @Override
  public List<User> getUsers(Integer groupid) throws Exception {
    dLog.info("Entering method getUser | Group ID: " + groupid);
    List<User> users = new ArrayList<User>();
    Session session = null;

    try {
      session = getSession();
      String hql = "from User where groupid = " + groupid.toString();
      users = session.createQuery(hql).list();
    } catch (Exception e) {
      dLog.error("Exception in getUser", e);
    } finally {
      // ensure that session is close regardless of the errors in try/catch
      if (session != null) {
        session.close();
      }
    }

    return users;
  }