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 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;
31 @Entity(name = "Chunk")
32 @Table(name = "chunk")
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")
42 public class Chunk implements Serializable {
43 private static final long serialVersionUID = 1L;
45 @Basic(optional = false)
47 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_GEN_SEQUENCE")
48 @SequenceGenerator(name = "SEQ_GEN_SEQUENCE", allocationSize = 50)
51 @Column(name = "file_id", nullable = false)
53 @Column(name = "rank")
56 @Column(name = "checksum")
57 private String checksum;
58 @Column(name = "size")
61 @Column(name = "data")
67 public Chunk(long id) {
75 public void setId(long id) {
79 public long getFileId() {
83 public void setFileId(long fileId) {
87 public long getRank() {
91 public void setRank(long rank) {
95 public String getChecksum() {
99 public void setChecksum(String checksum) {
100 this.checksum = checksum;
103 public long getSize() {
107 public void setSize(long size) {
111 public byte[] getData() {
115 public void setData(byte[] data) {
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();
125 c.rank = cto.getRank();
126 c.size = cto.getSize();
130 public ChunkTO toChunkTO() {
131 ChunkTO cto = new ChunkTO();
132 cto.setChecksum(this.checksum);
133 cto.setData(this.data);
134 cto.setFileId(this.fileId);
136 cto.setRank(this.rank);
137 cto.setSize(this.size);
142 public String toString() {
143 return "com.edf.gde.entities.Chunk[ id=" + id + " ]";
147 public int hashCode() {
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);
159 public boolean equals(Object obj) {
163 if (getClass() != obj.getClass()) {
166 final Chunk other = (Chunk) obj;
167 if (this.id != other.id) {