]> SALOME platform Git repositories - modules/gde.git/blob - projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Chunk.java
Salome HOME
- Code refactoring and simplification
[modules/gde.git] / projects / GDE_App / GDE-ejb / src / java / com / edf / gde / entities / Chunk.java
1 /*
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.
5  */
6 package com.edf.gde.entities;
7
8 import com.edf.gde.transferables.ChunkTO;
9 import java.io.Serializable;
10 import java.util.Arrays;
11 import java.util.Objects;
12 import javax.persistence.Basic;
13 import javax.persistence.Column;
14 import javax.persistence.Entity;
15 import javax.persistence.GeneratedValue;
16 import javax.persistence.GenerationType;
17 import javax.persistence.Id;
18 import javax.persistence.Lob;
19 import javax.persistence.NamedQueries;
20 import javax.persistence.NamedQuery;
21 import javax.persistence.SequenceGenerator;
22 import javax.persistence.Table;
23 import javax.validation.constraints.NotNull;
24 import javax.validation.constraints.Size;
25 import javax.xml.bind.annotation.XmlRootElement;
26
27 /**
28  *
29  * @author F62173
30  */
31 @Entity(name = "Chunk")
32 @Table(name = "chunk")
33 @XmlRootElement
34 @NamedQueries({
35     @NamedQuery(name = "Chunk.findAll", query = "SELECT c FROM Chunk c"),
36     @NamedQuery(name = "Chunk.findById", query = "SELECT c FROM Chunk c WHERE c.id = :id"),
37     @NamedQuery(name = "Chunk.findByFileId", query = "SELECT c FROM Chunk c WHERE c.fileId = :fileId"),
38     //@NamedQuery(name = "Chunk.findByRank", query = "SELECT c FROM Chunk c WHERE c.rank = :rank"),
39     //@NamedQuery(name = "Chunk.findByChecksum", query = "SELECT c FROM Chunk c WHERE c.checksum = :checksum"),
40     //@NamedQuery(name = "Chunk.findBySize", query = "SELECT c FROM Chunk c WHERE c.size = :size")
41 })
42 public class Chunk implements Serializable {
43     private static final long serialVersionUID = 1L;
44     @Id
45     @Basic(optional = false)
46     @NotNull
47     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_GEN_SEQUENCE")
48     @SequenceGenerator(name = "SEQ_GEN_SEQUENCE", allocationSize = 50)
49     @Column(name = "id")
50     private long id;
51     @Column(name = "file_id", nullable = false)
52     private long fileId;
53     @Column(name = "rank")
54     private long rank;
55     @Size(max = 255)
56     @Column(name = "checksum")
57     private String checksum;
58     @Column(name = "size")
59     private long size;
60     @Lob
61     @Column(name = "data")
62     private byte[] data;
63
64     public Chunk() {
65     }
66
67     public Chunk(long id) {
68         this.id = id;
69     }
70
71     public long getId() {
72         return id;
73     }
74
75     public void setId(long id) {
76         this.id = id;
77     }
78
79     public long getFileId() {
80         return fileId;
81     }
82
83     public void setFileId(long fileId) {
84         this.fileId = fileId;
85     }
86
87     public long getRank() {
88         return rank;
89     }
90
91     public void setRank(long rank) {
92         this.rank = rank;
93     }
94
95     public String getChecksum() {
96         return checksum;
97     }
98
99     public void setChecksum(String checksum) {
100         this.checksum = checksum;
101     }
102
103     public long getSize() {
104         return size;
105     }
106
107     public void setSize(long size) {
108         this.size = size;
109     }
110
111     public byte[] getData() {
112         return data;
113     }
114
115     public void setData(byte[] data) {
116         this.data = data;
117     }
118
119     public static Chunk fromChunkTO(ChunkTO cto) {
120         Chunk c = new Chunk();
121         c.checksum = cto.getChecksum();
122         c.data = cto.getData();
123         c.fileId = cto.getFileId();
124         c.id = cto.getId();
125         c.rank = cto.getRank();
126         c.size = cto.getSize();
127         return c;
128     }
129     
130     public ChunkTO toChunkTO() {
131         ChunkTO cto = new ChunkTO();
132         cto.setChecksum(this.checksum);
133         cto.setData(this.data);
134         cto.setFileId(this.fileId);
135         cto.setId(this.id);
136         cto.setRank(this.rank);
137         cto.setSize(this.size);
138         return cto;
139     }
140     
141     @Override
142     public String toString() {
143         return "com.edf.gde.entities.Chunk[ id=" + id + " ]";
144     }
145
146     @Override
147     public int hashCode() {
148         int hash = 7;
149         hash = 37 * hash + (int) (this.id ^ (this.id >>> 32));
150         hash = 37 * hash + (int) (this.fileId ^ (this.fileId >>> 32));
151         hash = 37 * hash + (int) (this.rank ^ (this.rank >>> 32));
152         hash = 37 * hash + Objects.hashCode(this.checksum);
153         hash = 37 * hash + (int) (this.size ^ (this.size >>> 32));
154         hash = 37 * hash + Arrays.hashCode(this.data);
155         return hash;
156     }
157
158     @Override
159     public boolean equals(Object obj) {
160         if (obj == null) {
161             return false;
162         }
163         if (getClass() != obj.getClass()) {
164             return false;
165         }
166         final Chunk other = (Chunk) obj;
167         if (this.id != other.id) {
168             return false;
169         }
170         return true;
171     }
172
173 }