Contact.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.contacts;

  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 Contact implements DatabaseObject {

  30.     private transient String owner;

  31.     private String uri;
  32.     private String displayName;
  33.     private Long added;
  34.     private Long removed;
  35.     private Boolean banned = false;
  36.     private Boolean confirmed = false;
  37.     private String conversationId;

  38.     public Contact(ResultSet rs) throws Exception {
  39.         this.owner = rs.getString("owner");
  40.         this.uri = rs.getString("uri");
  41.         this.displayName = rs.getString("displayName");
  42.         this.added = rs.getLong("added");
  43.         this.removed = rs.getLong("removed");
  44.         this.banned = rs.getBoolean("banned");
  45.         this.confirmed = rs.getBoolean("confirmed");
  46.         this.conversationId = rs.getString("conversationId");
  47.     }

  48.     public boolean isAdded() {
  49.         return added > removed;
  50.     }

  51.     @Override
  52.     public PreparedStatement getInsert(PreparedStatement ps) throws Exception {
  53.         ps.setString(1, owner);
  54.         ps.setString(2, uri);
  55.         if (displayName != null) ps.setString(3, displayName);
  56.         else ps.setString(3, "");
  57.         ps.setLong(4, added);
  58.         ps.setLong(5, removed);
  59.         ps.setBoolean(6, banned);
  60.         ps.setBoolean(7, confirmed);
  61.         ps.setString(8, conversationId);
  62.         return ps;
  63.     }

  64.     @Override
  65.     public PreparedStatement getDelete(PreparedStatement ps) throws Exception {
  66.         return null;
  67.     }

  68.     @Override
  69.     public PreparedStatement getUpdate(PreparedStatement ps) throws Exception {
  70.         if (displayName != null) ps.setString(1, displayName);
  71.         else ps.setString(1, "");
  72.         ps.setLong(2, added);
  73.         ps.setLong(3, removed);
  74.         ps.setBoolean(4, banned);
  75.         ps.setBoolean(5, confirmed);
  76.         ps.setString(6, conversationId);
  77.         ps.setString(7, owner);
  78.         ps.setString(8, uri);
  79.         return ps;
  80.     }
  81. }