/* Copyright 2006 - 2010 Under Dusken 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 no.dusken.aranea.model; import org.compass.annotations.Searchable; import org.compass.annotations.SearchableProperty; import javax.persistence.*; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.util.Collection; import static javax.persistence.CascadeType.ALL; import static javax.persistence.FetchType.LAZY; /** * Represents a Tag. * * @author Erlend Hamnaberg<erlenha@underdusken.no> */ @Entity @Table(name = "tag", uniqueConstraints = @UniqueConstraint(columnNames = { "name"})) @SequenceGenerator(name = "tag_seq", sequenceName = "tag_id_seq") @NamedQueries({ @NamedQuery(name = "tag_tags", query = "select t from Tag t order by t.name"), @NamedQuery(name = "tag_image", query = "select t from Tag t where :image member of t.images order by t.name"), @NamedQuery(name = "tag_byname", query = "select t from Tag t where t.name = :name")}) @Searchable public class Tag extends AraneaObject { @Column(nullable = false) @SearchableProperty @Size(max = 255, min = 1) @NotNull private String name; @ManyToMany(mappedBy = "tags", fetch = LAZY, cascade = ALL) private Collection<Page> pages; @ManyToMany(mappedBy = "tags", fetch = LAZY, cascade = ALL) private Collection<Image> images; public Tag(Long ID) { super(ID); } public Tag() { } public String getName() { return name; } public void setName(String name) { this.name = name; } public Collection<Page> getPages() { return pages; } public void setPages(Collection<Page> pages) { this.pages = pages; } public Collection<Image> getImages() { return images; } public void setImages(Collection<Image> images) { this.images = images; } public String toString() { return new StringBuilder("ID: ").append(ID).append(", Name: ").append( name).toString(); } }