Source code file content
main / trunk / jtentative / jtentative-ejb / src / main / java / com / aperigeek / jtentative / entity / Entry.java
Size: 6737 bytes, 1 line
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.aperigeek.jtentative.entity;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
*
* @author Vivien Barousse
*/
@Entity
@NamedQueries({
@NamedQuery(name="Entry.findAllFavoritesByUser", query="SELECT DISTINCT f.entry FROM Favorite AS f WHERE f.user = :user"),
@NamedQuery(name="Entry.findBySourceAndLink", query="SELECT e FROM Entry AS e WHERE e.source = :source AND e.link = :link"),
@NamedQuery(name="Entry.findBySourceAndUri", query="SELECT e FROM Entry AS e WHERE e.source = :source AND e.uri = :uri"),
@NamedQuery(name="Entry.findAll", query="SELECT e FROM Entry AS e"),
@NamedQuery(name="Entry.findAllParentEntries", query="SELECT p FROM Entry AS e, IN (e.parentEntries) AS p WHERE e = :entry"),
@NamedQuery(name="Entry.findAllFollowupEntries", query="SELECT e FROM Entry AS e, IN (e.parentEntries) AS p WHERE p = :entry"),
@NamedQuery(name="Entry.findAllUnreadsByUserAndSource", query="SELECT e FROM Entry AS e WHERE e.source = :source AND e.id NOT IN (SELECT s.entry.id FROM ReadStatus AS s WHERE s.user = :user AND s.value = true)"),
@NamedQuery(name="Entry.findAllUnreadsByUserAndSourceOrderedByDateAsc", query="SELECT e FROM Entry AS e WHERE e.source = :source AND e.id NOT IN (SELECT s.entry.id FROM ReadStatus AS s WHERE s.user = :user AND s.value = true) ORDER BY e.publicationDate ASC"),
@NamedQuery(name="Entry.countAllUnreadsByUserAndSource", query="SELECT COUNT(e.id) FROM Entry AS e WHERE e.source = :source AND e.id NOT IN (SELECT s.entry.id FROM ReadStatus AS s WHERE s.user = :user AND s.value = true)")
})
@Table(name="entries")
public class Entry implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="id")
private Long id;
@ManyToOne
@JoinColumn(name="source_id")
private InputSource source;
@Column(name="title")
private String title;
@Column(name="author")
private String author;
@Column(name="link")
private String link;
@Column(name="uri")
private String uri;
@Lob
@Column(name="description")
private String description;
@Lob
@Column(name="content")
private String content;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="publication_date")
private Date publicationDate;
@ManyToMany
@JoinTable(name="link_entries_tags")
private List<Tag> tags;
@ManyToMany
@JoinTable(name="link_parent_entries")
private List<Entry> parentEntries;
public Entry() {
}
/**
* This constructor is used through JPAQL queries to construct objects without content, description and tags.
* @param id entry's id
* @param source entry's input source
* @param title entry's title
* @param author entry's author
* @param link entry's link
* @param uri entry's URI
* @param publicationDate entry's publication date
*/
public Entry(Long id, InputSource source, String title, String author, String link, String uri, Date publicationDate) {
this.id = id;
this.source = source;
this.title = title;
this.author = author;
this.link = link;
this.uri = uri;
this.publicationDate = publicationDate;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public InputSource getSource() {
return source;
}
public void setSource(InputSource source) {
this.source = source;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Date getPublicationDate() {
return publicationDate;
}
public void setPublicationDate(Date publicationDate) {
this.publicationDate = publicationDate;
}
public List<Tag> getTags() {
return tags;
}
public void setTags(List<Tag> tags) {
this.tags = tags;
}
public List<Entry> getParentEntries() {
return parentEntries;
}
public void setParentEntries(List<Entry> parentEntries) {
this.parentEntries = parentEntries;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Entry)) {
return false;
}
Entry other = (Entry) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.aperigeek.entity.Entry[id=" + id + "]";
}
}





