Example #1
0
  public synchronized Disciplina getElementByNome(String valor) throws Exception {

    Disciplina elem;
    // percorre a lista
    for (int i = 0; i < this.listaObj.size(); i++) {
      elem = (Disciplina) this.listaObj.elementAt(i);
      if (elem.getNome().equals(valor)) {
        return elem;
      }
    }

    return null;
  }
Example #2
0
  public synchronized Vector getDisciplinasAtivas() throws Exception {

    Vector resp = new Vector();
    Disciplina elem;
    // percorre a lista
    for (int i = 0; i < this.listaObj.size(); i++) {
      elem = (Disciplina) this.listaObj.elementAt(i);
      if (!elem.isDesativada()) {
        resp.addElement(elem);
      }
    }

    return resp;
  }
Example #3
0
  public synchronized Disciplina getElementByCod(String cod) throws Exception {

    Disciplina obj;

    // percorre a lista procurando o id
    for (int i = 0; i < this.listaObj.size(); i++) {
      obj = (Disciplina) this.listaObj.elementAt(i);
      if (cod.equals(obj.getCod())) {
        return obj;
      }
    }

    // throw new Exception ("Disciplina com código " + cod + " não foi encontrado em mem�ria.");
    return null;
  }
Example #4
0
  public synchronized void remove(Disciplina obj) throws Exception {

    // PROCEDIMENTOS PR�-Remoção
    // remove listas correspondentes
    Lista_ger listager = new Lista_ger();
    listager.removeByDisciplina(obj);

    // remove turmas correspondentes
    Turma_ger turmager = new Turma_ger();
    turmager.removeByDisciplina(obj);

    // Remoção
    // ------- Remove do banco -------
    Connection dbCon = BancoDados.abreConexao();
    Statement dbStmt = dbCon.createStatement();
    ResultSet dbRs;
    String str;

    str = "DELETE FROM Disciplina WHERE cod=" + obj.getCod();
    BancoDadosLog.log(str);
    dbStmt.executeUpdate(str);

    dbStmt.close();
    dbCon.close();

    // ------- Remove da mem�ria -------
    this.listaObj.removeElement(obj);

    // PROCEDIMENTOS P�S-Remoção

  }
Example #5
0
  public void altera(Disciplina obj, String nome, String descricao) throws Exception {

    // ------- Testa consist�ncia dos dados -------
    String testeCons = testaConsistencia(obj, nome, descricao);
    if (testeCons != null)
      throw new Exception("não foi possível alterar devido ao campo " + testeCons + "");

    // ------- Altera na base de dados -------
    // Inicia a conexão com a base de dados
    Connection dbCon = BancoDados.abreConexao();
    Statement dbStmt = dbCon.createStatement();
    ResultSet dbRs;
    String str;

    nome = StringConverter.toDataBaseNotation(nome);

    str =
        "UPDATE Disciplina SET nome='"
            + nome
            + "', descricao='"
            + StringConverter.toDataBaseNotation(descricao)
            + "' WHERE cod="
            + obj.getCod();
    BancoDadosLog.log(str);
    dbStmt.executeUpdate(str);

    // Finaliza conexao
    dbStmt.close();
    dbCon.close();

    // Altera dados do objeto
    if (!obj.getNome().equals(nome)) {
      obj.setNome(nome);
    }

    if (!obj.getDescricao().equals(descricao)) {
      obj.setDescricao(descricao);
    }
  }
Example #6
0
  public synchronized String testaConsistencia(Disciplina obj, String nome, String descricao)
      throws Exception {

    boolean inclusao = (obj == null);

    // Testa atributos obrigat�rios
    if (nome == null) return "nome";
    if (nome.equals("")) return "nome";

    // Testa atributos exclusivos
    if (inclusao || !(obj.getNome().equals(nome))) {
      if (getElementByNome(nome) != null) return "nome";
    }

    /* Coloque aqui o código restante do código referente ao teste de consist�ncia */

    return null;
  }