1 package com.trendmicro.grid.acl.ds.jpa.entities;
2
3 import static net.sf.tinyjee.util.Assert.assertNotNull;
4
5 import javax.persistence.*;
6 import java.io.Serializable;
7
8 import org.hibernate.annotations.Index;
9
10
11
12
13
14
15
16 @Embeddable
17 public class JpaFileSourceId implements Serializable {
18
19 private static final long serialVersionUID = 237219229585915404L;
20
21 @ManyToOne(optional = false, fetch = FetchType.LAZY)
22 @JoinColumn(name = "FILE_CONTENT_ID")
23 private JpaFileDetails fileDetails;
24
25 @ManyToOne(optional = false, fetch = FetchType.LAZY)
26 @JoinColumn(name = "SOURCE_ID")
27 @Index(name = "IX_FILE_CONTENT_SOURCES__SOURCE_INDEX")
28 private JpaSource source;
29
30 public JpaFileSourceId() {
31 }
32
33 public JpaFileSourceId(JpaFileDetails fileDetails, JpaSource source) {
34 assertNotNull("fileDetails", fileDetails);
35 assertNotNull("source", source);
36 this.fileDetails = fileDetails;
37 this.source = source;
38 }
39
40 public JpaFileDetails getFileDetails() {
41 return fileDetails;
42 }
43
44 public JpaSource getSource() {
45 return source;
46 }
47
48 @Override
49 public boolean equals(Object o) {
50 if (this == o) return true;
51 if (!(o instanceof JpaFileSourceId)) return false;
52 JpaFileSourceId that = (JpaFileSourceId) o;
53 return fileDetails.getPrimaryKey() == that.fileDetails.getPrimaryKey() &&
54 source.getPrimaryKey() == that.source.getPrimaryKey();
55 }
56
57 @Override
58 public int hashCode() {
59 int result = fileDetails.getPrimaryKey();
60 result = 31 * result + source.getPrimaryKey();
61 return result;
62 }
63
64 @Override
65 public String toString() {
66 return "JpaFileSourceId{" +
67 "fileDetails=" + fileDetails +
68 ", source=" + source +
69 '}';
70 }
71 }