ConversationRequest.java

  1. /*
  2.  * Copyright (C) 2020-2024 by Savoir-faire Linux
  3.  *
  4.  * This program is free software; you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 3 of the License, or
  7.  * (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  16.  */
  17. package net.jami.jams.common.objects.conversations;

  18. import lombok.EqualsAndHashCode;
  19. import lombok.Getter;
  20. import lombok.NoArgsConstructor;
  21. import lombok.Setter;

  22. import net.jami.jams.common.serialization.database.DatabaseObject;

  23. import java.sql.PreparedStatement;
  24. import java.sql.ResultSet;

  25. @Getter
  26. @Setter
  27. @NoArgsConstructor
  28. @EqualsAndHashCode
  29. public class ConversationRequest implements DatabaseObject {

  30.     private transient String owner;

  31.     private String conversationId;
  32.     private String sender; // 'from' became sender because 'from' is a reserved keyword in SQL
  33.     private String metadatas;
  34.     private Long received;
  35.     private Long declined;

  36.     public ConversationRequest(ResultSet rs) throws Exception {
  37.         this.owner = rs.getString("owner");
  38.         this.conversationId = rs.getString("conversationId");
  39.         this.sender = rs.getString("sender");
  40.         this.metadatas = rs.getString("metadatas");
  41.         this.received = rs.getLong("received");
  42.         this.declined = rs.getLong("declined");
  43.     }

  44.     @Override
  45.     public PreparedStatement getInsert(PreparedStatement ps) throws Exception {
  46.         ps.setString(1, owner);
  47.         ps.setString(2, conversationId);
  48.         ps.setString(3, sender);
  49.         ps.setString(4, metadatas);
  50.         ps.setLong(5, received);
  51.         ps.setLong(6, declined);
  52.         return ps;
  53.     }

  54.     @Override
  55.     public PreparedStatement getDelete(PreparedStatement ps) throws Exception {
  56.         ps.setString(1, owner);
  57.         ps.setString(2, conversationId);
  58.         return ps;
  59.     }

  60.     @Override
  61.     public PreparedStatement getUpdate(PreparedStatement ps) throws Exception {
  62.         ps.setString(1, sender);
  63.         ps.setString(2, metadatas);
  64.         ps.setLong(3, received);
  65.         ps.setLong(4, declined);
  66.         ps.setString(5, owner);
  67.         ps.setString(6, conversationId);
  68.         return ps;
  69.     }
  70. }