Пример #1
1
  @SuppressWarnings("unchecked")
  public ResidentConverter(List<ObjectConverter.ColumnInfo> allColumns) throws java.io.IOException {
    Optional<ObjectConverter.ColumnInfo> column;

    final java.util.List<ObjectConverter.ColumnInfo> columns =
        allColumns
            .stream()
            .filter(
                it ->
                    "mixinReference".equals(it.typeSchema) && "Resident_entity".equals(it.typeName))
            .collect(Collectors.toList());
    columnCount = columns.size();

    readers = new ObjectConverter.Reader[columnCount];
    for (int i = 0; i < readers.length; i++) {
      readers[i] = (instance, rdr, ctx) -> StringConverter.skip(rdr, ctx);
    }

    final java.util.List<ObjectConverter.ColumnInfo> columnsExtended =
        allColumns
            .stream()
            .filter(
                it ->
                    "mixinReference".equals(it.typeSchema)
                        && "-ngs_Resident_type-".equals(it.typeName))
            .collect(Collectors.toList());
    columnCountExtended = columnsExtended.size();

    readersExtended = new ObjectConverter.Reader[columnCountExtended];
    for (int i = 0; i < readersExtended.length; i++) {
      readersExtended[i] = (instance, rdr, ctx) -> StringConverter.skip(rdr, ctx);
    }

    column = columns.stream().filter(it -> "id".equals(it.columnName)).findAny();
    if (!column.isPresent())
      throw new java.io.IOException(
          "Unable to find 'id' column in mixinReference Resident_entity. Check if DB is in sync");
    __index___id = (int) column.get().order - 1;

    column = columnsExtended.stream().filter(it -> "id".equals(it.columnName)).findAny();
    if (!column.isPresent())
      throw new java.io.IOException(
          "Unable to find 'id' column in mixinReference Resident. Check if DB is in sync");
    __index__extended_id = (int) column.get().order - 1;

    column = columns.stream().filter(it -> "birth".equals(it.columnName)).findAny();
    if (!column.isPresent())
      throw new java.io.IOException(
          "Unable to find 'birth' column in mixinReference Resident_entity. Check if DB is in sync");
    __index___birth = (int) column.get().order - 1;

    column = columnsExtended.stream().filter(it -> "birth".equals(it.columnName)).findAny();
    if (!column.isPresent())
      throw new java.io.IOException(
          "Unable to find 'birth' column in mixinReference Resident. Check if DB is in sync");
    __index__extended_birth = (int) column.get().order - 1;
  }
Пример #2
0
  public boolean comparaDuasRespostas(String resp1, String resp2) throws java.lang.Exception {

    // --- prepara respostas para comparacao ---

    // From DataBase Notation
    String temp1 = StringConverter.fromDataBaseNotation(resp1);
    String temp2 = StringConverter.fromDataBaseNotation(resp2);

    // lowercase
    temp1 = temp1.toLowerCase();
    temp2 = temp2.toLowerCase();

    // sem acentos
    temp1 = StringConverter.removeAcentos(temp1);
    temp2 = StringConverter.removeAcentos(temp2);

    // corrige parenteses
    temp1 = StringConverter.replace(temp1, ") (", ")(");
    temp1 = StringConverter.replace(temp1, "( ", "(");
    temp1 = StringConverter.replace(temp1, " )", ")");
    temp2 = StringConverter.replace(temp2, ") (", ")(");
    temp2 = StringConverter.replace(temp2, "( ", "(");
    temp2 = StringConverter.replace(temp2, " )", ")");

    return temp1.equals(temp2);
  }
