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