1 package com.trendmicro.grid.acl.ds.jpa.entities;
2
3 import com.trendmicro.grid.acl.ds.datatypes.SharedSourceInformation;
4 import com.trendmicro.grid.acl.l0.datatypes.SourceIdentifier;
5 import com.trendmicro.grid.acl.l0.datatypes.SourceInformation;
6 import org.hibernate.annotations.Index;
7 import org.hibernate.annotations.NaturalId;
8 import org.hibernate.annotations.Type;
9
10 import javax.persistence.*;
11 import java.sql.Timestamp;
12 import java.util.Date;
13
14 import static com.trendmicro.grid.acl.Limits.SOURCE_MAX_CONTENT_TAG_LENGTH;
15
16
17
18
19
20
21
22 @Cacheable
23 @Embeddable
24 public class JpaSourceInformation extends SharedSourceInformation {
25
26 private static final long serialVersionUID = 6735651302201345418L;
27
28 public JpaSourceInformation() {
29 }
30
31 public JpaSourceInformation(SourceIdentifier identifier) {
32 super(identifier, null, null, false);
33 }
34
35 public JpaSourceInformation(SourceInformation info, SourceIdentifier identifier) {
36 super(identifier, info.getLastModified(), info.getContentTag(), info.isTemporary());
37 }
38
39 public void updateFrom(SourceInformation info) {
40 setLastModified(info.getLastModified());
41 setContentTag(info.getContentTag());
42 }
43
44 @NaturalId
45 @Index(name = "IX_SOURCE__PUBLIC_GUID_INDEX")
46 @Column(name = "PUBLIC_GUID", length = 20, unique = true, updatable = false)
47 public byte[] getPublicGUID() {
48 return identifier.getSHA1Hash();
49 }
50
51 public void setPublicGUID(byte[] hash) {
52 this.identifier = new SourceIdentifier(hash);
53 }
54
55 @Index(name = "PUBLIC_LAST_MODIFIED_INDEX")
56 @Column(name = "PUBLIC_LAST_MODIFIED")
57 @Temporal(TemporalType.TIMESTAMP)
58 public Date getLastModified() {
59 return lastModified;
60 }
61
62 public void setLastModified(Date lastModified) {
63
64 this.lastModified = lastModified instanceof Timestamp ? new Date(lastModified.getTime()) : lastModified;
65 }
66
67 @Type(type = "nstring")
68 @Column(name = "PUBLIC_CONTENT_TAG", length = SOURCE_MAX_CONTENT_TAG_LENGTH)
69 public String getContentTag() {
70 return contentTag;
71 }
72
73 public void setContentTag(String contentTag) {
74 this.contentTag = contentTag;
75 }
76
77 @Column(name = "TEMPORARY")
78 public boolean isTemporary() {
79 return temporary;
80 }
81
82 public void setTemporary(boolean temporary) {
83 this.temporary = temporary;
84 }
85 }