Java tutorial
/* Copyright 2012 Tim Garrett, Mothsoft LLC * * 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.mothsoft.alexis.domain; import java.util.Date; import java.util.List; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; import javax.persistence.Version; import org.apache.commons.lang.StringUtils; @Entity(name = "Topic") @Table(name = "topic") public class Topic { @Id @GeneratedValue private Long id; @Column(name = "name") private String name; @Column(name = "search_expression", length = 255) private String searchExpression; @Column(name = "description") private String description; @Column(name = "user_id") private Long userId; @Column(name = "last_document_match_date") private Date lastDocumentMatchDate; @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, orphanRemoval = true) @JoinColumn(name = "topic_id") @OrderBy("score DESC") private List<TopicDocument> topicDocuments; @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, orphanRemoval = true) @JoinColumn(name = "topic_id") protected Set<TopicActivityDataSet> topicActivityDataSets; @Version @Column(name = "version", columnDefinition = "smallint unsigned") protected Integer version; public Topic() { super(); } public Long getId() { return id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public String getDescriptionSummary() { return StringUtils.abbreviate(this.description, 75); } public void setDescription(String description) { this.description = description; } public String getSearchExpression() { return searchExpression; } public void setSearchExpression(String searchExpression) { this.searchExpression = searchExpression; } public Long getUserId() { return userId; } public void setUserId(Long userId) { this.userId = userId; } public Date getLastDocumentMatchDate() { return lastDocumentMatchDate; } public void setLastDocumentMatchDate(Date lastDocumentMatchDate) { this.lastDocumentMatchDate = lastDocumentMatchDate; } public List<TopicDocument> getTopicDocuments() { return topicDocuments; } public void setTopicDocuments(List<TopicDocument> topicDocuments) { this.topicDocuments = topicDocuments; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((userId == null) ? 0 : userId.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Topic other = (Topic) obj; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (userId == null) { if (other.userId != null) return false; } else if (!userId.equals(other.userId)) return false; return true; } }