コード例 #1
0
ファイル: GenericDAO.java プロジェクト: jeffersonarar/Chimera
  public ArrayList<HashMap<String, Object>> pesquisarQuantidade(
      IModel<?> entidade, String condicional, String colunaConta, String parametro)
      throws SQLException {

    String sql = "select COUNT(" + colunaConta + ") from " + entidade.getTableName() + " ";
    sql = sql + " where  ativo = 'true' and " + condicional + "='" + parametro + "'";

    System.out.println("sql:" + sql);
    if (Connect.getConexao()) {

      ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();

      ResultSet rs = Connect.setResultSet(sql);
      int colCount = rs.getMetaData().getColumnCount();
      while (rs.next()) {
        HashMap<String, Object> record = new HashMap<String, Object>();
        for (int i = 1; i <= colCount; i++) {
          record.put(rs.getMetaData().getColumnName(i), rs.getString(i));
        }
        result.add(record);
      }
      Connect.close();
      return result;
    }
    System.out.println(
        "O "
            + entidade.getTableName()
            + " Não Foi pesquisado problema no DAOUsuario pesquisarusuario(String) Connect.getConexão");
    return null;
  }
コード例 #2
0
ファイル: GenericDAO.java プロジェクト: jeffersonarar/Chimera
  public ArrayList<HashMap<String, Object>> pesquisarListaMotivo(IModel<?> entidade, int id)
      throws SQLException {

    String sql =
        "select * from 	motivo as m, solicitacoes as s, "
            + "usuario as u where 	m.idsolicitacoes = s.idsolicitacoes "
            + "and	s.idusuario = u.idusuario and s.idusuario =	"
            + id
            + "";
    System.out.println("sql:" + sql);
    if (Connect.getConexao()) {

      ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();

      ResultSet rs = Connect.setResultSet(sql);
      int colCount = rs.getMetaData().getColumnCount();
      while (rs.next()) {
        HashMap<String, Object> record = new HashMap<String, Object>();
        for (int i = 1; i <= colCount; i++) {
          record.put(rs.getMetaData().getColumnName(i), rs.getString(i));
        }
        result.add(record);
      }
      Connect.close();
      return result;
    }
    System.out.println(
        "O "
            + entidade.getTableName()
            + " Não Foi pesquisado problema no DAOUsuario pesquisarusuario(String) Connect.getConexão");
    return null;
  }
コード例 #3
0
ファイル: GenericDAO.java プロジェクト: jeffersonarar/Chimera
 public Return validarItemUnico(IModel<?> entidade, String[] valores, String[] nomesVariaveis)
     throws SQLException {
   int contador = 0;
   String sql = null;
   if (valores.length != nomesVariaveis.length) {
     return new Return(
         false,
         "Validacão de item ùnico Incorreta, valores devem possuir o mesmo número de variáveis",
         TypeMessage.ERROR);
   }
   if (Connect.getConexao()) {
     while (contador < valores.length) {
       sql = "select " + entidade.getTableColumnNames() + " from " + entidade.getTableName() + " ";
       sql = sql + " where " + nomesVariaveis[contador] + " = '" + valores[contador] + "' ;";
       ResultSet rs = Connect.setResultSet(sql);
       if (rs.next()) {
         return new Return(
             false,
             "Já possui este registro no campo " + nomesVariaveis[contador],
             TypeMessage.ERROR);
       }
       contador++;
     }
     return new Return(true, "", TypeMessage.SUCESSO);
   } else {
     return new Return(
         false, "Erro de conexão com o banco na validação de item único...", TypeMessage.ERROR);
   }
 }
コード例 #4
0
ファイル: GenericDAO.java プロジェクト: jeffersonarar/Chimera
  public ArrayList<HashMap<String, Object>> listarTodos(IModel<?> entidade) throws SQLException {
    String sql = null;

    String sqlAll =
        "select " + entidade.getTableColumnNames() + " from " + entidade.getTableName() + " ";
    sqlAll = sqlAll + " where ativo = true";
    sql = sqlAll;
    System.out.println("sql:" + sql);
    if (Connect.getConexao()) {

      ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();

      ResultSet rs = Connect.setResultSet(sql);
      int colCount = rs.getMetaData().getColumnCount();
      while (rs.next()) {
        HashMap<String, Object> record = new HashMap<String, Object>();
        for (int i = 1; i <= colCount; i++) {
          record.put(rs.getMetaData().getColumnName(i), rs.getString(i));
        }
        result.add(record);
      }
      Connect.close();
      return result;
    }
    System.out.println(
        "O "
            + entidade.getTableName()
            + " Não Foi pesquisado problema no DAOUsuario pesquisarusuario(String) Connect.getConexão");
    return null;
  }
