From 9318201fd53ab4d299be232107fffb85f1a3af89 Mon Sep 17 00:00:00 2001 From: kske Date: Thu, 2 Jan 2020 18:50:56 +0200 Subject: [PATCH 1/6] Added ORM classes --- pom.xml | 5 ++ src/main/java/envoy/server/data/Message.java | 81 ++++++++++++++++++++ src/main/java/envoy/server/data/User.java | 57 ++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 src/main/java/envoy/server/data/Message.java create mode 100644 src/main/java/envoy/server/data/User.java diff --git a/pom.xml b/pom.xml index b85a456..5b81ded 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,11 @@ java-nio-server 0.0.1-SNAPSHOT + + org.hibernate + hibernate-core + 5.4.10.Final + diff --git a/src/main/java/envoy/server/data/Message.java b/src/main/java/envoy/server/data/Message.java new file mode 100644 index 0000000..be11608 --- /dev/null +++ b/src/main/java/envoy/server/data/Message.java @@ -0,0 +1,81 @@ +package envoy.server.data; + +import java.util.Date; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import envoy.data.MessageBuilder; + +/** + * Project: envoy-server-standalone
+ * File: Message.java
+ * Created: 02.01.2020
+ * + * @author Kai S. K. Engelbart + * @since Envoy Server Standalone v0.1-alpha + */ +@Entity +public class Message { + + @Id + private long id; + private User sender, recipient; + @Temporal(TemporalType.TIMESTAMP) + private Date creationDate; + @Temporal(TemporalType.TIMESTAMP) + private Date receivedDate; + @Temporal(TemporalType.TIMESTAMP) + private Date readDate; + private envoy.data.Message.MessageStatus status; + private String text; + private byte[] attachment; + + public Message() {} + + // TODO: everything except ID + public Message(envoy.data.Message message) { id = message.getId(); } + + public envoy.data.Message toCommonMessage() { + // TODO: Attachment, dates + return new MessageBuilder(sender.getId(), recipient.getId()).setText(text).setDate(creationDate).setStatus(status).build(); + } + + public long getId() { return id; } + + public void setId(long id) { this.id = id; } + + public User getSender() { return sender; } + + public void setSender(User sender) { this.sender = sender; } + + public User getRecipient() { return recipient; } + + public void setRecipient(User recipient) { this.recipient = recipient; } + + public Date getCreationDate() { return creationDate; } + + public void setCreationDate(Date creationDate) { this.creationDate = creationDate; } + + public Date getReceivedDate() { return receivedDate; } + + public void setReceivedDate(Date receivedDate) { this.receivedDate = receivedDate; } + + public Date getReadDate() { return readDate; } + + public void setReadDate(Date readDate) { this.readDate = readDate; } + + public envoy.data.Message.MessageStatus getStatus() { return status; } + + public void setStatus(envoy.data.Message.MessageStatus status) { this.status = status; } + + public String getText() { return text; } + + public void setText(String text) { this.text = text; } + + public byte[] getAttachment() { return attachment; } + + public void setAttachment(byte[] attachment) { this.attachment = attachment; } +} diff --git a/src/main/java/envoy/server/data/User.java b/src/main/java/envoy/server/data/User.java new file mode 100644 index 0000000..28dbc0f --- /dev/null +++ b/src/main/java/envoy/server/data/User.java @@ -0,0 +1,57 @@ +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.Temporal; +import javax.persistence.TemporalType; + +/** + * Project: envoy-server-standalone
+ * File: User.java
+ * Created: 02.01.2020
+ * + * @author Kai S. K. Engelbart + * @since Envoy Server Standalone v0.1-alpha + */ +@Entity +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 contacts; + + public long getId() { return id; } + + public void setId(long id) { this.id = id; } + + public String getName() { return name; } + + public void setName(String name) { this.name = name; } + + public byte[] getPasswordHash() { return passwordHash; } + + public void setPasswordHash(byte[] passwordHash) { this.passwordHash = passwordHash; } + + public Date getLastSeen() { return lastSeen; } + + public void setLastSeen(Date lastSeen) { this.lastSeen = lastSeen; } + + public envoy.data.User.UserStatus getStatus() { return status; } + + public void setStatus(envoy.data.User.UserStatus status) { this.status = status; } + + public List getContacts() { return contacts; } + + public void setContacts(List contacts) { this.contacts = contacts; } +} From b83ef8b4efcb7b0abe20b217aebe50b9f75ce977 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 3 Jan 2020 16:21:35 +0100 Subject: [PATCH 2/6] Updated Javadoc --- .classpath | 1 + .project | 6 + .settings/org.eclipse.jdt.ui.prefs | 3 +- .settings/org.hibernate.eclipse.console.prefs | 3 + src/main/java/envoy/server/data/Message.java | 107 +++++++++++++++++- src/main/java/envoy/server/data/User.java | 61 +++++++++- .../server/database/PersistenceManager.java | 21 ++++ 7 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 .settings/org.hibernate.eclipse.console.prefs create mode 100644 src/main/java/envoy/server/database/PersistenceManager.java diff --git a/.classpath b/.classpath index 002ad57..2a83b68 100644 --- a/.classpath +++ b/.classpath @@ -34,5 +34,6 @@ + diff --git a/.project b/.project index 45a395e..f87ca5c 100644 --- a/.project +++ b/.project @@ -15,9 +15,15 @@ + + org.hibernate.eclipse.console.hibernateBuilder + + + org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature + org.hibernate.eclipse.console.hibernateNature diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs index 7103be7..20da6a0 100644 --- a/.settings/org.eclipse.jdt.ui.prefs +++ b/.settings/org.eclipse.jdt.ui.prefs @@ -1,2 +1,3 @@ eclipse.preferences.version=1 -org.eclipse.jdt.ui.text.custom_code_templates= +org.eclipse.jdt.ui.javadoc=true +org.eclipse.jdt.ui.text.custom_code_templates=