1   package com.trendmicro.grid.acl.ds.jpa.entities;
2   
3   import javax.persistence.Column;
4   import javax.persistence.Embeddable;
5   import javax.persistence.JoinColumn;
6   import javax.persistence.ManyToOne;
7   import java.io.Serializable;
8   
9   import static net.sf.tinyjee.util.Assert.assertNotNull;
10  
11  /**
12   * Defines the ID of a history entry.
13   */
14  @Embeddable
15  public class JpaPackageHistoryId implements Serializable {
16  
17  	private static final long serialVersionUID = -8535664911794270325L;
18  
19  	@ManyToOne(optional = false)
20  	@JoinColumn(name = "PACKAGE_ID", nullable = false, updatable = false)
21  	private JpaPackageDetails parent;
22  
23  	@Column(name = "REVISION", nullable = false, updatable = false)
24  	private int revision;
25  
26  	public JpaPackageHistoryId() {
27  	}
28  
29  	public JpaPackageHistoryId(JpaPackageDetails parent) {
30  		assertNotNull("JpaPackageDetails", parent);
31  		this.parent = parent;
32  		this.revision = parent.getRevision();
33  
34  		parent.setRevision(parent.getRevision() + 1);
35  	}
36  
37  	public JpaPackageDetails getParent() {
38  		return parent;
39  	}
40  
41  	public int getRevision() {
42  		return revision;
43  	}
44  
45  	@Override
46  	public boolean equals(Object o) {
47  		if (this == o) return true;
48  		if (!(o instanceof JpaPackageHistoryId)) return false;
49  		JpaPackageHistoryId id = (JpaPackageHistoryId) o;
50  		return revision == id.revision && parent.equals(id.parent);
51  	}
52  
53  	@Override
54  	public int hashCode() {
55  		int result = parent.hashCode();
56  		result = 31 * result + revision;
57  		return result;
58  	}
59  
60  	@Override
61  	public String toString() {
62  		return "JpaPackageHistoryId{" +
63  				"packageDetails=" + parent +
64  				", revision=" + revision +
65  				'}';
66  	}
67  }