Merge pull request #37 from informatik-ag-ngl/f/refactor_column_names

Fix JPA validator warnings with explicit column names
This commit is contained in:
Kai S. K. Engelbart 2020-06-21 07:15:12 +00:00 committed by GitHub
commit cd38f116aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 28 deletions

View File

@ -3,17 +3,7 @@ package envoy.server.data;
import java.util.Date;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.*;
/**
* This class acts as a superclass for all contacts, being {@link User}s and
@ -29,7 +19,7 @@ import javax.persistence.TemporalType;
@Entity
@Table(name = "contacts")
@Inheritance(strategy = InheritanceType.JOINED)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class Contact {
@Id
@ -37,6 +27,7 @@ public abstract class Contact {
protected long id;
protected String name;
@Column(name = "creation_date")
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate;

View File

@ -5,7 +5,6 @@ import java.util.stream.Collectors;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
/**
* Represents a group inside the database. Referred to as "server group" as
@ -19,7 +18,6 @@ import javax.persistence.Table;
* @since Envoy Server Standalone v0.1-alpha
*/
@Entity
@Table(name = "groups")
@NamedQueries({
@NamedQuery(
name = Group.findByName,
@ -46,17 +44,11 @@ public class Group extends Contact {
*/
public static final String findPendingGroups = "Group.findPendingGroups";
/**
* {@inheritDoc}
*/
@Override
public envoy.data.Group toCommon() {
return new envoy.data.Group(id, name, contacts.parallelStream().map(User.class::cast).map(User::toFlatCommon).collect(Collectors.toSet()));
}
/**
* {@inheritDoc}
*/
@Override
protected envoy.data.Group toFlatCommon() { return toCommon(); }
}

View File

@ -3,10 +3,7 @@ package envoy.server.data;
import java.util.Date;
import java.util.Map;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.*;
import envoy.data.MessageBuilder;
@ -24,6 +21,7 @@ public class GroupMessage extends Message {
@ElementCollection
private Map<Long, envoy.data.Message.MessageStatus> memberMessageStatus;
@Column(name = "last_status_change_date")
@Temporal(TemporalType.TIMESTAMP)
protected Date lastStatusChangeDate;
@ -64,7 +62,6 @@ public class GroupMessage extends Message {
.setForwarded(forwarded)
.setStatus(status)
.setText(text)
// .setAttachment(attachment) TODO make this work
.buildGroupMessage((envoy.data.Group) recipient.toCommon(), memberMessageStatus);
groupMessage.setReceivedDate(receivedDate);
groupMessage.setReadDate(readDate);

View File

@ -49,12 +49,15 @@ public class Message {
@JoinColumn
protected Contact recipient;
@Column(name = "creation_date")
@Temporal(TemporalType.TIMESTAMP)
protected Date creationDate;
@Column(name = "received_date")
@Temporal(TemporalType.TIMESTAMP)
protected Date receivedDate;
@Column(name = "read_date")
@Temporal(TemporalType.TIMESTAMP)
protected Date readDate;
@ -88,7 +91,7 @@ public class Message {
sender = persistenceManager.getUserByID(message.getSenderID());
recipient = persistenceManager.getContactByID(message.getRecipientID());
forwarded = message.isForwarded();
// TODO: attachment = message.getAttachment().toByteArray();DOES NOT WORK YET
// TODO: Attachment
}
/**
@ -104,7 +107,6 @@ public class Message {
.setDate(creationDate)
.setStatus(status)
.setForwarded(forwarded)
// .setAttachment(attachment) TODO make this work
.build();
message.setReceivedDate(receivedDate);
message.setReadDate(readDate);

View File

@ -22,7 +22,6 @@ import envoy.data.User.UserStatus;
* @since Envoy Server Standalone v0.1-alpha
*/
@Entity
@Table(name = "users")
@NamedQueries({
@NamedQuery(
name = User.findByName,
@ -63,8 +62,10 @@ public class User extends Contact {
*/
public static final String searchByName = "User.searchByName";
@Column(name = "password_hash")
private byte[] passwordHash;
@Column(name = "last_seen")
@Temporal(TemporalType.TIMESTAMP)
private Date lastSeen;