Added creationDate variable in Contact & added pendingGroups query
This commit is contained in:
		| @@ -1,8 +1,19 @@ | |||||||
| package envoy.server.data; | package envoy.server.data; | ||||||
|  |  | ||||||
|  | import java.util.Date; | ||||||
| import java.util.Set; | 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 |  * 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 long		id; | ||||||
| 	protected String	name; | 	protected String	name; | ||||||
|  |  | ||||||
|  | 	@Temporal(TemporalType.TIMESTAMP) | ||||||
|  | 	private Date creationDate; | ||||||
|  |  | ||||||
| 	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) | 	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) | ||||||
| 	protected Set<Contact> contacts; | 	protected Set<Contact> contacts; | ||||||
|  |  | ||||||
| @@ -86,6 +100,18 @@ public abstract class Contact { | |||||||
| 	 */ | 	 */ | ||||||
| 	public void setContacts(Set<Contact> contacts) { this.contacts = contacts; } | 	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} | 	 * {@inheritDoc} | ||||||
| 	 */ | 	 */ | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ package envoy.server.data; | |||||||
| import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||||
|  |  | ||||||
| import javax.persistence.Entity; | import javax.persistence.Entity; | ||||||
|  | import javax.persistence.NamedQueries; | ||||||
| import javax.persistence.NamedQuery; | import javax.persistence.NamedQuery; | ||||||
| import javax.persistence.Table; | import javax.persistence.Table; | ||||||
|  |  | ||||||
| @@ -19,19 +20,32 @@ import javax.persistence.Table; | |||||||
|  */ |  */ | ||||||
| @Entity | @Entity | ||||||
| @Table(name = "groups") | @Table(name = "groups") | ||||||
| @NamedQuery( | @NamedQueries({ | ||||||
|  | 	@NamedQuery( | ||||||
| 		name = Group.findByName, | 		name = Group.findByName, | ||||||
| 		query = "SELECT g FROM Group g WHERE g.name = :name" | 		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 { | 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 | 	 * @since Envoy Server Standalone v0.1-beta | ||||||
| 	 */ | 	 */ | ||||||
| 	public static final String findByName = "Group.findByName"; | 	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} | 	 * {@inheritDoc} | ||||||
| 	 */ | 	 */ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 DieGurke
					DieGurke