1 package com.trendmicro.grid.acl.ds.jpa.entities;
2
3 import com.trendmicro.grid.acl.Limits;
4 import com.trendmicro.grid.acl.ds.datatypes.SharedSourceDomain;
5 import com.trendmicro.grid.acl.l0.datatypes.SourceDomain;
6 import com.trendmicro.grid.acl.metadata.Metadata;
7 import org.hibernate.annotations.Index;
8 import org.hibernate.annotations.NaturalId;
9 import org.hibernate.annotations.Type;
10
11 import javax.persistence.*;
12
13 import static com.trendmicro.grid.acl.Limits.SOURCE_DOMAIN_MAX_NAME_LENGTH;
14 import static com.trendmicro.grid.acl.ds.jpa.QueryHints.*;
15 import static com.trendmicro.grid.acl.ds.jpa.QueryHints.CACHE_STORE_MODE;
16 import static com.trendmicro.grid.acl.ds.jpa.QueryHints.V_USE;
17
18
19
20
21
22
23
24 @NamedQueries({
25 @NamedQuery(name = "SourceDomain.SelectAll", query = "" +
26 "SELECT d FROM SOURCE_DOMAIN d"),
27
28 @NamedQuery(name = "SourceDomain.SelectIdByName", query = "" +
29 "SELECT d.primaryKey FROM SOURCE_DOMAIN d " +
30 "WHERE d.name = :name",
31 hints = {@QueryHint(name = CACHEABLE, value = V_YES),
32 @QueryHint(name = CACHE_RETRIEVE_MODE, value = V_USE), @QueryHint(name = CACHE_STORE_MODE, value = V_USE)}),
33
34 @NamedQuery(name = "SourceDomain.SelectDomainByName", query = "" +
35 "SELECT d FROM SOURCE_DOMAIN d " +
36 "WHERE d.name = :name",
37 hints = {@QueryHint(name = CACHEABLE, value = V_YES),
38 @QueryHint(name = CACHE_RETRIEVE_MODE, value = V_USE), @QueryHint(name = CACHE_STORE_MODE, value = V_USE)})
39 })
40 @Cacheable
41 @Entity(name = "SOURCE_DOMAIN")
42 public class JpaSourceDomain extends SharedSourceDomain {
43
44 private static final long serialVersionUID = 3692715551891344428L;
45
46 int primaryKey;
47
48 public JpaSourceDomain() {
49 }
50
51 public JpaSourceDomain(String name) {
52 super(name, null);
53 }
54
55 public JpaSourceDomain(SourceDomain domain) {
56 super(domain.getName(), domain.getMetadata());
57 if (domain instanceof JpaSourceDomain)
58 setPrimaryKey(((JpaSourceDomain) domain).getPrimaryKey());
59 }
60
61 @Id
62 @GeneratedValue
63 @Column(name = "SOURCE_DOMAIN_ID")
64 public int getPrimaryKey() {
65 return primaryKey;
66 }
67
68 public void setPrimaryKey(int primaryKey) {
69 this.primaryKey = primaryKey;
70 }
71
72 @NaturalId
73 @Type(type = "nstring")
74 @Index(name = "IX_SOURCE_DOMAIN__NAME_INDEX")
75 @Column(name = "NAME", nullable = false, unique = true, length = SOURCE_DOMAIN_MAX_NAME_LENGTH, updatable = false)
76 public String getName() {
77 return name;
78 }
79
80 public void setName(String name) {
81 this.name = name;
82 }
83
84 @Override
85 @Type(type = "metadata")
86 @Basic(fetch = FetchType.EAGER)
87 @Column(name = "META_DATA", length = Limits.MAX_SERIALIZED_METADATA_LENGTH)
88 public Metadata getMetadata() {
89 return super.getMetadata();
90 }
91
92 @Override
93 public void setMetadata(Metadata metadata) {
94 super.setMetadata(metadata == null ? null : metadata.clone());
95 }
96
97 @Override
98 public String toString() {
99 return "JpaSourceDomain{" +
100 "primaryKey=" + primaryKey +
101 ", name='" + name + '\'' +
102 ", metadata='" + metadata + '\'' +
103 '}';
104 }
105 }