1 package com.trendmicro.grid.acl.ds.jpa.entities;
2
3 import javax.persistence.*;
4 import java.io.Serializable;
5
6 import static com.trendmicro.grid.acl.ds.jpa.QueryHints.*;
7 import static com.trendmicro.grid.acl.ds.jpa.QueryHints.CACHE_STORE_MODE;
8 import static com.trendmicro.grid.acl.ds.jpa.QueryHints.V_USE;
9
10
11
12
13
14
15
16
17
18
19
20
21 @NamedQueries({
22 @NamedQuery(name = "FileSources.SelectSourceIsAssigned", query = "" +
23 "SELECT 1 FROM FILE_CONTENT_SOURCES f " +
24 "WHERE f.id.fileDetails.id = :fileId AND f.id.source.id = :sourceId",
25 hints = {@QueryHint(name = CACHEABLE, value = V_YES),
26 @QueryHint(name = CACHE_RETRIEVE_MODE, value = V_USE), @QueryHint(name = CACHE_STORE_MODE, value = V_USE)}),
27
28 @NamedQuery(name = "FileSources.SelectSourceIsAssignedToAnyFile", query = "" +
29 "SELECT 1 FROM FILE_CONTENT_SOURCES f " +
30 "WHERE f.id.source.id = :sourceId"),
31
32 @NamedQuery(name = "FileSources.SelectAssignedFiles", query = "" +
33 "SELECT f.id.fileDetails.id FROM FILE_CONTENT_SOURCES f " +
34 "WHERE f.id.source.id = :sourceId"),
35
36 @NamedQuery(name = "FileSources.SelectAssignedFileIdentifiers", query = "" +
37 "SELECT f.id.fileDetails.identifier FROM FILE_CONTENT_SOURCES f " +
38 "WHERE f.id.source.sourceInformation.publicGUID = :publicGUID"),
39
40 @NamedQuery(name = "FileSources.SelectAssignedPackages", query = "" +
41 "SELECT p.packageInformation.name FROM FILE_CONTENT_SOURCES f, PACKAGES p " +
42 "WHERE p.packageFileDetails = f.id.fileDetails AND " +
43 " f.id.source.sourceInformation.publicGUID = :publicGUID"),
44
45 @NamedQuery(name = "FileSources.SelectAssignedSourceIds", query = "" +
46 "SELECT f.id.source.sourceInformation.publicGUID FROM FILE_CONTENT_SOURCES f " +
47 "WHERE f.id.fileDetails.primaryKey = :primaryKey"),
48
49
50 @NamedQuery(name = "FileSources.SelectAssignedSourceBySHA1", query = "" +
51 "SELECT f.id.source.sourceInformation.publicGUID FROM FILE_CONTENT_SOURCES f " +
52 "WHERE f.id.fileDetails.identifier.sha1 = :sha1 " +
53 "ORDER BY f.id.source.sourceInformation.lastModified DESC"),
54 @NamedQuery(name = "FileSources.SelectAssignedSourceByMD5", query = "" +
55 "SELECT f.id.source.sourceInformation.publicGUID FROM FILE_CONTENT_SOURCES f " +
56 "WHERE f.id.fileDetails.identifier.md5 = :md5 " +
57 "ORDER BY f.id.source.sourceInformation.lastModified DESC"),
58 @NamedQuery(name = "FileSources.SelectAssignedSourceBySHA1AndMD5", query = "" +
59 "SELECT f.id.source.sourceInformation.publicGUID FROM FILE_CONTENT_SOURCES f " +
60 "WHERE f.id.fileDetails.identifier.sha1 = :sha1 AND " +
61 " f.id.fileDetails.identifier.md5 = :md5 " +
62 "ORDER BY f.id.source.sourceInformation.lastModified DESC")
63 })
64 @Entity(name = "FILE_CONTENT_SOURCES")
65 public class JpaFileSource implements Serializable {
66
67 private static final long serialVersionUID = -154037219229595824L;
68
69 @EmbeddedId
70 private JpaFileSourceId id;
71
72 public JpaFileSource() {
73 }
74
75 public JpaFileSource(JpaFileDetails fileDetails, JpaSource source) {
76 id = new JpaFileSourceId(fileDetails, source);
77 }
78
79 public JpaFileSourceId getId() {
80 return id;
81 }
82
83 @Override
84 public boolean equals(Object o) {
85 if (this == o) return true;
86 if (!(o instanceof JpaFileSource)) return false;
87
88 JpaFileSource that = (JpaFileSource) o;
89 return id.equals(that.id);
90 }
91
92 @Override
93 public int hashCode() {
94 return id.hashCode();
95 }
96
97 @Override
98 public String toString() {
99 return "JpaFileSource{" +
100 "id=" + id +
101 '}';
102 }
103 }