Added creationDate variable in Contact & added pendingGroups query

This commit is contained in:
DieGurke 2020-06-11 13:22:48 +02:00
parent 1fffb12423
commit 638770c75f
2 changed files with 46 additions and 6 deletions

View File

@ -1,8 +1,19 @@
package envoy.server.data;
import java.util.Date;
import java.util.Set;
import javax.persistence.*;
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;
/**
* This class acts as a superclass for all contacts, being {@link User}s and
@ -26,6 +37,9 @@ public abstract class Contact {
protected long id;
protected String name;
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
protected Set<Contact> contacts;
@ -86,6 +100,18 @@ public abstract class Contact {
*/
public void setContacts(Set<Contact> contacts) { this.contacts = contacts; }
/**
* @return the creationDate
* @since Envoy Server Standalone v0.1-beta
*/
public Date getCreationDate() { return creationDate; }
/**
* @param creationDate the creationDate to set
* @since Envoy Server Standalone v0.1-beta
*/
public void setCreationDate(Date creationDate) { this.creationDate = creationDate; }
/**
* {@inheritDoc}
*/

View File

@ -3,6 +3,7 @@ package envoy.server.data;
import java.util.stream.Collectors;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
@ -19,18 +20,31 @@ import javax.persistence.Table;
*/
@Entity
@Table(name = "groups")
@NamedQuery(
name = Group.findByName,
query = "SELECT g FROM Group g WHERE g.name = :name"
)
@NamedQueries({
@NamedQuery(
name = Group.findByName,
query = "SELECT g FROM Group g WHERE g.name = :name"
),
@NamedQuery(
name = Group.findPendingGroups,
query = "SELECT g FROM Group g WHERE g.creationDate > :lastSeen AND :user MEMBER OF g.contacts"
)
})
public class Group extends Contact {
/**
* Named query retrieving a group by name (parameter {@code :name}.
* Named query retrieving a group by name (parameter {@code :name}).
*
* @since Envoy Server Standalone v0.1-beta
*/
public static final String findByName = "Group.findByName";
/**
* Named query retrieving all pending groups for a specific user (parameter {@code :user}, {@code :lastSeen}).
*
* @since Envoy Server Standalone v0.1-beta
*/
public static final String findPendingGroups = "Group.findPendingGroups";
/**
* {@inheritDoc}