Added ORM classes

This commit is contained in:
Kai S. K. Engelbart 2020-01-02 18:50:56 +02:00
parent 557774945f
commit 9318201fd5
3 changed files with 143 additions and 0 deletions

View File

@ -28,6 +28,11 @@
<artifactId>java-nio-server</artifactId> <artifactId>java-nio-server</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.10.Final</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -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: <strong>envoy-server-standalone</strong><br>
* File: <strong>Message.java</strong><br>
* Created: <strong>02.01.2020</strong><br>
*
* @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; }
}

View File

@ -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: <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
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;
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<User> getContacts() { return contacts; }
public void setContacts(List<User> contacts) { this.contacts = contacts; }
}