Пример #3
0
  public synchronized Disciplina inclui(String nome, String descricao) throws Exception {

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

    // ------- Insere 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;

    // Pega Id maximo
    long maxId = 1;
    str = "SELECT Max(cod) AS maxId From Disciplina";
    BancoDadosLog.log(str);
    dbRs = dbStmt.executeQuery(str);
    if (dbRs.next()) {
      maxId = dbRs.getLong("maxId");
      maxId++;
    }
    String id = Long.toString(maxId);

    nome = StringConverter.toDataBaseNotation(nome);

    // Insere o elemento na base de dados
    str = "INSERT INTO Disciplina (cod, nome, descricao, desativada)";
    str +=
        " VALUES ("
            + id
            + ",'"
            + nome
            + "'"
            + ",'"
            + StringConverter.toDataBaseNotation(descricao)
            + "',0)";

    BancoDadosLog.log(str);
    dbStmt.executeUpdate(str);

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

    // ------- Insere na mem�ria -------
    // Cria um novo objeto
    Disciplina obj = new Disciplina(id, nome, descricao, false);

    // Insere o objeto na lista do gerente
    this.listaObj.addElement(obj);

    // ---- Cria uma nova turma ----
    Turma_ger turmager = new Turma_ger();
    turmager.inclui("Turma 1", "", obj);

    return obj;
  }
Пример #4
0
  private static int writeLine(Writer w, String s) throws IOException {

    String logLine = StringConverter.unicodeToAscii(s).append(lineSep).toString();

    w.write(logLine);

    return logLine.length();
  }
Пример #5
0
  public String trataResposta(String resposta) throws Exception {

    if (resposta == null) return "";

    // remove tabs da resposta
    resposta = StringConverter.replace(resposta, "\t", " ");

    // remove espacos duplos
    while (resposta.indexOf("  ") != -1) {
      resposta = StringConverter.replace(resposta, "  ", " ");
    }

    // remove espacos do inicio e do final
    resposta.trim();

    // Corrige posicionamento da virgula
    resposta = StringConverter.replace(resposta, " ,", ",");
    resposta = StringConverter.replace(resposta, ",", ", ");

    // Corrige posicionamento dos pontos
    // resposta = StringConverter.replace(resposta," .",".");
    // resposta = StringConverter.replace(resposta,".",". ");

    // remove espacos duplos
    resposta = StringConverter.replace(resposta, "  ", " ");

    // remove enter no inicio e no final da string
    while (resposta.startsWith("\n") || resposta.startsWith("\r") || resposta.startsWith(" ")) {
      resposta = resposta.substring(1);
    }
    while (resposta.endsWith("\n") || resposta.endsWith("\r") || resposta.endsWith(" ")) {
      resposta = resposta.substring(0, resposta.length() - 1);
    }

    // resposta = StringConverter.replace(resposta,"  "," ");

    // while

    return resposta;
  }
Пример #6
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);
    }
  }
Пример #7
0
  protected static synchronized void inicializa() throws Exception {

    if (listaObj == null) { // primeira utilização do gerente de objetos

      listaObj = new Vector();

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

      // seleciona todos objetos
      String str = "SELECT * FROM Disciplina ORDER BY Nome";
      BancoDadosLog.log(str);
      dbRs = dbStmt.executeQuery(str);

      while (dbRs.next()) {
        // Le dados da base
        String cod = dbRs.getString("cod");
        String nome = dbRs.getString("nome");
        String descricao = StringConverter.fromDataBaseNotation(dbRs.getString("descricao"));
        boolean desativada = dbRs.getBoolean("desativada");

        // Instancia o objeto
        Disciplina obj = new Disciplina(cod, nome, descricao, desativada);

        // Coloca-o na lista de objetos
        listaObj.addElement(obj);
      }

      listaObj.trimToSize();

      // Finaliza conexao
      dbStmt.close();
      dbCon.close();
    }
  }
Пример #8
0
  /**
   * Method declaration
   *
   * @param r
   * @return
   * @throws IOException
   */
  private static String readLine(LineNumberReader r) throws IOException {

    String s = r.readLine();

    return StringConverter.asciiToUnicode(s);
  }
Пример #9
0
 public String htmlParaImpressao() throws Exception {
   return "<B>" + StringConverter.replace(this.getEnunciado(), "\n", "<BR>") + "</B>";
 }
