Source code file content

Revision: 23

Lazy loading on entries content and description.
» Project Revision History

» Checkout URL

main / trunk / jtentative / jtentative-ejb / src / main / java / com / aperigeek / jtentative / entity / Entry.java

Size: 6303 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.findByFeedAndLink", query="SELECT e FROM Entry AS e WHERE e.feed = :feed AND e.link = :link"),
    @NamedQuery(name="Entry.findByFeedAndUri", query="SELECT e FROM Entry AS e WHERE e.feed = :feed AND e.uri = :uri"),
    @NamedQuery(name="Entry.findAll", query="SELECT e FROM Entry AS e"),
    @NamedQuery(name="Entry.findAllUnreadsByUserAndFeed", query="SELECT new com.aperigeek.jtentative.entity.Entry(e.id, e.feed, e.title, e.author, e.link, e.uri, e.publicationDate) FROM Entry AS e WHERE e.feed = :feed AND e.id NOT IN (SELECT s.entry.id FROM ReadStatus AS s WHERE s.user = :user AND s.value = true)"),
    @NamedQuery(name="Entry.findAllUnreadsByUserAndFeedOrderedByDateAsc", query="SELECT new com.aperigeek.jtentative.entity.Entry(e.id, e.feed, e.title, e.author, e.link, e.uri, e.publicationDate) FROM Entry AS e WHERE e.feed = :feed 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.countAllUnreadsByUserAndFeed", query="SELECT COUNT(e) FROM Entry AS e WHERE e.feed = :feed 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="feed_id")
    private Feed feed;

    @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;

    public Entry() {
    }

    /**
     * This constructor is used through JPAQL queries to construct objects without content, description and tags.
     * @param id entry's id
     * @param feed entry's feed
     * @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, Feed feed, String title, String author, String link, String uri, Date publicationDate) {
        this.id = id;
        this.feed = feed;
        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 Feed getFeed() {
        return feed;
    }

    public void setFeed(Feed feed) {
        this.feed = feed;
    }

    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;
    }

    @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 + "]";
    }

}
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20100521.d19488a)
 
 
loading
Please Confirm