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.Column;
17 import javax.persistence.Entity;
18 import javax.persistence.Id;
19 import javax.persistence.NamedQueries;
20 import javax.persistence.NamedQuery;
21 import javax.persistence.OneToMany;
22 import javax.persistence.Table;
23 import javax.persistence.Temporal;
24 import javax.persistence.TemporalType;
25 import javax.validation.constraints.NotNull;
26 import javax.validation.constraints.Size;
27 import javax.xml.bind.annotation.XmlRootElement;
33 @Entity(name = "File")
37 @NamedQuery(name = "File.findAll", query = "SELECT f FROM File f"),
38 @NamedQuery(name = "File.findById", query = "SELECT f FROM File f WHERE f.id = :id"),
39 @NamedQuery(name = "File.findByName", query = "SELECT f FROM File f WHERE f.name = :name"),
40 //@NamedQuery(name = "File.findByLength", query = "SELECT f FROM File f WHERE f.length = :length"),
41 //@NamedQuery(name = "File.findByChecksum", query = "SELECT f FROM File f WHERE f.checksum = :checksum"),
42 @NamedQuery(name = "File.findByCreationDate", query = "SELECT f FROM File f WHERE f.creationDate = :creationDate"),
43 @NamedQuery(name = "File.findByUpdateDate", query = "SELECT f FROM File f WHERE f.updateDate = :updateDate"),
44 //@NamedQuery(name = "File.findByValid", query = "SELECT f FROM File f WHERE f.valid = :valid"),
45 //@NamedQuery(name = "File.findByDeleted", query = "SELECT f FROM File f WHERE f.deleted = :deleted"),
46 @NamedQuery(name = "File.findByDeletionDate", query = "SELECT f FROM File f WHERE f.deletionDate = :deletionDate")
48 public class GDEFile implements Serializable {
49 private static final long serialVersionUID = 1L;
52 @Basic(optional = false)
57 @Column(name = "name")
59 @Column(name = "length")
62 @Column(name = "checksum")
63 private String checksum;
64 @Column(name = "creation_date")
65 @Temporal(TemporalType.TIMESTAMP)
66 private Date creationDate;
67 @Column(name = "update_date")
68 @Temporal(TemporalType.TIMESTAMP)
69 private Date updateDate;
70 @Column(name = "valid")
71 private Boolean valid;
72 @Column(name = "deleted")
73 private Boolean deleted;
74 @Column(name = "deletion_date")
75 @Temporal(TemporalType.TIMESTAMP)
76 private Date deletionDate;
77 //@JoinColumn(name = "group_id", referencedColumnName = "id", nullable = false)
78 @Column(name = "group_id", nullable = false)
82 private Collection<Chunk> chunks;
87 public GDEFile(long id) {
95 public void setId(long id) {
99 public String getName() {
103 public void setName(String name) {
107 public long getLength() {
111 public void setLength(long length) {
112 this.length = length;
115 public String getChecksum() {
119 public void setChecksum(String checksum) {
120 this.checksum = checksum;
123 public Date getCreationDate() {
127 public void setCreationDate(Date creationDate) {
128 this.creationDate = creationDate;
131 public Date getUpdateDate() {
135 public void setUpdateDate(Date updateDate) {
136 this.updateDate = updateDate;
139 public Boolean getValid() {
143 public void setValid(Boolean valid) {
147 public Boolean getDeleted() {
151 public void setDeleted(Boolean deleted) {
152 this.deleted = deleted;
155 public Date getDeletionDate() {
159 public void setDeletionDate(Date deletionDate) {
160 this.deletionDate = deletionDate;
163 public long getGroupId() {
167 public void setGroupId(long groupId) {
168 this.groupId = groupId;
171 public Collection<Chunk> getChunks() {
175 public void setChunks(Collection<Chunk> chunks) {
176 this.chunks = chunks;
179 public static GDEFile fromFileTO(FileTO fto) {
180 GDEFile f = new GDEFile();
181 f.checksum = fto.getChecksum();
183 f.chunks = new ArrayList<>();
184 Collection<ChunkTO> chunks = fto.getChunks();
185 for (ChunkTO cto : chunks) {
186 f.chunks.add(Chunk.fromChunkTO(cto));
189 f.creationDate = fto.getCreationDate();
190 f.deleted = fto.getDeleted();
191 f.deletionDate = fto.getDeletionDate();
192 f.groupId = 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.chunks) {
207 ctos.add(c.toChunkTO());
211 fto.setCreationDate(this.creationDate);
212 fto.setDeleted(this.deleted);
213 fto.setDeletionDate(this.deletionDate);
214 fto.setAttributeGroupId(this.groupId);
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.File[ id=" + id + " ]";
229 public int hashCode() {
231 hash = 41 * hash + (int) (this.id ^ (this.id >>> 32));
232 hash = 41 * hash + Objects.hashCode(this.name);
233 hash = 41 * hash + (int) (this.length ^ (this.length >>> 32));
234 hash = 41 * hash + Objects.hashCode(this.checksum);
235 hash = 41 * hash + Objects.hashCode(this.creationDate);
236 hash = 41 * hash + Objects.hashCode(this.updateDate);
237 hash = 41 * hash + Objects.hashCode(this.valid);
238 hash = 41 * hash + Objects.hashCode(this.deleted);
239 hash = 41 * hash + Objects.hashCode(this.deletionDate);
240 hash = 41 * hash + (int) (this.groupId ^ (this.groupId >>> 32));
241 hash = 41 * hash + Objects.hashCode(this.chunks);
246 public boolean equals(Object obj) {
250 if (getClass() != obj.getClass()) {
253 final GDEFile other = (GDEFile) obj;
254 if (this.id != other.id) {