| package org.eclipse.osbp.dsl.tests.hist.entities; |
| |
| import javax.persistence.Column; |
| import javax.persistence.EntityListeners; |
| import javax.persistence.GeneratedValue; |
| import javax.persistence.GenerationType; |
| import javax.persistence.Id; |
| import javax.persistence.MappedSuperclass; |
| import javax.persistence.PreRemove; |
| import javax.persistence.Transient; |
| import javax.persistence.Version; |
| import org.eclipse.osbp.dsl.common.datatypes.IEntity; |
| import org.eclipse.osbp.jpa.services.listener.EntityInfoListener; |
| import org.eclipse.osbp.runtime.common.annotations.Dispose; |
| |
| @MappedSuperclass |
| @EntityListeners(value = EntityInfoListener.class) |
| @SuppressWarnings("all") |
| public class HBaseID implements IEntity { |
| @Transient |
| @Dispose |
| private boolean disposed; |
| |
| @Id |
| @GeneratedValue(strategy = GenerationType.IDENTITY) |
| @Column(name = "ID") |
| private int id; |
| |
| @Version |
| @Column(name = "VERSION") |
| private long version; |
| |
| /** |
| * @return true, if the object is disposed. |
| * Disposed means, that it is prepared for garbage collection and may not be used anymore. |
| * Accessing objects that are already disposed will cause runtime exceptions. |
| * |
| */ |
| @Dispose |
| public boolean isDisposed() { |
| return this.disposed; |
| } |
| |
| /** |
| * Checks whether the object is disposed. |
| * @throws RuntimeException if the object is disposed. |
| */ |
| private void checkDisposed() { |
| if (isDisposed()) { |
| throw new RuntimeException("Object already disposed: " + this); |
| } |
| } |
| |
| /** |
| * Calling dispose will destroy that instance. The internal state will be |
| * set to 'disposed' and methods of that object must not be used anymore. |
| * Each call will result in runtime exceptions.<br> |
| * If this object keeps composition containments, these will be disposed too. |
| * So the whole composition containment tree will be disposed on calling this method. |
| */ |
| @Dispose |
| public void dispose() { |
| if (isDisposed()) { |
| return; |
| } |
| disposed = true; |
| } |
| |
| /** |
| * @return Returns the id property or <code>null</code> if not present. |
| */ |
| public int getId() { |
| checkDisposed(); |
| return this.id; |
| } |
| |
| /** |
| * Sets the id property to this instance. |
| */ |
| public void setId(final int id) { |
| checkDisposed(); |
| this.id = id; |
| } |
| |
| /** |
| * @return Returns the version property or <code>null</code> if not present. |
| */ |
| public long getVersion() { |
| checkDisposed(); |
| return this.version; |
| } |
| |
| /** |
| * Sets the version property to this instance. |
| */ |
| public void setVersion(final long version) { |
| checkDisposed(); |
| this.version = version; |
| } |
| |
| public boolean equalVersions(final Object obj) { |
| if (this == obj) |
| return true; |
| if (obj == null) |
| return false; |
| if (getClass() != obj.getClass()) |
| return false; |
| HBaseID other = (HBaseID) obj; |
| if (this.id != other.id || (other.id == 0 && this.id == 0)) |
| return false; |
| if (other.version != this.version) |
| return false; |
| return true; |
| } |
| |
| @Override |
| public boolean equals(final Object obj) { |
| return equalVersions(obj); |
| } |
| |
| @Override |
| public int hashCode() { |
| int prime = 31; |
| int result = 1; |
| result = prime * result + this.id; |
| return result; |
| } |
| |
| /** |
| * Iterates all cross references and removes them from the parent to avoid ConstraintViolationException |
| */ |
| @PreRemove |
| protected void preRemove() { |
| |
| } |
| } |