1   package com.trendmicro.grid.acl.ds.jpa.entities;
2   
3   import org.hibernate.annotations.Index;
4   
5   import javax.persistence.Embeddable;
6   import javax.persistence.FetchType;
7   import javax.persistence.JoinColumn;
8   import javax.persistence.ManyToOne;
9   
10  import static net.sf.tinyjee.util.Assert.assertNotNull;
11  
12  /**
13   * Implements the primary key for the table "PACKAGE_FILES".
14   */
15  @Embeddable
16  public class JpaNamedFileIdentifierId extends AbstractJpaNamedFileIdentifierId {
17  
18  	private static final long serialVersionUID = -5149230697690521286L;
19  
20  	@ManyToOne(optional = false, fetch = FetchType.LAZY)
21  	@JoinColumn(name = "FILE_CONTENT_ID", nullable = false, updatable = false)
22  	@Index(name = "IX_PACKAGE_FILES__FILE_CONTENT_INDEX")
23  	private JpaFileDetails fileDetails;
24  
25  	public JpaNamedFileIdentifierId() {
26  		super();
27  	}
28  
29  	public JpaNamedFileIdentifierId(JpaFileDetails fileDetails, JpaPackageDetails packageDetails, String fileName) {
30  		super(packageDetails, fileName);
31  		assertNotNull("JpaFileDetails", fileDetails);
32  		this.fileDetails = fileDetails;
33  	}
34  
35  	public JpaFileDetails getFileDetails() {
36  		return fileDetails;
37  	}
38  
39  	@Override
40  	public boolean equals(Object o) {
41  		if (this == o) return true;
42  		if (!(o instanceof JpaNamedFileIdentifierId)) return false;
43  		if (!super.equals(o)) return false;
44  
45  		JpaNamedFileIdentifierId that = (JpaNamedFileIdentifierId) o;
46  		return fileDetails.equals(that.fileDetails);
47  	}
48  
49  	@Override
50  	public int hashCode() {
51  		int result = super.hashCode();
52  		result = 31 * result + fileDetails.hashCode();
53  		return result;
54  	}
55  
56  	@Override
57  	public String toString() {
58  		return "JpaNamedFileIdentifierId{" +
59  				"packageDetails=" + getPackageDetails() +
60  				", fileDetails=" + fileDetails +
61  				", fileName=" + getFileName() +
62  				'}';
63  	}
64  }