This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
delvh 0ecc9cf0e9 Added PersistenceManager and Namedqueries
In theory, this code is all we need for database integration
2020-01-03 18:17:26 +01:00

121 lines
3.3 KiB
Java

package envoy.server.data;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
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.<br>
* It will be referenced as "database user" to clarify between the different
* user objects.<br>
* <br>
* Project: <strong>envoy-server-standalone</strong><br>
* File: <strong>User.java</strong><br>
* Created: <strong>02.01.2020</strong><br>
*
* @author Kai S. K. Engelbart
* @since Envoy Server Standalone v0.1-alpha
*/
@Entity
@Table(name = "users")
@NamedQuery(query = "SELECT u FROM DBUser u WHERE u.id = :id", name = "getUserById")
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;
private List<User> contacts;
/**
* @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<User> getContacts() { return contacts; }
/**
* @param contacts the contacts to set
* @since Envoy Server Standalone v0.1-alpha
* @see User#getContacts()
*/
public void setContacts(List<User> contacts) { this.contacts = contacts; }
}