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.
This commit is contained in:
parent
071d715674
commit
6b34bf9edc
@ -3,17 +3,7 @@ package envoy.server.data;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.*;
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class acts as a superclass for all contacts, being {@link User}s and
|
* This class acts as a superclass for all contacts, being {@link User}s and
|
||||||
@ -29,7 +19,7 @@ import javax.persistence.TemporalType;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "contacts")
|
@Table(name = "contacts")
|
||||||
@Inheritance(strategy = InheritanceType.JOINED)
|
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||||
public abstract class Contact {
|
public abstract class Contact {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@ -37,6 +27,7 @@ public abstract class Contact {
|
|||||||
protected long id;
|
protected long id;
|
||||||
protected String name;
|
protected String name;
|
||||||
|
|
||||||
|
@Column(name = "creation_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
private Date creationDate;
|
private Date creationDate;
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import java.util.stream.Collectors;
|
|||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.NamedQueries;
|
import javax.persistence.NamedQueries;
|
||||||
import javax.persistence.NamedQuery;
|
import javax.persistence.NamedQuery;
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a group inside the database. Referred to as "server group" as
|
* 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
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "groups")
|
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = Group.findByName,
|
name = Group.findByName,
|
||||||
@ -46,17 +44,11 @@ public class Group extends Contact {
|
|||||||
*/
|
*/
|
||||||
public static final String findPendingGroups = "Group.findPendingGroups";
|
public static final String findPendingGroups = "Group.findPendingGroups";
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public envoy.data.Group toCommon() {
|
public envoy.data.Group toCommon() {
|
||||||
return new envoy.data.Group(id, name, contacts.parallelStream().map(User.class::cast).map(User::toFlatCommon).collect(Collectors.toSet()));
|
return new envoy.data.Group(id, name, contacts.parallelStream().map(User.class::cast).map(User::toFlatCommon).collect(Collectors.toSet()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
protected envoy.data.Group toFlatCommon() { return toCommon(); }
|
protected envoy.data.Group toFlatCommon() { return toCommon(); }
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,7 @@ package envoy.server.data;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.persistence.ElementCollection;
|
import javax.persistence.*;
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Temporal;
|
|
||||||
import javax.persistence.TemporalType;
|
|
||||||
|
|
||||||
import envoy.data.MessageBuilder;
|
import envoy.data.MessageBuilder;
|
||||||
|
|
||||||
@ -24,6 +21,7 @@ public class GroupMessage extends Message {
|
|||||||
@ElementCollection
|
@ElementCollection
|
||||||
private Map<Long, envoy.data.Message.MessageStatus> memberMessageStatus;
|
private Map<Long, envoy.data.Message.MessageStatus> memberMessageStatus;
|
||||||
|
|
||||||
|
@Column(name = "last_status_change_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
protected Date lastStatusChangeDate;
|
protected Date lastStatusChangeDate;
|
||||||
|
|
||||||
@ -64,7 +62,6 @@ public class GroupMessage extends Message {
|
|||||||
.setForwarded(forwarded)
|
.setForwarded(forwarded)
|
||||||
.setStatus(status)
|
.setStatus(status)
|
||||||
.setText(text)
|
.setText(text)
|
||||||
// .setAttachment(attachment) TODO make this work
|
|
||||||
.buildGroupMessage((envoy.data.Group) recipient.toCommon(), memberMessageStatus);
|
.buildGroupMessage((envoy.data.Group) recipient.toCommon(), memberMessageStatus);
|
||||||
groupMessage.setReceivedDate(receivedDate);
|
groupMessage.setReceivedDate(receivedDate);
|
||||||
groupMessage.setReadDate(readDate);
|
groupMessage.setReadDate(readDate);
|
||||||
|
@ -49,12 +49,15 @@ public class Message {
|
|||||||
@JoinColumn
|
@JoinColumn
|
||||||
protected Contact recipient;
|
protected Contact recipient;
|
||||||
|
|
||||||
|
@Column(name = "creation_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
protected Date creationDate;
|
protected Date creationDate;
|
||||||
|
|
||||||
|
@Column(name = "received_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
protected Date receivedDate;
|
protected Date receivedDate;
|
||||||
|
|
||||||
|
@Column(name = "read_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
protected Date readDate;
|
protected Date readDate;
|
||||||
|
|
||||||
@ -88,7 +91,7 @@ public class Message {
|
|||||||
sender = persistenceManager.getUserByID(message.getSenderID());
|
sender = persistenceManager.getUserByID(message.getSenderID());
|
||||||
recipient = persistenceManager.getContactByID(message.getRecipientID());
|
recipient = persistenceManager.getContactByID(message.getRecipientID());
|
||||||
forwarded = message.isForwarded();
|
forwarded = message.isForwarded();
|
||||||
// TODO: attachment = message.getAttachment().toByteArray();DOES NOT WORK YET
|
// TODO: Attachment
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,7 +107,6 @@ public class Message {
|
|||||||
.setDate(creationDate)
|
.setDate(creationDate)
|
||||||
.setStatus(status)
|
.setStatus(status)
|
||||||
.setForwarded(forwarded)
|
.setForwarded(forwarded)
|
||||||
// .setAttachment(attachment) TODO make this work
|
|
||||||
.build();
|
.build();
|
||||||
message.setReceivedDate(receivedDate);
|
message.setReceivedDate(receivedDate);
|
||||||
message.setReadDate(readDate);
|
message.setReadDate(readDate);
|
||||||
|
@ -22,7 +22,6 @@ import envoy.data.User.UserStatus;
|
|||||||
* @since Envoy Server Standalone v0.1-alpha
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "users")
|
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = User.findByName,
|
name = User.findByName,
|
||||||
@ -63,8 +62,10 @@ public class User extends Contact {
|
|||||||
*/
|
*/
|
||||||
public static final String searchByName = "User.searchByName";
|
public static final String searchByName = "User.searchByName";
|
||||||
|
|
||||||
|
@Column(name = "password_hash")
|
||||||
private byte[] passwordHash;
|
private byte[] passwordHash;
|
||||||
|
|
||||||
|
@Column(name = "last_seen")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
private Date lastSeen;
|
private Date lastSeen;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user