示例#1
0
  public int crearRol(Rol rol) {

    int resultado;

    if (log.isDebugEnabled()) {
      log.debug(">guardarRol(rol)");
    }

    try {
      HibernateUtil.beginTransaction();

      if (dao.existeRol(rol.getNombre())) {
        resultado = 1; // Excepción. El nombre de rol ya existe
      } else {

        dao.hazPersistente(rol);

        resultado = 0; // Exito. El rol se creo satisfactoriamente.
      }

      HibernateUtil.commitTransaction();

    } catch (ExcepcionInfraestructura e) {
      HibernateUtil.rollbackTransaction();

      if (log.isWarnEnabled()) {
        log.warn("<ExcepcionInfraestructura");
      }
      resultado = 2; // Excepción. Falla en la infraestructura
    } finally {
      HibernateUtil.closeSession();
    }
    return resultado;
  }