View Javadoc

1   /**
2    * Copyright 2008 WebPhotos
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /*
17   * To change this template, choose Tools | Templates
18   * and open the template in the editor.
19   */
20  package net.sf.webphotos.model;
21  
22  import java.io.Serializable;
23  import javax.persistence.*;
24  import net.sf.webphotos.entity.HasID;
25  import net.sf.webphotos.entity.PhotoEntity;
26  
27  /**
28   *
29   * @author Guilherme
30   */
31  @Entity
32  @Table(name = "FOTOS")
33  @NamedQueries({
34      @NamedQuery(name = "PhotoVO.findByFotoid", query = "SELECT f FROM PhotoVO f WHERE f.fotoid = :fotoid"),
35      @NamedQuery(name = "PhotoVO.findByAlbumid", query = "SELECT f FROM PhotoVO f WHERE f.album.albumid = :albumid"),
36      @NamedQuery(name = "PhotoVO.findByNmfoto", query = "SELECT f FROM PhotoVO f WHERE f.nmfoto = :nmfoto"),
37      @NamedQuery(name = "PhotoVO.findByLegenda", query = "SELECT f FROM PhotoVO f WHERE f.legenda = :legenda"),
38      @NamedQuery(name = "PhotoVO.findByCreditoid", query = "SELECT f FROM PhotoVO f WHERE f.creditos.creditoid = :creditoid")})
39  public class PhotoVO extends PhotoEntity implements Serializable, HasID<Integer> {
40      
41      private static final long serialVersionUID = 1L;
42      
43      @Id
44      @Column(name = "FOTOID", nullable = false)
45      @GeneratedValue(strategy = GenerationType.IDENTITY)
46      private Integer fotoid;
47      
48      @Column(name = "NMFOTO")
49      private String nmfoto;
50      
51      @Column(name = "LEGENDA", nullable = false)
52      private String legenda;
53      
54      @ManyToOne
55      @JoinColumn(name = "CREDITOID", nullable = false)
56      private CreditsVO creditos;
57      
58      @ManyToOne
59      @JoinColumn(name = "ALBUMID", nullable = false)
60      private AlbumVO album;
61      
62      @Transient
63      private String caminhoArquivo;
64      
65      @Transient
66      private Integer largura, altura;
67  
68      /**
69       * TODO: remove
70       */
71      @Deprecated
72      public PhotoVO() {
73          this.creditos = new CreditsVO();
74          this.album = new AlbumVO();
75          this.legenda = "";
76      }
77      
78      @Deprecated
79      public PhotoVO(Integer fotoid, int albumid, String legenda, int creditoid, Integer largura, Integer altura) {
80          this();
81          this.fotoid = fotoid;
82          this.legenda = legenda;
83          this.largura = largura;
84          this.altura = altura;
85      }
86  
87      /**
88       * Default Constructor for new albuns
89       * @param nmfoto
90       * @param legenda
91       * @param creditos
92       * @param album 
93       */
94      public PhotoVO(String nmfoto, String legenda, CreditsVO creditos, String caminhoArquivo) {
95          this.nmfoto = nmfoto;
96          this.legenda = legenda;
97          this.creditos = creditos;
98          this.caminhoArquivo = caminhoArquivo;
99      }
100 
101     /**
102      * Constructor to add photos to existing album
103      * @param nmfoto
104      * @param legenda
105      * @param creditos
106      * @param album 
107      */
108     public PhotoVO(String nmfoto, String legenda, CreditsVO creditos, String caminhoArquivo, AlbumVO album) {
109         this(nmfoto, legenda, creditos, caminhoArquivo);
110         this.album = album;
111     }
112 
113     public Integer getFotoid() {
114         return fotoid;
115     }
116 
117     public void setFotoid(Integer fotoid) {
118         this.fotoid = fotoid;
119     }
120 
121     public String getNmfoto() {
122         return nmfoto;
123     }
124 
125     public void setNmfoto(String nmfoto) {
126         this.nmfoto = nmfoto;
127     }
128 
129     @Override
130     public String getLegenda() {
131         return legenda;
132     }
133 
134     public void setLegenda(String legenda) {
135         this.legenda = legenda;
136     }
137 
138     @Override
139     public String toString() {
140         return this.getClass().getCanonicalName() + "[fotoid=" + fotoid + "]";
141     }
142 
143     @Override
144     public CreditsVO getCreditos() {
145         return creditos;
146     }
147 
148     public void setCreditos(CreditsVO creditos) {
149         this.creditos = creditos;
150     }
151 
152     public AlbumVO getAlbum() {
153         return album;
154     }
155 
156     public void setAlbum(AlbumVO album) {
157         this.album = album;
158     }
159 
160     /**
161      * @return the caminhoArquivo
162      */
163     public String getCaminhoArquivo() {
164         return caminhoArquivo;
165     }
166 
167     public Integer getAltura() {
168         return altura;
169     }
170 
171     public Integer getLargura() {
172         return largura;
173     }
174 
175     @Override
176     public Integer getId() {
177         return this.fotoid;
178     }
179 
180     @Override
181     public String getKey() {
182         return this.getId() != null ? this.getId().toString() : this.getCaminhoArquivo();
183     }
184 }