コード例 #1
0
ファイル: DaoRol.java プロジェクト: kiramonc/seeiiProjectF
 @Override
 public List<Rol> verTodo() {
   Session session = HibernateUtil.getSessionFactory().openSession();
   session.beginTransaction();
   Criteria criteria = session.createCriteria(Rol.class);
   //        String hql="from Rol";
   //        Query query=session.createQuery(hql);
   List<Rol> listaRol = (List<Rol>) criteria.list();
   session.close();
   return listaRol;
 }
コード例 #2
0
  public static List<Detallecompra> detallecompr(Session session) {
    session = null;
    Query query = null;
    try {

      session = HibernateUtil.getSessionFactory().openSession();
      String hql = "from Detallecompra as dc ORDER BY dc.compra.idcompra DESC ";
      query = session.createQuery(hql);

      return query.list();
    } catch (Exception e) {
    } finally {
      session.close();
    }
    return null;
  }
コード例 #3
0
ファイル: MbSLogin.java プロジェクト: giovivas10/parkul
  public String login() {
    this.session = null;
    this.transaction = null;

    try {
      DaoUsuario daoUsuario = new DaoUsuario();

      this.session = HibernateUtil.getSessionFactory().openSession();
      this.transaction = this.session.beginTransaction();

      Usuario usuarioConsulta = daoUsuario.getByNombreUsuario(this.session, this.usuario);
      // int rol = usuarioConsulta.getRol().getId();

      if (usuarioConsulta != null && usuarioConsulta.getEstado() != false) {
        if (usuarioConsulta.getContrasenia().equals(EncryptMD5.encriptaEnMD5(this.contrasenia))) {
          // if(rol==1){
          HttpSession httpSession =
              (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
          httpSession.setAttribute("usuario", this.usuario);
          httpSession.setAttribute("rol", usuarioConsulta.getRol().getId());
          this.rol = usuarioConsulta.getRol().getId();

          if (this.rol == 1) {
            RequestContext.getCurrentInstance()
                .execute(
                    "mostrarMenu('liParametros,liUsuario,liPropietarios,liAuxiliar,liInformes')");
          } else if (this.rol == 2) {
            RequestContext.getCurrentInstance().execute("mostrarMenu('liAuxiliar')");
          } else if (this.rol == 3) {
            RequestContext.getCurrentInstance().execute("mostrarMenu('liPropietarios')");
          }

          return "principal";
        }
      }

      this.transaction.commit();

      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(
                  FacesMessage.SEVERITY_ERROR,
                  "Error de acceso ",
                  " Usuario o contraseña incorrecto"));
      this.usuario = null;
      this.contrasenia = null;

      return "/index";

    } catch (Exception ex) {
      if (this.transaction != null) {
        this.transaction.rollback();
      }

      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(
                  FacesMessage.SEVERITY_FATAL,
                  "Error fatal",
                  ex.getMessage() + " Contacte al administrador"));

      return null;
    } finally {
      if (this.transaction != null) {
        this.session.close();
      }
    }
  }