Пример #10
0
  @SuppressWarnings("unchecked")
  public Detail2Converter(List<ObjectConverter.ColumnInfo> allColumns) throws java.io.IOException {
    Optional<ObjectConverter.ColumnInfo> column;

    final java.util.List<ObjectConverter.ColumnInfo> columns =
        allColumns
            .stream()
            .filter(it -> "test".equals(it.typeSchema) && "Detail2_entity".equals(it.typeName))
            .collect(Collectors.toList());
    columnCount = columns.size();

    readers = new ObjectConverter.Reader[columnCount];
    for (int i = 0; i < readers.length; i++) {
      readers[i] =
          (instance, rdr, ctx) -> {
            StringConverter.skip(rdr, ctx);
            return instance;
          };
    }

    final java.util.List<ObjectConverter.ColumnInfo> columnsExtended =
        allColumns
            .stream()
            .filter(it -> "test".equals(it.typeSchema) && "-ngs_Detail2_type-".equals(it.typeName))
            .collect(Collectors.toList());
    columnCountExtended = columnsExtended.size();

    readersExtended = new ObjectConverter.Reader[columnCountExtended];
    for (int i = 0; i < readersExtended.length; i++) {
      readersExtended[i] =
          (instance, rdr, ctx) -> {
            StringConverter.skip(rdr, ctx);
            return instance;
          };
    }

    column = columns.stream().filter(it -> "u".equals(it.columnName)).findAny();
    if (!column.isPresent())
      throw new java.io.IOException(
          "Unable to find 'u' column in test Detail2_entity. Check if DB is in sync");
    __index___u = (int) column.get().order - 1;

    column = columnsExtended.stream().filter(it -> "u".equals(it.columnName)).findAny();
    if (!column.isPresent())
      throw new java.io.IOException(
          "Unable to find 'u' column in test Detail2. Check if DB is in sync");
    __index__extended_u = (int) column.get().order - 1;

    column = columns.stream().filter(it -> "dd".equals(it.columnName)).findAny();
    if (!column.isPresent())
      throw new java.io.IOException(
          "Unable to find 'dd' column in test Detail2_entity. Check if DB is in sync");
    __index___dd = (int) column.get().order - 1;

    column = columnsExtended.stream().filter(it -> "dd".equals(it.columnName)).findAny();
    if (!column.isPresent())
      throw new java.io.IOException(
          "Unable to find 'dd' column in test Detail2. Check if DB is in sync");
    __index__extended_dd = (int) column.get().order - 1;

    column = columns.stream().filter(it -> "EntityCompositeid".equals(it.columnName)).findAny();
    if (!column.isPresent())
      throw new java.io.IOException(
          "Unable to find 'EntityCompositeid' column in test Detail2_entity. Check if DB is in sync");
    __index___EntityCompositeid = (int) column.get().order - 1;

    column =
        columnsExtended.stream().filter(it -> "EntityCompositeid".equals(it.columnName)).findAny();
    if (!column.isPresent())
      throw new java.io.IOException(
          "Unable to find 'EntityCompositeid' column in test Detail2. Check if DB is in sync");
    __index__extended_EntityCompositeid = (int) column.get().order - 1;

    column = columns.stream().filter(it -> "EntityIndex".equals(it.columnName)).findAny();
    if (!column.isPresent())
      throw new java.io.IOException(
          "Unable to find 'EntityIndex' column in test Detail2_entity. Check if DB is in sync");
    __index___EntityIndex = (int) column.get().order - 1;

    column = columnsExtended.stream().filter(it -> "EntityIndex".equals(it.columnName)).findAny();
    if (!column.isPresent())
      throw new java.io.IOException(
          "Unable to find 'EntityIndex' column in test Detail2. Check if DB is in sync");
    __index__extended_EntityIndex = (int) column.get().order - 1;

    column = columns.stream().filter(it -> "Index".equals(it.columnName)).findAny();
    if (!column.isPresent())
      throw new java.io.IOException(
          "Unable to find 'Index' column in test Detail2_entity. Check if DB is in sync");
    __index___Index = (int) column.get().order - 1;

    column = columnsExtended.stream().filter(it -> "Index".equals(it.columnName)).findAny();
    if (!column.isPresent())
      throw new java.io.IOException(
          "Unable to find 'Index' column in test Detail2. Check if DB is in sync");
    __index__extended_Index = (int) column.get().order - 1;
  }