2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
6 package com.edf.gde.entities;
8 import com.edf.gde.transferables.ChunkTO;
9 import com.edf.gde.transferables.FileTO;
10 import java.io.Serializable;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.Date;
14 import java.util.Objects;
15 import javax.persistence.Basic;
16 import javax.persistence.CascadeType;
17 import javax.persistence.Column;
18 import javax.persistence.Entity;
19 import javax.persistence.Id;
20 import javax.persistence.NamedQueries;
21 import javax.persistence.NamedQuery;
22 import javax.persistence.OneToMany;
23 import javax.persistence.Table;
24 import javax.persistence.Temporal;
25 import javax.persistence.TemporalType;
26 import javax.validation.constraints.NotNull;
27 import javax.validation.constraints.Size;
28 import javax.xml.bind.annotation.XmlRootElement;
29 import javax.xml.bind.annotation.XmlTransient;
35 @Entity(name = "File")
36 @Table(name = "gde_file")
39 @NamedQuery(name = "File.findAll", query = "SELECT f FROM File f"),
40 @NamedQuery(name = "File.findById", query = "SELECT f FROM File f WHERE f.id = :id"),
41 @NamedQuery(name = "File.findByName", query = "SELECT f FROM File f WHERE f.name = :name"),
42 //@NamedQuery(name = "File.findByLength", query = "SELECT f FROM File f WHERE f.length = :length"),
43 //@NamedQuery(name = "File.findByChecksum", query = "SELECT f FROM File f WHERE f.checksum = :checksum"),
44 @NamedQuery(name = "File.findByCreationDate", query = "SELECT f FROM File f WHERE f.creationDate = :creationDate"),
45 @NamedQuery(name = "File.findByUpdateDate", query = "SELECT f FROM File f WHERE f.updateDate = :updateDate"),
46 //@NamedQuery(name = "File.findByValid", query = "SELECT f FROM File f WHERE f.valid = :valid"),
47 //@NamedQuery(name = "File.findByDeleted", query = "SELECT f FROM File f WHERE f.deleted = :deleted"),
48 @NamedQuery(name = "File.findByDeletionDate", query = "SELECT f FROM File f WHERE f.deletionDate = :deletionDate")
50 public class GDEFile implements Serializable {
51 private static final long serialVersionUID = 1L;
53 @Basic(optional = false)
58 @Column(name = "name")
60 @Column(name = "length")
63 @Column(name = "checksum")
64 private String checksum;
65 @Column(name = "creation_date")
66 @Temporal(TemporalType.TIMESTAMP)
67 private Date creationDate;
68 @Column(name = "update_date")
69 @Temporal(TemporalType.TIMESTAMP)
70 private Date updateDate;
71 @Column(name = "valid")
72 private Boolean valid;
73 @Column(name = "deleted")
74 private Boolean deleted;
75 @Column(name = "deletion_date")
76 @Temporal(TemporalType.TIMESTAMP)
77 private Date deletionDate;
78 @OneToMany(cascade = CascadeType.ALL)
79 private Collection<Chunk> chunkCollection;
80 @Column(name = "attribute_group_id")
81 private long attributeGroupId;
86 public GDEFile(long id) {
94 public void setId(long id) {
98 public String getName() {
102 public void setName(String name) {
106 public long getLength() {
110 public void setLength(long length) {
111 this.length = length;
114 public String getChecksum() {
118 public void setChecksum(String checksum) {
119 this.checksum = checksum;
122 public Date getCreationDate() {
126 public void setCreationDate(Date creationDate) {
127 this.creationDate = creationDate;
130 public Date getUpdateDate() {
134 public void setUpdateDate(Date updateDate) {
135 this.updateDate = updateDate;
138 public Boolean getValid() {
142 public void setValid(Boolean valid) {
146 public Boolean getDeleted() {
150 public void setDeleted(Boolean deleted) {
151 this.deleted = deleted;
154 public Date getDeletionDate() {
158 public void setDeletionDate(Date deletionDate) {
159 this.deletionDate = deletionDate;
163 public Collection<Chunk> getChunkCollection() {
164 return chunkCollection;
167 public void setChunkCollection(Collection<Chunk> chunkCollection) {
168 this.chunkCollection = chunkCollection;
171 public long getAttributeGroupId() {
172 return attributeGroupId;
175 public void setAttributeGroupId(long attributeGroupId) {
176 this.attributeGroupId = attributeGroupId;
179 public static GDEFile fromFileTO(FileTO fto) {
180 GDEFile f = new GDEFile();
181 f.checksum = fto.getChecksum();
183 f.chunkCollection = new ArrayList<>();
184 Collection<ChunkTO> chunks = fto.getChunkCollection();
185 for (ChunkTO cto : chunks) {
186 f.chunkCollection.add(Chunk.fromChunkTO(cto));
189 f.creationDate = fto.getCreationDate();
190 f.deleted = fto.getDeleted();
191 f.deletionDate = fto.getDeletionDate();
192 f.attributeGroupId = fto.getAttributeGroupId();
194 f.length = fto.getLength();
195 f.name = fto.getName();
196 f.updateDate = fto.getUpdateDate();
197 f.valid = fto.getValid();
201 public FileTO toFileTO() {
202 FileTO fto = new FileTO();
203 fto.setChecksum(this.checksum);
205 Collection<ChunkTO> ctos = new ArrayList<>();
206 for (Chunk c : this.chunkCollection) {
207 ctos.add(c.toChunkTO());
209 fto.setChunkCollection(ctos);
211 fto.setCreationDate(this.creationDate);
212 fto.setDeleted(this.deleted);
213 fto.setDeletionDate(this.deletionDate);
214 fto.setAttributeGroupId(this.attributeGroupId);
216 fto.setLength(this.length);
217 fto.setName(this.name);
218 fto.setUpdateDate(this.updateDate);
219 fto.setValid(this.valid);
224 public String toString() {
225 return "com.edf.gde.entities.GDEFile[ id=" + id + " ]";
229 public int hashCode() {
231 hash = 29 * hash + (int) (this.id ^ (this.id >>> 32));
232 hash = 29 * hash + Objects.hashCode(this.name);
233 hash = 29 * hash + (int) (this.length ^ (this.length >>> 32));
234 hash = 29 * hash + Objects.hashCode(this.checksum);
235 hash = 29 * hash + Objects.hashCode(this.creationDate);
236 hash = 29 * hash + Objects.hashCode(this.updateDate);
237 hash = 29 * hash + Objects.hashCode(this.valid);
238 hash = 29 * hash + Objects.hashCode(this.deleted);
239 hash = 29 * hash + Objects.hashCode(this.deletionDate);
240 hash = 29 * hash + Objects.hashCode(this.chunkCollection);
241 hash = 29 * hash + (int) (this.attributeGroupId ^ (this.attributeGroupId >>> 32));
246 public boolean equals(Object obj) {
250 if (getClass() != obj.getClass()) {
253 final GDEFile other = (GDEFile) obj;
254 if (this.id != other.id) {