1 package com.trendmicro.grid.acl.ds.jpa.entities;
2
3 import com.trendmicro.grid.acl.ds.datatypes.SharedNamedFileIdentifier;
4 import com.trendmicro.grid.acl.l0.datatypes.FileIdentifier;
5
6 import javax.persistence.*;
7 import java.io.Serializable;
8
9 import static com.trendmicro.grid.acl.ds.jpa.QueryHints.*;
10 import static com.trendmicro.grid.acl.ds.jpa.QueryHints.CACHE_STORE_MODE;
11 import static com.trendmicro.grid.acl.ds.jpa.QueryHints.V_USE;
12
13
14
15
16
17
18
19 @NamedQueries({
20 @NamedQuery(name = "NamedFileIdentifier.SelectFilesInPackage", query = "" +
21 "SELECT p, p.reference.fileDetails.identifier " +
22 "FROM PACKAGE_FILES p " +
23 "WHERE p.id.packageDetails = :package",
24 hints = {@QueryHint(name = CACHEABLE, value = V_YES),
25 @QueryHint(name = CACHE_RETRIEVE_MODE, value = V_USE), @QueryHint(name = CACHE_STORE_MODE, value = V_USE)}),
26
27 @NamedQuery(name = "NamedFileIdentifier.SelectEntryExists", query = "" +
28 "SELECT 1 " +
29 "FROM PACKAGE_FILES p " +
30 "WHERE p.id.packageDetails = :package AND p.id.fileDetails = :file AND p.id.fileName = :fileName",
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 = "NamedFileIdentifier.UpdateFileNameById", query = "" +
35 "UPDATE PACKAGE_FILES p SET p.id.fileName = :fileName WHERE p.id = :id")
36 })
37 @Cacheable(value = false)
38 @Entity(name = "PACKAGE_FILES")
39 public class JpaNamedFileIdentifier implements Serializable {
40
41 private static final long serialVersionUID = -6605212849235170699L;
42
43 @EmbeddedId
44 private JpaNamedFileIdentifierId reference;
45
46 public JpaNamedFileIdentifier() {
47 }
48
49 public JpaNamedFileIdentifier(JpaFileDetails fileDetails, JpaPackageDetails packageDetails, String fileName) {
50 reference = new JpaNamedFileIdentifierId(fileDetails, packageDetails, fileName);
51 }
52
53 public JpaNamedFileIdentifierId getReference() {
54 return reference;
55 }
56
57
58
59
60
61
62
63 public SharedNamedFileIdentifier export(FileIdentifier identifier) {
64 return new SharedNamedFileIdentifier(identifier, reference.getFileName());
65 }
66
67
68
69
70
71
72 public SharedNamedFileIdentifier export() {
73 return new SharedNamedFileIdentifier(reference.getFileDetails().getIdentifier(), reference.getFileName());
74 }
75
76 @Override
77 public boolean equals(Object o) {
78 if (this == o) return true;
79 if (!(o instanceof JpaNamedFileIdentifier)) return false;
80 JpaNamedFileIdentifier that = (JpaNamedFileIdentifier) o;
81 return reference.equals(that.reference);
82 }
83
84 @Override
85 public int hashCode() {
86 return reference.hashCode();
87 }
88
89 @Override
90 public String toString() {
91 return "JpaNamedFileIdentifier{" +
92 "reference=" + reference +
93 '}';
94 }
95 }