コード例 #5
0
ファイル: GenericDAO.java プロジェクト: jeffersonarar/Chimera
  public ArrayList<HashMap<String, Object>> listarSolicitacoes(
      IModel<?> entidade, Usuario usuario, String string) throws SQLException {
    String sql = null;
    if (string.equals("APROVADOR")) {

      String sqlAll =
          "select " + entidade.getTableColumnNames() + " from " + entidade.getTableName() + " ";
      sqlAll = sqlAll + " where ativo = true";
      sql = sqlAll;
    } else if (string.equals("SOLICITANTE")) {
      String sqlAll = "select * " + "from " + entidade.getTableName() + " as s ," + "usuario as u ";
      sqlAll =
          sqlAll
              + "where s.idusuario = u.idusuario "
              + "and u.idusuario='"
              + usuario.getIdusuario()
              + "' "
              + "and s.ativo = true";
      sql = sqlAll;
    } else if (string.equals("EXECUTOR")) {
      String sqlAll =
          "select " + entidade.getTableColumnNames() + " from " + entidade.getTableName() + " ";
      sqlAll = sqlAll + " where situacao='APROVADA' " + "and ativo = true";
      sql = sqlAll;
    } else if (string.equals("TOTAL")) {
      String sqlAll =
          "select " + entidade.getTableColumnNames() + " from " + entidade.getTableName() + " ";
      sqlAll = sqlAll + " where ativo = true";
      sql = sqlAll;
    }

    System.out.println("sql:" + sql);
    if (Connect.getConexao()) {

      ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();

      ResultSet rs = Connect.setResultSet(sql);
      int colCount = rs.getMetaData().getColumnCount();
      while (rs.next()) {
        HashMap<String, Object> record = new HashMap<String, Object>();
        for (int i = 1; i <= colCount; i++) {
          record.put(rs.getMetaData().getColumnName(i), rs.getString(i));
        }
        result.add(record);
      }
      Connect.close();
      return result;
    }
    System.out.println(
        "O "
            + entidade.getTableName()
            + " Não Foi pesquisado problema no DAOUsuario pesquisarusuario(String) Connect.getConexão");
    return null;
  }
コード例 #6
0
ファイル: GenericDAO.java プロジェクト: jeffersonarar/Chimera
  /*
   * função pesquisarUsuario pode ser chamada por uma string onde pesquisa qualquer
   * parte da palavra do titulo, diretor ou genero
   * ou por um inteiro onde se pesquisa pelo id do filme..
   */
  public ArrayList<HashMap<String, Object>> pesquisarNome(IModel<?> entidade, String nome)
      throws SQLException {
    String sql = null;

    String sqlPorNome =
        "select " + entidade.getTableColumnNames() + " from " + entidade.getTableName() + " ";
    sqlPorNome = sqlPorNome + " where ativo = true and ";

    String nomeVariaveis = entidade.getVariaveisPesquisarNome();
    String[] vetorVariaveis = new String[nomeVariaveis.split(",").length];
    vetorVariaveis = nomeVariaveis.split(",");
    for (int i = 0; i < vetorVariaveis.length; i++) {
      sqlPorNome = sqlPorNome + " " + vetorVariaveis[i] + " LIKE '%" + nome + "%' OR";
    }

    sqlPorNome = sqlPorNome.substring(0, sqlPorNome.length() - 2);
    sqlPorNome = sqlPorNome + " ;";
    System.out.println("sql:" + sqlPorNome);
    sql = sqlPorNome;

    //	System.out.println("sql:"+sql);
    if (Connect.getConexao()) {

      ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();

      ResultSet rs = Connect.setResultSet(sql);
      int colCount = rs.getMetaData().getColumnCount();
      while (rs.next()) {
        HashMap<String, Object> record = new HashMap<String, Object>();
        for (int i = 1; i <= colCount; i++) {
          record.put(rs.getMetaData().getColumnName(i), rs.getString(i));
        }
        result.add(record);
      }
      Connect.close();
      return result;
    }
    System.out.println(
        "O "
            + entidade.getTableName()
            + " Não Foi pesquisado problema no DAOUsuario pesquisarusuario(String) Connect.getConexão");
    return null;
  }
コード例 #7
0
ファイル: GenericDAO.java プロジェクト: jeffersonarar/Chimera
  public ArrayList<HashMap<String, Object>> pesquisarCriteriosData(
      IModel<?> entidade, String coluna, String criterio1, String criterio2) throws SQLException {

    String sql =
        "select " + entidade.getTableColumnNames() + " from " + entidade.getTableName() + " ";
    sql =
        sql
            + " where ativo = 'true' and "
            + coluna
            + " BEETWEN '"
            + criterio1
            + "' and '"
            + criterio2
            + "' order by "
            + entidade.getOrdenacao()
            + " ;";

    System.out.println("sql pesquisarCriterio :" + sql);
    if (Connect.getConexao()) {

      ArrayList<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();

      ResultSet rs = Connect.setResultSet(sql);
      int colCount = rs.getMetaData().getColumnCount();
      while (rs.next()) {
        HashMap<String, Object> record = new HashMap<String, Object>();
        for (int i = 1; i <= colCount; i++) {
          record.put(rs.getMetaData().getColumnName(i), rs.getString(i));
        }
        result.add(record);
      }
      Connect.close();
      return result;
    }
    System.out.println(
        "O "
            + entidade.getTableName()
            + " Não Foi pesquisado problema no DAOUsuario pesquisarusuario(String) Connect.getConexão");
    return null;
  }