Пример #1
0
  @Override
  public StatusChamado getById(int codigo) throws BusinessException {
    Connection con = null;
    String sql = null;

    try {
      // Obtem a conexão
      con = Conexao.getInstance().obterConexao();

      String origem = Conexao.getInstance().obterOrigem();
      sql = FabricaSql.getSql(origem + PROCURAR_STATUS_BY_ID);

      if (DEBUG) System.out.println("SQL - " + sql);

      PreparedStatement stmt = con.prepareStatement(sql);
      stmt.setInt(1, codigo);

      ResultSet rs = stmt.executeQuery();
      StatusChamado status = null;
      while (rs.next()) {
        String nome = rs.getString("NOME");
        status = new StatusChamado(nome);
      }
      rs.close();
      stmt.close();
      return status;

    } catch (SQLException e) {
      SQLExceptionHandler.tratarSQLException(this.getClass().getName(), e);
      return null;

    } finally {
      Conexao.getInstance().fecharConexao(con);
    }
  }
Пример #2
0
  public boolean adicionaStatus(StatusChamado status) throws BusinessException {
    Connection con = null;
    String sql = null;

    try {
      con = Conexao.getInstance().obterConexao();
      con.setAutoCommit(false);

      String origem = Conexao.getInstance().obterOrigem();
      sql = FabricaSql.getSql(origem + INSERIR_STATUS);

      if (DEBUG) System.out.println(sql);

      PreparedStatement stmt = con.prepareStatement(sql);
      // TODO -colocar os parametros

      int qtd = stmt.executeUpdate();

      if (DEBUG) System.out.println("QTDE: " + qtd);

      if (qtd != 1) {
        con.rollback();
        stmt.close();
        throw new BusinessException("Quantidade de linhas afetadas inválida: " + qtd);
      } else con.commit();
      stmt.close();
    } catch (SQLException e) {
      SQLExceptionHandler.tratarSQLException(this.getClass().getName(), e);
      return false;

    } finally {
      Conexao.getInstance().fecharConexao(con);
    }
    return true;
  }
Пример #3
0
  public int procurarStatus(StatusChamado status) throws BusinessException {
    Connection con = null;
    String sql = null;

    try {
      // Obtem a conexão
      con = Conexao.getInstance().obterConexao();

      String origem = Conexao.getInstance().obterOrigem();
      sql = FabricaSql.getSql(origem + PROCURAR_STATUS);

      if (DEBUG) System.out.println("SQL - " + sql);

      PreparedStatement stmt = con.prepareStatement(sql);
      stmt.setString(1, status.getNome());

      ResultSet rs = stmt.executeQuery();

      int codigo = -1;

      while (rs.next()) {
        codigo = rs.getInt("CODIGO");
      }
      rs.close();
      stmt.close();
      return codigo;

    } catch (SQLException e) {
      SQLExceptionHandler.tratarSQLException(this.getClass().getName(), e);
      return -1;

    } finally {
      Conexao.getInstance().fecharConexao(con);
    }
  }
Пример #4
0
  @Override
  public List<StatusChamado> listarTodos() throws BusinessException {
    Connection con = null;
    String sql = null;

    try {
      // Obtem a conexão
      con = Conexao.getInstance().obterConexao();

      String origem = Conexao.getInstance().obterOrigem();
      sql = FabricaSql.getSql(origem + LISTAR_TODOS_STATUS);

      if (DEBUG) System.out.println("SQL - " + sql);

      PreparedStatement stmt = con.prepareStatement(sql);
      ResultSet rs = stmt.executeQuery();

      List<StatusChamado> listaStatus = new ArrayList<StatusChamado>();
      while (rs.next()) {
        String nome = rs.getString("NOME");
        StatusChamado status = new StatusChamado(nome);
        int codigo = rs.getInt("CODIGO");
        status.setCodigo(codigo);
        listaStatus.add(status);
      }
      rs.close();
      stmt.close();
      return listaStatus;

    } catch (SQLException e) {
      SQLExceptionHandler.tratarSQLException(this.getClass().getName(), e);
      return null;

    } finally {
      Conexao.getInstance().fecharConexao(con);
    }
  }