From 6b34bf9edcb2268aec6dc84865dc7a5a1330a18b Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Mon, 15 Jun 2020 11:59:48 +0200 Subject: [PATCH] Fix JPA validator warnings with explicit column names Due to a bug in the JPA validator columns with camel case names are flagged as missing (probably due to the case-insensitive nature of SQL). This has been circumvented by assigning every column with a camel case name a new name with underscores. The inheritance strategy of the Contacts class has been changed to single table for performance reasons. --- src/main/java/envoy/server/data/Contact.java | 15 +++------------ src/main/java/envoy/server/data/Group.java | 8 -------- src/main/java/envoy/server/data/GroupMessage.java | 7 ++----- src/main/java/envoy/server/data/Message.java | 6 ++++-- src/main/java/envoy/server/data/User.java | 3 ++- 5 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/main/java/envoy/server/data/Contact.java b/src/main/java/envoy/server/data/Contact.java index 475b3ef..7ad1d6b 100644 --- a/src/main/java/envoy/server/data/Contact.java +++ b/src/main/java/envoy/server/data/Contact.java @@ -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; diff --git a/src/main/java/envoy/server/data/Group.java b/src/main/java/envoy/server/data/Group.java index 5f3be22..bad4db9 100644 --- a/src/main/java/envoy/server/data/Group.java +++ b/src/main/java/envoy/server/data/Group.java @@ -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(); } } diff --git a/src/main/java/envoy/server/data/GroupMessage.java b/src/main/java/envoy/server/data/GroupMessage.java index 4c64cf7..13dcc49 100644 --- a/src/main/java/envoy/server/data/GroupMessage.java +++ b/src/main/java/envoy/server/data/GroupMessage.java @@ -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 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); diff --git a/src/main/java/envoy/server/data/Message.java b/src/main/java/envoy/server/data/Message.java index 9203a4f..8a0a0ca 100755 --- a/src/main/java/envoy/server/data/Message.java +++ b/src/main/java/envoy/server/data/Message.java @@ -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); diff --git a/src/main/java/envoy/server/data/User.java b/src/main/java/envoy/server/data/User.java index f1076c1..99941f4 100755 --- a/src/main/java/envoy/server/data/User.java +++ b/src/main/java/envoy/server/data/User.java @@ -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;