package envoy.server.data; import java.util.Date; import java.util.List; import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; /** * This class serves as a way to let Hibernate communicate with the server * without bringing the dependency of JPA/Hibernate into the client.
* It will be referenced as "database user" to clarify between the different * user objects.
*
* Project: envoy-server-standalone
* File: User.java
* Created: 02.01.2020
* * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha */ @Entity @Table(name = "users") @NamedQueries( { @NamedQuery(query = "SELECT u FROM User u WHERE u.id = :id", name = "getUserById"), @NamedQuery(query = "SELECT u.contacts FROM User u WHERE u = :user", name = "getContactsOfUser")// not tested } ) public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; private String name; private byte[] passwordHash; @Temporal(TemporalType.TIMESTAMP) private Date lastSeen; private envoy.data.User.UserStatus status; @ElementCollection private List contacts; /** * Creates an instance of @link{User}. * Solely used for JPA/ Hibernate * * @since Envoy Server Standalone v0.1-alpha */ public User() {} /** * Creates an instance of @link{User}. * * @param user the {@link envoy.data.User} to convert * @since Envoy Server Standalone v0.1-alpha */ public User(envoy.data.User user) { id = user.getId(); name = user.getName(); status = user.getStatus(); } /** * @return a database {@link User} converted into an {@link envoy.data.User} * @since Envoy Server Standalone v0.1-alpha */ public envoy.data.User toCommonUser() { return new envoy.data.User(this.id, this.name); } /** * @return the id of a {link envoy.data.User} * @since Envoy Server Standalone v0.1-alpha */ public long getId() { return id; } /** * @param id the id to set * @since Envoy Server Standalone v0.1-alpha * @see User#getId */ public void setId(long id) { this.id = id; } /** * @return the name of a {link envoy.data.User} * @since Envoy Server Standalone v0.1-alpha */ public String getName() { return name; } /** * @param name the username to set * @since Envoy Server Standalone v0.1-alpha * @see User#getName() */ public void setName(String name) { this.name = name; } /** * @return the passwordHash of a {link envoy.data.User} * @since Envoy Server Standalone v0.1-alpha */ public byte[] getPasswordHash() { return passwordHash; } /** * @param passwordHash the password hash to set * @since Envoy Server Standalone v0.1-alpha * @see User#getPasswordHash() */ public void setPasswordHash(byte[] passwordHash) { this.passwordHash = passwordHash; } /** * @return the last date an {link envoy.data.User} has been online * @since Envoy Server Standalone v0.1-alpha */ public Date getLastSeen() { return lastSeen; } /** * @param lastSeen the latest date at which has been seen to set * @since Envoy Server Standalone v0.1-alpha * @see User#getLastSeen() */ public void setLastSeen(Date lastSeen) { this.lastSeen = lastSeen; } /** * @return the status of a {link envoy.data.User} * @since Envoy Server Standalone v0.1-alpha */ public envoy.data.User.UserStatus getStatus() { return status; } /** * @param status the status to set * @since Envoy Server Standalone v0.1-alpha * @see User#getStatus() */ public void setStatus(envoy.data.User.UserStatus status) { this.status = status; } /** * @return the contacts of a {link envoy.data.User} * @since Envoy Server Standalone v0.1-alpha */ public List getContacts() { return contacts; } /** * @param contacts the contacts to set * @since Envoy Server Standalone v0.1-alpha * @see User#getContacts() */ public void setContacts(List contacts) { this.contacts = contacts; } }