Improved Message.java and User.java to remain compatible with database

This commit is contained in:
delvh 2020-01-01 19:16:40 +01:00
parent 9825204437
commit be7459d18b
2 changed files with 118 additions and 26 deletions

View File

@ -48,11 +48,11 @@ public class Message implements Serializable {
READ
}
private final long id, senderId, recipientId;
private final transient User sender, recipient;
private final Date date;
private final String text;
private final MessageAttachment<?> attachment;
private long id, senderId, recipientId;
private transient User sender, recipient;
private Date date;
private String text;
private MessageAttachment<?> attachment;
private MessageStatus status;
@ -168,4 +168,74 @@ public class Message implements Serializable {
* @since Envoy Common v0.2-alpha
*/
public MessageStatus getStatus() { return status; }
/**
* Only used for Hibernate. Please do not use.
*
* @param id the id to set
* @since Envoy Common v0.2-alpha
*/
public void setId(long id) { this.id = id; }
/**
* Only used for Hibernate. Please do not use.
*
* @param senderId the senderId to set
* @since Envoy Common v0.2-alpha
*/
public void setSenderId(long senderId) { this.senderId = senderId; }
/**
* Only used for Hibernate. Please do not use.
*
* @param recipientId the recipientId to set
* @since Envoy Common v0.2-alpha
*/
public void setRecipientId(long recipientId) { this.recipientId = recipientId; }
/**
* Only used for Hibernate. Please do not use.
*
* @param sender the sender to set
* @since Envoy Common v0.2-alpha
*/
public void setSender(User sender) { this.sender = sender; }
/**
* Only used for Hibernate. Please do not use.
*
* @param recipient the recipient to set
* @since Envoy Common v0.2-alpha
*/
public void setRecipient(User recipient) { this.recipient = recipient; }
/**
* Only used for Hibernate. Please do not use.
*
* @param date the date to set
* @since Envoy Common v0.2-alpha
*/
public void setDate(Date date) { this.date = date; }
/**
* Only used for Hibernate. Please do not use.
*
* @param text the text to set
* @since Envoy Common v0.2-alpha
*/
public void setText(String text) { this.text = text; }
/**
* Only used for Hibernate. Please do not use.
*
* @param attachment the attachment to set
* @since Envoy Common v0.2-alpha
*/
public void setAttachment(MessageAttachment<?> attachment) { this.attachment = attachment; }
/**
* @param status the status to set
* @since Envoy Common v0.2-alpha
*/
public void setStatus(MessageStatus status) { this.status = status; }
}

View File

@ -1,8 +1,7 @@
package envoy.data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
/**
* Represents a unique user with a unique, numeric ID, a name and a current
@ -46,11 +45,10 @@ public class User implements Serializable {
OFFLINE;
}
private final long id;
private final String name;
private final List<User> contacts = new ArrayList<>();
private long id;
private String name;
private UserStatus status;
private Date lastOnline;
private static final long serialVersionUID = 3530947374856708236L;
@ -60,46 +58,70 @@ public class User implements Serializable {
*
* @param id unique ID
* @param name user name
* @since Envoy Client v0.2-alpha
* @since Envoy Common v0.2-alpha
*/
public User(long id, String name) {
this.id = id;
this.name = name;
status = UserStatus.OFFLINE;
status = UserStatus.ONLINE;
setLastOnline(new Date());
}
/**
* Used to let Hibernate modify the values of an {@link User}
*
* @since Envoy Common v0.2-alpha
*/
public User() {}
@Override
public String toString() { return String.format("User[id=%d,name=%s,status=%s]", id, name, status); }
/**
* @return the ID of this {@link User}
* @since Envoy Client v0.2-alpha
* @since Envoy Common v0.2-alpha
*/
public long getId() { return id; }
/**
* @return the name of this {@link User}
* @since Envoy Client v0.2-alpha
* @since Envoy Common v0.2-alpha
*/
public String getName() { return name; }
/**
* @return a list of all users this user can send messages to
* @since Envoy Client v0.2-alpha
*/
public List<User> getContacts() { return contacts; }
/**
* @return the current status of this user
* @since Envoy Client v0.2-alpha
* @since Envoy Common v0.2-alpha
*/
public UserStatus getStatus() { return status; }
/**
* Sets the current status of this user
*
* @param status the status to set
* @since Envoy Client v0.2-alpha
* @since Envoy Common v0.2-alpha
*/
public void setStatus(UserStatus status) { this.status = status; }
/**
* @param id the id to set
* @since Envoy Common v0.2-alpha
*/
public void setId(long id) { this.id = id; }
/**
* @param name the name to set
* @since Envoy Common v0.2-alpha
*/
public void setName(String name) { this.name = name; }
/**
* @return the lastOnline
* @since Envoy Common v0.2-alpha
*/
public Date getLastOnline() { return lastOnline; }
/**
* @param lastOnline the lastOnline to set
* @since Envoy Common v0.2-alpha
*/
public void setLastOnline(Date lastOnline) { this.lastOnline = lastOnline; }
}