Beispiel #1
0
 public void excluiTodosDoUsuario(String email) {
   PreparedStatement stat = null;
   try {
     con = new Conexao();
     String sql = "Delete from mensagem where remetente = ? or destinatario = ?";
     stat = con.getConnection().prepareStatement(sql);
     stat.setString(1, email);
     stat.setString(2, email);
     stat.executeUpdate();
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     con.closeAll(stat);
   }
 }
Beispiel #2
0
  public void exclui(BigInteger codigo) throws FonteDeDadosException {
    Statement stat = null;
    try {

      con = new Conexao();
      String sql = "DELETE FROM mensagem WHERE codigo = " + codigo + "";
      stat = con.getConnection().createStatement();
      stat.executeUpdate(sql);

    } catch (SQLException e) {
      throw new FonteDeDadosException("N�o foi possivel excluir a mensagem!");
    } finally {
      con.closeAll(stat);
    }
  }
Beispiel #3
0
 public List<Mensagem> localizaPorRemetente(String login) {
   ConexaoIF con = null;
   PreparedStatement stat = null;
   try {
     String sql = "Select * from mensagem where remetente ilike ?";
     con = new Conexao();
     stat = con.getConnection().prepareStatement(sql);
     stat.setString(1, login);
     return geraMensagens(stat.executeQuery());
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     con.closeAll(stat);
   }
   return null;
 }
Beispiel #4
0
 public void persiste(Mensagem mensagem) {
   PreparedStatement stat = null;
   try {
     con = new Conexao();
     String sql =
         "INSERT INTO mensagem(descricao, remetente, destinatario, data)" + "VALUES (?, ?, ?, ?)";
     stat = con.getConnection().prepareStatement(sql);
     stat.setString(1, mensagem.getDescricao());
     stat.setString(2, mensagem.getRemetente().getEmail());
     stat.setString(3, mensagem.getDestinatario().getEmail());
     stat.setTimestamp(4, new java.sql.Timestamp(mensagem.getData().getTimeInMillis()));
     stat.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     con.closeAll(stat);
   }
 }
Beispiel #5
0
 public List<Usuario> localizarParceiroConversa(String usuario) {
   ConexaoIF con = null;
   PreparedStatement stat = null;
   try {
     String sql =
         "Select remetente, destinatario FROM mensagem WHERE remetente = ? or destinatario = ?";
     con = new Conexao();
     stat = con.getConnection().prepareStatement(sql);
     stat.setString(1, usuario);
     stat.setString(2, usuario);
     return getParceiros(stat.executeQuery(), usuario);
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     con.closeAll(stat);
   }
   return null;
 }
Beispiel #6
0
  public Mensagem localiza(BigInteger codigo) throws FonteDeDadosException {
    Statement stat = null;
    try {
      con = new Conexao();
      stat = con.getConnection().createStatement();

      String sql = "SELECT * FROM mensagem WHERE codigo=" + codigo + "";

      ResultSet result = stat.executeQuery(sql);

      if (result.next()) return geraMensagem(result);
      else return null;

    } catch (SQLException e) {
      throw new FonteDeDadosException("Erro ao localizar mensagem!");
    } finally {
      con.closeAll(stat);
    }
  }
Beispiel #7
0
 public List<Mensagem> localizaPorUsuarios(String usuario1, String usuario2) {
   ConexaoIF con = null;
   PreparedStatement stat = null;
   try {
     String sql =
         "Select * from mensagem where (remetente = ? or remetente = ?)"
             + "and (destinatario = ? or destinatario = ?) ORDER BY data DESC";
     con = new Conexao();
     stat = con.getConnection().prepareStatement(sql);
     stat.setString(1, usuario1);
     stat.setString(2, usuario2);
     stat.setString(3, usuario1);
     stat.setString(4, usuario2);
     return geraMensagens(stat.executeQuery());
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     con.closeAll(stat);
   }
   return null;
 }